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

发布于 2024-12-29 07:48:13 字数 290 浏览 1 评论 0原文

使用如下所示的捕获模板,我可以将条目添加到文件中的不同标题中。如何在捕获期间手动输入标题,而不是像我现在所做的那样将每个标题设置为 .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))

Using capture templates like the one below, I can add entries to different headlines in a file. How can I manually enter a headline during capture, instead of setting up each headline to a key in the .emacs file like I am now doing?

(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))

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

将军与妓 2025-01-05 07:48:13

看起来,至少在较新版本的 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

It looks like, in newer versions of org at least, that custom functions can be used in capture templates to do this.

Instead of:

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

You can use:

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

Where 'function-finding-location' is a custom function you have written yourself, which could easily prompt you for a headline.

Or, you can go even farther, and define a custom function which will prompt for both file name and headline name (or anything else you can dream up):

entry
(function function-finding-location)

I don't really know enough elisp to write these functions myself, but this looks like the place to start. It'd be nice if someone else could offer up some code. The relevant documentation is here:

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

咆哮 2025-01-05 07:48:13

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

它使用 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))

I wrote a function to be used with file+function which will prompt for a location on capture.

It uses the internal prompting function of org-refile so we get completions of headings in the prompt (with maxlevels overridden to 9). When the user enters an unknown heading, it creates it at the end of the file.

(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))

In your case, you use it like this:

(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))
阿楠 2025-01-05 07:48:13

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

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

然后,不要使用 Cc Cc 完成,而是选择使用 Cc Cw 重新提交,系统会要求您选择要将新条目发送到的标题。


我用于捕获所有内容的捕获模板如下(改编自 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::

如果我正在等待同事,我目前倾向于使用标签作为参考/经理到处理票证,或者提醒我在看到它们时与他们谈论它,以便末尾的标签清晰可见,如果我试图记住问题是什么,则未排序也会如此(因为我只是有一个案例显示号码和用户名,条目中的详细信息)。

I don't believe you can have it prompt for the headline on capture. You can however refile from within the capture window which should result in the desired behaviour.

I would define a catch-all target headline/file so that if you forget you will always collect them in the same location and then just have to refile them once created. If you also set a category/tag on this headline you will be able to easily see the misfiled capture entry and refile it as desired. (Example below)

Then instead of finishing with C-c C-c choose to refile with C-c C-w and you will be asked to select the headline you want to send the new entry to.


The capture template I use for this catch all is as follows (adapted from Bernt Hansen's capture settings)

      ("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)

(Line breaks are added to avoid scrolling when reading here)

The heading is configured as follows

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

With this I end up with all non-refiled tasks showing up as

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

I currently tend to use tags as reference if I'm waiting for coworkers/managers to deal with the ticket, or to remind me to speak to them about it when I see them so the tag at the end stands out clearly, as does Unsorted if I'm trying to remember what the issue is (since I simply have a case number and user name showing, details within the entry).

爱冒险 2025-01-05 07:48:13

捕获笔记时,完成写入后按 Cu Cc Cw 在所需的新标题下重新归档。

您还需要设置此变量,

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

您可以将其设置为t而不是确认。但我喜欢确认,因为我不经常重新提交新目标

while capturing a note, after finishing writeup press C-u C-c C-w to refile under desired new headline.

you also need to set this variable

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

you can set it to t instead of confirm. But I like it be confirm because I dont often refile to new targets

甜点 2025-01-05 07:48:13

对于 org-mode 版本 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

(setq org-capture-templates `("t" "Todo" entry
  (file+function "/path/to/todo.org" "My Headline" my/org-ask-headline-target)
  "* TODO %?"))

但在版本 >= 9.5.5 中 Cc Cw + :refile-targets 具有相同的结果,您可以根据模板定义定义目标。

(setq org-capture-templates `("t" "Todo" entry
  (file+headline "/path/to/todo.org" "My Headline")
  "* TODO %?" :refile-targets ((nil :maxlevel . 2))))

For org-mode version 9.5.x you can use this adaptation of the code from the initial answers

    (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)))))

in this version you don't need to insert \n, you can use :empty-lines

(setq org-capture-templates `("t" "Todo" entry
  (file+function "/path/to/todo.org" "My Headline" my/org-ask-headline-target)
  "* TODO %?"))

but in version >= 9.5.5 C-c C-w + :refile-targets have the same result and you can define the targets per template definition.

(setq org-capture-templates `("t" "Todo" entry
  (file+headline "/path/to/todo.org" "My Headline")
  "* TODO %?" :refile-targets ((nil :maxlevel . 2))))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文