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.
This commit is contained in:
parent
0691d25295
commit
9d7fd78421
1 changed files with 24 additions and 14 deletions
|
@ -199,7 +199,7 @@ rejected, and the function returns nil."
|
||||||
(and extra-test-inclusive
|
(and extra-test-inclusive
|
||||||
(funcall extra-test-inclusive))))))
|
(funcall extra-test-inclusive))))))
|
||||||
|
|
||||||
(defcustom next-error-find-buffer-function #'ignore
|
(defcustom next-error-find-buffer-function #'next-error-no-navigation-try-current
|
||||||
"Function called to find a `next-error' capable buffer.
|
"Function called to find a `next-error' capable buffer.
|
||||||
This functions takes the same three arguments as the function
|
This functions takes the same three arguments as the function
|
||||||
`next-error-find-buffer', and should return the buffer to be
|
`next-error-find-buffer', and should return the buffer to be
|
||||||
|
@ -211,6 +211,8 @@ all other buffers."
|
||||||
:type '(choice (const :tag "No default" ignore)
|
:type '(choice (const :tag "No default" ignore)
|
||||||
(const :tag "Single next-error capable buffer on selected frame"
|
(const :tag "Single next-error capable buffer on selected frame"
|
||||||
next-error-buffer-on-selected-frame)
|
next-error-buffer-on-selected-frame)
|
||||||
|
(const :tag "Current buffer if next-error capable and outside navigation"
|
||||||
|
next-error-no-navigation-try-current)
|
||||||
(function :tag "Other function"))
|
(function :tag "Other function"))
|
||||||
:group 'next-error
|
:group 'next-error
|
||||||
:version "27.1")
|
:version "27.1")
|
||||||
|
@ -240,6 +242,22 @@ from which next-error navigated, and a target buffer TO-BUFFER."
|
||||||
(if (eq (length window-buffers) 1)
|
(if (eq (length window-buffers) 1)
|
||||||
(car window-buffers))))
|
(car window-buffers))))
|
||||||
|
|
||||||
|
(defun next-error-no-navigation-try-current (&optional
|
||||||
|
avoid-current
|
||||||
|
extra-test-inclusive
|
||||||
|
extra-test-exclusive)
|
||||||
|
"Try the current buffer when outside navigation.
|
||||||
|
But return nil if we navigated to the current buffer by the means
|
||||||
|
of `next-error' command. Othewise, return it if it's next-error
|
||||||
|
capable."
|
||||||
|
;; Check that next-error-buffer has no buffer-local value
|
||||||
|
;; (i.e. we never navigated to the current buffer from another),
|
||||||
|
;; and the current buffer is a `next-error' capable buffer.
|
||||||
|
(if (and (not (local-variable-p 'next-error-buffer))
|
||||||
|
(next-error-buffer-p (current-buffer) avoid-current
|
||||||
|
extra-test-inclusive extra-test-exclusive))
|
||||||
|
(current-buffer)))
|
||||||
|
|
||||||
(defun next-error-find-buffer (&optional avoid-current
|
(defun next-error-find-buffer (&optional avoid-current
|
||||||
extra-test-inclusive
|
extra-test-inclusive
|
||||||
extra-test-exclusive)
|
extra-test-exclusive)
|
||||||
|
@ -260,24 +278,16 @@ that buffer is rejected."
|
||||||
(funcall next-error-find-buffer-function avoid-current
|
(funcall next-error-find-buffer-function avoid-current
|
||||||
extra-test-inclusive
|
extra-test-inclusive
|
||||||
extra-test-exclusive)
|
extra-test-exclusive)
|
||||||
;; 2. If next-error-buffer has no buffer-local value
|
;; 2. If next-error-last-buffer is an acceptable buffer, use that.
|
||||||
;; (i.e. never navigated to the current buffer from another),
|
|
||||||
;; and the current buffer is a `next-error' capable buffer,
|
|
||||||
;; use it unconditionally, so next-error will always use it.
|
|
||||||
(if (and (not (local-variable-p 'next-error-buffer))
|
|
||||||
(next-error-buffer-p (current-buffer) avoid-current
|
|
||||||
extra-test-inclusive extra-test-exclusive))
|
|
||||||
(current-buffer))
|
|
||||||
;; 3. If next-error-last-buffer is an acceptable buffer, use that.
|
|
||||||
(if (and next-error-last-buffer
|
(if (and next-error-last-buffer
|
||||||
(next-error-buffer-p next-error-last-buffer avoid-current
|
(next-error-buffer-p next-error-last-buffer avoid-current
|
||||||
extra-test-inclusive extra-test-exclusive))
|
extra-test-inclusive extra-test-exclusive))
|
||||||
next-error-last-buffer)
|
next-error-last-buffer)
|
||||||
;; 4. If the current buffer is acceptable, choose it.
|
;; 3. If the current buffer is acceptable, choose it.
|
||||||
(if (next-error-buffer-p (current-buffer) avoid-current
|
(if (next-error-buffer-p (current-buffer) avoid-current
|
||||||
extra-test-inclusive extra-test-exclusive)
|
extra-test-inclusive extra-test-exclusive)
|
||||||
(current-buffer))
|
(current-buffer))
|
||||||
;; 5. Look for any acceptable buffer.
|
;; 4. Look for any acceptable buffer.
|
||||||
(let ((buffers (buffer-list)))
|
(let ((buffers (buffer-list)))
|
||||||
(while (and buffers
|
(while (and buffers
|
||||||
(not (next-error-buffer-p
|
(not (next-error-buffer-p
|
||||||
|
@ -285,7 +295,7 @@ that buffer is rejected."
|
||||||
extra-test-inclusive extra-test-exclusive)))
|
extra-test-inclusive extra-test-exclusive)))
|
||||||
(setq buffers (cdr buffers)))
|
(setq buffers (cdr buffers)))
|
||||||
(car buffers))
|
(car buffers))
|
||||||
;; 6. Use the current buffer as a last resort if it qualifies,
|
;; 5. Use the current buffer as a last resort if it qualifies,
|
||||||
;; even despite AVOID-CURRENT.
|
;; even despite AVOID-CURRENT.
|
||||||
(and avoid-current
|
(and avoid-current
|
||||||
(next-error-buffer-p (current-buffer) nil
|
(next-error-buffer-p (current-buffer) nil
|
||||||
|
@ -293,7 +303,7 @@ that buffer is rejected."
|
||||||
(progn
|
(progn
|
||||||
(message "This is the only buffer with error message locations")
|
(message "This is the only buffer with error message locations")
|
||||||
(current-buffer)))
|
(current-buffer)))
|
||||||
;; 7. Give up.
|
;; 6. Give up.
|
||||||
(error "No buffers contain error message locations")))
|
(error "No buffers contain error message locations")))
|
||||||
|
|
||||||
(defun next-error (&optional arg reset)
|
(defun next-error (&optional arg reset)
|
||||||
|
|
Loading…
Add table
Reference in a new issue