Rafi Khan

Senior Software Engineer | Ottawa, Canada

Supporting society through innovation

Org mode capture template bug?

I’m starting to use org-mode/emacs full-time again for information, task and project management. I like having a portable platform that I can access using the same interface on all of my devices. And it is so easy to automate and write custom hooks into JIRA, confluence, todoist, gcal and other external services.

I ran into an issue where my capture template was not being evaluated properly. I think I had a bug in my template specification, and a version of org mode released in the last couple of years may have patched it.

Old code

(setq org-capture-templates
      '(("t" "TODO" entry (file ,org-default-notes-file)
         "* TODO [#C] %?\n%u\n\n" :clock-in t :clock-resume t)
        ("n" "note" entry (file ,org-default-notes-file)
         "* %? :NOTE:\n%u\n\n")
        ("i" "idea" entry (file ,org-default-notes-file)
         "* %? :IDEA:\n%u\n\n")
        ("m" "meeting" entry (file ,org-default-notes-file)
         "* %? :MEETING:\n%u\n\n- Attendees:\n- Start time:\n- Project:\n")
        ("r" "reading" entry (file ,org-default-notes-file)
         "* TODO %? :READING_LIST: \n%u\n\n- Source:\n- [ ] Read\n- [ ] Produce note")))

The fixed code

(setq org-capture-templates
      `(("t" "TODO" entry (file ,org-default-notes-file)
         "* TODO [#C] %?\n%u\n\n" :clock-in t :clock-resume t)
        ("n" "note" entry (file ,org-default-notes-file)
         "* %? :NOTE:\n%u\n\n")
        ("i" "idea" entry (file ,org-default-notes-file)
         "* %? :IDEA:\n%u\n\n")
        ("m" "meeting" entry (file ,org-default-notes-file)
         "* %? :MEETING:\n%u\n\n- Attendees:\n- Start time:\n- Project:\n")
        ("r" "reading" entry (file ,org-default-notes-file)
         "* TODO %? :READING_LIST: \n%u\n\n- Source:\n- [ ] Read\n- [ ] Produce note")))

If you look closely, the difference was in how the variable org-default-notes-file is evaluated.

In the first version we’re not escaping the var properly, in the second we are escaping by using a backtick and a comma inside it.

Some links that came up in my googling:

  • https://list.orgmode.org/[email protected]/t/
  • https://list.orgmode.org/orgmode/CAMg28OsxfL1Rv-S9zDOMubvj3Yn6aPMdY9AAif_rd8u2h=oX0Q@mail.gmail.com/T/

I got the clue for changing the way it was being evaluated by looking at this dotfile from another person which uses the backtick instead of the single quote.


Posted

in

by

Tags: