branch: externals/org-transclusion commit d479bec65a535e339f84244235510b58fed5e9eb Author: Noboru Ota <m...@nobiot.com> Commit: Noboru Ota <m...@nobiot.com>
add: #147 support :lines for org-id link Currently `:lines` property is only supported for file links. This change enables `:lines` to org-id links in the form of `[[id:<org id> :lines]]`. Note that when this is done, Org-transclusion treats the target buffer like a normal text file, thus other Org-specific filtering properties such as `:exclude-elements` and `:only-contents` won't work as they rely on `org-elements` (that is, the target buffer needs to be treated as an Org buffer not a text buffer). --- org-transclusion-src-lines.el | 35 +++++++++++++++++++++-------------- test/test-2.1-lines.org | 2 ++ 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/org-transclusion-src-lines.el b/org-transclusion-src-lines.el index 98725b4c39..3ae40e95a8 100644 --- a/org-transclusion-src-lines.el +++ b/org-transclusion-src-lines.el @@ -17,7 +17,7 @@ ;; Author: Noboru Ota <m...@nobiot.com> ;; Created: 24 May 2021 -;; Last modified: 28 December 2021 +;; Last modified: 26 June 2022 ;;; Commentary: ;; This is an extension to `org-transclusion'. When active, it adds features @@ -73,11 +73,11 @@ Return nil if PLIST does not contain \":src\" or \":lines\" properties." (org-transclusion-content-src-lines link plist))) ;; :lines needs to be the last condition to check because :src INCLUDE :lines ((or (plist-get plist :lines) - (plist-get plist :end) + (plist-get plist :end)) ;; Link contains a search-option ::<string> ;; and NOT for an Org file - (and (org-element-property :search-option link) - (not (org-transclusion-org-file-p (org-element-property :path link))))) +;; (and (org-element-property :search-option link) +;; (not (org-transclusion-org-file-p (org-element-property :path link))))) (append '(:tc-type "lines") (org-transclusion-content-range-of-lines link plist))))) @@ -104,21 +104,28 @@ line 10. Likewise, when the second number is omitted (e.g. 10-), it means from line 10 to the end of file." (let* ((path (org-element-property :path link)) (search-option (org-element-property :search-option link)) - (buf (find-file-noselect path)) + (type (org-element-property :type link)) + (entry-pos) (buf) (lines (plist-get plist :lines)) (end-search-op (plist-get plist :end))) + (if (not (string= type "id")) (setq buf (find-file-noselect path)) + (let ((filename-pos (org-id-find path))) + (setq buf (find-file-noselect (car filename-pos))) + (setq entry-pos (cdr filename-pos)))) (when buf (with-current-buffer buf (org-with-wide-buffer - (let* ((start-pos (or (when search-option - (save-excursion - (ignore-errors - ;; FIXME `org-link-search' does not return - ;; postion when ::/regex/ and ;;number are - ;; used - (if (org-link-search search-option) - (line-beginning-position))))) - (point-min))) + (let* ((start-pos (cond + (entry-pos) + ((when search-option + (save-excursion + (ignore-errors + ;; FIXME `org-link-search' does not + ;; return postion when eithher + ;; ::/regex/ or ::number is used + (if (org-link-search search-option) + (line-beginning-position)))))) + ((point-min)))) (end-pos (when end-search-op (save-excursion (ignore-errors diff --git a/test/test-2.1-lines.org b/test/test-2.1-lines.org index 6b98e79ed9..0b3f93439e 100644 --- a/test/test-2.1-lines.org +++ b/test/test-2.1-lines.org @@ -6,6 +6,8 @@ Including lines of source code [[file:./paragraph.org::/Lorem/]] +#+transclude: [[id:2022-06-26T141859]] :lines 5-10 + #+name: source code 1 #+transclude: [[file:../org-transclusion-src-lines.el]] :lines 1-10 :src elisp #+transclude: [[file:test-src.el]] :lines 1-