Disallow S-exp in capture templates

* lisp/org-capture.el (org-capture-expand-file): Disallow S-exp.
(org-capture-templates):
* doc/org.texi (Template elements): Update documentation.

A function is equivalent to using S-exp, without tainting code with an
yet another call to `eval'.
This commit is contained in:
Nicolas Goaziou 2016-11-04 17:41:27 +01:00
parent c81f9fff3b
commit f5645675a3
3 changed files with 22 additions and 10 deletions

View File

@ -7159,8 +7159,8 @@ 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. 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 node. Most target specifications contain a file name. If that file name is
the empty string, it defaults to @code{org-default-notes-file}. A file can 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. When an absolute also be given as a variable or as a function called with no argument. When
path is not specified for a target, it is taken as relative to an absolute path is not specified for a target, it is taken as relative to
@code{org-directory}. @code{org-directory}.
Valid values are: Valid values are:

View File

@ -8,6 +8,21 @@ See the end of the file for license conditions.
Please send Org bug reports to mailto:emacs-orgmode@gnu.org. Please send Org bug reports to mailto:emacs-orgmode@gnu.org.
* Version 9.1
** Incompatible changes
*** ~org-capture-templates~ no longer accepts S-expressions as file names
Since functions are allowed there, a straightforward way to migrate
is to turn, e.g.,
: (file (sexp))
into
: (file (lambda () (sexp)))
* Version 9.0 * Version 9.0
** Incompatible changes ** Incompatible changes

View File

@ -124,8 +124,8 @@ target Specification of where the captured item should be placed.
Most target specifications contain a file name. If that file Most target specifications contain a file name. If that file
name is the empty string, it defaults to `org-default-notes-file'. name is the empty string, it defaults to `org-default-notes-file'.
A file can also be given as a variable, function, or Emacs Lisp A file can also be given as a variable or as a function called
form. When an absolute path is not specified for a with no argument. When an absolute path is not specified for a
target, it is taken as relative to `org-directory'. target, it is taken as relative to `org-directory'.
Valid values are: Valid values are:
@ -1008,16 +1008,13 @@ Store them in the capture property list."
(defun org-capture-expand-file (file) (defun org-capture-expand-file (file)
"Expand functions and symbols for FILE. "Expand functions and symbols for FILE.
When FILE is a function, call it. When it is a form, evaluate When FILE is a function, call it. When it is a variable,
it. When it is a variable, retrieve the value. When it is retrieve its value. When it is the empty string, return
a string, return it. However, if it is the empty string, return `org-default-notes-file'. In any other case, return FILE as-is."
`org-default-notes-file' instead."
(cond (cond
((equal file "") org-default-notes-file) ((equal file "") org-default-notes-file)
((org-string-nw-p file) file)
((functionp file) (funcall file)) ((functionp file) (funcall file))
((and (symbolp file) (boundp file)) (symbol-value file)) ((and (symbolp file) (boundp file)) (symbol-value file))
((consp file) (eval file))
(t file))) (t file)))
(defun org-capture-target-buffer (file) (defun org-capture-target-buffer (file)