* [tip] Go to the org node from the attached directory
@ 2021-10-07 14:57 Juan Manuel Macías
0 siblings, 0 replies; only message in thread
From: Juan Manuel Macías @ 2021-10-07 14:57 UTC (permalink / raw)
To: orgmode
Hi,
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"))
(save-window-excursion
(add-dir-local-variable nil 'node-id id)
(save-buffer)
(read (current-buffer))
(kill-buffer)))))
#+end_src
and then:
#+begin_src emacs-lisp
(advice-add 'org-attach :after #'my-org-attach/add-dir-variable)
#+end_src
and the function to jump from the attached folder to the org node:
#+begin_src emacs-lisp
(defun my-org-attach/goto-node ()
(interactive)
(org-id-goto node-id))
#+end_src
(of course this only works if there is only one attached directory per
node).
Best regards,
Juan Manuel
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-10-07 14:59 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-07 14:57 [tip] Go to the org node from the attached directory Juan Manuel Macías
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).