From 266233164fffcf711422490772f13276ae0e0907 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Fri, 6 Jun 2014 12:04:04 -0400 Subject: [PATCH] when present resolve orig-buffer headlines w/IDs * lisp/ob-exp.el (org-babel-exp-in-export-file): Instead of using the headline text use the headline ID when one is present. This fixes a bug in the resolution of code block headers in properties during export when multiple headlines with the same name are present. --- lisp/ob-exp.el | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lisp/ob-exp.el b/lisp/ob-exp.el index 783892d92..75a00cf46 100644 --- a/lisp/ob-exp.el +++ b/lisp/ob-exp.el @@ -66,7 +66,12 @@ be executed." (defmacro org-babel-exp-in-export-file (lang &rest body) (declare (indent 1)) `(let* ((lang-headers (intern (concat "org-babel-default-header-args:" ,lang))) - (heading (nth 4 (ignore-errors (org-heading-components)))) + (heading-query (or (org-id-get) + ;; CUSTOM_IDs don't work, maybe they are + ;; stripped, or maybe they resolve too + ;; late in `org-link-search'. + ;; (org-entry-get nil "CUSTOM_ID") + (nth 4 (ignore-errors (org-heading-components))))) (export-buffer (current-buffer)) results) (when org-babel-exp-reference-buffer @@ -75,17 +80,17 @@ be executed." ;; heading in the original file (set-buffer org-babel-exp-reference-buffer) (save-restriction - (when heading + (when heading-query (condition-case nil (let ((org-link-search-inhibit-query t)) ;; TODO: When multiple headings have the same title, ;; this returns the first, which is not always ;; the right heading. Consider a better way to ;; find the proper heading. - (org-link-search heading)) - (error (when heading + (org-link-search heading-query)) + (error (when heading-query (goto-char (point-min)) - (re-search-forward (regexp-quote heading) nil t))))) + (re-search-forward (regexp-quote heading-query) nil t))))) (setq results ,@body)) (set-buffer export-buffer) results))) -- 2.11.4.GIT