From 623cc4625950f84442d4cde0faa9cc3ea0233283 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sat, 7 Jul 2018 12:37:24 +0200 Subject: [PATCH] org-macro: Small refactoring * lisp/org-macro.el (org-macro--get-property): New function. (org-macro-initialize-templates): Use new function. --- lisp/org-macro.el | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/lisp/org-macro.el b/lisp/org-macro.el index dddc5c899..6e9a5cb7d 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