I usually use occur to make an index of the beginning of different things. When I jump to the occurrence, Occur shows the line in the middle of the buffer. How can I instruct occur to show the occurrence in the top of the buffer?


1 Answer 1


You can scroll the window in occur-mode-find-occurrence-hook such that point is at the top of the window:

(defun my-occur-recenter ()
  "Scroll point to the top of the window."
  (recenter 0))

(add-hook 'occur-mode-find-occurrence-hook #'my-occur-recenter)


  1. The functions registered in occur-mode-find-occurrence-hook are called with point at the position of the selected occurence.
  2. recenter called with a non-negative argument adjusts the vscroll of the window such that point is located that many lines from the top line.
  • hi, if the registered functions are called with point, how does it work without error if the function is parameterless like it is here? Commented Mar 20, 2023 at 6:55
  • 1
    @MustafaAydın They are not called with an argument but with point at the occurence.
    – Tobias
    Commented Mar 20, 2023 at 7:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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