为 org-capture-template 添加装饰器函数

Add a decorator function to org-capture-template

我写了一个 org-capture-templates 将条目添加到适当的标题中:

** Plan
** Writing

org-capture-templates为:

(setq org-capture-templates
      '(("p" "Plan" entry
         (file+function "~/Documents/OrgMode/ORG/Master/todo.today.org"
                        (my-org-goto-last-headline "\*\* Plan"))
         "* TODO %i%?")
        ("w" "Writing" entry
         (file+function "~/Documents/OrgMode/ORG/Master/todo.today.org"
                        (my-org-goto-last-headline "\*\* Writing"))
         "* %i%? \n%T")))

my-org-goto-last-headline 被定义为装饰器:

(defun my-org-goto-last-headline (heading)
  (defun nested ()
    "Move point to the last headline in file matching \"** Headline\"."
    (end-of-buffer)
    (re-search-backward heading))
  `nested)

此外,我设置了lexical-binding: t

不幸的是,它报告如下错误:

org-capture-set-target-location: Invalid function: (my-org-goto-last-headline "\*\* Plan")

如何在这样的地方应用装饰器org-capture-template?

函数格式应该是(file+function "filename" function-finding-location).

您没有提供功能本身。您正在给它一个列表 (function argument)。因为它没有被执行,所以你有那个错误。

您可以将其写在反引号中并评估 return 作为函数对象的函数。

(setq org-capture-templates
      `(("p" "Plan" entry
         (file+function "~/Documents/OrgMode/ORG/Master/todo.today.org"
                        ,(my-org-goto-last-headline "\*\* Plan"))
         "* TODO %i%?")
        ("w" "Writing" entry
         (file+function "~/Documents/OrgMode/ORG/Master/todo.today.org"
                        ,(my-org-goto-last-headline "\*\* Writing"))
         "* %i%? \n%T")))

您还需要在 my-org- 函数中引用 return nested