Browse Source

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'.
Nicolas Goaziou 3 years ago
parent
commit
f5645675a3
3 changed files with 22 additions and 10 deletions
  1. 2 2
      doc/org.texi
  2. 15 0
      etc/ORG-NEWS
  3. 5 8
      lisp/org-capture.el

+ 2 - 2
doc/org.texi

@@ -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.  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
-also be given as a variable, function, or Emacs Lisp form.  When an absolute
-path is not specified for a target, it is taken as relative to
+also be given as a variable or as a function called with no argument.  When
+an absolute path is not specified for a target, it is taken as relative to
 @code{org-directory}.
 
 Valid values are:

+ 15 - 0
etc/ORG-NEWS

@@ -8,6 +8,21 @@ See the end of the file for license conditions.
 
 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
 
 ** Incompatible changes

+ 5 - 8
lisp/org-capture.el

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