summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2018-07-07 12:37:24 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2018-07-07 12:37:24 +0200
commit623cc4625950f84442d4cde0faa9cc3ea0233283 (patch)
treec50420696dd070bd80ed23b1fb6e93492e9a9019
parent84d87d990e378e696936eadce34f0147f9ab9c08 (diff)
downloadorg-mode-623cc4625950f84442d4cde0faa9cc3ea0233283.tar.gz
org-macro: Small refactoring
* lisp/org-macro.el (org-macro--get-property): New function. (org-macro-initialize-templates): Use new function.
-rw-r--r--lisp/org-macro.el24
1 files changed, 14 insertions, 10 deletions
diff --git a/lisp/org-macro.el b/lisp/org-macro.el
index dddc5c8..6e9a5cb 100644
--- a/lisp/org-macro.el
+++ b/lisp/org-macro.el
@@ -164,16 +164,7 @@ associated to a file, \"input-file\" and \"modification-time\"."
'("results" . "$1")
'("time" . "(eval (format-time-string $1))")
`("title" . ,(org-macro--find-keyword-value "TITLE"))
- '("property" . "(eval
- (save-excursion
- (let ((l $2))
- (when (org-string-nw-p l)
- (condition-case _
- (let ((org-link-search-must-match-exact-headline t))
- (org-link-search l nil t))
- (error
- (error \"Macro property failed: cannot find location %s\" l)))))
- (org-entry-get nil $1 'selective)))")
+ '("property" . "(eval (org-macro--get-property $1 $2))")
`("date" .
,(let* ((value (org-macro--find-keyword-value "DATE"))
(date (org-element-parse-secondary-string
@@ -319,6 +310,19 @@ Return a list of arguments, as strings. This is the opposite of
;;; Helper functions and variables for internal macros
+(defun org-macro--get-property (property location)
+ "Find PROPERTY's value at LOCATION.
+PROPERTY is a string. LOCATION is a search string, as expected
+by `org-link-search', or the empty string."
+ (save-excursion
+ (when (org-string-nw-p location)
+ (condition-case _
+ (let ((org-link-search-must-match-exact-headline t))
+ (org-link-search location nil t))
+ (error
+ (error "Macro property failed: cannot find location %s" location))))
+ (org-entry-get nil property 'selective)))
+
(defun org-macro--find-keyword-value (name)
"Find value for keyword NAME in current buffer.
KEYWORD is a string. Return value associated to the keywords