Subject: Re: bug#24585: 25.1; avoid hack in ggtags.el to run compilation-auto-jump timer

From: Leo Liu <[email-masked]>
Date: Fri, 07 Oct 2016 02:31:39 +0800

On 2016-10-06 14:10 -0400, Stefan Monnier wrote:
> I thought that's what I had proposed, so yes, I think that's
> a good solution.

By exposing the position I can change ggtags not to depend on the order
of auto-jump and clean up.

The patch could look like this. Any objection to installing it in
emacs-25?

diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el
index f2e397a4..a7804fd7 100644
--- a/lisp/progmodes/compile.el
+++ b/lisp/progmodes/compile.el
@@ -1052,13 +1052,16 @@ POS and RES.")
 	      l2
 	    (setcdr l1 (cons (list ,key) l2)))))))
 
+(defvar-local compilation-auto-jump-pos nil)
+
 (defun compilation-auto-jump (buffer pos)
-  (with-current-buffer buffer
-    (goto-char pos)
-    (let ((win (get-buffer-window buffer 0)))
-      (if win (set-window-point win pos)))
-    (if compilation-auto-jump-to-first-error
-	(compile-goto-error))))
+  (when (buffer-live-p buffer)
+    (with-current-buffer buffer
+      (goto-char pos)
+      (let ((win (get-buffer-window buffer 0)))
+        (if win (set-window-point win pos)))
+      (if compilation-auto-jump-to-first-error
+          (compile-goto-error)))))
 
 ;; This function is the central driver, called when font-locking to gather
 ;; all information needed to later jump to corresponding source code.
@@ -1126,8 +1129,9 @@ POS and RES.")
     (when (and compilation-auto-jump-to-next
                (>= type compilation-skip-threshold))
       (kill-local-variable 'compilation-auto-jump-to-next)
+      (setq compilation-auto-jump-pos (match-beginning 0))
       (run-with-timer 0 nil 'compilation-auto-jump
-                      (current-buffer) (match-beginning 0)))
+                      (current-buffer) compilation-auto-jump-pos))
 
     (compilation-internal-error-properties
      file line end-line col end-col type fmt)))