Ver código fonte

org-macro: Implement "keyword" macro

* lisp/org-macro.el (org-macro-initialize-templates): Implement
  "keyword" macro.
* doc/org.texi (Macro replacement): Document new macro.

* testing/lisp/test-org-macro.el (test-org-macro/keyword): New test.
Nicolas Goaziou 7 anos atrás
pai
commit
51234f9555
3 arquivos alterados com 34 adições e 4 exclusões
  1. 8 3
      doc/org.texi
  2. 3 1
      lisp/org-macro.el
  3. 23 0
      testing/lisp/test-org-macro.el

+ 8 - 3
doc/org.texi

@@ -11080,14 +11080,19 @@ options.
 Org comes with following pre-defined macros:
 
 @table @code
-@item @{@{@{title@}@}@}
+@item @{@{@{keyword(@var{NAME})@}@}@}
+@itemx @{@{@{title@}@}@}
 @itemx @{@{@{author@}@}@}
 @itemx @{@{@{email@}@}@}
+@cindex keyword, macro
 @cindex title, macro
 @cindex author, macro
 @cindex email, macro
-Org replaces these macro references with available information at the time of
-export.
+The @samp{keyword} macro collects all values from @var{NAME} keywords
+throughout the buffer, separated with white space.  @samp{title},
+@samp{author} and @samp{email} macros are shortcuts for, respectively,
+@samp{@{@{@{keyword(TITLE)@}@}@}}, @samp{@{@{@{keyword(AUTHOR)@}@}@}} and
+@samp{@{@{@{keyword(EMAIL)@}@}@}}.
 
 @item @{@{@{date@}@}@}
 @itemx @{@{@{date(@var{FORMAT})@}@}@}

+ 3 - 1
lisp/org-macro.el

@@ -136,7 +136,8 @@ function installs the following ones: \"property\",
 	    (let ((old-template (assoc (car cell) templates)))
 	      (if old-template (setcdr old-template (cdr cell))
 		(push cell templates))))))
-    ;; Install "author, "date, "email", "title" and "results" macros.
+    ;; Install "author, "date, "email", "keyword", "title" and
+    ;; "results" macros.
     (mapc update-templates
 	  (list
 	   (cons "author" (org-macro--find-keyword-value "AUTHOR"))
@@ -153,6 +154,7 @@ function installs the following ones: \"property\",
 			       value)
 		     value)))
 	   (cons "email" (org-macro--find-keyword-value "EMAIL"))
+	   (cons "keyword" "(eval (org-macro--find-keyword-value \"$1\"))")
 	   (cons "results" "$1")
 	   (cons "title" (org-macro--find-keyword-value "TITLE"))))
     ;; Install "property", "time" macros.

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

@@ -322,6 +322,29 @@
             (buffer-substring-no-properties
              (line-beginning-position) (line-end-position))))))
 
+(ert-deftest test-org-macro/keyword ()
+  "Test {{{keyword}}} macro."
+  ;; Replace macro with keyword's value.
+  (should
+   (equal
+    "value"
+    (org-test-with-temp-text
+	"#+keyword: value\n<point>{{{keyword(KEYWORD)}}}"
+      (org-macro-initialize-templates)
+      (org-macro-replace-all org-macro-templates)
+      (buffer-substring-no-properties
+       (line-beginning-position) (point-max)))))
+  ;; Replace macro with keyword's value.
+  (should
+   (equal
+    "value value2"
+    (org-test-with-temp-text
+	"#+keyword: value\n#+keyword: value2\n<point>{{{keyword(KEYWORD)}}}"
+      (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.