1
0
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-11-26 07:33:39 +00:00

Allow file names in capture templates to be functions, forms, or variables

* lisp/org-capture.el (org-capture-expand-file): New function.
(org-capture-target-buffer):
(org-capture-set-target-location): Use `org-capture-expand-file'.

* doc/org.texi (Template elements): Document that files can be given
as function, form, or variable.
This commit is contained in:
Carsten Dominik 2011-02-22 10:04:00 +01:00
parent 1e35a5ea37
commit c654620d73
2 changed files with 18 additions and 2 deletions

View File

@ -6316,7 +6316,8 @@ Specification of where the captured item should be placed. In Org-mode
files, targets usually define a node. Entries will become children of this
node. Other types will be added to the table or list in the body of this
node. Most target specifications contain a file name. If that file name is
the empty string, it defaults to @code{org-default-notes-file}.
the empty string, it defaults to @code{org-default-notes-file}. A file can
also be given as a variable, function, or Emacs Lisp form.
Valid values are:
@table @code

View File

@ -669,7 +669,9 @@ already gone. Any prefix argument will be passed to the refile comand."
(beginning-of-line 0))))
((eq (car target) 'file+olp)
(let ((m (org-find-olp (cdr target))))
(let ((m (org-find-olp
(cons (org-capture-expand-file (nth 1 target))
(cddr target)))))
(set-buffer (marker-buffer m))
(goto-char m)))
@ -729,8 +731,21 @@ already gone. Any prefix argument will be passed to the refile comand."
(org-capture-put :buffer (current-buffer) :pos (point)
:target-entry-p target-entry-p))))
(defun org-capture-expand-file (file)
"Expand functions and symbols for FILE.
When FILE is a function, call it. When it is a form, evaluate
it. When it is a variable, retrieve the value. Return whatever we get."
(setq file
(cond
((org-string-nw-p file) file)
((functionp file) (funcall file))
((and (symbolp file) (boundp file)) (symbol-value file))
((and file (consp file)) (eval file))
t file)))
(defun org-capture-target-buffer (file)
"Get a buffer for FILE."
(setq file (org-capture-expand-file file))
(setq file (or (org-string-nw-p file)
org-default-notes-file
(error "No notes file specified, and no default available")))