mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2025-01-18 18:51:52 +00:00
Fix c9a52787c1
* lisp/org-macro.el (org-macro--collect-macros): Ignore macro definitions in commented subtrees. * lisp/ox.el (org-export--get-inbuffer-options): Ignore options in commented subtrees. (org-export--delete-commented-subtrees): Remove function. (org-export-as): Apply removal. Removing the whole subtree is not subtle as Babel might want to use data there. Reported-by: Robert Klein <RoKlein@roklein.de> <http://permalink.gmane.org/gmane.emacs.orgmode/96347>
This commit is contained in:
parent
ec54a5852d
commit
359572d37e
@ -83,28 +83,31 @@ Return an alist containing all macro templates found."
|
||||
(goto-char (point-min))
|
||||
(while (re-search-forward
|
||||
"^[ \t]*#\\+\\(MACRO\\|SETUPFILE\\):" nil t)
|
||||
(let ((element (org-element-at-point)))
|
||||
(when (eq (org-element-type element) 'keyword)
|
||||
(let ((val (org-element-property :value element)))
|
||||
(if (equal (org-element-property :key element) "MACRO")
|
||||
;; Install macro in TEMPLATES.
|
||||
(when (string-match
|
||||
"^\\(.*?\\)\\(?:\\s-+\\(.*\\)\\)?\\s-*$" val)
|
||||
(let* ((name (match-string 1 val))
|
||||
(template (or (match-string 2 val) ""))
|
||||
(old-cell (assoc name templates)))
|
||||
(if old-cell (setcdr old-cell template)
|
||||
(push (cons name template) templates))))
|
||||
;; Enter setup file.
|
||||
(let ((file (expand-file-name
|
||||
(org-remove-double-quotes val))))
|
||||
(unless (member file files)
|
||||
(with-temp-buffer
|
||||
(org-mode)
|
||||
(insert (org-file-contents file 'noerror))
|
||||
(setq templates
|
||||
(funcall collect-macros (cons file files)
|
||||
templates)))))))))))
|
||||
(if (org-in-commented-heading-p) (outline-next-heading)
|
||||
(let ((element (org-element-at-point)))
|
||||
(when (eq (org-element-type element) 'keyword)
|
||||
(let ((val (org-element-property :value element)))
|
||||
(if (equal (org-element-property :key element) "MACRO")
|
||||
;; Install macro in TEMPLATES.
|
||||
(when (string-match
|
||||
"^\\(.*?\\)\\(?:\\s-+\\(.*\\)\\)?\\s-*$"
|
||||
val)
|
||||
(let* ((name (match-string 1 val))
|
||||
(template (or (match-string 2 val) ""))
|
||||
(old-cell (assoc name templates)))
|
||||
(if old-cell (setcdr old-cell template)
|
||||
(push (cons name template) templates))))
|
||||
;; Enter setup file.
|
||||
(let ((file (expand-file-name
|
||||
(org-remove-double-quotes val))))
|
||||
(unless (member file files)
|
||||
(with-temp-buffer
|
||||
(org-mode)
|
||||
(insert (org-file-contents file 'noerror))
|
||||
(setq templates
|
||||
(funcall collect-macros
|
||||
(cons file files)
|
||||
templates))))))))))))
|
||||
templates))))
|
||||
(funcall collect-macros nil nil)))
|
||||
|
||||
|
130
lisp/ox.el
130
lisp/ox.el
@ -1479,7 +1479,7 @@ Assume buffer is in Org mode. Narrowing, if any, is ignored."
|
||||
(and backend (org-export-get-all-options backend))
|
||||
org-export-options-alist))
|
||||
(regexp (format "^[ \t]*#\\+%s:"
|
||||
(regexp-opt (nconc (delq nil (mapcar 'cadr options))
|
||||
(regexp-opt (nconc (delq nil (mapcar #'cadr options))
|
||||
org-export-special-keywords))))
|
||||
(find-properties
|
||||
(lambda (keyword)
|
||||
@ -1496,62 +1496,67 @@ Assume buffer is in Org mode. Narrowing, if any, is ignored."
|
||||
(org-with-wide-buffer
|
||||
(goto-char (point-min))
|
||||
(while (re-search-forward regexp nil t)
|
||||
(let ((element (org-element-at-point)))
|
||||
(when (eq (org-element-type element) 'keyword)
|
||||
(let ((key (org-element-property :key element))
|
||||
(val (org-element-property :value element)))
|
||||
(cond
|
||||
;; Options in `org-export-special-keywords'.
|
||||
((equal key "SETUPFILE")
|
||||
(let ((file (expand-file-name
|
||||
(org-remove-double-quotes (org-trim val)))))
|
||||
;; Avoid circular dependencies.
|
||||
(unless (member file files)
|
||||
(with-temp-buffer
|
||||
(insert (org-file-contents file 'noerror))
|
||||
(let ((org-inhibit-startup t)) (org-mode))
|
||||
(setq plist (funcall get-options
|
||||
(cons file files) plist))))))
|
||||
((equal key "OPTIONS")
|
||||
(setq plist
|
||||
(org-combine-plists
|
||||
plist
|
||||
(org-export--parse-option-keyword val backend))))
|
||||
((equal key "FILETAGS")
|
||||
(setq plist
|
||||
(org-combine-plists
|
||||
plist
|
||||
(list :filetags
|
||||
(org-uniquify
|
||||
(append (org-split-string val ":")
|
||||
(plist-get plist :filetags)))))))
|
||||
(t
|
||||
;; Options in `org-export-options-alist'.
|
||||
(dolist (property (funcall find-properties key))
|
||||
(let ((behaviour (nth 4 (assq property options))))
|
||||
(setq plist
|
||||
(plist-put
|
||||
plist property
|
||||
;; Handle value depending on specified
|
||||
;; BEHAVIOR.
|
||||
(case behaviour
|
||||
(space
|
||||
(if (not (plist-get plist property))
|
||||
(org-trim val)
|
||||
(concat (plist-get plist property)
|
||||
" "
|
||||
(org-trim val))))
|
||||
(newline
|
||||
(org-trim
|
||||
(concat (plist-get plist property)
|
||||
"\n"
|
||||
(org-trim val))))
|
||||
(split `(,@(plist-get plist property)
|
||||
,@(org-split-string val)))
|
||||
('t val)
|
||||
(otherwise
|
||||
(if (not (plist-member plist property)) val
|
||||
(plist-get plist property))))))))))))))
|
||||
(if (org-in-commented-heading-p) (outline-next-heading)
|
||||
(let ((element (org-element-at-point)))
|
||||
(when (eq (org-element-type element) 'keyword)
|
||||
(let ((key (org-element-property :key element))
|
||||
(val (org-element-property :value element)))
|
||||
(cond
|
||||
;; Options in `org-export-special-keywords'.
|
||||
((equal key "SETUPFILE")
|
||||
(let ((file (expand-file-name
|
||||
(org-remove-double-quotes
|
||||
(org-trim val)))))
|
||||
;; Avoid circular dependencies.
|
||||
(unless (member file files)
|
||||
(with-temp-buffer
|
||||
(insert (org-file-contents file 'noerror))
|
||||
(let ((org-inhibit-startup t)) (org-mode))
|
||||
(setq plist
|
||||
(funcall get-options
|
||||
(cons file files) plist))))))
|
||||
((equal key "OPTIONS")
|
||||
(setq plist
|
||||
(org-combine-plists
|
||||
plist
|
||||
(org-export--parse-option-keyword
|
||||
val backend))))
|
||||
((equal key "FILETAGS")
|
||||
(setq plist
|
||||
(org-combine-plists
|
||||
plist
|
||||
(list :filetags
|
||||
(org-uniquify
|
||||
(append (org-split-string val ":")
|
||||
(plist-get plist :filetags)))))))
|
||||
(t
|
||||
;; Options in `org-export-options-alist'.
|
||||
(dolist (property (funcall find-properties key))
|
||||
(let ((behaviour (nth 4 (assq property options))))
|
||||
(setq plist
|
||||
(plist-put
|
||||
plist property
|
||||
;; Handle value depending on
|
||||
;; specified BEHAVIOUR.
|
||||
(case behaviour
|
||||
(space
|
||||
(if (not (plist-get plist property))
|
||||
(org-trim val)
|
||||
(concat (plist-get plist property)
|
||||
" "
|
||||
(org-trim val))))
|
||||
(newline
|
||||
(org-trim
|
||||
(concat (plist-get plist property)
|
||||
"\n"
|
||||
(org-trim val))))
|
||||
(split `(,@(plist-get plist property)
|
||||
,@(org-split-string val)))
|
||||
((t) val)
|
||||
(otherwise
|
||||
(if (plist-member plist property)
|
||||
(plist-get plist property)
|
||||
val))))))))))))))
|
||||
;; Return final value.
|
||||
plist))))
|
||||
;; Read options in the current buffer.
|
||||
@ -2665,16 +2670,6 @@ The function assumes BUFFER's major mode is `org-mode'."
|
||||
(overlays-in (point-min) (point-max)))
|
||||
ov-set)))))
|
||||
|
||||
(defun org-export--delete-commented-subtrees ()
|
||||
"Delete commented subtrees or inlinetasks in the buffer."
|
||||
(org-with-wide-buffer
|
||||
(goto-char (point-min))
|
||||
(let ((regexp (concat org-outline-regexp-bol org-comment-string)))
|
||||
(while (re-search-forward regexp nil t)
|
||||
(delete-region
|
||||
(line-beginning-position)
|
||||
(org-element-property :end (org-element-at-point)))))))
|
||||
|
||||
(defun org-export--prune-tree (data info)
|
||||
"Prune non exportable elements from DATA.
|
||||
DATA is the parse tree to traverse. INFO is the plist holding
|
||||
@ -2865,7 +2860,6 @@ Return code as a string."
|
||||
(run-hook-with-args 'org-export-before-processing-hook
|
||||
(org-export-backend-name backend))
|
||||
(org-export-expand-include-keyword)
|
||||
(org-export--delete-commented-subtrees)
|
||||
;; Update macro templates since #+INCLUDE keywords might have
|
||||
;; added some new ones.
|
||||
(org-macro-initialize-templates)
|
||||
|
@ -48,7 +48,6 @@ body to execute. Parse tree is available under the `tree'
|
||||
variable, and communication channel under `info'."
|
||||
(declare (debug (form body)) (indent 1))
|
||||
`(org-test-with-temp-text ,data
|
||||
(org-export--delete-commented-subtrees)
|
||||
(let* ((tree (org-element-parse-buffer))
|
||||
(info (org-export-get-environment)))
|
||||
(org-export--prune-tree tree info)
|
||||
|
Loading…
Reference in New Issue
Block a user