From: Jens Neuhalfen <email@example.com>
Subject: [SUGGESTION] Allow EXPORT_FILE_NAME to use elisp
Date: Sat, 05 Dec 2020 20:26:32 +0100 [thread overview]
Message-ID: <firstname.lastname@example.org> (raw)
I wrote a patch that allows the users to generate
the exported filename via elisp in EXPORT_FILE_NAME.
This suggestion encourages to reuse configuration (e.g. the document version
or title) in the export filename. A common use case when writing
documentation is that different versions of the document will be
exported over time. These are then distributed, e.g. via e-mail or
archived. By allowing the user to derive descriptive names during export
exchange of the document is greatly simplified.
E.g. the following excerpt will create a filename that contains the date
of export, the document title and the document version:
#+TITLE: My wonderful document
#+EXPORT_FILE_NAME: `(format "%s-%s (v%s)" (org-format-time-string "%Y-%m-%d_%Hh%Mm" (org-current-time)) (org-macro--find-keyword-value "TITLE") (org-macro--find-keyword-value "X-DOCUMENT-VERSION"))`
Including the patch would make the life of "document writers" easier by
improving the consistency of their work. Just including the document
version in the filename would make it easier to exchange documents with
others. Allowing pure lisp is just the next step.
The gist of the patch is attached below. The whole patch is still
As soon as I have the papers with the fsf signed, I can send the
SECURITY CONSIDERATION: Since running elisp on export is a security
risk I am looking for advice on how to make sure the user knows.
Any suggestions on how to achieve that?
diff --git a/lisp/ox.el b/lisp/ox.el
index 6dd2cd4a0..b79880666 100644
@@ -6147,6 +6147,14 @@ to `:default' encoding. If it fails, return S."
(plist-get translations :default)
+ "A regexp to recognize an anchored lisp-expression between backticks.
+Spaces before and after the backticks are ignored.
+The syntax of the expression is not validated.")
;;; Asynchronous Export
@@ -6390,6 +6398,16 @@ or FILE."
(or (and (functionp post-process) (funcall post-process file))
+(defun org-export-output-file-name--expand-name (file-name)
+ "If the filename is surrounded by `EXPR` then EXPR is evaluated and returned.
+ Otherwise return FILE-NAME"
+ (if (string-match org-export--backquote-lisp-expression-regexp file-name)
+ (let ((expression (match-string 1 file-name)))
+ (eval (car (read-from-string expression)))
(defun org-export-output-file-name (extension &optional subtreep pub-dir)
"Return output file's name according to buffer specifications.
@@ -6400,6 +6418,16 @@ With a non-nil optional argument SUBTREEP, try to determine
output file's name by looking for \"EXPORT_FILE_NAME\" property
of subtree at point.
+If the filename (without extension) is enclosed in backticks, then
+the text between the backticks is evaluated and the result is taken
+as file name.
+#+EXPORT_FILE_NAME: `(format \"This is a %s\" \"test\")`
+will evaluate to \"This is a test\".
When optional argument PUB-DIR is set, use it as the publishing
@@ -6407,7 +6435,7 @@ Return file name as a string."
(let* ((visited-file (buffer-file-name (buffer-base-buffer)))
+ (org-export-output-file-name--expand-name (file-name-sans-extension
;; Check EXPORT_FILE_NAME subtree property.
(and subtreep (org-entry-get nil "EXPORT_FILE_NAME" 'selective))
@@ -6426,7 +6454,7 @@ Return file name as a string."
;; Can't determine file name on our own: ask user.
"Output file: " pub-dir nil nil nil
- (lambda (n) (string= extension (file-name-extension n t))))))
+ (lambda (n) (string= extension (file-name-extension n t)))))))
;; Build file name. Enforce EXTENSION over whatever user
reply other threads:[~2020-12-06 15:29 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).