emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Custom link type that attaches file in :follow
@ 2021-04-12  7:39 Tarjei Bærland via General discussions about Org-mode.
  2021-04-12  9:52 ` Nicolas Goaziou
  0 siblings, 1 reply; 2+ messages in thread
From: Tarjei Bærland via General discussions about Org-mode. @ 2021-04-12  7:39 UTC (permalink / raw)
  To: emacs-orgmode

Hi!

I am having some trouble adding a link via =org-link-set-parameters=.

I want to have a custom =xournalpp=-link type that behaves as follows:
- follow :: Open attached file
  - exists :: open the file
  - don't exist :: create attachment directory and copy template file into it
- export :: Use [[https://xournalpp.github.io/][Xournalpp]] to export the file as an svg. Inline this svg.

#+begin_src emacs-lisp
  (org-link-set-parameters
   "xournalpp"
   :follow (lambda (path)
	     (let ((xoppfile (concat (org-attach-dir-get-create) "/" path))
		   (template "/home/tarjei/repos/konturer/maler/skisse.xopp"))
	       (cond ((not (file-exists-p xoppfile)) (copy-file template xoppfile)))
	       (org-attach-sync)
	       (shell-command (format "xournalpp %s" xoppfile))))
   :export (lambda (path desc backend)
	     (let ((xoppfile (concat (org-attach-dir-get-create) "/" path))
		   (tempfile "/home/tarjei/temp/xournal_export.svg"))
	       (shell-command (format "xournalpp --create-img %s %s" tempfile xoppfile))
	       (with-temp-buffer
		 (insert-file tempfile)
		 (buffer-string)))))

#+end_src

Something seems to go wrong during the export, however, where a new attachment directory is created. Is my assumption that the export will run with =point= at the link incorrect?

All other feedback on the implementation would be much appreciated, I seem to repeat myself way more than should be necessary.

Regards,
Tarjei Bærland



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-04-12 10:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-04-12  7:39 Custom link type that attaches file in :follow Tarjei Bærland via General discussions about Org-mode.
2021-04-12  9:52 ` Nicolas Goaziou

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).