[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[tip] Go to the org node from the attached directory
From: |
Juan Manuel Macías |
Subject: |
[tip] Go to the org node from the attached directory |
Date: |
Thu, 07 Oct 2021 14:57:18 +0000 |
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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [tip] Go to the org node from the attached directory,
Juan Manuel Macías <=