2

when I do next-error, the *ggtags-global* buffer scrolls down one line.

I hope that the *ggtags-global* buffer doesn't scroll, whether it's executing next-error, previous-error, or compile-goto-error.

By default it scrolls which is annoying: enter image description here

8
  • It'll eventually have to scroll (e.g. when the next error is off the screen). You might want to specify what you want to do in that case.
    – NickD
    Jan 11 at 15:46
  • @NickD when the next error is off the screen, it can scroll down one line, when the previous error is off the screen, it can scroll up one line.
    – dongli si
    Jan 12 at 3:56
  • @NickD Other than that, don't scroll under any circumstances, When the current error is at the border of the screen, I can use the mouse wheel to scroll down or up multiple lines at once.
    – dongli si
    Jan 12 at 3:59
  • In similar circumstances, grep uses a *grep* buffer which scrolls by half the height of the window, thereby putting the current error in the middle of the window. I don't know why ggtags doesn't do that, but it seems to me that that's a better way to deal with the next "error" being outside the window : if you scroll by one line, then on the next next-error you'd have to scroll again. BTW, if you switch to the *ggtags* buffer and say C-h v next-error-function, what is the result? Also, what is the result of C-h v next-error-hook? Please update the question with this information.
    – NickD
    Jan 12 at 7:53
  • @NickD In the *ggtags-global* buffer: next-error-function value is compilation-next-error-function, next-error-hook value is ggtags-global-next-error-function
    – dongli si
    Jan 12 at 8:39

1 Answer 1

2
+50

This scrolling happens in compilation-set-window.

Its definition in my Emacs is

(defsubst compilation-set-window (w mk)
  "Maybe align the compilation output window W with marker MK near top."
  (cond ((integerp compilation-context-lines)
         (set-window-start w (save-excursion
                               (goto-char mk)
                               (compilation-beginning-of-line
                                (- 1 compilation-context-lines))
                               (point))))
        ((and (null compilation-context-lines)
              ;; If there is no left fringe.
              (equal (car (window-fringes w)) 0))
         (set-window-start w (save-excursion
                               (goto-char mk)
                               (beginning-of-line 1)
                               (point)))))
  (set-window-point w mk))

Changing it to

(defsubst compilation-set-window (w mk)
  "Maybe align the compilation output window W with marker MK near top."
  (unless (pos-visible-in-window-p mk w)
    (cond ((integerp compilation-context-lines)
           (set-window-start w (save-excursion
                                 (goto-char mk)
                                 (compilation-beginning-of-line
                                  (- 1 compilation-context-lines))
                                 (point))))
          ((and (null compilation-context-lines)
                ;; If there is no left fringe.
                (equal (car (window-fringes w)) 0))
           (set-window-start w (save-excursion
                                 (goto-char mk)
                                 (beginning-of-line 1)
                                 (point))))))
  (set-window-point w mk))

accomplishes the desired behavior of not scrolling unless the position is not visible. You may need to tweak it a bit, especially if using compilation-context-lines or if some custom scrolling is desired (as opposed to aligning near top).

3
  • I may be wrong, but I believe that this scrolls the output buffer (i.e. where the "error" occurs), not the compilation buffer. In support of this, I get a "scroll by half-window" effect, not a "scroll-by-one-line" effect, even though I don't have this change in my emacs (and I've tried both a recent upstream and 27.2).
    – NickD
    Jan 12 at 17:06
  • That's not true, the output buffer is the buffer with the list of errors (or references in the case of ggtags — the *ggtags-global* buffer). Note that you need to eval the new definition of compilation-set-window and then re-eval compilation-goto-locus for it to work.
    – d125q
    Jan 12 at 17:31
  • @d125q This solved my problem, and I found that my scrolling behavior was caused by the fact that I had (fringe-mode 0) set. thank.
    – dongli si
    Jan 13 at 7:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.