ソースを参照

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>
Nicolas Goaziou 5 年 前
コミット
4cf8ffdba6
2 ファイル変更70 行追加5 行削除
  1. 4 5
      lisp/org-macro.el
  2. 66 0
      testing/lisp/test-org-macro.el

+ 4 - 5
lisp/org-macro.el

@@ -88,11 +88,10 @@ directly, use instead:
 VALUE is the template of the macro.  The new value override the
 VALUE is the template of the macro.  The new value override the
 previous one, unless VALUE is nil.  TEMPLATES is the list of
 previous one, unless VALUE is nil.  TEMPLATES is the list of
 templates.  Return the updated list."
 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)
   templates)
 
 
 (defun org-macro--collect-macros (&optional files templates)
 (defun org-macro--collect-macros (&optional files templates)

+ 66 - 0
testing/lisp/test-org-macro.el

@@ -304,6 +304,72 @@
       (buffer-substring-no-properties
       (buffer-substring-no-properties
        (line-beginning-position) (point-max))))))
        (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 ()
 (ert-deftest test-org-macro/escape-arguments ()
   "Test `org-macro-escape-arguments' specifications."
   "Test `org-macro-escape-arguments' specifications."
   ;; Regular tests.
   ;; Regular tests.