Escaping characters in org-mode capture template - org-mode

I'm using emacs with org-mode for my notes and have the following capture template for my meeting notes. I would like to use columnview to create a quick overview over tasks after the meeting. I cant escape the special charaters in the columnview commands (under Actions: below), and get syntax error when running the elisp code in emacs.
(defvar my/org-meeting-template "** %u %^{meeting_title} %^G
:PROPERTIES:
:exportHeadlineOnly: t
:EXPORT_AUTHOR: author
:EXPORT_OPTIONS: H:0 num:nil toc:nil author:t timestamp:nil creator:nil date:nil
:EXPORT_FILE_NAME: %<%Y%m%d_%H%M_%^{filename}>
:ID: ID_%<%Y%m%d-%H%M%S>
:END:
CREATED %U
*** Attendees:
[X] author
[ ] %?
*** Agenda:
*** Notes:
*** Actions:
#+BEGIN: columnview :id ID_%<%Y%m%d-%H%M%S> :match "%%TODO|DONE" :format "%%ITEM(What) %%TAGS(Who) %%DEADLINE(When) %%TODO(State)")
#+END
" "Meeting Template")
(setq org-capture-templates
`(("m" "Meeting" entry (file+headline "~/notes.org" "Meeting Notes")
,my/org-meeting-template)
))
If I paste in the following lines:
#+BEGIN: columnview :id ID_20200209_120000 :match "/TODO|DONE" :format "%ITEM(What) %TAGS(Who) %DEADLINE(When) %TODO(State)"
#+END:
after I have captured the meeting everything works and when I press C-c C-c in the columnview I get a nice table of tasks, deadlines etc. But, I would really like to add the lines with my capture template.
Any ideas?
kind regards,
Agnar

So, my problem was escaping '%' in the org-mode template above. This should be done using '\\' after '%'. Like this: %\\. The correct syntax for the lines under *Actions: above is now:
#+BEGIN: columnview :id ID%<%Y%m%d-%H%M%S> :match \"/TODO|DONE\" :format \"%\\ITEM(What) %\\TAGS(Who) %\\DEADLINE(When) %\\TODO(State)\"
#+END:

Related

emacs elisp why won't a variable work here? [duplicate]

I've seen this:
How to type a dynamic file entry for org capture
but cannot get it to work; I get "Invalid file location: nil". Has something changed in org-mode or in Emacs itself to stop this from working? Otherwise: suggestions for how to debug what has gone wrong?
What I'm really trying to get working is what is described on this page:
http://www.howardism.org/Technical/Emacs/journaling-org.html
The capture template I'm interested in is the "Journal Note" one all the way at the bottom of the page:
(setq org-capture-templates '(
;; ...
("j" "Journal Note"
entry (file (get-journal-file-today))
"* Event: %?\n\n %i\n\n From: %a"
:empty-lines 1)
;; ..
))
Thanks for any assistance.
Figured it out ... it is using a backquote instead of a normal quote for the entire capture template block! I missed this because all of the answers I saw had only a single capture template with a backquote in front of it; I tried doing that but this doesn't work if the template is "one of" ...
So here is a snippet a bit richer than those I found; I hope it helps someone else.
(setq org-capture-templates
`(("t" "TODO" entry (file+datetree "~/Documents/org/tasks.org" "Tasks")
"* TODO [#C] %?\n SCHEDULED: <%<%Y-%m-%d %a>>\n [%<%Y-%m-%d %a>]\n %a")
("T" "Travel" entry (file+datetree+prompt "~/Documents/org/travel.org")
"* %?\n :PROPERTIES:\n :LOCATION:\n :END:\n %t\n %a")
("j" "Journal Note" entry (
file+olp+datetree
,(concat
org-journal-dir
(format-time-string "journal-%m-%d.org")))
"* Event: %?\n %i\n From: %a")
)
)
The keys are the backquote ` at the start of the capture template def block, and the comma , before (concat ... ) on the function being called.
It seems like something has changed between Org-mode 8.2.10 and 9.1.9 specifically in the way Org handles template elements. Whereas in earlier version of Org the second value in the pair (file ...) could be a function that Org would evaluate, now it seems only a string (file path) is valid here.
The fix is to use the backquote list form, and explicitly state that the function needs evaluating using the comma:
(setq org-capture-templates `(
;; ...
("j" "Journal Note"
entry (file ,(get-journal-file-today))
"* Event: %?\n\n %i\n\n From: %a"
:empty-lines 1)
;; ..
))

Customized org-capture-template for Org Capture Extension

I am using the great Org Capture Extension Firefox addon to directly capture my web links into my Emacs documents.
A minimal org capture template is:
(setq org-capture-templates `(
("L" "Protocol Link" entry (file+headline "~/web.org" "Links")
"* [[%:link][%:description]]\n")
;; ... your other templates
))
I use this to bookmark articles, in peculiar a lot of them are on
arxiv.org. The problem is that arxiv title pages contain [] characters, for instance:
[1606.04838] Optimization Methods for Large-Scale Machine Learning
This does not mix well with the [[%:link][%:description]] used in the template to create the org mode link. For instance a capture returns:
** [[https://arxiv.org/abs/1606.04838][[1606.04838] Optimization Methods for Large-Scale Machine Learning]]
and the Org-Mode link is broken because of the brackets in the "[1606.04838]" string.
How to solve this?
The cure is to transform the link [%:description] description into a string that does not contain squared brackets []. For this we can define a function that transforms the [, ] chars into (, ) ones.
(defun transform-square-brackets-to-round-ones(string-to-transform)
"Transforms [ into ( and ] into ), other chars left unchanged."
(concat
(mapcar #'(lambda (c) (if (equal c ?[) ?\( (if (equal c ?]) ?\) c))) string-to-transform))
)
Then we can use this function into the org-capture-template. The %(sexp) syntax is used to evaluate the lisp code into the template:
%(sexp) Evaluate Elisp sexp and replace with the result.
For convenience, %:keyword (see below) placeholders
within the expression will be expanded prior to this.
The sexp must return a string.
The modified org-capture-template is:
(setq org-capture-templates '(
("L" "Protocol Link" entry (file+headline "~/web.org" "Links")
"* [[%:link][%(transform-square-brackets-to-round-ones \"%:description\")]]\n")
;; ... your other templates
))
Then when you click on the Firefox Org-Capture button the template is correctly expended to
** (1606.04838) Optimization Methods for Large-Scale Machine Learning
with a well formed Org-Mode link (note that the [1606.04838] was turned into (1606.04838))

emacs remember tag template returning as invalid

I have been following Charles Cave's GTD description for using emacs' remember mode for making todo lists, etc. I understand the tutorial is a bit dated, so any suggestions on how to update the .emacs file to org-capture will be appreciated. That being said, that is not the current problem.
I define the org templates like so:
(setq org-remember-templates
'(("Todo" ?t "\n* TODO %^{Brief Description} %^g%? \nAdded: %U" "~/orgfiles/GTD/newgtd.org" "Tasks")
("Journal" ?j "** %^{Head Line} %U %^g\n%i%?" "~/orgfiles/GTD/journal.org")
("Clipboard" ?c "** %^{Head Line} %U %^g\n%c\n%?" "~/orgfiles/GTD/journal.org")
("Receipt" ?r "** %^{BriefDesc} %U %^g\n%?" "~/orgfiles/GTD/finances.org")
("Book" ?b "** %^{Book Title} %t :BOOK: \n%[~/orgfiles/GTD/.book_template.txt]\n"
"~/orgfiles/GTD/journal.org")
("Film" ?f "** %^{Film Title} %t :FILM: \n%[~/orgfiles/GTD/.film_template.txt]\n"
"~/orgfiles/GTD/journal.org")
("Daily Review" ?a "** %t :COACH: \n%[~/orgfiles/GTD/.daily_review.txt]\n"
"~/orgfiles/GTD/journal.org")
("Private" ?p "\n* %^{topic} %T \n%i%?\n" "~/orgfiles/GTD/privnotes.org")
("Contact" ?c "\n* %^{Name} :CONTACT:\n%[~/orgfiles/contemp.txt]\n"
"~/orgfiles/GTD/privnotes.org")
("Someday" ?s "** %^{Someday Heading} %U\n%?\n" "~/orgfiles/GTD/someday.org")
("Vocab" ?v "** %^{Word?}\n%?\n" "~/orgfiles/GTD/vocab.org")
)
)
This is pretty much cut-and-paste from the tutorial. When I attempt a "Todo" (C-c r t shortcut) a new emacs window opens in remember mode with text
* TODO %^g%?
already within the screen. There is something going on here because I should only have
* TODO
showing up, with remember waiting for me to make an entry. However, if I remove the %g from the template definition all works well (I just can't insert a tag while creating my entry). I have searched around to see if perhaps the %^g entry has been changed (maybe when remember was replaced by capture), but I have found nothing so far. Is there anything wrong with the template as defined? Any help (especially to references for further reading) will be appreciated.
Unfortunately my organization is stuck on RHEL 6, so updating emacs is not currently possible.
org-mode version: 8.3.4
emacs version: 23.1.1
You have a recent enough version of org that you can ditch org-remember (which is obsolete and no longer maintained AFAIK) and start using org-capture instead. You can use the function org-capture-import-remember-templates to translate your org-remember-templates to org-capture-templates.
If you still have troubles after that, post to the mailing list.

How to add tags completion to org mode capture?

I use org mode's capture functionality to make all my todo's. It is clean and practical and let me add a consistent content to all my todo's, including a prompt for heading, a prompt for tags and an automatic insertion of created date. Here is my code:
(setq org-capture-templates '((
"t" ; key
"Todo" ; description
entry ; type
(file+headline "C:/.../org/notes.org" "tasks") ; target
"* TODO [#B] %^{Todo} :%^{Tags}: \n:PROPERTIES:\n:Created: %U\n:END:\n\n%?" ; template
:prepend t ; properties
:empty-lines 1 ; properties
:created t ; properties
)))
However, my prompt for tags forces me to enter tags from memory. How could I add tags from the tags list set by the following code:
(setq org-tag-alist `(
("OFFICE" . ?o)
("HOME" . ?h)
("ERRAND" . ?e) ))
When my point is in the heading of an already created task, this list pops up when I hit C-c C-c and let me chose the tags by their short cut single letters "o", "h" or "e".
So my question is: is it possible to include this pop-up list of tags inside the code for my capture?
The built in solution is to use %^g. From the help for org-capture-templates:
%^g Prompt for tags, with completion on tags in target file.
%^G Prompt for tags, with completion on all tags in all agenda files.
You can also do this "by hand" by calling some function that adds the tags. Adding tags is generally done with org-set-tags (this is what C-c C-c is doing). So, all we have to do is call that in our template with the %(func) syntax:
(setq org-capture-templates '((
"t" ; key
"Todo" ; description
entry ; type
(file+headline "C:/.../org/notes.org" "tasks") ; target
"* TODO [#B] %^{Todo} %(org-set-tags) \n:PROPERTIES:\n:Created: %U\n:END:\n\n%?" ; template
:prepend t ; properties
:empty-lines 1 ; properties
:created t ; properties
)))
If you have a specific list of tags you want to select from (say org-tag-alist) you can use completing-read to select from it:
(completing-read "Tag: " (mapcar #'first org-tag-persistent-alist) nil t)

Emacs org-mode capture without expansions

I've been trying to make an org capture template for storing quick ideas to my current project so I can get back to what I'm working on and evaluating the notes later.
This is the template code:
(setq org-capture-templates '(
("a" "quick notes" entry (file+olp "~/myproject" "NOTES" "IDEAS")
"") ))
When I hit C-c c a *** invent flying light bulb RET this is what I expect the target will look like:
* NOTES
** IDEAS
*** invent flying light bulb
Instead I get:
* NOTES
** IDEAS
*** invent flying light bulb
$THE-HEADING-THAT-THE-CURSOR-IS-ON
That is: whatever headline the cursor touches when 'org-capture is called is inserted along with my note. When I delete that string this appears:
[[file:~/$PATH-TO-FILE-I-WAS-WORKING-ON][]]
I haven't chosen any template expansions so why is this stuff inserted?
When using entry, the last field should not be blank. The example in the frequently asked questions for org-mode uses item when leaving the last field blank.
(setq org-capture-templates '(
("a" "quick notes" entry
(file+olp "~/Desktop/myproject.org" "NOTES" "IDEAS")
"*** %?") ))