forked from mirrors/org-mode
Merge branch 'maint'
This commit is contained in:
commit
57bf6bbbde
|
@ -52,11 +52,7 @@
|
||||||
|
|
||||||
(declare-function org-element-at-point "org-element" ())
|
(declare-function org-element-at-point "org-element" ())
|
||||||
(declare-function org-element-context "org-element" (&optional element))
|
(declare-function org-element-context "org-element" (&optional element))
|
||||||
(declare-function org-element-map "org-element"
|
(declare-function org-element-macro-parser "org-element" ())
|
||||||
(data types fun &optional info first-match no-recursion
|
|
||||||
with-affiliated))
|
|
||||||
(declare-function org-element-parse-buffer "org-element"
|
|
||||||
(&optional granularity visible-only))
|
|
||||||
(declare-function org-element-property "org-element" (property element))
|
(declare-function org-element-property "org-element" (property element))
|
||||||
(declare-function org-element-type "org-element" (element))
|
(declare-function org-element-type "org-element" (element))
|
||||||
(declare-function org-file-contents "org" (file &optional noerror))
|
(declare-function org-file-contents "org" (file &optional noerror))
|
||||||
|
@ -197,55 +193,53 @@ found in the buffer with no definition in TEMPLATES.
|
||||||
|
|
||||||
Optional argument KEYWORDS, when non-nil is a list of keywords,
|
Optional argument KEYWORDS, when non-nil is a list of keywords,
|
||||||
as strings, where macro expansion is allowed."
|
as strings, where macro expansion is allowed."
|
||||||
(org-with-wide-buffer
|
(save-excursion
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(let ((properties-regexp
|
(let ((properties-regexp
|
||||||
(format "\\`EXPORT_%s\\+?\\'" (regexp-opt keywords)))
|
(format "\\`EXPORT_%s\\+?\\'" (regexp-opt keywords)))
|
||||||
record)
|
record)
|
||||||
(while (re-search-forward "{{{[-A-Za-z0-9_]" nil t)
|
(while (re-search-forward "{{{[-A-Za-z0-9_]" nil t)
|
||||||
(let* ((datum (save-match-data (org-element-context)))
|
(let* ((datum (save-match-data (org-element-context)))
|
||||||
(type (org-element-type datum))
|
(type (org-element-type datum))
|
||||||
(macro
|
(macro
|
||||||
(cond
|
(cond
|
||||||
((eq type 'macro) datum)
|
((eq type 'macro) datum)
|
||||||
;; In parsed keywords and associated node properties,
|
;; In parsed keywords and associated node properties,
|
||||||
;; force macro recognition.
|
;; force macro recognition.
|
||||||
((or (and (eq type 'keyword)
|
((or (and (eq type 'keyword)
|
||||||
(member (org-element-property :key datum) keywords))
|
(member (org-element-property :key datum) keywords))
|
||||||
(and (eq type 'node-property)
|
(and (eq type 'node-property)
|
||||||
(string-match-p
|
(string-match-p properties-regexp
|
||||||
properties-regexp
|
(org-element-property :key datum))))
|
||||||
(org-element-property :key datum))))
|
(save-excursion
|
||||||
(save-restriction
|
(goto-char (match-beginning 0))
|
||||||
(narrow-to-region (match-beginning 0) (line-end-position))
|
(org-element-macro-parser))))))
|
||||||
(org-element-map (org-element-parse-buffer) 'macro
|
(when macro
|
||||||
#'identity nil t))))))
|
(let* ((value (org-macro-expand macro templates))
|
||||||
(when macro
|
(begin (org-element-property :begin macro))
|
||||||
(let* ((value (org-macro-expand macro templates))
|
(signature (list begin
|
||||||
(begin (org-element-property :begin macro))
|
macro
|
||||||
(signature (list begin
|
(org-element-property :args macro))))
|
||||||
macro
|
;; Avoid circular dependencies by checking if the same
|
||||||
(org-element-property :args macro))))
|
;; macro with the same arguments is expanded at the same
|
||||||
;; Avoid circular dependencies by checking if the same
|
;; position twice.
|
||||||
;; macro with the same arguments is expanded at the same
|
(cond ((member signature record)
|
||||||
;; position twice.
|
(error "Circular macro expansion: %s"
|
||||||
(cond ((member signature record)
|
(org-element-property :key macro)))
|
||||||
(error "Circular macro expansion: %s"
|
(value
|
||||||
(org-element-property :key macro)))
|
(push signature record)
|
||||||
(value
|
(delete-region
|
||||||
(push signature record)
|
begin
|
||||||
(delete-region
|
;; Preserve white spaces after the macro.
|
||||||
begin
|
(progn (goto-char (org-element-property :end macro))
|
||||||
;; Preserve white spaces after the macro.
|
(skip-chars-backward " \t")
|
||||||
(progn (goto-char (org-element-property :end macro))
|
(point)))
|
||||||
(skip-chars-backward " \t")
|
;; Leave point before replacement in case of
|
||||||
(point)))
|
;; recursive expansions.
|
||||||
;; Leave point before replacement in case of
|
(save-excursion (insert value)))
|
||||||
;; recursive expansions.
|
(finalize
|
||||||
(save-excursion (insert value)))
|
(error "Undefined Org macro: %s; aborting"
|
||||||
(finalize
|
(org-element-property :key macro)))))))))))
|
||||||
(error "Undefined Org macro: %s; aborting"
|
|
||||||
(org-element-property :key macro)))))))))))
|
|
||||||
|
|
||||||
(defun org-macro-escape-arguments (&rest args)
|
(defun org-macro-escape-arguments (&rest args)
|
||||||
"Build macro's arguments string from ARGS.
|
"Build macro's arguments string from ARGS.
|
||||||
|
|
|
@ -77,8 +77,8 @@
|
||||||
(buffer-string))))
|
(buffer-string))))
|
||||||
;; Macro expansion ignores narrowing.
|
;; Macro expansion ignores narrowing.
|
||||||
(should
|
(should
|
||||||
(string-match
|
(string-match-p
|
||||||
"expansion"
|
"{{{macro}}}"
|
||||||
(org-test-with-temp-text
|
(org-test-with-temp-text
|
||||||
"#+MACRO: macro expansion\n{{{macro}}}\n<point>Contents"
|
"#+MACRO: macro expansion\n{{{macro}}}\n<point>Contents"
|
||||||
(narrow-to-region (point) (point-max))
|
(narrow-to-region (point) (point-max))
|
||||||
|
|
Loading…
Reference in a new issue