From 0e5de0ff6476ac9ee95ccb0ded17540e7b22b5ff Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Wed, 18 Jan 2023 11:41:03 +0300 Subject: [PATCH] org-export-expand-include-keyword: Fix relative links in recursive includes * lisp/ox.el (org-export-expand-include-keyword): Add new optional argument INCLUDER-FILE to explicitly pass the includer file path when expanding inside a temporary buffer. Pass the INCLUDER-FILE later during recursive expansion. Reported-by: Gabriel Petrini da Silveira Link: https://orgmode.org/list/CAHCA-UvaqnegPYfpPcJCqiY8+dDoj0pfX0vDckUui-MCj3wq5A@mail.gmail.com --- lisp/ox.el | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/lisp/ox.el b/lisp/ox.el index 07f789361..b9c57321f 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -3283,15 +3283,24 @@ locally for the subtree through node properties." (downcase (car key)) (if (org-string-nw-p val) (format " %s" val) "")))))))) -(defun org-export-expand-include-keyword (&optional included dir footnotes) +(defun org-export-expand-include-keyword (&optional included dir footnotes includer-file) "Expand every include keyword in buffer. + Optional argument INCLUDED is a list of included file names along with their line restriction, when appropriate. It is used to -avoid infinite recursion. Optional argument DIR is the current -working directory. It is used to properly resolve relative -paths. Optional argument FOOTNOTES is a hash-table used for -storing and resolving footnotes. It is created automatically." - (let ((includer-file (buffer-file-name (buffer-base-buffer))) +avoid infinite recursion. + +Optional argument DIR is the current working directory. It is used to +properly resolve relative paths. + +Optional argument FOOTNOTES is a hash-table used for +storing and resolving footnotes. It is created automatically. + +Optional argument INCLUDER-FILE is the file path corresponding to the +buffer contents being included. It is used when current buffer does +not have `buffer-file-name' assigned." + (let ((includer-file (or includer-file + (buffer-file-name (buffer-base-buffer)))) (case-fold-search t) (file-prefix (make-hash-table :test #'equal)) (current-prefix 0) @@ -3422,7 +3431,7 @@ storing and resolving footnotes. It is created automatically." (cons (list file lines) included) (unless (org-url-p file) (file-name-directory file)) - footnotes) + footnotes includer-file) (buffer-string))))) ;; Expand footnotes after all files have been ;; included. Footnotes are stored at end of buffer.