annotate lisp/energize/energize-advice.el @ 50:ee648375d8d6 r19-16b91

Import from CVS: tag r19-16b91
author cvs
date Mon, 13 Aug 2007 08:56:41 +0200
parents 376386a54a3c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; -*- Mode:Emacs-Lisp -*-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;;; Copyright (c) 1991, 1992, 1993, 1994 by Lucid, Inc. All Rights Reserved.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;;; This file contains the definitions of existing functions which Energize
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;;; must encapsulate. (The number of such functions should be minimized.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;;; This is greatly complicated by the fact that both the old functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;;; and the new functions are dumped. The only method I've found that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;;; works and doesn't have obscure bootstrapping/feedback problems is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;;; to RELOAD the original definition of the function we are advising
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;;; at compile time so that we can extract its original docstring, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;;; emit a modified version of that to the .elc version of this file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 (eval-when-compile ; this only works at compile-time anyway...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 (or noninteractive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 (error "bad idea to compile this file in a non-batch-mode emacs!"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 (load-library "advice")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 (fset 'ad-make-freeze-docstring 'ad-make-plain-docstring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 (load-library "files.el")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 (load-library "userlock.el")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 (load-library "compile.el")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 (load-library "gdb.el")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ) ;closes eval-when-compile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;;; The actual definitions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 (defadvice ask-user-about-lock (around energize freeze)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 "Energize buffers do this by asking the server."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 (if (energize-buffer-p (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 (setq ad-return-value t) ; note: return value matters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ad-do-it))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 (defadvice normal-mode (after energize freeze)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 "If this is an Energize buffer, the Energize modes are turned on as well."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (if (and (energize-buffer-p (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 (not inside-energize-buffer-creation-hook-function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (funcall energize-create-buffer-hook (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (defadvice find-file-noselect (around energize freeze)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 "This function has been encapsulated to work with Energize."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (if (and (connected-to-energize-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (not (file-directory-p (ad-get-arg 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (energize-query-buffer (ad-get-arg 0) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;; after-find-file and abbreviate-file-name are called from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;; energize-buffer-creation-hook-function, which is run from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;; editorside.c (way down under energize-query-buffer).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;; This is a mess...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (setq ad-return-value ; note: return value matters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (energize-query-buffer (ad-get-arg 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;; else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ad-do-it))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (defadvice write-file (around energize freeze)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 "When executed on an Energize buffer, this will cause all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 annotations to be lost (that is, the buffer will become a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 normal buffer, not one that the Energize server knows about.)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (if (not (energize-write-file-buffer-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 ad-do-it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ;; else...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (let ((filename (ad-get-arg 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (if (and (file-exists-p filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (yes-or-no-p (format "File %s already exists. Overwrite it? "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 filename))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (error "Aborted"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (write-region (point-min) (point-max) filename nil nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (if buffer-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (revert-buffer t t)) ; revert this buffer from the Energize server
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (kill-buffer nil) ; kill the current buffer, to lose Energize properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (set-window-buffer ; and now visit the "new" file, and all that entails
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (selected-window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (find-file-noselect filename)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (defadvice set-visited-file-name (around energize freeze)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 "The file name associated with an Energize buffer cannot be changed in this\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 way.\nUse the `write-file' command instead."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (if (and (energize-write-file-buffer-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (not (equal (ad-get-arg 0) buffer-file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (error "Can't change the name associated with an Energize buffer.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 ad-do-it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (if (energize-buffer-p (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (energize-mode-internal)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (defadvice next-error (around energize freeze)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 "This function has been encapsulated to work with the Energize Error Log."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (if (or (not (connected-to-energize-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (non-energize-errors-exist-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 ad-do-it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (energize-execute-command (if (ad-get-arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 "previouserror"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 "nexterror"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (defadvice gdb-break (around energize freeze)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 "This function has been encapsulated to work with the Energize debugger."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (if (not (energize-buffer-p (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 ad-do-it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (energize-execute-command "setbreakpoint")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (defadvice gdb-step (around energize freeze)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 "This function has been encapsulated to work with the Energize debugger."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (if (not (energize-buffer-p (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 ad-do-it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (let ((arg (ad-get-arg 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (while (> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (energize-execute-command "steponce")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (setq arg (1- arg))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (defadvice gdb-stepi (around energize freeze)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 "This function has been encapsulated to work with the Energize debugger."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (if (not (energize-buffer-p (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 ad-do-it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (let ((arg (ad-get-arg 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 ;; there's no energize command for this, so do it this way...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (set-buffer "*Debugger*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (insert (format "stepi %d" arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (comint-send-input)))))