这是一个不需要外部包的轻量级解决方案。我是从@MarcinAntczak 的回答、@Clément 的评论和这个类似的线程中得到的。它与org-capture
和 一起使用M-S-RET
。把它放在你的 Emacs 初始化文件中(例如~/.emacs
):
(defun insert-created-date(&rest ignore)
(insert (format-time-string
(concat "\nCREATED: "
(cdr org-time-stamp-formats))
))
(org-back-to-heading) ; in org-capture, this folds the entry; when inserting a heading, this moves point back to the heading line
(move-end-of-line()) ; when inserting a heading, this moves point to the end of the line
)
; add to the org-capture hook
(add-hook 'org-capture-before-finalize-hook
#'insert-created-date
)
; hook it to adding headings with M-S-RET
; do not add this to org-insert-heading-hook, otherwise this also works in non-TODO items
; and Org-mode has no org-insert-todo-heading-hook
(advice-add 'org-insert-todo-heading :after #'insert-created-date)
我没有将此函数添加到状态更改(例如,从普通标题到TODO
),因为它需要在属性抽屉中,我更喜欢没有那些额外的行。如果您更喜欢在属性中使用它,请使用查看此线程中定义的函数。