As with any buffer within Emacs, you can run the command M-x rename-buffer
to change the name of the current buffer.
Is there a way to have org-agenda
rename its buffer automatically? Sure, this is the perfect use case for hooks! The hook we are interested in here is called 'org-agenda-mode-hook
.
Our goal is to draft a function that renames an agenda buffer automatically, then add it to the agenda mode hook so that it runs after an agenda is made. This question has an interesting discussion on the order in which this hook is called when an agenda is being created.
- Draft a function to rename your agenda buffer.
(defun my-function ()
; This names all of the buffers run by agenda to "Agenda x"
; To name your buffer dynamically,
; make your function grab the name you're trying to look for.
(rename-buffer "Agenda x")
)
- Add your function to the
org-agenda-mode-hook
(add-hook 'org-agenda-mode-hook 'my-function)
Depending on where the hook runs, the buffer name may be overwritten. In this case, you have a backup plan: Reimplement the org-agenda
command. Taking the suggestion of @lawlist from the previously linked question, you can write a function like this:
(defun my-org-agenda ()
"Doc-string."
(interactive "P")
(call-interactively 'org-agenda)
; As discussed before, this can be dynamic by
; writing the function to grab what you're looking for.
(rename-buffer "Agenda X"))