2

I am trying to write a custom org-capture template, but I get an error if I try to use the %\N functionality to insert the N-th prompt. The relevant excerpt of my org-capture-templates variable is

("ao" "Other meeting" entry
 (file+headline "~/org/meeting.org" "Meetings")
 "* %^{meeting date}u Meeting with %^{meeting with}
   :PROPERTIES:
   :MEETWITH: %\\2
   :DESCRIPTION: %\\3
   :END:

   Created on %U
   Description: %^{description}

   %?" :jump-to-captured t :empty-lines 1)

When I try to capture, everything goes fine until I C-c C-c the note. Then, the new note fails to save due to the following error:

org-capture: Capture abort: Wrong type argument: stringp, nil

This error only occurs when I try to use the %\N functionality, not otherwise. I assume the issue must be somehow related to the relevant section of org-capture-fill-template, but I am unable to discern what could be causing this errant behaviour. That section of code is as follows (from org-capture.el).

    ;; Replace %n escapes with nth %^{...} string.
    (setq strings (nreverse strings))
    (save-excursion
      (while (re-search-forward "%\\\\\\([1-9][0-9]*\\)" nil t)
        (unless (org-capture-escaped-%)
          (replace-match
           (nth (1- (string-to-number (match-string 1))) strings)
           nil t))))

Note: I have org-roam and org-roam-bibtex installed. Could this have anything to do with it?

1 Answer 1

2

Apparently, the %^{meeting date}u does not count as a prompted entry (perhaps because of the u? I'm not really sure). So it thinks there are only two prompted entries: %^{meeting with} and %^{description} so the template should look like this:

("ao" "Other meeting" entry
 (file+headline "~/org/meeting.org" "Meetings")
 "* %^{meeting date}u Meeting with %^{meeting with}
   :PROPERTIES:
   :MEETWITH: %\\1
   :DESCRIPTION: %\\2
   :END:

   Created on %U
   Description: %^{description}

   %?" :jump-to-captured t :empty-lines 1)

EDIT: I looked at the code (in org-capture.el:org-capture-fill-template) more carefully. The only time when prompted entries are saved for later use with %\N constructs is when they are not decorated with a key (CgGLptTuUptTuU). So the diagnosis above is correct: the u causes the entry not to be remembered for further use with %\N.

This seems deliberate so it's probably not a bug, but a design decision. In particular, the doc string for org-capture-templates says:

%\1 ... %\N Insert the text entered at the nth %^{prompt}, where N is a number, starting from 1.

Note that it does not mention the %^{prompt}<key> form at all.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.