Interactively enter headline under which to place an entry using capture

前端 未结 4 1112
被撕碎了的回忆
被撕碎了的回忆 2021-01-05 00:29

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 eac

相关标签:
4条回答
  • 2021-01-05 00:45

    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

    0 讨论(0)
  • 2021-01-05 00:54

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

    0 讨论(0)
  • 2021-01-05 00:54

    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

    0 讨论(0)
  • 2021-01-05 00:57

    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))
    
    0 讨论(0)
提交回复
热议问题