mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-11-24 07:20:29 +00:00
org-macro: Fix {{{author}}} expansion without AUTHOR keyword
* lisp/org-macro.el (org-macro--set-template): Allow setting a nil value, which becomes an empty template. * testing/lisp/test-org-macro.el (test-org-macro/author): (test-org-macro/email): (test-org-macro/title): New tests. Reported-by: "Dauer, Michael" <michael.dauer@smartpm.com> <http://lists.gnu.org/r/emacs-orgmode/2020-03/msg00094.html>
This commit is contained in:
parent
01ee25c605
commit
965cdbfd4b
@ -88,11 +88,10 @@ directly, use instead:
|
||||
VALUE is the template of the macro. The new value override the
|
||||
previous one, unless VALUE is nil. TEMPLATES is the list of
|
||||
templates. Return the updated list."
|
||||
(when value
|
||||
(let ((old-definition (assoc name templates)))
|
||||
(if old-definition
|
||||
(setcdr old-definition value)
|
||||
(push (cons name value) templates))))
|
||||
(let ((old-definition (assoc name templates)))
|
||||
(if (and value old-definition)
|
||||
(setcdr old-definition value)
|
||||
(push (cons name (or value "")) templates)))
|
||||
templates)
|
||||
|
||||
(defun org-macro--collect-macros (&optional files templates)
|
||||
|
@ -304,6 +304,72 @@
|
||||
(buffer-substring-no-properties
|
||||
(line-beginning-position) (point-max))))))
|
||||
|
||||
(ert-deftest test-org-macro/author ()
|
||||
"Test {{{author}}} macro."
|
||||
;; Return AUTHOR keyword value.
|
||||
(should
|
||||
(equal "me"
|
||||
(org-test-with-temp-text "#+author: me\n<point>{{{author}}}"
|
||||
(org-macro-initialize-templates)
|
||||
(org-macro-replace-all org-macro-templates)
|
||||
(buffer-substring-no-properties
|
||||
(line-beginning-position) (point-max)))))
|
||||
;; When AUTHOR keyword is missing, return the empty string.
|
||||
(should
|
||||
(equal ""
|
||||
(org-test-with-temp-text "{{{author}}}"
|
||||
(org-macro-initialize-templates)
|
||||
(org-macro-replace-all org-macro-templates)
|
||||
(buffer-substring-no-properties
|
||||
(line-beginning-position) (point-max))))))
|
||||
|
||||
(ert-deftest test-org-macro/email ()
|
||||
"Test {{{email}}} macro."
|
||||
;; Return EMAIL keyword value.
|
||||
(should
|
||||
(equal "me@home"
|
||||
(org-test-with-temp-text "#+email: me@home\n<point>{{{email}}}"
|
||||
(org-macro-initialize-templates)
|
||||
(org-macro-replace-all org-macro-templates)
|
||||
(buffer-substring-no-properties
|
||||
(line-beginning-position) (point-max)))))
|
||||
;; When EMAIL keyword is missing, return the empty string.
|
||||
(should
|
||||
(equal ""
|
||||
(org-test-with-temp-text "{{{email}}}"
|
||||
(org-macro-initialize-templates)
|
||||
(org-macro-replace-all org-macro-templates)
|
||||
(buffer-substring-no-properties
|
||||
(line-beginning-position) (point-max))))))
|
||||
|
||||
(ert-deftest test-org-macro/title ()
|
||||
"Test {{{title}}} macro."
|
||||
;; Return TITLE keyword value.
|
||||
(should
|
||||
(equal "Foo!"
|
||||
(org-test-with-temp-text "#+title: Foo!\n<point>{{{title}}}"
|
||||
(org-macro-initialize-templates)
|
||||
(org-macro-replace-all org-macro-templates)
|
||||
(buffer-substring-no-properties
|
||||
(line-beginning-position) (point-max)))))
|
||||
;; When TITLE keyword is missing, return the empty string.
|
||||
(should
|
||||
(equal ""
|
||||
(org-test-with-temp-text "{{{title}}}"
|
||||
(org-macro-initialize-templates)
|
||||
(org-macro-replace-all org-macro-templates)
|
||||
(buffer-substring-no-properties
|
||||
(line-beginning-position) (point-max)))))
|
||||
;; When multiple TITLE keywords are used, concatenate them.
|
||||
(should
|
||||
(equal "Foo Bar!"
|
||||
(org-test-with-temp-text
|
||||
"#+title: Foo\n#+title: Bar!\n<point>{{{title}}}"
|
||||
(org-macro-initialize-templates)
|
||||
(org-macro-replace-all org-macro-templates)
|
||||
(buffer-substring-no-properties
|
||||
(line-beginning-position) (point-max))))))
|
||||
|
||||
(ert-deftest test-org-macro/escape-arguments ()
|
||||
"Test `org-macro-escape-arguments' specifications."
|
||||
;; Regular tests.
|
||||
|
Loading…
Reference in New Issue
Block a user