Over at the Emacs subreddit, seidenkaufman asks how he can narrow to a subheading when he types Tab in the Org Agenda. If you don’t do that sort of thing it may not seem all that useful but, believe me, when you want to edit a headline in the agenda, narrowing would be a big win. That’s because by default you always end up at the timestamp in the entry.
Seidenkaufman’s idea was to simply add a hook for org-agenda-goto
to call narrow. But that didn’t work and he was wondering why. As usual, the Emacs community came to the rescue with their own solutions to the problem. They ranged from a fairly elaborate bunch of Elisp to a simple macro.
In the end, though, the answer was really simple. There is no org-agenda-goto
hook. Instead, you have to use the org-agenda-after-show-hook
. Then you can simply use it to call org-narrow-to-subtree
to get the desired result.
I really like this post because it shows a couple of things. First, there’s a lot a knowledge embedded in the Emacs user community and those users are generous about sharing it. Second, even those that had working solutions found that there was a simpler solution available. In other words, everybody benefits from the discussion of Seidenkaufman’s question