comparison lisp/energize/energize-advice.el @ 0:376386a54a3c r19-14

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