0

I've seen a few similar questions, but I load this in my init.el and org-agenda-custom-commands is still empty when Emacs starts, so I have to evaluate this code block manually.

I basically just want to populate org-agenda-custom-commands, but I want to spread out in different parts of the init file, so that I don't have to add everything at once.

I've tried all sorts of quoting and parenthesising, but it's always empty.

(setq todos
    `(, "xt"
      "Todos"
      tags-todo               
      "TODO=\"TODO\" "        
      (
       (org-agenda-files '("~/agenda"))
       )
      ))

  (add-to-list 'org-agenda-custom-commands todos)

Any pointers as to what I can try?

Trevoke
  • 2,375
  • 21
  • 34
Jason Hunter
  • 519
  • 2
  • 9
  • 1
    That code has problems and won’t do what you want, but if it isn’t being evaluated then you have some other problem in your init file. Are you sure that you're not getting a warning about errors during init? An error would abort execution of your init file, causing code after the error to not be executed. – db48x Jul 30 '23 at 08:39
  • 1
    What do you want to implement? Your code is weird to me. – shynur Jul 30 '23 at 10:23
  • I basically just want to populate org-agenda-custom-commands, but I want to spread out in different parts of the init file, so that I don't have to add everything at once. I also want to insert and delete entries when I test commands for org-agenda – Jason Hunter Jul 30 '23 at 10:41
  • To be clear, the block of code works when you evaluate it yourself, it just doesn't work when it's part of the init file? – Trevoke Jul 30 '23 at 14:54
  • Yes, that is correct. – Jason Hunter Jul 30 '23 at 19:11
  • 1
    What exactly is always empty? And do you get an error message (check `*Messages*`)? Also, can you try without the comma and replace the backquote with a single quote? It's not clear to me that backquote/comma do *anything* different here. But AFAICT, either way, putting everything in a minimal init file (including a `(require 'org-agenda)` to make sure that `org-agenda-custom-commands` is defined before it is used) works fine. As @db48x surmises, there must be some *other* problem in your init file: that's one reason to *always* try a *minimal* init. – NickD Jul 30 '23 at 22:24
  • Running `emacs --debug-init` does not trigger the debugger? – phils Jul 30 '23 at 22:45
  • I don't have the time now to look closely at your question. Others have apparently done that and didn't suggest it's a duplicate. But the title suggests it might be a duplicate of this question: https://emacs.stackexchange.com/q/7481. If so, please delete it. – Drew Jul 31 '23 at 02:01

1 Answers1

1

[Not an answer: just an attempt at elucidating what is going on.]

AFAICT, there is no reason for using backquote/comma here: that's useful when you want to quote some expression so that it does not get evaluated, except that you do want to evaluate a subexpression. Otherwise, use a single quote ' and quote everything.

If I put the above (well, the modified version with a single quote, but other than readability, it does not make any difference in this particular case) in a file /tmp/foo.el (and add (require 'org-agenda) to make sure that org-agenda-custom-commands is defined before it is used), like this:

(require 'org-agenda)

(setq todos
    '("xt"
      "Todos"
      tags-todo               
      "TODO=\"TODO\" "        
      (
       (org-agenda-files '("~/agenda"))
       )
      ))

  (add-to-list 'org-agenda-custom-commands todos)

I can start a new emacs with emacs -q -l /tmp/foo.el and then go to the *scratch* buffer and evaluate org-agenda-custom-commands:

;; make sure you are in the *scratch* buffer and press C-j after typing in
;; the next line
org-agenda-custom-commands
(("xt" "Todos" tags-todo "TODO=\"TODO\" " ((org-agenda-files '("~/agenda")))) ("n" "Agenda and all TODOs" ((agenda "") (alltodo ""))))

As you can see, the entry was added. Try to reproduce the above and make sure that you get the same result. BTW, the "n" entry is the default value of org-agenda-custom-commands: the add-to-list added your entry to the front, so you now have two entries.

NickD
  • 27,023
  • 3
  • 23
  • 42
  • After I cleaned up all warnings during startup, it started working. I don't really understand it, cause everything else in my init file was loaded, even the stuff after org*. Thanks so much, again. – Jason Hunter Jul 31 '23 at 08:30