embark
embark copied to clipboard
Add file action to insert as org link
I don't know if there is a more elegant way to do this, but I bind this to L in embark-file-map. Would there be interest in a PR?
(defun embark-insert-org-link (file)
"Insert relative path to FILE.
The insert path is relative to `default-directory'."
(interactive "FFile: ")
(insert (concat "[[./"(file-relative-name (substitute-in-file-name file)) "]]")))
This might be a good fit for the "secret" `embark-org package.
Something like that would be nice to have :-) Is it possible to only bind it if the major-mode of the current buffer is org-mode?
Perfect timing, @unhammer! I added support for extended menu-items yesterday! Those have a :filter property which you can use (among other things) to conditionally enable them only in certain situations. See (info "(elisp)Extended Menu Items") for more information. You can use this to bind @dangom's action only when you are in a minibuffer such that the previously selected buffer was an org mode buffer (I'm guessing you don't really want to use this action in org-mode buffers, but rather in minibuffers open from an org mode buffer, right? I imagine the usage being you are in a org mode buffer, and want to insert a relative file link, so you fire up find-file or maybe locate, and then from the minibuffer call this action):
(define-key embark-file-map "L"
`(menu-item "Insert Org link to file"
embark-insert-org-link
:filter
,(lambda (item)
(with-minibuffer-selected-window
(when (derived-mode-p 'org-mode)
item)))))
I think this action is useful for any major mode. You can use org links as global links in the style of Hyperbole via org-global-open-at-point.
True, @minad. Maybe embark-org's link target finder should find links in all buffers and use org-global-open-at-point instead of the non-global one.