交互式输入标题,并使用捕获在标题下放置条目

问题描述 投票:0回答:5

使用如下所示的捕获模板,我可以将条目添加到文件中的不同标题。如何在捕获过程中手动输入标题,而不是像我现在所做的那样将每个标题设置为 .emacs 文件中的一个键?

(setq org-capture-templates
      '(
      ("l" "Log" entry
     (file+headline "c:/Org/log.org" "Log")
     "\n\n** %?\n<%<%Y-%m-%d %a %T>>"
     :empty-lines 1))
emacs org-mode
5个回答
7
投票

看起来,至少在较新版本的 org 中,可以在捕获模板中使用自定义函数来执行此操作。

代替:

entry
(file+headline "~/Work/work.org" "Refile")

您可以使用:

entry
(file+function "~/Work/work.org" function-finding-location)

其中“function-finding-location”是您自己编写的自定义函数,它可以轻松提示您输入标题。

或者,您可以更进一步,定义一个自定义函数,该函数将提示输入文件名和标题名称(或您可以想到的任何其他名称):

entry
(function function-finding-location)

我对 elisp 的了解还不够多,无法自己编写这些函数,但这看起来是一个起点。如果其他人可以提供一些代码,那就太好了。相关文档在这里:

http://orgmode.org/manual/Template-elements.html


7
投票

我编写了一个与文件+函数一起使用的函数,它将提示捕获时的位置。

它使用 org-refile 的内部提示功能,因此我们可以在提示中获得标题的完成(最大级别覆盖为 9)。当用户输入未知标题时,它会在文件末尾创建它。

(defun org-ask-location ()
  (let* ((org-refile-targets '((nil :maxlevel . 9)))
         (hd (condition-case nil
                 (car (org-refile-get-location nil nil t t))
               (error (car org-refile-history)))))
    (goto-char (point-min))
    (outline-next-heading)
    (if (re-search-forward
         (format org-complex-heading-regexp-format (regexp-quote hd))
         nil t)
        (goto-char (point-at-bol))
      (goto-char (point-max))
      (or (bolp) (insert "\n"))
      (insert "* " hd "\n")))
    (end-of-line))

在你的情况下,你可以这样使用它:

(setq org-capture-templates
 '(("l" "Log" entry
    (file+function "c:/Org/log.org" org-ask-location)
    "\n\n** %?\n<%<%Y-%m-%d %a %T>>"
    :empty-lines 1))

5
投票

我不相信你可以让它在捕获时提示标题。但是,您可以从捕获窗口内重新归档,这应该会产生所需的行为。

我会定义一个包罗万象的目标标题/文件,这样,如果您忘记了,您将始终将它们收集在同一位置,然后只需在创建后重新归档它们即可。如果您还在该标题上设置了类别/标签,您将能够轻松查看错误归档的捕获条目并根据需要重新归档。 (如下例)

然后不要使用

C-c C-c
完成,而是选择使用
C-c C-w
重新提交,系统会要求您选择要将新条目发送到的标题。


我用于此捕获所有内容的捕获模板如下(改编自 Bernt Hansen 的捕获设置

      ("i"
       "Incidents"
       entry
       (file+headline "~/Work/work.org" "Refile")
       "* TODO %^{Ticket} - %^{User}\nSCHEDULED: %^t DEADLINE: %^t\n:PROPERTIES:  
       \n:DATE: %^U\n:END:\n%^{MANAGER}p%^{HOSTNAME}p%^{LOCATION}p%^{TEL}p\n%c"
       :empty-lines 1 :clock-in t :clock-resume t)

(添加换行符以避免阅读时滚动)

标题配置如下

* Refile                                                             :refile:
:PROPERTIES:
:CATEGORY: Unsorted
:END:

这样我最终所有未重新提交的任务都显示为

Unsorted:     Deadline:    TODO <Headline>                          :refile::

如果我正在等待同事/经理处理票证,我目前倾向于使用标签作为参考,或者提醒我在看到他们时与他们谈论这件事,以便最后的标签清晰可见,就像如果我想记住问题是什么,则未排序(因为我只显示案例编号和用户名,以及条目中的详细信息)。


2
投票

在记录笔记时,完成书写后按

C-u C-c C-w
以所需的新标题重新归档。

你还需要设置这个变量

 (setq org-refile-allow-creating-parent-nodes (quote confirm))

您可以将其设置为

t
而不是确认。但我喜欢它被确认,因为我不经常重新提交到新目标


0
投票

对于组织模式版本 9.5.x,您可以使用最初答案中的代码改编版

    (defun my/org-ask-headline-target (&optional prompt targets)
      (let* ((loc-prompt (or prompt "Headline"))
            (org-refile-targets (or targets '((nil :maxlevel . 2))))
            (hd (condition-case nil
                   (car (org-refile-get-location loc-prompt nil t))
                   (error (car org-refile-history)))))
        (goto-char (point-min))
        (outline-next-heading)
        (if (re-search-forward
             (format org-complex-heading-regexp-format (regexp-quote hd))
             nil t)
          (goto-char (point-at-bol))
        (goto-char (point-max)))))

在此版本中,您不需要插入

\n
,您可以使用
:empty-lines
,但在 >= 9.5.5 版本中
C-c C-w
+
:refile-targets ((nil :maxlevel . 2))
具有相同的结果,您可以根据模板定义定义目标。

© www.soinside.com 2019 - 2024. All rights reserved.