When right- or middle-clicking on a headline generated in the agenda, org will open a buffer with the file containing that headline. That headline will be centered in the buffer.

How can I make it so that clicking on an agenda link aligns the headline to the top of the buffer rather than the center?

I found that I could do this manually by customizing recenter-positions and then hitting C l (recenter-top-bottom), but I really would like this to happen automatically.

  • 1
    You should consider modifying org-agenda-goto, since it does not use a variable or argument to control recentering -- instead, it uses (recenter (/ (window-height) 2)) If we describe the middle-mouse-click with describe-key, we see that it triggers org-agenda-goto-mouse If we look at that function, we see that it uses org-agenda-goto, and if we look at that function, we see a modification of said function would be required based on the foregoing line of code dealing with recentering.
    – lawlist
    Oct 4, 2016 at 1:36
  • 1
    To redefine an existing function, use (require 'org-agenda) (defun org-agenda-goto (&optional highlight) "Go to the Org-mode file which contains the item at point." ...) Change the portion relating to recentering. Or, if you are an anti-modification believer in the holy scripture org-mode source code, you can use the org-agenda-after-show-hook to recenter again using whatever you like -- note that this is technically inefficient considering that recentering could have been customized by modifying org-agenda-goto.
    – lawlist
    Oct 4, 2016 at 1:48
  • Redefining org-agenda-goto worked like a charm. Want to post that as an answer?
    – wiuah
    Oct 4, 2016 at 4:20

1 Answer 1


Using the function describe-key, we can trace org-agenda-goto-mouse to org-agenda-goto, and from there we can examine the function in the org-agenda.el library to see what makes it tick. The re-centering command is hard-coded as (recenter (/ (window-height) 2)), which means it cannot be easily controlled by the user with an optional argument or by customizing a variable. In general, functions an be redefined by require-ing the library followed by the newly defined function with the same name: (require 'org-agenda) (defun org-agenda-goto (&optional highlight) "Go to the Org-mode file which contains the item at point." ...) Change the portion relating to recentering. The doc-string for recenter describes the available methods of controling the behavior of said function.

During the process of inspecting org-agenda-goto, we learned that org-agenda-after-show-hook is called at the tail-end. A less efficient alternative approach to modifying org-agenda-goto would be to add new behavior to the aforementioned hook -- however, that would essentially call again recenter to fix the undesired previous call.

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.