1

I need to run a function every time I run org-agenda. However, I need it to run prior to the agenda. I wasn't able to find any hooks for the agenda command in the documentation. Any guidance is appreciated.

  • Perhaps if you are a little more specific about what you would like to achieve, you can obtain a more specific answer. You can advise org-agenda to run your custom function first (using advice ...), or you can simply create a new function: (defun my-org-agenda () "Doc-string." (interactive "P") (message "hello-world") (call-interactively 'org-agenda)) In that example, replace (message "hello-world") with your function that you want to run first in time. [CAVEAT: I have not tested/attempted to pass a prefix arg to org-agenda using the aforementioned example, but it may suffice] – lawlist Apr 30 '20 at 6:32
  • org-agenda-mode-hook is run from org-agenda-mode which in turn is run from org-agenda-prepare which is run by org-agenda-list before the agenda is created (and while the buffer is still writable). If that's not early enough, then @lawlist's suggestions for a wrapper function or a before advice would be the only solutions I can see. – NickD Apr 30 '20 at 14:36
  • @Drew Sorry about that. Won't do it again – juanerasmoe Apr 30 '20 at 20:06
  • @NickD this was what I was looking for. Thanks. I just needed to run a function before every run of org-agenda. I you provide an answer to the question I will mark it as the right answer. – juanerasmoe Apr 30 '20 at 20:07
  • Done - glad it helped. – NickD Apr 30 '20 at 20:11
1

org-agenda-mode-hook is run from org-agenda-mode which in turn is run from org-agenda-prepare which is run by org-agenda-list before the agenda is created (and while the buffer is still writable). If that's early enough, you can add your function to the hook with

 (add-hook 'org-agenda-mode-hook 'my-function)

If that's not early enough, then @lawlist's suggestions for a wrapper function or a before advice would be the only solutions I can see.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.