[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Custom link type that attaches file in :follow
From: |
Tarjei Bærland |
Subject: |
Custom link type that attaches file in :follow |
Date: |
Mon, 12 Apr 2021 09:39:02 +0200 |
User-agent: |
mu4e 1.2.0; emacs 27.1 |
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
- Custom link type that attaches file in :follow,
Tarjei Bærland <=