[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Inserting org-mode heading links the org-refile way
From: |
Josh Moller-Mara |
Subject: |
Re: Inserting org-mode heading links the org-refile way |
Date: |
Wed, 06 May 2020 19:13:40 -0700 |
Hi,
Here's an example of how to create an ivy prompt that inserts links.
It isn't exactly what you're looking for, as it doesn't hijack
`org-insert-link` functionality, nor does it specifically use
`org-refile-target-verify-function` to do filtering.
Instead, this uses org-ql to select TODO headers with a level of at
least 3. org-ql will cache queries in a manner similar to the initial
collecting of org-refile targets. You can add other filter criteria
using org-ql's sexp query syntax. You can also replace the
`(org-agenda-files)` to be some expression that returns the specific
list of files you're interested in.
(defun jmm/org-ql-ivy-prompt-for-link ()
"Select a todo header with ivy and insert its link"
(interactive)
(ivy-read "Link:"
(->> (org-ql-select (org-agenda-files)
'(and (todo)
(level >= 3)
(not (tags "ARCHIVE")))
:action 'element-with-markers)
(-map #'org-ql-view--format-element))
:action (lambda (x)
(let ((org-id-link-to-org-use-id t)) ; Add an ID if it
doesn't exist
(insert
(org-with-point-at (get-text-property 0 'org-hd-marker
x)
(org-store-link nil)))))))
Note: This also uses dash.el functions/macros. You can replace that as
needed.
Best,
Josh
Daryl Manning <address@hidden> writes:
> This looks impressive, and is *similar* to the effect I am going for, but
> what I am looking at is intercepting the `org-insert-link` functionality
> (or replacing it) with the ability to insert a link from the global
> filter-and-select interface via ivy for `org-refile`. So, in other words,
> global access to the (say 3 levels down) headings and files available
> through the ivy interface (which further allows me to filter that down).
>
> This would give me the ability to arbitrarily add links across all files
> (and particularly handy with org-contact for adding in links in cal entries
> for meetings). Since the viy interface seems to work fine for refiling
> tasks (except for initial load of refile targets), it seems it'd be
> sufficiently performant.
>
> Daryl.