alphapapa / alphapapa/transclusion-in-emacs

Transclusion as overlay using org-link

Offen
#1 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Keine Sprachdaten
Sterne
96
Forks
4
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

I've experimented a bit with using `org-link` to create a sort of transclusion. The basic functionality is there, but it could probably be improved upon quite a lot. I haven't publilshed it anywhere else, but here it is if someone is interested. After the code has been added to Emacs you could use `org-insert-link` and choose `peek` and choose a file that you wish to transclude.

```
(defun org-peek-link-activate-func (start end path bracketp)
(remove-overlays start end)
(when (file-exists-p path)
(let ((overlay (make-overlay start end nil t)))
(overlay-put overlay 'display
(with-temp-buffer
(insert-file-contents path)
(buffer-string)))
(overlay-put overlay 'before-string (concat "PEEK: " path "\n"))
(overlay-put overlay 'face 'org-quote)
(overlay-put overlay 'evaporate t))))

(defun org-peek-link-complete (&optional arg)
"Create a peek link using completion.
Modified version of `org-file-complete-link'."
(let ((file (read-file-name "File: "))
(pwd (file-name-as-directory (expand-file-name ".")))
(pwd1 (file-name-as-directory (abbreviate-file-name
(expand-file-name ".")))))
(cond ((equal arg '(16))
(concat "peek:"
(abbreviate-file-name (expand-file-name file))))
((string-match
(concat "^" (regexp-quote pwd1) "\\(.+\\)") file)
(concat "peek:" (match-string 1 file)))
((string-match
(concat "^" (regexp-quote pwd) "\\(.+\\)")
(expand-file-name file))
(concat "peek:"
(match-string 1 (expand-file-name file))))
(t (concat "peek:" file)))))

(org-link-set-parameters "peek"
:activate-func 'org-peek-link-activate-func
:complete 'org-peek-link-complete)
```

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.