2

When I invoke org-agenda-list I get the org agenda buffer (works fine) but it is always named *Org Agenda* regardless of what type of agenda view I use (I also have a weekly agenda customized in org-agenda-custom-commands but when I invoke it the buffer name is still *Org Agenda*). Is there a way to set this to something else?

While we're at it, it would be great if we could make the buffer name dynamic -- e.g., Week 5 Review to denote that we are on Week 5 of 52 weeks in the year (or Weekly Review (23 DONE) to denote that 23 tasks were completed to a DONE state). Any tips other than digging through the sources?

1

2 Answers 2

2

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.

  1. 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")
)
  1. 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"))
3
  • 1
    I actually ended up providing the org-agenda-buffer-name option inside org-agenda-custom-commands as described in the manual. This appears to be simpler (at least in my use case) and does not run into the problem of rename-buffer failing if called twice in succession after org-agenda (apply: Buffer name ‘foo’ is in use). Aug 27, 2022 at 7:08
  • @linusarver Ah, good work! I didn't realize that's what you were looking for, since I thought you wanted for every agenda buffer. If it's for custom agenda buffers, then your solution sounds perfect! It may be helpful for people who have this same question in the future to provide what you found as an answer to your question.
    – Malle Yeno
    Aug 27, 2022 at 16:56
  • I followed your suggestion and added my comment as an answer. Aug 27, 2022 at 21:58
1

I actually ended up providing the org-agenda-buffer-name option inside org-agenda-custom-commands as described in the manual. This appears to be simpler (at least in my use case) and does not run into the problem of rename-buffer failing if called twice in succession after org-agenda (apply: Buffer name ‘foo’ is in use).

Also for whatever reason this only seems to work with block agendas. I'm using doom emacs and org 9.6.

1
  • I took me a while to figure out that this setting (org-agenda-buffer-name "My agenda title") goes into the list of shared settings after the list of blocks, rather than in the list of settings for a given block. It also works for a block agenda with a single block... :-)
    – AstroFloyd
    Nov 25, 2023 at 16:21

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.