emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Inserting org-mode heading links the org-refile way
@ 2020-05-03 20:04 Daryl Manning
  2020-05-04  5:09 ` Ihor Radchenko
  0 siblings, 1 reply; 8+ messages in thread
From: Daryl Manning @ 2020-05-03 20:04 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1351 bytes --]

I use ivy and org-refile to process my inbox.org file hyper-efficiently and
get things into my GTD system.

In a recent discussion on org-roam (which nicely links to files in a nice
wiki-like manner) it occurred to me if I had a similar interface to search
for headlines in the manner of org-refile and then insert them effortlessly
without having to switch to a doc and copy/store them and then switching
back to my doc and inserting them, I'd be a happy camper.

Is there a package/functions that does/do that in some fashion (say
configurable to avoid link sprawl so say, like 3 heading levels down and to
files in specific directories like deft). Googling did not give joy, though
I noticed someone had used a similar approach for addressing link *within*
a document, but not quite there (swiper and worf combo and an ivy-org-ref
package looked interesting).

(I always worry when I post these questions that someone is going to just
say "but did you not know about M-x org-insert-link-like-ivy-with-refile"
so go gentle on me if I've missed something obvious. It seems I often do.
This weekend in particular I've added on a whole bunch of small but in the
aggregate, large productivity improvements to my emacs setup which I
approached solving the wrong way until I asked and someone mentioned
another way to do things, so.... ).

thanks,
Daryl.

[-- Attachment #2: Type: text/html, Size: 1566 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Inserting org-mode heading links the org-refile way
  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-05 14:19   ` Daryl Manning
  0 siblings, 2 replies; 8+ messages in thread
From: Ihor Radchenko @ 2020-05-04  5:09 UTC (permalink / raw)
  To: Daryl Manning, emacs-orgmode

If I understand you correctly, the following code should achieve what
you want. The code reuses org-refile interface to complete id: links.  

(defun org-id-prompt-id ()
  "Prompt for the id during completion of id: link."
  (let ((org-refile-history nil)
	(org-refile-cache nil)
	(org-refile-target-verify-function nil))
    (let ((prompt-ans (org-refile-get-location "Select org entry")))
      (prog1
	  (or (org-id-get (seq-find #'markerp
				    prompt-ans)
			  'create)
              (user-error "Cannot find ID of the entry: %s" prompt-ans))
	(setq org-id-history org-refile-history)
	(setq org-id-cache org-refile-cache)))))


(defun org-id-link-complete (&optional arg)
  "Completion function for id: link."
  (let* ((id (org-id-prompt-id)))
    (format "id:%s" id)))

(defun org-id-link-desk (link desk)
  "Description function for id: link."
  (or desk
      (let ((id (cadr (split-string link ":"))))
	(org-with-point-at (org-id-find id 'marker)
	  (org-get-heading 'strip 'all 'the 'extra)))))

(org-link-set-parameters "id"
			 :complete #'org-id-link-complete
                         :desk #'org-id-link-desk)



Daryl Manning <dwm+orgmode@wakatara.com> writes:

> I use ivy and org-refile to process my inbox.org file hyper-efficiently and
> get things into my GTD system.
>
> In a recent discussion on org-roam (which nicely links to files in a nice
> wiki-like manner) it occurred to me if I had a similar interface to search
> for headlines in the manner of org-refile and then insert them effortlessly
> without having to switch to a doc and copy/store them and then switching
> back to my doc and inserting them, I'd be a happy camper.
>
> Is there a package/functions that does/do that in some fashion (say
> configurable to avoid link sprawl so say, like 3 heading levels down and to
> files in specific directories like deft). Googling did not give joy, though
> I noticed someone had used a similar approach for addressing link *within*
> a document, but not quite there (swiper and worf combo and an ivy-org-ref
> package looked interesting).
>
> (I always worry when I post these questions that someone is going to just
> say "but did you not know about M-x org-insert-link-like-ivy-with-refile"
> so go gentle on me if I've missed something obvious. It seems I often do.
> This weekend in particular I've added on a whole bunch of small but in the
> aggregate, large productivity improvements to my emacs setup which I
> approached solving the wrong way until I asked and someone mentioned
> another way to do things, so.... ).
>
> thanks,
> Daryl.

-- 
Ihor Radchenko,
PhD,
Center for Advancing Materials Performance from the Nanoscale (CAMP-nano)
State Key Laboratory for Mechanical Behavior of Materials, Xi'an Jiaotong University, Xi'an, China
Email: yantar92@gmail.com, ihor_radchenko@alumni.sutd.edu.sg


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Inserting org-mode heading links the org-refile way
  2020-05-04  5:09 ` Ihor Radchenko
@ 2020-05-04  6:28   ` Joseph Vidal-Rosset
  2020-05-04  7:11     ` Ihor Radchenko
  2020-05-05 14:19   ` Daryl Manning
  1 sibling, 1 reply; 8+ messages in thread
From: Joseph Vidal-Rosset @ 2020-05-04  6:28 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode, Daryl Manning

Le   lun.   05/04/20   mai   2020    à   01:09:53   ,   Ihor   Radchenko
<yantar92@gmail.com> a envoyé ce message:
> If I understand you correctly, the following code should achieve what
> you want. The code reuses org-refile interface to complete id: links.  
>
> (defun org-id-prompt-id ()
>   "Prompt for the id during completion of id: link."
>   (let ((org-refile-history nil)
> 	(org-refile-cache nil)
> 	(org-refile-target-verify-function nil))
>     (let ((prompt-ans (org-refile-get-location "Select org entry")))
>       (prog1
> 	  (or (org-id-get (seq-find #'markerp
> 				    prompt-ans)
> 			  'create)
>               (user-error "Cannot find ID of the entry: %s" prompt-ans))
> 	(setq org-id-history org-refile-history)
> 	(setq org-id-cache org-refile-cache)))))
>
> (defun org-id-link-complete (&optional arg)
>   "Completion function for id: link."
>   (let* ((id (org-id-prompt-id)))
>     (format "id:%s" id)))
>
> (defun org-id-link-desk (link desk)
>   "Description function for id: link."
>   (or desk
>       (let ((id (cadr (split-string link ":"))))
> 	(org-with-point-at (org-id-find id 'marker)
> 	  (org-get-heading 'strip 'all 'the 'extra)))))
>
> (org-link-set-parameters "id"
> 			 :complete #'org-id-link-complete
>                          :desk #'org-id-link-desk)

Hi,

Always interested in  org-links, I have tested your code.  It will maybe
interesting that  I point out  that, even if  I am unable  to understand
why, I  have checked that  it breaks  the function for  org-linking from
emails in gnus, at least in my setup i.e. with the following code: 

(setq org-agenda-custom-commands
      '(("t" "Agenda and Email-links tasks"
         ((agenda "")
          (tags-todo "email")
          (tags "link")))
        ))

;; (global-set-key (kbd "<f11> c") 'org-capture)
;; capture todo items using C-c c t
;; (define-key global-map (kbd "C-c c") 'org-capture)
(setq org-capture-templates
      '(
	("t" "todo" entry (file+headline "~/Dropbox/Orgzly/todo.org" "Tasks")
         "* TODO [#A] %?\n [[~/Dropbox/Orgzly/links.org::%(org-insert-time-stamp (org-read-date nil t \"%:date\"))]] \n* %(org-insert-time-stamp (org-read-date nil t \"%:date\")) %a "
	 )
	("n"      ; key
	 "note"   ;name
	 entry    ;type
	 (file+headline "~/Dropbox/Orgzly/notes.org" "Notes")  ;target 
         "* NOTE du %(org-insert-time-stamp (org-read-date nil t \"%:date\")) \n Voir %a " ; template
	 )
	("H" "HOWTO: C-c C-s : schedule ; C-c C-d : deadline ; C-c C-w : org-refile at a point; last: C-c C-t : DONE - F11-a: org-archive"
	  entry (file+headline "" "") ""
	 )
	)
      )
;; Merci à  Bob Newell , avec ce code, le lien de l'email est modifié correctement dès l'usage de la fonction refile C-c C-w  
  (defun jr/fix-the-link (&rest args)
 (interactive)
 (save-excursion
   (find-file "~/Dropbox/Orgzly/todo.org")
   (goto-char (point-min))
   (while (search-forward "gnus:INBOX#" nil t)
     (replace-match "gnus:\\[Gmail\\]/Tous les messages#"))
   (save-buffer)))
(advice-add 'org-capture-finalize :after #'jr/fix-the-link)

Best wishes,

Jo. 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Inserting org-mode heading links the org-refile way
  2020-05-04  6:28   ` Joseph Vidal-Rosset
@ 2020-05-04  7:11     ` Ihor Radchenko
  2020-05-04 17:41       ` Joseph Vidal-Rosset
  0 siblings, 1 reply; 8+ messages in thread
From: Ihor Radchenko @ 2020-05-04  7:11 UTC (permalink / raw)
  To: Joseph Vidal-Rosset; +Cc: emacs-orgmode, Daryl Manning

> Always interested in  org-links, I have tested your code.  It will maybe
> interesting that  I point out  that, even if  I am unable  to understand
> why, I  have checked that  it breaks  the function for  org-linking from
> emails in gnus, at least in my setup i.e. with the following code: 

It is also not very clear for me what could be broken in your setup.
One guess would be that I use non-standard :desk link property to setup
default link description. That property actually need some extra custom
code to work. I imagine that it might somehow interfere with the
existing org code when set.
Can you try the following simplified code?

(defun org-id-prompt-id ()
  "Prompt for the id during completion of id: link."
  (let ((org-refile-history nil)
	(org-refile-cache nil)
	(org-refile-target-verify-function nil))
    (let ((prompt-ans (org-refile-get-location "Select org entry")))
      (prog1
	  (or (org-id-get (seq-find #'markerp
				    prompt-ans)
			  'create)
              (user-error "Cannot find ID of the entry: %s" prompt-ans))
	(setq org-id-history org-refile-history)
	(setq org-id-cache org-refile-cache)))))

(defun org-id-link-complete (&optional arg)
  "Completion function for id: link."
  (let* ((id (org-id-prompt-id)))
    (format "id:%s" id)))

(org-link-set-parameters "id"
			 :complete #'org-id-link-complete)

P.S. You can use %^t instead of %(org-insert-time-stamp ...).

From org-capture-templates docstring:
>  %^t         Like %t, but prompt for date.  Similarly %^T, %^u, %^U.
>              You may define a prompt like: %^{Please specify birthday}t.
>              The default date is that of %t, see above.

Best,
Ihor

Joseph Vidal-Rosset <joseph.vidal.rosset@gmail.com> writes:

> Le   lun.   05/04/20   mai   2020    à   01:09:53   ,   Ihor   Radchenko
> <yantar92@gmail.com> a envoyé ce message:
>> If I understand you correctly, the following code should achieve what
>> you want. The code reuses org-refile interface to complete id: links.  
>>
>> (defun org-id-prompt-id ()
>>   "Prompt for the id during completion of id: link."
>>   (let ((org-refile-history nil)
>> 	(org-refile-cache nil)
>> 	(org-refile-target-verify-function nil))
>>     (let ((prompt-ans (org-refile-get-location "Select org entry")))
>>       (prog1
>> 	  (or (org-id-get (seq-find #'markerp
>> 				    prompt-ans)
>> 			  'create)
>>               (user-error "Cannot find ID of the entry: %s" prompt-ans))
>> 	(setq org-id-history org-refile-history)
>> 	(setq org-id-cache org-refile-cache)))))
>>
>> (defun org-id-link-complete (&optional arg)
>>   "Completion function for id: link."
>>   (let* ((id (org-id-prompt-id)))
>>     (format "id:%s" id)))
>>
>> (defun org-id-link-desk (link desk)
>>   "Description function for id: link."
>>   (or desk
>>       (let ((id (cadr (split-string link ":"))))
>> 	(org-with-point-at (org-id-find id 'marker)
>> 	  (org-get-heading 'strip 'all 'the 'extra)))))
>>
>> (org-link-set-parameters "id"
>> 			 :complete #'org-id-link-complete
>>                          :desk #'org-id-link-desk)
>
> Hi,
>
> Always interested in  org-links, I have tested your code.  It will maybe
> interesting that  I point out  that, even if  I am unable  to understand
> why, I  have checked that  it breaks  the function for  org-linking from
> emails in gnus, at least in my setup i.e. with the following code: 
>
> (setq org-agenda-custom-commands
>       '(("t" "Agenda and Email-links tasks"
>          ((agenda "")
>           (tags-todo "email")
>           (tags "link")))
>         ))
>
> ;; (global-set-key (kbd "<f11> c") 'org-capture)
> ;; capture todo items using C-c c t
> ;; (define-key global-map (kbd "C-c c") 'org-capture)
> (setq org-capture-templates
>       '(
> 	("t" "todo" entry (file+headline "~/Dropbox/Orgzly/todo.org" "Tasks")
>          "* TODO [#A] %?\n [[~/Dropbox/Orgzly/links.org::%(org-insert-time-stamp (org-read-date nil t \"%:date\"))]] \n* %(org-insert-time-stamp (org-read-date nil t \"%:date\")) %a "
> 	 )
> 	("n"      ; key
> 	 "note"   ;name
> 	 entry    ;type
> 	 (file+headline "~/Dropbox/Orgzly/notes.org" "Notes")  ;target 
>          "* NOTE du %(org-insert-time-stamp (org-read-date nil t \"%:date\")) \n Voir %a " ; template
> 	 )
> 	("H" "HOWTO: C-c C-s : schedule ; C-c C-d : deadline ; C-c C-w : org-refile at a point; last: C-c C-t : DONE - F11-a: org-archive"
> 	  entry (file+headline "" "") ""
> 	 )
> 	)
>       )
> ;; Merci à  Bob Newell , avec ce code, le lien de l'email est modifié correctement dès l'usage de la fonction refile C-c C-w  
>   (defun jr/fix-the-link (&rest args)
>  (interactive)
>  (save-excursion
>    (find-file "~/Dropbox/Orgzly/todo.org")
>    (goto-char (point-min))
>    (while (search-forward "gnus:INBOX#" nil t)
>      (replace-match "gnus:\\[Gmail\\]/Tous les messages#"))
>    (save-buffer)))
> (advice-add 'org-capture-finalize :after #'jr/fix-the-link)
>
> Best wishes,
>
> Jo. 

-- 
Ihor Radchenko,
PhD,
Center for Advancing Materials Performance from the Nanoscale (CAMP-nano)
State Key Laboratory for Mechanical Behavior of Materials, Xi'an Jiaotong University, Xi'an, China
Email: yantar92@gmail.com, ihor_radchenko@alumni.sutd.edu.sg


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Inserting org-mode heading links the org-refile way
  2020-05-04  7:11     ` Ihor Radchenko
@ 2020-05-04 17:41       ` Joseph Vidal-Rosset
  0 siblings, 0 replies; 8+ messages in thread
From: Joseph Vidal-Rosset @ 2020-05-04 17:41 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode, Daryl Manning

Le   lun.   05/04/20   mai   2020    à   03:11:57   ,   Ihor   Radchenko
<yantar92@gmail.com> a envoyé ce message:
> Can you try the following simplified code?

Hello,

I confirm that the  simplified code below does not break  the code of my
setup and that org-links for gnus work.  Thanks ! 


> (defun org-id-prompt-id ()
>   "Prompt for the id during completion of id: link."
>   (let ((org-refile-history nil)
> 	(org-refile-cache nil)
> 	(org-refile-target-verify-function nil))
>     (let ((prompt-ans (org-refile-get-location "Select org entry")))
>       (prog1
> 	  (or (org-id-get (seq-find #'markerp
> 				    prompt-ans)
> 			  'create)
>               (user-error "Cannot find ID of the entry: %s" prompt-ans))
> 	(setq org-id-history org-refile-history)
> 	(setq org-id-cache org-refile-cache)))))
>
> (defun org-id-link-complete (&optional arg)
>   "Completion function for id: link."
>   (let* ((id (org-id-prompt-id)))
>     (format "id:%s" id)))
>
> (org-link-set-parameters "id"
> 			 :complete #'org-id-link-complete)
>
> P.S. You can use %^t instead of %(org-insert-time-stamp ...).
>
> From org-capture-templates docstring:
>>  %^t         Like %t, but prompt for date.  Similarly %^T, %^u, %^U.
>>              You may define a prompt like: %^{Please specify birthday}t.
>>              The default date is that of %t, see above.
>
> Best,
> Ihor


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Inserting org-mode heading links the org-refile way
  2020-05-04  5:09 ` Ihor Radchenko
  2020-05-04  6:28   ` 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
  1 sibling, 2 replies; 8+ messages in thread
From: Daryl Manning @ 2020-05-05 14:19 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Org-mode

[-- Attachment #1: Type: text/plain, Size: 3937 bytes --]

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.


On Mon, May 4, 2020 at 1:14 PM Ihor Radchenko <yantar92@gmail.com> wrote:

> If I understand you correctly, the following code should achieve what
> you want. The code reuses org-refile interface to complete id: links.
>
> (defun org-id-prompt-id ()
>   "Prompt for the id during completion of id: link."
>   (let ((org-refile-history nil)
>         (org-refile-cache nil)
>         (org-refile-target-verify-function nil))
>     (let ((prompt-ans (org-refile-get-location "Select org entry")))
>       (prog1
>           (or (org-id-get (seq-find #'markerp
>                                     prompt-ans)
>                           'create)
>               (user-error "Cannot find ID of the entry: %s" prompt-ans))
>         (setq org-id-history org-refile-history)
>         (setq org-id-cache org-refile-cache)))))
>
>
> (defun org-id-link-complete (&optional arg)
>   "Completion function for id: link."
>   (let* ((id (org-id-prompt-id)))
>     (format "id:%s" id)))
>
> (defun org-id-link-desk (link desk)
>   "Description function for id: link."
>   (or desk
>       (let ((id (cadr (split-string link ":"))))
>         (org-with-point-at (org-id-find id 'marker)
>           (org-get-heading 'strip 'all 'the 'extra)))))
>
> (org-link-set-parameters "id"
>                          :complete #'org-id-link-complete
>                          :desk #'org-id-link-desk)
>
>
>
> Daryl Manning <dwm+orgmode@wakatara.com> writes:
>
> > I use ivy and org-refile to process my inbox.org file hyper-efficiently
> and
> > get things into my GTD system.
> >
> > In a recent discussion on org-roam (which nicely links to files in a nice
> > wiki-like manner) it occurred to me if I had a similar interface to
> search
> > for headlines in the manner of org-refile and then insert them
> effortlessly
> > without having to switch to a doc and copy/store them and then switching
> > back to my doc and inserting them, I'd be a happy camper.
> >
> > Is there a package/functions that does/do that in some fashion (say
> > configurable to avoid link sprawl so say, like 3 heading levels down and
> to
> > files in specific directories like deft). Googling did not give joy,
> though
> > I noticed someone had used a similar approach for addressing link
> *within*
> > a document, but not quite there (swiper and worf combo and an ivy-org-ref
> > package looked interesting).
> >
> > (I always worry when I post these questions that someone is going to just
> > say "but did you not know about M-x org-insert-link-like-ivy-with-refile"
> > so go gentle on me if I've missed something obvious. It seems I often do.
> > This weekend in particular I've added on a whole bunch of small but in
> the
> > aggregate, large productivity improvements to my emacs setup which I
> > approached solving the wrong way until I asked and someone mentioned
> > another way to do things, so.... ).
> >
> > thanks,
> > Daryl.
>
> --
> Ihor Radchenko,
> PhD,
> Center for Advancing Materials Performance from the Nanoscale (CAMP-nano)
> State Key Laboratory for Mechanical Behavior of Materials, Xi'an Jiaotong
> University, Xi'an, China
> Email: yantar92@gmail.com, ihor_radchenko@alumni.sutd.edu.sg
>

[-- Attachment #2: Type: text/html, Size: 5111 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Inserting org-mode heading links the org-refile way
  2020-05-05 14:19   ` Daryl Manning
@ 2020-05-05 14:32     ` Ihor Radchenko
  2020-05-07  2:13     ` Josh Moller-Mara
  1 sibling, 0 replies; 8+ messages in thread
From: Ihor Radchenko @ 2020-05-05 14:32 UTC (permalink / raw)
  To: Daryl Manning; +Cc: Org-mode


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

I feel that I am missing something. Probably, because I am not using
ivy. For helm (which I am using), org-refile-get-location provides
filter-and-select interface automatically. So, I can get on-the-fly
filtering for id: link automatically. I just type `C-c C-l id: RET` and 
filter the candidates just like in org-refile. Do you need to call some
special function to use ivy with org-refile? If so, just replace
org-refile-get-location in my code with your ivy version. If you want to
go straight into inserting the link without a need to type `C-c C-l id:
RET`, you may just bind (insert "[[" (org-id-link-complete) "]]") to key
binding of your choice.

Best,
Ihor



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.
>
>
> On Mon, May 4, 2020 at 1:14 PM Ihor Radchenko <yantar92@gmail.com> wrote:
>
>> If I understand you correctly, the following code should achieve what
>> you want. The code reuses org-refile interface to complete id: links.
>>
>> (defun org-id-prompt-id ()
>>   "Prompt for the id during completion of id: link."
>>   (let ((org-refile-history nil)
>>         (org-refile-cache nil)
>>         (org-refile-target-verify-function nil))
>>     (let ((prompt-ans (org-refile-get-location "Select org entry")))
>>       (prog1
>>           (or (org-id-get (seq-find #'markerp
>>                                     prompt-ans)
>>                           'create)
>>               (user-error "Cannot find ID of the entry: %s" prompt-ans))
>>         (setq org-id-history org-refile-history)
>>         (setq org-id-cache org-refile-cache)))))
>>
>>
>> (defun org-id-link-complete (&optional arg)
>>   "Completion function for id: link."
>>   (let* ((id (org-id-prompt-id)))
>>     (format "id:%s" id)))
>>
>> (defun org-id-link-desk (link desk)
>>   "Description function for id: link."
>>   (or desk
>>       (let ((id (cadr (split-string link ":"))))
>>         (org-with-point-at (org-id-find id 'marker)
>>           (org-get-heading 'strip 'all 'the 'extra)))))
>>
>> (org-link-set-parameters "id"
>>                          :complete #'org-id-link-complete
>>                          :desk #'org-id-link-desk)
>>
>>
>>
>> Daryl Manning <dwm+orgmode@wakatara.com> writes:
>>
>> > I use ivy and org-refile to process my inbox.org file hyper-efficiently
>> and
>> > get things into my GTD system.
>> >
>> > In a recent discussion on org-roam (which nicely links to files in a nice
>> > wiki-like manner) it occurred to me if I had a similar interface to
>> search
>> > for headlines in the manner of org-refile and then insert them
>> effortlessly
>> > without having to switch to a doc and copy/store them and then switching
>> > back to my doc and inserting them, I'd be a happy camper.
>> >
>> > Is there a package/functions that does/do that in some fashion (say
>> > configurable to avoid link sprawl so say, like 3 heading levels down and
>> to
>> > files in specific directories like deft). Googling did not give joy,
>> though
>> > I noticed someone had used a similar approach for addressing link
>> *within*
>> > a document, but not quite there (swiper and worf combo and an ivy-org-ref
>> > package looked interesting).
>> >
>> > (I always worry when I post these questions that someone is going to just
>> > say "but did you not know about M-x org-insert-link-like-ivy-with-refile"
>> > so go gentle on me if I've missed something obvious. It seems I often do.
>> > This weekend in particular I've added on a whole bunch of small but in
>> the
>> > aggregate, large productivity improvements to my emacs setup which I
>> > approached solving the wrong way until I asked and someone mentioned
>> > another way to do things, so.... ).
>> >
>> > thanks,
>> > Daryl.
>>
>> --
>> Ihor Radchenko,
>> PhD,
>> Center for Advancing Materials Performance from the Nanoscale (CAMP-nano)
>> State Key Laboratory for Mechanical Behavior of Materials, Xi'an Jiaotong
>> University, Xi'an, China
>> Email: yantar92@gmail.com, ihor_radchenko@alumni.sutd.edu.sg
>>

-- 
Ihor Radchenko,
PhD,
Center for Advancing Materials Performance from the Nanoscale (CAMP-nano)
State Key Laboratory for Mechanical Behavior of Materials, Xi'an Jiaotong University, Xi'an, China
Email: yantar92@gmail.com, ihor_radchenko@alumni.sutd.edu.sg


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Inserting org-mode heading links the org-refile way
  2020-05-05 14:19   ` Daryl Manning
  2020-05-05 14:32     ` Ihor Radchenko
@ 2020-05-07  2:13     ` Josh Moller-Mara
  1 sibling, 0 replies; 8+ messages in thread
From: Josh Moller-Mara @ 2020-05-07  2:13 UTC (permalink / raw)
  To: Daryl Manning, Org-mode

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-05-07  2:14 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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

Code repositories for project(s) associated with this 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).