emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Josh Moller-Mara <j.mollermara@gmail.com>
To: Daryl Manning <dwm+orgmode@wakatara.com>,
	Org-mode <emacs-orgmode@gnu.org>
Subject: Re: Inserting org-mode heading links the org-refile way
Date: Wed, 06 May 2020 19:13:40 -0700	[thread overview]
Message-ID: <87k11olcff.fsf@cns.nyu.edu> (raw)
In-Reply-To: <CAL9aZkvSGCrv+EpCYHXfiB216XUeyqet-BPqdOtchSkJcZG3yw@mail.gmail.com>


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"
  (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
			 (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


Daryl Manning <dwm+orgmode@wakatara.com> 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.

      parent reply	other threads:[~2020-05-07  2:14 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-03 20:04 Inserting org-mode heading links the org-refile way Daryl Manning
2020-05-04  5:09 ` Ihor Radchenko
2020-05-04  6:28   ` Joseph Vidal-Rosset
2020-05-04  7:11     ` Ihor Radchenko
2020-05-04 17:41       ` Joseph Vidal-Rosset
2020-05-05 14:19   ` Daryl Manning
2020-05-05 14:32     ` Ihor Radchenko
2020-05-07  2:13     ` Josh Moller-Mara [this message]

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:

  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=87k11olcff.fsf@cns.nyu.edu \
    --to=j.mollermara@gmail.com \
    --cc=dwm+orgmode@wakatara.com \
    --cc=emacs-orgmode@gnu.org \


* 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


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).