nobiot / org-transclusion

Emacs package to enable transclusion with Org Mode
https://nobiot.github.io/org-transclusion/
GNU General Public License v3.0
902 stars 43 forks source link

Add support for ::line-number in file-type links #241

Closed akashpal-21 closed 2 months ago

akashpal-21 commented 3 months ago

Lightly tested in org-mode -- will test more and update later in time

(defun custom/org-transclusion-content-org-link (link plist)
  "Return a list of payload from Org LINK object and PLIST.
  This function is intended to be used for Org-ID.  It delegates the
  work to
`org-transclusion-content-org-buffer-or-element'."
  (save-excursion
    ;; First visit the buffer and go to the relevant element if
    ;; search-option is present.
    (let* ((path (org-element-property :path link))
           (search-option (org-element-property :search-option link))

      (search-option-numberp (if (and search-option (string-match "\\`\\([0-9]+\\)\\'" search-option))
                    t
                      nil))

       (buf (find-file-noselect path))

           (org-link-search-must-match-exact-headline
            ;; Don't ever prompt to create a headline when transcluding
            (if (eq 'query-to-create org-link-search-must-match-exact-headline)
        t
              org-link-search-must-match-exact-headline)))

       (with-current-buffer buf
             (org-with-wide-buffer
              (org-transclusion-content-org-buffer-or-element
               (cond
        (search-option-numberp                             
         (goto-line (string-to-number search-option))
         t)
        ((stringp search-option)                          
         (org-link-search search-option)
         t)
           (t nil))
               plist)))
       )))

(advice-add 'org-transclusion-content-org-link :override #'custom/org-transclusion-content-org-link)

Updates