emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Juan Manuel Macías" <maciaschain@posteo.net>
To: orgmode <emacs-orgmode@gnu.org>
Subject: [tip] Go to the org node from the attached directory
Date: Thu, 07 Oct 2021 14:57:18 +0000	[thread overview]
Message-ID: <87tuhsnar5.fsf@posteo.net> (raw)


I often come across the following use case:

helm-locate leads me to a file named (for example) document.pdf, which
is in an attached folder of an Org node. I open the document and then I
would like to jump from there to the Org node. I don't know if anyone
has found any solutions for this or if there is any specific package. I
have come up with this poor man's solution: add a local variable to the
attached directory, which should contain the org node ID.

The function that adds the variable after I run org-attach:

#+begin_src emacs-lisp
  (defun my-org-attach/add-dir-variable (&rest _ignore)
    (let* ((dir (org-attach-dir))
	   (id (org-id-get-create))
	   (default-directory dir))
      (unless (file-exists-p (concat dir "/" ".dir-locals.el"))
	  (add-dir-local-variable nil 'node-id id)
	  (read (current-buffer))

and then:

#+begin_src emacs-lisp
  (advice-add 'org-attach :after  #'my-org-attach/add-dir-variable)

and the function to jump from the attached folder to the org node:

#+begin_src emacs-lisp
  (defun my-org-attach/goto-node ()
    (org-id-goto node-id))

(of course this only works if there is only one attached directory per

Best regards,

Juan Manuel 

                 reply	other threads:[~2021-10-07 14:59 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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:

  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=87tuhsnar5.fsf@posteo.net \
    --to=maciaschain@posteo.net \
    --cc=emacs-orgmode@gnu.org \


* 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


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