Reputation: 125
I'd like to be able to get the file path of a link in emacs org-mode as a string, which I could then parse in various ways and return to org-open-file
. So, e.g., the link [[file:/path/to/file.org]][link text]
would return the string /path/to/file.org
. I'm betting this is basic elisp, but I'm new to elisp.
Upvotes: 0
Views: 782
Reputation: 1586
You can access this information from the Org element API. Here is an example that gets the path and opens it in a Dired buffer.
(defun km/org-link-dired-jump ()
"Open Dired for directory of file link at point."
(interactive)
(let ((el (org-element-lineage (org-element-context) '(link) t)))
(unless (and el (equal (org-element-property :type el) "file"))
(user-error "Not on file link"))
(dired-jump 'other-window
(expand-file-name (org-element-property :path el)))))
(This depends on Org version 8.3 or greater.)
Upvotes: 0