aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Gutov2020-05-27 22:15:41 +0300
committerDmitry Gutov2020-05-27 22:15:41 +0300
commit9d7fd78421a339f00892b3241845b1024e2eff7d (patch)
tree3e320487f079deaa299da7eda66cfd08d4f8c712
parent0691d25295c3d7ddca1c5958a0c27781e70821a5 (diff)
downloademacs-9d7fd78421a339f00892b3241845b1024e2eff7d.tar.gz
emacs-9d7fd78421a339f00892b3241845b1024e2eff7d.zip
Make next-error behavior a bit more flexible
* lisp/simple.el (next-error-no-navigation-try-current): Extract from the case #2 in next-error-find-buffer (bug#40919). (next-error-find-buffer-function): Use it as the default.
-rw-r--r--lisp/simple.el38
1 files changed, 24 insertions, 14 deletions
diff --git a/lisp/simple.el b/lisp/simple.el
index e8bf77c7e6a..6d7600e414c 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -199,7 +199,7 @@ rejected, and the function returns nil."
199 (and extra-test-inclusive 199 (and extra-test-inclusive
200 (funcall extra-test-inclusive)))))) 200 (funcall extra-test-inclusive))))))
201 201
202(defcustom next-error-find-buffer-function #'ignore 202(defcustom next-error-find-buffer-function #'next-error-no-navigation-try-current
203 "Function called to find a `next-error' capable buffer. 203 "Function called to find a `next-error' capable buffer.
204This functions takes the same three arguments as the function 204This functions takes the same three arguments as the function
205`next-error-find-buffer', and should return the buffer to be 205`next-error-find-buffer', and should return the buffer to be
@@ -211,6 +211,8 @@ all other buffers."
211 :type '(choice (const :tag "No default" ignore) 211 :type '(choice (const :tag "No default" ignore)
212 (const :tag "Single next-error capable buffer on selected frame" 212 (const :tag "Single next-error capable buffer on selected frame"
213 next-error-buffer-on-selected-frame) 213 next-error-buffer-on-selected-frame)
214 (const :tag "Current buffer if next-error capable and outside navigation"
215 next-error-no-navigation-try-current)
214 (function :tag "Other function")) 216 (function :tag "Other function"))
215 :group 'next-error 217 :group 'next-error
216 :version "27.1") 218 :version "27.1")
@@ -240,6 +242,22 @@ from which next-error navigated, and a target buffer TO-BUFFER."
240 (if (eq (length window-buffers) 1) 242 (if (eq (length window-buffers) 1)
241 (car window-buffers)))) 243 (car window-buffers))))
242 244
245(defun next-error-no-navigation-try-current (&optional
246 avoid-current
247 extra-test-inclusive
248 extra-test-exclusive)
249 "Try the current buffer when outside navigation.
250But return nil if we navigated to the current buffer by the means
251of `next-error' command. Othewise, return it if it's next-error
252capable."
253 ;; Check that next-error-buffer has no buffer-local value
254 ;; (i.e. we never navigated to the current buffer from another),
255 ;; and the current buffer is a `next-error' capable buffer.
256 (if (and (not (local-variable-p 'next-error-buffer))
257 (next-error-buffer-p (current-buffer) avoid-current
258 extra-test-inclusive extra-test-exclusive))
259 (current-buffer)))
260
243(defun next-error-find-buffer (&optional avoid-current 261(defun next-error-find-buffer (&optional avoid-current
244 extra-test-inclusive 262 extra-test-inclusive
245 extra-test-exclusive) 263 extra-test-exclusive)
@@ -260,24 +278,16 @@ that buffer is rejected."
260 (funcall next-error-find-buffer-function avoid-current 278 (funcall next-error-find-buffer-function avoid-current
261 extra-test-inclusive 279 extra-test-inclusive
262 extra-test-exclusive) 280 extra-test-exclusive)
263 ;; 2. If next-error-buffer has no buffer-local value 281 ;; 2. If next-error-last-buffer is an acceptable buffer, use that.
264 ;; (i.e. never navigated to the current buffer from another),
265 ;; and the current buffer is a `next-error' capable buffer,
266 ;; use it unconditionally, so next-error will always use it.
267 (if (and (not (local-variable-p 'next-error-buffer))
268 (next-error-buffer-p (current-buffer) avoid-current
269 extra-test-inclusive extra-test-exclusive))
270 (current-buffer))
271 ;; 3. If next-error-last-buffer is an acceptable buffer, use that.
272 (if (and next-error-last-buffer 282 (if (and next-error-last-buffer
273 (next-error-buffer-p next-error-last-buffer avoid-current 283 (next-error-buffer-p next-error-last-buffer avoid-current
274 extra-test-inclusive extra-test-exclusive)) 284 extra-test-inclusive extra-test-exclusive))
275 next-error-last-buffer) 285 next-error-last-buffer)
276 ;; 4. If the current buffer is acceptable, choose it. 286 ;; 3. If the current buffer is acceptable, choose it.
277 (if (next-error-buffer-p (current-buffer) avoid-current 287 (if (next-error-buffer-p (current-buffer) avoid-current
278 extra-test-inclusive extra-test-exclusive) 288 extra-test-inclusive extra-test-exclusive)
279 (current-buffer)) 289 (current-buffer))
280 ;; 5. Look for any acceptable buffer. 290 ;; 4. Look for any acceptable buffer.
281 (let ((buffers (buffer-list))) 291 (let ((buffers (buffer-list)))
282 (while (and buffers 292 (while (and buffers
283 (not (next-error-buffer-p 293 (not (next-error-buffer-p
@@ -285,7 +295,7 @@ that buffer is rejected."
285 extra-test-inclusive extra-test-exclusive))) 295 extra-test-inclusive extra-test-exclusive)))
286 (setq buffers (cdr buffers))) 296 (setq buffers (cdr buffers)))
287 (car buffers)) 297 (car buffers))
288 ;; 6. Use the current buffer as a last resort if it qualifies, 298 ;; 5. Use the current buffer as a last resort if it qualifies,
289 ;; even despite AVOID-CURRENT. 299 ;; even despite AVOID-CURRENT.
290 (and avoid-current 300 (and avoid-current
291 (next-error-buffer-p (current-buffer) nil 301 (next-error-buffer-p (current-buffer) nil
@@ -293,7 +303,7 @@ that buffer is rejected."
293 (progn 303 (progn
294 (message "This is the only buffer with error message locations") 304 (message "This is the only buffer with error message locations")
295 (current-buffer))) 305 (current-buffer)))
296 ;; 7. Give up. 306 ;; 6. Give up.
297 (error "No buffers contain error message locations"))) 307 (error "No buffers contain error message locations")))
298 308
299(defun next-error (&optional arg reset) 309(defun next-error (&optional arg reset)