Here's two implementations. The first one is along the lines that @Aquaactress suggested in a comment:
(defun my/org-agenda-list-current-buffer ()
(interactive)
(let ((org-agenda-files (list (buffer-file-name (current-buffer)))))
(call-interactively #'org-agenda)))
Basically, rebind org-agenda-files
temporarily before calling org-agenda
. You get the dispatcher, type a
and get the daily/weekly/whatever agenda but with just the current buffer contributing. The code is missing error handling: in particular, it should check that the current buffer is associated with a file and the file is in Org mode.
The second implementation bypasses the dispatcher, so it is closer to your "few keystrokes" desideratum:
(defun my/org-agenda-list-current-buffer (&optional arg)
(interactive "P")
(org-agenda arg "a" t))
This pre-chooses the daily/weekly/whatever agenda (the "a"
argument) and sets the restriction (the t
argument) when calling org-agenda
. It uses the same "P"
interactive
spec that org-agenda
uses in order to deal with a prefix argument. The error handling comments above apply to this case too.
You can then bind whichever function you prefer to a key that will allow you to call it. It's probably best to use the Org mode map for that, since it does not make sense to call either of the functions above in a non-Org mode buffer. That ameliorates a bit the need for error handling: the key is only bound in Org mode buffers - but you will get an error if the buffer is not associated with a file in either implementation. If you are using GUI emacs, you probably have access to function keys with modifiers, so I'm using the C-<f12>
key, since it was undefined in my case - which key to use is up to you though: I just wanted to provide an example:
(define-key org-mode-map (kbd "<C-f12>") #'my/org-agenda-list-current-buffer)
EDIT: In reply to how to restrict to subtree, all you need to do is to change the t
argument in the second implementation. That argument can be a symbol with any of the following values: buffer
, subtree
and region
. The call
(org-agenda arg "a" t)
is equivalent to
(org-agenda arg "a" 'buffer)
so you can restrict to e.g. the current subtree with
(org-agenda arg "a" 'subtree)
PS. I hope this works, but I have not tested it, so there may be problems. I'll do some testing at some point to verify.
org-agenda-files
. So that the file corresponding to the buffer is the only thing in there. The only tricky thing is that the buffer might not have a corresponding file, but I imagine you could create a temporary file for it if necessary.<
in the agenda dispatcher?