组织模式议程:在块议程中重用代码

Org mode agenda: Reuse code in block agenda

我有一个这样的 org-agenda-custom-commands:

("u" "Unscheduled TODO"
           todo ""
           ((org-agenda-overriding-header "\nUnscheduled TODO")
           (org-agenda-skip-function '(org-agenda-skip-entry-if
                                              'scheduled 'deadline 'timestamp
                                              'todo '("BACKBURNER")))))

我想在其他块议程视图中重用此议程视图的待办事项部分。因此,例如定义一个 unscheduled-todo 列表以供重用(伪代码,不起作用):

(setq unscheduled-todo '((org-agenda-overriding-header "\nUnscheduled TODO")
                           (org-agenda-skip-function '(org-agenda-skip-entry-if
                                                       'scheduled 'deadline 'timestamp
                                                       'todo '("BACKBURNER")))))
(setq org-agenda-custom-commands
        '(("u" "Unscheduled TODO"
            (todo "" unscheduled-todo))
          ("c" "Complete View"
            ((agenda "")
             (todo "" unscheduled-todo))))

如何让上面的代码工作?我认为我对如何以及何时评估代码和列表存在根本性的误解。我已经在 setqorg-agenda-custom-commands 中尝试了一些 ' 和 () 的配置,以及 append 来创建列表,但我也想了解这里发生了什么.

这是我评论中的一个实现(虽然我认为你真的不需要宏:一个函数也一样或更好):

(defun unscheduled-todo ()
    '((org-agenda-overriding-header "\nUnscheduled TODO")
      (org-agenda-skip-function '(org-agenda-skip-entry-if
                                  'scheduled 'deadline 'timestamp
                                  'todo '("BACKBURNER")))))

(setq org-agenda-custom-commands
      ; N.B. the character following this comment is a *backquote* 
      ; (the key to the left of the 1 key on a standard US keyboard);
      ; it is *NOT* a quote (the key to the left of the ENTER key
      ; on a standard US keyboard).
      `(("u" "Unscheduled TODO"
         todo "" ,(unscheduled-todo))
        ("c" "Complete View"
            ((agenda "")
             (todo "" ,(unscheduled-todo))))))

我希望它现在是正确的(我不得不修复它的几个错误)但它只经过了轻微的测试。

请注意,这使用 backquote 机制来引用 org-agenda-custom-commandssetq,同时允许使用逗号机制评估对宏的调用。

编辑:正如@Rorschach 在(现已删除)评论中指出的那样,我把事情复杂化了。你仍然需要反引号和逗号,但你可以使用你定义的变量:

(setq unscheduled-todo
    '((org-agenda-overriding-header "\nUnscheduled TODO")
      (org-agenda-skip-function '(org-agenda-skip-entry-if
                                  'scheduled 'deadline 'timestamp
                                  'todo '("BACKBURNER")))))

(setq org-agenda-custom-commands
      ; N.B. the character following this comment is a *backquote* 
      ; (the key to the left of the 1 key on a standard US keyboard);
      ; it is *NOT* a quote (the key to the left of the ENTER key
      ; on a standard US keyboard).
      `(("u" "Unscheduled TODO"
         todo "" ,unscheduled-todo)
        ("c" "Complete View"
            ((agenda "")
             (todo "" ,unscheduled-todo)))))

backquote/comma 机制允许评估一个拼接变量,就像它允许评估一个拼接函数调用一样。