Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transclusion as overlay using org-link #1

Open
Kungsgeten opened this issue Apr 3, 2020 · 3 comments
Open

Transclusion as overlay using org-link #1

Kungsgeten opened this issue Apr 3, 2020 · 3 comments

Comments

@Kungsgeten
Copy link

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)
@alphapapa
Copy link
Owner

Thanks, Erik. Would you like to add that to the repo as a code file, or in a code block in the Org file? Or would you prefer to leave it in the issue here and link to it from the Org file? I'll leave the decision up to you.

Also, if you would like to be a collaborator on this repo, please let me know, and I'll be happy to give you access.

@Kungsgeten
Copy link
Author

Since it isn't "complete" (even though it works) and I currently do not have any plans on further development of the idea, maybe it can be left as an issue? Feel free to link to it from the README. I could submit a PR, but would prefer not to since the change is so small. I don't know why, but I find it a bit cumbersome to fork, make a local rep, commit, push etc. Maybe because I don't do that very often and my (ma)git skills are a bit lacking. Sorry for the laziness!

@alphapapa
Copy link
Owner

I don't know why, but I find it a bit cumbersome to fork, make a local rep, commit, push etc.

Of course, you're right. You could use the GitHub Web UI to make PRs for small changes like this without having to deal with local forks, but it's up to you. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants