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