0

I would like to make a quick access agenda for today and just for the current buffer.

So my approach looks like this, but it does not work.

(setq org-agenda-custom-commands
   '(
     ("o"                                ;; Key
      "todays agenda for current buffer" ;; Description
      agenda                             ;; Type agenda
      ((org-agenda-files `(,(buffer-file-name))) 
       (org-agenda-span 1))              ;; Options
     )))

I found some inspiration here but it does not really work here atm.

I know you can narrow the agenda to current buffer with < but if it is possible I would prefer to use a custom agenda.

An explanation why this approach does not work would be appreciated.

1

The only problem is that you have forgotten a mandatory piece in the command. C-h v org-agenda-custom-commands says in part:

Each entry is a list like this:

   (key desc type match settings files)

...

type     The command type, any of the following symbols:
          agenda      The daily/weekly agenda.
...
match    What to search for:
          ...
          For all other commands, this should be the empty string.
settings  A list of option settings, similar to that in a let form, so like
          this: ((opt1 val1) (opt2 val2) ...).   The values will be
          evaluated at the moment of execution, so quote them when needed.
...

Since you are not using a match you just omitted it, but that's not correct: For all other commands, this (i.e. the match expression) should be the empty string. So it is looking for a match expression and since there is no empty string there, it goes after the settings instead and tries to interpret them as a match expression, with predictably chaotic results.

Try this:

(setq org-agenda-custom-commands
   '(
     ("o"                                ;; Key
      "todays agenda for current buffer" ;; Description
      agenda                             ;; Type agenda
      ""                                 ;; Match expression
      ((org-agenda-files `(,(buffer-file-name))) 
       (org-agenda-span 1))              ;; Options
     )))

That seems to have worked in my (rather superficial) experiment.

4
  • Thank you for taking the time to explain! For me it works under two conditions: if the current buffer is also an agenda-file and if sticky agenda is disabled. If it's not in the usual agenda-list I see the error if: Wrong type argument: stringp, nil and if I refresh the agenda the error is let*: Args out of range: 0, 0 Does refreshing the agenda work for you? – breathe_in_breathe_out Aug 2 '20 at 8:49
  • I tested it starting from emacs -q where I don't have any files in the agenda (and certainly no sticky agenda): it seems to work in that case. I am not sure what happens when you refresh the agenda, but I can try it later on today and let you know. – NickD Aug 2 '20 at 12:24
  • I tried out emacs -q and it worked even if the file is not in the agenda. But refreshing did not work for me, neither did changing to the next day. If you confirm, then I might start another question about why this occurs. Would you support this suggestion? – breathe_in_breathe_out Aug 2 '20 at 20:33
  • 1
    Yes, refreshing does not work fro me either. I believe that has to do with the local binding of org-agenda-files in the settings above: buffer-file-name returns nil since there is no file associated with the agenda buffer. By all means, ask another question: you do not need my support for that (or for anything else for that matter). – NickD Aug 2 '20 at 21:27

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.