summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2017-11-21 23:20:20 +0100
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2017-11-21 23:38:24 +0100
commit51234f9555b4652627f37f1b4bc8b9dc172d20c3 (patch)
tree6fe85a7f73e9aa8d61432a3fa931cdac376b7302
parent5f5d82ed516b7b385a9258271becbfa247e94af3 (diff)
downloadorg-mode-51234f9555b4652627f37f1b4bc8b9dc172d20c3.tar.gz
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.
-rw-r--r--doc/org.texi11
-rw-r--r--lisp/org-macro.el4
-rw-r--r--testing/lisp/test-org-macro.el23
3 files changed, 34 insertions, 4 deletions
diff --git a/doc/org.texi b/doc/org.texi
index babe7d6..2ef24ed 100644
--- a/doc/org.texi
+++ b/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})@}@}@}
diff --git a/lisp/org-macro.el b/lisp/org-macro.el
index f78eaf0..e2f70a2 100644
--- a/lisp/org-macro.el
+++ b/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.
diff --git a/testing/lisp/test-org-macro.el b/testing/lisp/test-org-macro.el
index 5650dca..ff542f8 100644
--- a/testing/lisp/test-org-macro.el
+++ b/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.