emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Tarjei Bærland via General discussions about Org-mode." <emacs-orgmode@gnu.org>
To: emacs-orgmode@gnu.org
Subject: Custom link type that attaches file in :follow
Date: Mon, 12 Apr 2021 09:39:02 +0200	[thread overview]
Message-ID: <87h7kcymsp.fsf@purelymail.com> (raw)

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



             reply	other threads:[~2021-04-12  7:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-12  7:39 Tarjei Bærland via General discussions about Org-mode. [this message]
2021-04-12  9:52 ` Custom link type that attaches file in :follow Nicolas Goaziou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87h7kcymsp.fsf@purelymail.com \
    --to=emacs-orgmode@gnu.org \
    --cc=tarjei@purelymail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).