65 |
(setq found buffer))) |
(setq found buffer))) |
66 |
(setq list (cdr list))) |
(setq list (cdr list))) |
67 |
(switch-to-buffer found))) |
(switch-to-buffer found))) |
68 |
|
|
69 |
;;; next-error support framework |
;;; next-error support framework |
70 |
(defvar next-error-last-buffer nil |
(defvar next-error-last-buffer nil |
71 |
"The most recent next-error buffer. |
"The most recent next-error buffer. |
91 |
(or (and extra-test (funcall extra-test)) |
(or (and extra-test (funcall extra-test)) |
92 |
next-error-function))) |
next-error-function))) |
93 |
|
|
|
;; Return a next-error capable buffer according to the following rules: |
|
|
;; 1. If the current buffer is a next-error capable buffer, return it. |
|
|
;; 2. If one window on the selected frame displays such buffer, return it. |
|
|
;; 3. If next-error-last-buffer is set to a live buffer, use that. |
|
|
;; 4. Otherwise, look for a next-error capable buffer in a buffer list. |
|
|
;; 5. Signal an error if there are none. |
|
94 |
(defun next-error-find-buffer (&optional other-buffer extra-test) |
(defun next-error-find-buffer (&optional other-buffer extra-test) |
95 |
(if (and (not other-buffer) |
"Return a next-error capable buffer." |
96 |
(next-error-buffer-p (current-buffer) extra-test)) |
(or |
97 |
;; The current buffer is a next-error capable buffer. |
;; 1. If one window on the selected frame displays such buffer, return it. |
98 |
(current-buffer) |
(let ((window-buffers |
99 |
(or |
(delete-dups |
100 |
(let ((window-buffers |
(delq nil (mapcar (lambda (w) |
101 |
(delete-dups |
(if (next-error-buffer-p |
102 |
(delq nil |
(window-buffer w) extra-test) |
103 |
(mapcar (lambda (w) |
(window-buffer w))) |
104 |
(and (next-error-buffer-p (window-buffer w) extra-test) |
(window-list)))))) |
105 |
(window-buffer w))) |
(if other-buffer |
106 |
(window-list)))))) |
(setq window-buffers (delq (current-buffer) window-buffers))) |
107 |
(if other-buffer |
(if (eq (length window-buffers) 1) |
108 |
(setq window-buffers (delq (current-buffer) window-buffers))) |
(car window-buffers))) |
109 |
(if (eq (length window-buffers) 1) |
;; 2. If next-error-last-buffer is set to a live buffer, use that. |
110 |
(car window-buffers))) |
(if (and next-error-last-buffer |
111 |
(if (and next-error-last-buffer (buffer-name next-error-last-buffer) |
(buffer-name next-error-last-buffer) |
112 |
(next-error-buffer-p next-error-last-buffer extra-test) |
(next-error-buffer-p next-error-last-buffer extra-test) |
113 |
(or (not other-buffer) (not (eq next-error-last-buffer |
(or (not other-buffer) |
114 |
(current-buffer))))) |
(not (eq next-error-last-buffer (current-buffer))))) |
115 |
next-error-last-buffer |
next-error-last-buffer) |
116 |
(let ((buffers (buffer-list))) |
;; 3. If the current buffer is a next-error capable buffer, return it. |
117 |
(while (and buffers (or (not (next-error-buffer-p (car buffers) extra-test)) |
(if (and (not other-buffer) |
118 |
(and other-buffer |
(next-error-buffer-p (current-buffer) extra-test)) |
119 |
(eq (car buffers) (current-buffer))))) |
(current-buffer)) |
120 |
(setq buffers (cdr buffers))) |
;; 4. Look for a next-error capable buffer in a buffer list. |
121 |
(if buffers |
(let ((buffers (buffer-list))) |
122 |
(car buffers) |
(while (and buffers |
123 |
(or (and other-buffer |
(or (not (next-error-buffer-p (car buffers) extra-test)) |
124 |
(next-error-buffer-p (current-buffer) extra-test) |
(and other-buffer (eq (car buffers) (current-buffer))))) |
125 |
;; The current buffer is a next-error capable buffer. |
(setq buffers (cdr buffers))) |
126 |
(progn |
(if buffers |
127 |
(if other-buffer |
(car buffers) |
128 |
(message "This is the only next-error capable buffer.")) |
(or (and other-buffer |
129 |
(current-buffer))) |
(next-error-buffer-p (current-buffer) extra-test) |
130 |
(error "No next-error capable buffer found")))))))) |
;; The current buffer is a next-error capable buffer. |
131 |
|
(progn |
132 |
|
(if other-buffer |
133 |
|
(message "This is the only next-error capable buffer")) |
134 |
|
(current-buffer))) |
135 |
|
(error "No next-error capable buffer found")))))) |
136 |
|
|
137 |
(defun next-error (arg &optional reset) |
(defun next-error (&optional arg reset) |
138 |
"Visit next next-error message and corresponding source code. |
"Visit next next-error message and corresponding source code. |
139 |
|
|
140 |
If all the error messages parsed so far have been processed already, |
If all the error messages parsed so far have been processed already, |
152 |
buffer with output from the \\[compile], \\[grep] commands, or, |
buffer with output from the \\[compile], \\[grep] commands, or, |
153 |
more generally, on any buffer in Compilation mode or with |
more generally, on any buffer in Compilation mode or with |
154 |
Compilation Minor mode enabled, or any buffer in which |
Compilation Minor mode enabled, or any buffer in which |
155 |
`next-error-function' is bound to an appropriate |
`next-error-function' is bound to an appropriate function. |
156 |
function. To specify use of a particular buffer for error |
To specify use of a particular buffer for error messages, type |
157 |
messages, type \\[next-error] in that buffer. |
\\[next-error] in that buffer when it is the only one displayed |
158 |
|
in the current frame. |
159 |
|
|
160 |
Once \\[next-error] has chosen the buffer for error messages, |
Once \\[next-error] has chosen the buffer for error messages, |
161 |
it stays with that buffer until you use it in some other buffer which |
it stays with that buffer until you use it in some other buffer which |
175 |
|
|
176 |
(define-key ctl-x-map "`" 'next-error) |
(define-key ctl-x-map "`" 'next-error) |
177 |
|
|
178 |
(defun previous-error (n) |
(defun previous-error (&optional n) |
179 |
"Visit previous next-error message and corresponding source code. |
"Visit previous next-error message and corresponding source code. |
180 |
|
|
181 |
Prefix arg N says how many error messages to move backwards (or |
Prefix arg N says how many error messages to move backwards (or |
183 |
|
|
184 |
This operates on the output from the \\[compile] and \\[grep] commands." |
This operates on the output from the \\[compile] and \\[grep] commands." |
185 |
(interactive "p") |
(interactive "p") |
186 |
(next-error (- n))) |
(next-error (- (or n 1)))) |
187 |
|
|
188 |
(defun first-error (n) |
(defun first-error (&optional n) |
189 |
"Restart at the first error. |
"Restart at the first error. |
190 |
Visit corresponding source code. |
Visit corresponding source code. |
191 |
With prefix arg N, visit the source code of the Nth error. |
With prefix arg N, visit the source code of the Nth error. |
193 |
(interactive "p") |
(interactive "p") |
194 |
(next-error n t)) |
(next-error n t)) |
195 |
|
|
196 |
(defun next-error-no-select (n) |
(defun next-error-no-select (&optional n) |
197 |
"Move point to the next error in the next-error buffer and highlight match. |
"Move point to the next error in the next-error buffer and highlight match. |
198 |
Prefix arg N says how many error messages to move forwards (or |
Prefix arg N says how many error messages to move forwards (or |
199 |
backwards, if negative). |
backwards, if negative). |
200 |
Finds and highlights the source line like \\[next-error], but does not |
Finds and highlights the source line like \\[next-error], but does not |
201 |
select the source buffer." |
select the source buffer." |
202 |
(interactive "p") |
(interactive "p") |
203 |
(next-error n) |
(let ((next-error-highlight next-error-highlight-no-select)) |
204 |
|
(next-error n)) |
205 |
(pop-to-buffer next-error-last-buffer)) |
(pop-to-buffer next-error-last-buffer)) |
206 |
|
|
207 |
(defun previous-error-no-select (n) |
(defun previous-error-no-select (&optional n) |
208 |
"Move point to the previous error in the next-error buffer and highlight match. |
"Move point to the previous error in the next-error buffer and highlight match. |
209 |
Prefix arg N says how many error messages to move backwards (or |
Prefix arg N says how many error messages to move backwards (or |
210 |
forwards, if negative). |
forwards, if negative). |
211 |
Finds and highlights the source line like \\[previous-error], but does not |
Finds and highlights the source line like \\[previous-error], but does not |
212 |
select the source buffer." |
select the source buffer." |
213 |
(interactive "p") |
(interactive "p") |
214 |
(next-error-no-select (- n))) |
(next-error-no-select (- (or n 1)))) |
215 |
|
|
216 |
|
(defgroup next-error nil |
217 |
|
"next-error support framework." |
218 |
|
:group 'compilation |
219 |
|
:version "21.4") |
220 |
|
|
221 |
|
(defface next-error |
222 |
|
'((t (:inherit region))) |
223 |
|
"Face used to highlight next error locus." |
224 |
|
:group 'next-error |
225 |
|
:version "21.4") |
226 |
|
|
227 |
|
(defcustom next-error-highlight 0.1 |
228 |
|
"*Highlighting of locations in selected source buffers. |
229 |
|
If number, highlight the locus in next-error face for given time in seconds. |
230 |
|
If t, use persistent overlays fontified in next-error face. |
231 |
|
If nil, don't highlight the locus in the source buffer. |
232 |
|
If `fringe-arrow', indicate the locus by the fringe arrow." |
233 |
|
:type '(choice (number :tag "Delay") |
234 |
|
(const :tag "Persistent overlay" t) |
235 |
|
(const :tag "No highlighting" nil) |
236 |
|
(const :tag "Fringe arrow" 'fringe-arrow)) |
237 |
|
:group 'next-error |
238 |
|
:version "21.4") |
239 |
|
|
240 |
|
(defcustom next-error-highlight-no-select 0.1 |
241 |
|
"*Highlighting of locations in non-selected source buffers. |
242 |
|
If number, highlight the locus in next-error face for given time in seconds. |
243 |
|
If t, use persistent overlays fontified in next-error face. |
244 |
|
If nil, don't highlight the locus in the source buffer. |
245 |
|
If `fringe-arrow', indicate the locus by the fringe arrow." |
246 |
|
:type '(choice (number :tag "Delay") |
247 |
|
(const :tag "Persistent overlay" t) |
248 |
|
(const :tag "No highlighting" nil) |
249 |
|
(const :tag "Fringe arrow" 'fringe-arrow)) |
250 |
|
:group 'next-error |
251 |
|
:version "21.4") |
252 |
|
|
253 |
;;; |
;;; |
254 |
|
|
255 |
(defun fundamental-mode () |
(defun fundamental-mode () |