5

On next-error in the grep or compilation window, I can use something like

(setq next-error-recenter 35)

to ensure that window displaying the match scrolls to show the whole match, as described in more detail in this stackoverflow question.

How do I do the same thing in the grep or compilation window itself? I often have grep output or compile output that is off the bottom of the window, and on days when I spend all of my time going through grep output or compile errors, switching back and forth between windows adds a significant overhead.

  • You want to look at compilation-goto-locus and put in a recenter command where appropriate -- at the section that begins with the comment: If the compilation buffer window was selected . . . , You can recenter at different location of the window -- see the doc-string for recenter. – lawlist Feb 26 '16 at 7:40
1

I use such workaround for the exact saving of point position in the compilation/grep buffer:

(defun eab/compile-goto-error ()
  (interactive)
  (let ((istc? truncate-lines))
    (toggle-truncate-lines t)
    (let ((buf (current-buffer))
          (line (- (count-lines (window-start) (point))
                   (if (eq (point) (point-at-bol)) 0 1)))
          (point (point)))
      (compile-goto-error)
      (run-with-timer 0.01 nil `(lambda ()
                                 (let ((cb (current-buffer)))
                                       (pop-to-buffer ,buf)
                                       (recenter ,line)
                                       (goto-char ,point)
                                       (toggle-truncate-lines ,istc?)
                                       (pop-to-buffer cb)))))))

If you want simple centering of the point in the compilation/grep buffer, use:

(defun eab/next-error ()
  (interactive)
  (let ((buf (current-buffer)))
    (next-error)
    (run-with-timer 0.01 nil `(lambda ()
                             (let ((cb (current-buffer)))
                               (pop-to-buffer ,buf)
                               (recenter)
                               (pop-to-buffer cb))))))

You can use next-error instead of compile-goto-error in the first example.

Upd. Emacs 25.1 is needed for non-zero time period.

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.