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

* Re: Custom link type that attaches file in :follow
  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
  0 siblings, 0 replies; 2+ messages in thread
From: Nicolas Goaziou @ 2021-04-12  9:52 UTC (permalink / raw)
  To: Tarjei Bærland via General discussions about Org-mode.
  Cc: Tarjei Bærland

Hello,

Tarjei Bærland writes:

> 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?

Yes, this assumption is incorrect. The export process operates on
a parse tree, and doesn't need to move point at all. Current buffer is
not even the original buffer.

You may use hooks that are run before parsing happens, i.e.,
`org-export-before-parsing-hook' and `org-export-before-processing-hook.
I didn't look at your export function, so take my advice with a grain of
salt.

Regards,
-- 
Nicolas Goaziou


^ 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 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).