aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim F. Storm2004-04-21 21:36:15 +0000
committerKim F. Storm2004-04-21 21:36:15 +0000
commit50f007fb09bc893294d0229e339e770e16a22f2b (patch)
treee4b291a01f3069af48ade79359e9ae76ce711f72
parenta568a2cc4fb321d9370a94136a9a36960e58b20e (diff)
downloademacs-50f007fb09bc893294d0229e339e770e16a22f2b.tar.gz
emacs-50f007fb09bc893294d0229e339e770e16a22f2b.zip
From: Teodor Zlatanov <tzz@lifelogs.com>
(next-error-last-buffer, next-error-function): New variables for the next-error framework. (next-error-buffer-p): New function. (next-error-find-buffer): Generalize compilation-find-buffer. (next-error, previous-error, first-error, next-error-no-select) (previous-error-no-select): Move from compile.el.
-rw-r--r--lisp/simple.el131
1 files changed, 131 insertions, 0 deletions
diff --git a/lisp/simple.el b/lisp/simple.el
index 6287090312c..494a9884100 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -66,6 +66,137 @@
66 (setq list (cdr list))) 66 (setq list (cdr list)))
67 (switch-to-buffer found))) 67 (switch-to-buffer found)))
68 68
69;;; next-error support framework
70(defvar next-error-last-buffer nil
71 "The most recent next-error buffer.
72A buffer becomes most recent when its compilation, grep, or
73similar mode is started, or when it is used with \\[next-error]
74or \\[compile-goto-error].")
75
76(defvar next-error-function nil
77 "The next-error vehicle for other modes.
78This variable can be bound to a function by a mode. It is
79buffer-local by default. Together with
80`next-error-last-buffer', this variable lets modes hook into
81\\[next-error].")
82
83(make-variable-buffer-local 'next-error-function)
84
85(defsubst next-error-buffer-p (buffer &optional extra-test)
86 "Test if BUFFER is a next-error capable buffer."
87 (with-current-buffer buffer
88 (or (and extra-test (funcall extra-test))
89 next-error-function)))
90
91;; Return a next-error capable buffer.
92;; If the current buffer is such, return it.
93;; If next-error-last-buffer is set to a live buffer, use that.
94;; Otherwise, look for a next-error capable buffer and signal an error
95;; if there are none.
96(defun next-error-find-buffer (&optional other-buffer extra-test)
97 (if (and (not other-buffer)
98 (next-error-buffer-p (current-buffer) extra-test))
99 ;; The current buffer is a next-error capable buffer.
100 (current-buffer)
101 (if (and next-error-last-buffer (buffer-name next-error-last-buffer)
102 (next-error-buffer-p next-error-last-buffer extra-test)
103 (or (not other-buffer) (not (eq next-error-last-buffer
104 (current-buffer)))))
105 next-error-last-buffer
106 (let ((buffers (buffer-list)))
107 (while (and buffers (or (not (next-error-buffer-p (car buffers) extra-test))
108 (and other-buffer
109 (eq (car buffers) (current-buffer)))))
110 (setq buffers (cdr buffers)))
111 (if buffers
112 (car buffers)
113 (or (and other-buffer
114 (next-error-buffer-p (current-buffer) extra-test)
115 ;; The current buffer is a next-error capable buffer.
116 (progn
117 (if other-buffer
118 (message "This is the only next-error capable buffer."))
119 (current-buffer)))
120 (error "No next-error capable buffer found!")))))))
121
122(defun next-error (argp &optional reset)
123 "Visit next next-error message and corresponding source code.
124
125If all the error messages parsed so far have been processed already,
126the message buffer is checked for new ones.
127
128A prefix ARGP specifies how many error messages to move;
129negative means move back to previous error messages.
130Just \\[universal-argument] as a prefix means reparse the error message buffer
131and start at the first error.
132
133The RESET argument specifies that we should restart from the beginning
134
135\\[next-error] normally uses the most recently started
136compilation, grep, or occur buffer. It can also operate on any
137buffer with output from the \\[compile], \\[grep] commands, or,
138more generally, on any buffer in Compilation mode or with
139Compilation Minor mode enabled, or any buffer in which
140`next-error-function' is bound to an appropriate
141function. To specify use of a particular buffer for error
142messages, type \\[next-error] in that buffer.
143
144Once \\[next-error] has chosen the buffer for error messages,
145it stays with that buffer until you use it in some other buffer which
146uses Compilation mode or Compilation Minor mode.
147
148See variables `compilation-parse-errors-function' and
149\`compilation-error-regexp-alist' for customization ideas."
150 (interactive "P")
151 (when (setq next-error-last-buffer (next-error-find-buffer))
152 ;; we know here that next-error-function is a valid symbol we can funcall
153 (with-current-buffer next-error-last-buffer
154 (funcall next-error-function argp reset))))
155
156(defalias 'goto-next-locus 'next-error)
157(defalias 'next-match 'next-error)
158
159(define-key ctl-x-map "`" 'next-error)
160
161(defun previous-error (n)
162 "Visit previous next-error message and corresponding source code.
163
164Prefix arg N says how many error messages to move backwards (or
165forwards, if negative).
166
167This operates on the output from the \\[compile] and \\[grep] commands."
168 (interactive "p")
169 (next-error (- n)))
170
171(defun first-error (n)
172 "Restart at the first error.
173Visit corresponding source code.
174With prefix arg N, visit the source code of the Nth error.
175This operates on the output from the \\[compile] command, for instance."
176 (interactive "p")
177 (next-error n t))
178
179(defun next-error-no-select (n)
180 "Move point to the next error in the next-error buffer and highlight match.
181Prefix arg N says how many error messages to move forwards (or
182backwards, if negative).
183Finds and highlights the source line like \\[next-error], but does not
184select the source buffer."
185 (interactive "p")
186 (next-error n)
187 (pop-to-buffer next-error-last-buffer))
188
189(defun previous-error-no-select (n)
190 "Move point to the previous error in the next-error buffer and highlight match.
191Prefix arg N says how many error messages to move backwards (or
192forwards, if negative).
193Finds and highlights the source line like \\[previous-error], but does not
194select the source buffer."
195 (interactive "p")
196 (next-error-no-select (- n)))
197
198;;;
199
69(defun fundamental-mode () 200(defun fundamental-mode ()
70 "Major mode not specialized for anything in particular. 201 "Major mode not specialized for anything in particular.
71Other major modes are defined by comparison with this one." 202Other major modes are defined by comparison with this one."