Subject: bug#20489: 25.0.50; next-error-find-buffer chooses non-current buffer without good reason

From: Dmitry Gutov <[email-masked]>
Date: Tue, 27 Feb 2018 20:07:54 +0200

On 2/27/18 3:54 AM, Dmitry Gutov wrote:

> On that subject: why did we make next-error-last-buffer always 
> buffer-local?

So... Any objections to this patch? It does fix the problem I described.

diff --git a/lisp/simple.el b/lisp/simple.el
index 2101cfe833..b3ec30edba 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -121,7 +121,6 @@ next-error-last-buffer
 A buffer becomes most recent when its compilation, grep, or
 similar mode is started, or when it is used with \\[next-error]
 or \\[compile-goto-error].")
-(make-variable-buffer-local 'next-error-last-buffer)
 
 (defvar next-error-function nil
   "Function to use to find the next error in the current buffer.
@@ -280,12 +279,10 @@ next-error
     (when buffer
       ;; We know here that next-error-function is a valid symbol we can funcall
       (with-current-buffer buffer
-        ;; Allow next-error to be used from the next-error capable buffer.
-        (setq next-error-last-buffer buffer)
         (funcall next-error-function (prefix-numeric-value arg) reset)
-        ;; Override possible change of next-error-last-buffer in next-error-function
+        ;; Allow next-error to be used from the next-error capable buffer.
+        ;; (If next-error-function changed this var, it will have no effect).
         (setq next-error-last-buffer buffer)
-        (setq-default next-error-last-buffer buffer)
         (when next-error-recenter
           (recenter next-error-recenter))
         (message "%s error from %s"
@@ -301,12 +298,10 @@ next-error-internal
   (let ((buffer (current-buffer)))
     ;; We know here that next-error-function is a valid symbol we can funcall
     (with-current-buffer buffer
-      ;; Allow next-error to be used from the next-error capable buffer.
-      (setq next-error-last-buffer buffer)
       (funcall next-error-function 0 nil)
-      ;; Override possible change of next-error-last-buffer in next-error-function
+      ;; Allow next-error to be used from the next-error capable buffer.
+      ;; (If next-error-function changed this var, it will have no effect).
       (setq next-error-last-buffer buffer)
-      (setq-default next-error-last-buffer buffer)
       (when next-error-recenter
         (recenter next-error-recenter))
       (message "Current error from %s" next-error-last-buffer)
@@ -318,8 +313,7 @@ next-error-select-buffer
    (list (get-buffer
           (read-buffer "Select next-error buffer: " nil nil
                        (lambda (b) (next-error-buffer-p (cdr b)))))))
-  (setq next-error-last-buffer buffer)
-  (setq-default next-error-last-buffer buffer))
+  (setq next-error-last-buffer buffer))
 
 (defalias 'goto-next-locus 'next-error)
 (defalias 'next-match 'next-error)