diff --git a/lisp/org-macro.el b/lisp/org-macro.el index a1b987a8e..63425eaee 100644 --- a/lisp/org-macro.el +++ b/lisp/org-macro.el @@ -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) diff --git a/testing/lisp/test-org-macro.el b/testing/lisp/test-org-macro.el index 28bc712e3..5ff37f11f 100644 --- a/testing/lisp/test-org-macro.el +++ b/testing/lisp/test-org-macro.el @@ -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{{{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{{{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{{{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{{{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.