I played with it a bit. Here is a link that displays file links as
overlays. Clicking on them jump to the source, and C-click will toggle
the overlay. It works ok, but I didn't test it a lot.

Say you have a table named like this in a file.

#+name: test
| 555 | 66      |
|  te | tef     |
| 555 | ftre 5f |
| 555 | ftre 5f |

This link will display the table.

transclude:file:transcluding-org-elements.org::test                        

This link will display the headline named archive.

transclude:file:transcluding-org-elements.org::*archive


Here is the code. 

#+BEGIN_SRC emacs-lisp :results silent
(defvar *transclude* t "Put overlays on or not")
(setq *transclude* t)

(org-link-set-parameters
 "transclude"
 :face '(:background "gray80")
 :follow (lambda (path)
           (org-open-link-from-string path))
 :keymap (let ((map (copy-keymap org-mouse-map)))
           (define-key map [C-mouse-1] (lambda ()
                                         (interactive)
                                         (setq *transclude* (not *transclude*))
                                         (unless *transclude*
                                           (ov-clear 'transclude))
                                         (font-lock-fontify-buffer)))
           map)
 :help-echo "Transcluded element. Click to open source. C-mouse-1 to toggle 
overlay."
 :activate-func (lambda (start end path bracketp)
                  (if *transclude*
                      (let ((ov (make-overlay start end))
                            el disp)
                        (ov-put ov 'transclude t)
                        (save-window-excursion
                          (org-open-link-from-string path)
                          (setq el (org-element-context))
                          (setq disp (buffer-substring
                                      (org-element-property :begin el)
                                      (- (org-element-property :end el)
                                         (or (org-element-property :post-blank 
el) 0))))
                          (ov-put ov 'display disp)))
                    (ov-clear 'transclude 'any start end))))
#+END_SRC



Matt Price writes:

> On Wed, Dec 14, 2016 at 11:55 AM, John Kitchin <jkitc...@andrew.cmu.edu>
> wrote:
>
>>
>> David Talmage writes:
>>
>> > On Fri, Dec 9, 2016 at 11:28 AM, Eric S Fraga <e.fr...@ucl.ac.uk> wrote:
>> >
>> >> On Friday,  9 Dec 2016 at 15:29, John Kitchin wrote:
>> >> > Hi all,
>> >> >
>> >> > I have an idea for how I could transclude "copies" or links to
>> >>
>> >> [...]
>> >>
>> >> > Any thoughts? Do you see any potential issues?
>> >>
>> >> Potentially very interesting and useful idea.  Some thoughts/issues:
>> >>
>> >>
>> > I'm interested in this, too.  In my lab notebook org file, I have a
>> section
>> > that should be put into its own file and either linked or transcluded in
>> > several places.  Transclusion would be better because I could see the
>> text
>> > without following a link.  It suits my lazy nature. ;-)
>>
>> It turns out to be pretty easy to see the text; that can be done with a
>> simple overlay. What is not easy, is to be able to edit the text, or use
>> the text with org-machinery, e.g. org-map-entries. The text in the
>> overlay is not visible to the org-machinery, so you can not get
>> properties, edit it, etc... Editing could be made possible with a
>> special buffer, but it doesn't seem likely that you can make the overlay
>> display work with many org-functions.
>>
> Have you had an opportunity to work o nthis at all?  For my purposes, even
> having the transcluded text visible in a buffer + included in an export
> would be a major improvement over, say, a link.  attempting to edit would,
> I guess, pop up a special narrowed buffer that edits the original text.
> Those 3 features together would cover maybe 90% of what I personally need,
> so if you have the code for this, I would really love to see it. Thank you!
>
> Matt


-- 
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu

Reply via email to