From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dominic Surano Subject: Re: Insert org-id Link at Point via Outline Path Completion Date: Sat, 1 Aug 2015 12:17:02 -0700 Message-ID: References: <20150801090706.GA3296@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=089e013cc32c050829051c44c8f3 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:60521) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZLcHK-0000O0-Jx for emacs-orgmode@gnu.org; Sat, 01 Aug 2015 15:17:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZLcHH-0000z7-T3 for emacs-orgmode@gnu.org; Sat, 01 Aug 2015 15:17:06 -0400 Received: from mail-ig0-x230.google.com ([2607:f8b0:4001:c05::230]:34300) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZLcHH-0000yz-JF for emacs-orgmode@gnu.org; Sat, 01 Aug 2015 15:17:03 -0400 Received: by igk11 with SMTP id 11so50832789igk.1 for ; Sat, 01 Aug 2015 12:17:02 -0700 (PDT) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: John Kitchin Cc: Xebar Saram , org mode --089e013cc32c050829051c44c8f3 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Sorry, I meant to get to this yesterday. See my question on Emacs StackExchange and my configuration file where I added this functionality. Basically, you go to insert a link with C-c C-l, type id: and then you'll be prompted to find the org-id via outline completion. I've reproduced the code below for convenience: #+BEGIN_SRC emacs-lisp ;; Add ID properties to all headlines in the current file which do not already have one (defun my/org-add-ids-to-headlines-in-file () (interactive) (org-map-entries 'org-id-get-create)) #+END_SRC The other responses look good as well. Hope this helps! -D On Sat, Aug 1, 2015 at 12:03 PM, John Kitchin wrote: > usually it is pretty easy to add new functions in helm, but it is less > easy in this case because the source is dynamically generated from a > function. So, in this case I think we have to just redefine the function > that generates the source. here is an example that I think makes an id > link as a new action. > > #+BEGIN_SRC emacs-lisp > (defun helm-org-insert-id-link-to-heading-at-marker (marker) > (with-current-buffer (marker-buffer marker) > (let ((file-name (buffer-file-name)) > (id (save-excursion (goto-char (marker-position marker)) > (org-id-get-create) > (org-id-store-link)))) > > (with-helm-current-buffer > (org-insert-link > file-name id))))) > > > (cl-defun helm-source-org-headings-for-files (filenames > &optional (min-depth 1) > (max-depth 8)) > (helm-build-sync-source "Org Headings" > :candidates (helm-org-get-candidates filenames min-depth max-depth) > :action '(("Go to line" . helm-org-goto-marker) > ("Refile to this heading" . helm-org-heading-refile) > ("Insert link to this heading" > . helm-org-insert-link-to-heading-at-marker) > ("Insert id link to this heading" . > helm-org-insert-id-link-to-heading-at-marker)))) > > #+END_SRC > Xebar Saram writes: > > > Hi again > > > > so excited over this had to ask 2 more questions ;-) > > > > 1.can that function include/link to org-id (so that it can keep the > links > > even if the headers move around in/out of the files) > > 2.i saw there are 3 options to that helm function. can this be customiz= ed > > to add more commands (can really think of which ones know but could see > > potential in future :)) > > > > thx so much John as always you rock ;-) > > > > Z > > > > On Sat, Aug 1, 2015 at 8:36 PM, Xebar Saram wrote: > > > >> John, this is superb! > >> > >> thx so much it answers all my needs, what a great find :) > >> > >> kind regards > >> > >> Z > >> > >> On Sat, Aug 1, 2015 at 7:33 PM, John Kitchin > >> wrote: > >> > >>> (helm-org-agenda-files-headings) seems to do this already for all > >>> headlines in your agenda files. the third action is to insert a link = to > >>> the selected headline. > >>> > >>> You can use let to temporarily define the org-agenda-files list to wh= at > >>> you want, and just use the (helm-org-agenda-files-headings) command f= or > >>> non-agenda files. > >>> > >>> e.g. > >>> > >>> #+BEGIN_SRC emacs-lisp > >>> (defun insert-heading-link (dir) > >>> "select a headline from org-files in dir and insert a link to it." > >>> (interactive (list (read-directory-name "Directory: "))) > >>> (let ((org-agenda-files (f-entries > >>> dir > >>> (lambda (f) > >>> (string=3D > >>> "org" > >>> (file-name-extension f))) > >>> t))) > >>> (helm-org-agenda-files-headings))) > >>> #+END_SRC > >>> > >>> gives me a helm buffer to select headlines from org-files in the > >>> directory I select and when I press f3 (for the third > >>> action), it inserts a link to the selected headline. It does the file > >>> finding recursively, so you might not want to run this on / ;) > >>> > >>> You could bind it to a key for easy use. > >>> > >>> Xebar Saram writes: > >>> > >>> > Thx so much Bernhard > >>> > > >>> > this looks really promising. i never had luck with either company o= r > >>> > auto-complete t o get it to work reliably (it often stops working > even > >>> > though its still in the mod bar). > >>> > anyway i tried it and added this to my config (after cloning from > git): > >>> > > >>> > (add-to-list 'load-path "/home/zeltak/.emacs.g/company-org-headings= ") > >>> > (add-hook 'org-mode-hook > >>> > (lambda () (set (make-local-variable 'company-backends) > >>> > '((company-org-headings))))) > >>> > > >>> > i dont see it completes on org heading, is there any keys i need to > >>> press > >>> > or anything else in need to config? does this work only when you tr= y > to > >>> > insert a link? > >>> > > >>> > best and thx so much, this look awesome > >>> > > >>> > P.S have you considered Helm for this as well? > >>> > > >>> > best > >>> > > >>> > Z > >>> > > >>> > > >>> > > >>> > On Sat, Aug 1, 2015 at 12:07 PM, Bernhard Pr=C3=B6ll < > bmutbuerger@gmail.com> > >>> > wrote: > >>> > > >>> >> Hi Saram, > >>> >> > >>> >> I've been in the same boat and decided to write a company-backend > for > >>> >> this purpose. So if you're already using company-mode, this may be > >>> worth > >>> >> looking into: > >>> >> > >>> >> https://github.com/mutbuerger/company-org-headings > >>> >> > >>> >> Keep in mind that I'm in the process of learning Elisp and > >>> >> there has been little to no testing done on the package. > Furthermore it > >>> >> uses org-store-link instead of org-id-store-link. > >>> >> > >>> >> Regards, > >>> >> Bernhard Pr=C3=B6ll > >>> >> > >>> >> > >>> >> On Fri, 31. Jul 09:43, Xebar Saram wrote: > >>> >> > >>> >>> i also have a similar workflow and would love to hear Dominic if > you > >>> >>> found a > >>> >>> solution for this or if anyone on the list has other suggestions? > >>> >>> > >>> >>> best > >>> >>> > >>> >>> Z > >>> >>> > >>> >>> On Tue, May 12, 2015 at 10:57 PM, Dominic Surano < > sk8ingdom@gmail.com > >>> > > >>> >>> wrote: > >>> >>> > >>> >>> Hello, > >>> >>> > >>> >>> I use org-mode a lot like a wiki so links to other org-mode > >>> headings > >>> >>> are > >>> >>> very common. Currently, I navigate to the heading or pull it u= p > in > >>> an > >>> >>> agenda view, store the link with C-l, going back to where I > want to > >>> >>> insert the link, then insert the link with C-c C-l RET. This i= s > a > >>> bit > >>> >>> time consuming. > >>> >>> > >>> >>> Instead, I would prefer to map a key that allows me to insert = a > >>> link at > >>> >>> the current point using tab completion similar to org-refile > (C-c > >>> C-w). > >>> >>> Looking through org-id.el, it seems like > >>> org-id-get-with-outline-path > >>> >>> completion was designed for this purpose. I tried: > >>> >>> > >>> >>> (global-set-key "\C-ci" (lambda () (interactive) > (org-id-get-with > >>> >>> outline-path-completion))) > >>> >>> > >>> >>> but it didn't work as intended. Anyone have any ideas? > >>> >>> > >>> >>> Thanks! > >>> >>> -D > >>> >>> > >>> >>> For reference, I have the following set in my configuration: > >>> >>> > >>> >>> ;; Use global IDs > >>> >>> (require 'org-id) > >>> >>> (setq org-id-link-to-org-use-id t) > >>> >>> > >>> >>> ;; Update ID file .org-id-locations on startup > >>> >>> (org-id-update-id-locations) > >>> >>> > >>> >>> ;; Targets include this file and any file contributing to the > >>> agenda - > >>> >>> up to 9 levels deep > >>> >>> (setq org-refile-targets (quote ((nil :maxlevel . 9) > >>> >>> (org-agenda-files :maxlevel . > >>> 9)))) > >>> >>> (setq org-refile-use-outline-path 'file) > >>> >>> (setq org-outline-path-complete-in-steps t) > >>> >>> (setq org-refile-allow-creating-parent-nodes t) > >>> >>> > >>> >>> > >>> >>> > >>> >>> > >>> >>> > >>> > >>> -- > >>> Professor John Kitchin > >>> Doherty Hall A207F > >>> Department of Chemical Engineering > >>> Carnegie Mellon University > >>> Pittsburgh, PA 15213 > >>> 412-268-7803 > >>> @johnkitchin > >>> http://kitchingroup.cheme.cmu.edu > >>> > >> > >> > > -- > Professor John Kitchin > Doherty Hall A207F > Department of Chemical Engineering > Carnegie Mellon University > Pittsburgh, PA 15213 > 412-268-7803 > @johnkitchin > http://kitchingroup.cheme.cmu.edu > --=20 Dominic Surano Email is my fastest and preferred method of contact Phone, address, etc. available upon request Life should be an adventure --089e013cc32c050829051c44c8f3 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Sorry, I meant to get to this yesterday. See=C2=A0my question on Emacs StackExchange=C2= =A0and=C2=A0my configuration file=C2=A0where I added = this functionality. Basically, you go to insert a link with C-c C-l, type i= d: <ENTER> and then you'll be prompted to find the org-id via out= line completion. I've reproduced the code below for convenience:
#+BEGIN_SRC emacs-lisp
;; Add ID properties to all h= eadlines in the current file which do not already have one
(defun my/org= -add-ids-to-headlines-in-file ()
(interactive)
(org-map-entries '= org-id-get-create))
#+END_SRC

The ot= her responses look good as well. Hope this helps!
-D

On Sat,= Aug 1, 2015 at 12:03 PM, John Kitchin <jkitchin@andrew.cmu.edu&= gt; wrote:
usually it is pretty ea= sy to add new functions in helm, but it is less
easy in this case because the source is dynamically generated from a
function. So, in this case I think we have to just redefine the function that generates the source. here is an example that I think makes an id
link as a new action.

#+BEGIN_SRC emacs-lisp
(defun helm-org-insert-id-link-to-heading-at-marker (marker)
=C2=A0 (with-current-buffer (marker-buffer marker)
=C2=A0 =C2=A0 (let ((file-name (buffer-file-name))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (id (save-excursion (goto-char (marker-p= osition marker))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (org-id-get-create)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (org-id-store-link))))

=C2=A0 =C2=A0 =C2=A0 (with-helm-current-buffer
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (org-insert-link
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0file-name id)))))


(cl-defun helm-source-org-headings-for-files (filenames
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 &optional (min-depth 1) (max-depth 8))
=C2=A0 (helm-build-sync-source "Org Headings"
=C2=A0 =C2=A0 :candidates (helm-org-get-candidates filenames min-depth max-= depth)
=C2=A0 =C2=A0 :action '(("Go to line" . helm-org-goto-marker)=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ("Refile to this head= ing" . helm-org-heading-refile)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ("Insert link to this= heading"
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0. helm-org-insert-li= nk-to-heading-at-marker)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ("Insert id link to t= his heading" .
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0helm-org-insert-id-l= ink-to-heading-at-marker))))

#+END_SRC
Xebar Saram writes:

> Hi again
>
> so excited over this had to ask 2 more questions ;-)
>
> 1.can that function include/link to org-id=C2=A0 (so that it can keep = the links
> even if the headers move around in/out of the files)
> 2.i saw there are 3 options to that helm function. can this be customi= zed
> to add more commands (can really think of which ones know but could se= e
> potential in future :))
>
> thx so much John as always you rock ;-)
>
> Z
>
> On Sat, Aug 1, 2015 at 8:36 PM, Xebar Saram <zeltakc@gmail.com> wrote:
>
>> John, this is superb!
>>
>> thx so much it answers all my needs, what a great find :)
>>
>> kind regards
>>
>> Z
>>
>> On Sat, Aug 1, 2015 at 7:33 PM, John Kitchin <jkitchin@andrew.cmu.edu>
>> wrote:
>>
>>> (helm-org-agenda-files-headings) seems to do this already for = all
>>> headlines in your agenda files. the third action is to insert = a link to
>>> the selected headline.
>>>
>>> You can use let to temporarily define the org-agenda-files lis= t to what
>>> you want, and just use the (helm-org-agenda-files-headings) co= mmand for
>>> non-agenda files.
>>>
>>> e.g.
>>>
>>> #+BEGIN_SRC emacs-lisp
>>> (defun insert-heading-link (dir)
>>>=C2=A0 =C2=A0"select a headline from org-files in dir and = insert a link to it."
>>>=C2=A0 =C2=A0(interactive=C2=A0 (list (read-directory-name &quo= t;Directory: ")))
>>>=C2=A0 =C2=A0(let ((org-agenda-files (f-entries
>>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 dir
>>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (lambda (f)
>>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (string=3D
>>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"org"
>>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(file-name-extension f))) >>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 t)))
>>>=C2=A0 =C2=A0 =C2=A0(helm-org-agenda-files-headings)))
>>> #+END_SRC
>>>
>>> gives me a helm buffer to select headlines from org-files in t= he
>>> directory I select and when I press f3 (for the third
>>> action), it inserts a link to the selected headline. It does t= he file
>>> finding recursively, so you might not want to run this on /=C2= =A0 ;)
>>>
>>> You could bind it to a key for easy use.
>>>
>>> Xebar Saram writes:
>>>
>>> > Thx so much Bernhard
>>> >
>>> > this looks really promising. i never had luck with either= company or
>>> > auto-complete t o get it to work reliably (it often stops= working even
>>> > though its still in the mod bar).
>>> > anyway i tried it and added this to my config (after clon= ing from git):
>>> >
>>> > (add-to-list 'load-path "/home/zeltak/.emacs.g/c= ompany-org-headings")
>>> > (add-hook 'org-mode-hook
>>> >=C2=A0 (lambda () (set (make-local-variable 'company-b= ackends)
>>> >=C2=A0 =C2=A0 =C2=A0'((company-org-headings)))))
>>> >
>>> > i dont see it completes on org heading, is there any keys= i need to
>>> press
>>> > or anything else in need to config? does this work only w= hen you try to
>>> > insert a link?
>>> >
>>> > best and thx so much, this look awesome
>>> >
>>> > P.S have you considered Helm for this as well?
>>> >
>>> > best
>>> >
>>> > Z
>>> >
>>> >
>>> >
>>> > On Sat, Aug 1, 2015 at 12:07 PM, Bernhard Pr=C3=B6ll <= bmutbuerger@gmail.com>
>>> > wrote:
>>> >
>>> >> Hi Saram,
>>> >>
>>> >> I've been in the same boat and decided to write a= company-backend for
>>> >> this purpose. So if you're already using company-= mode, this may be
>>> worth
>>> >> looking into:
>>> >>
>>> >> https://github.com/mutbuerge= r/company-org-headings
>>> >>
>>> >> Keep in mind that I'm in the process of learning = Elisp and
>>> >> there has been little to no testing done on the packa= ge. Furthermore it
>>> >> uses org-store-link instead of org-id-store-link.
>>> >>
>>> >> Regards,
>>> >> Bernhard Pr=C3=B6ll
>>> >>
>>> >>
>>> >> On Fri, 31. Jul 09:43, Xebar Saram wrote:
>>> >>
>>> >>> i also have a similar workflow and would love to = hear Dominic if you
>>> >>> found a
>>> >>> solution for this or if anyone on the list has ot= her suggestions?
>>> >>>
>>> >>> best
>>> >>>
>>> >>> Z
>>> >>>
>>> >>> On Tue, May 12, 2015 at 10:57 PM, Dominic Surano = <sk8ingdom@gmail.com
>>> >
>>> >>> wrote:
>>> >>>
>>> >>>=C2=A0 =C2=A0 Hello,
>>> >>>
>>> >>>=C2=A0 =C2=A0 I use org-mode a lot like a wiki so = links to other org-mode
>>> headings
>>> >>> are
>>> >>>=C2=A0 =C2=A0 very common. Currently, I navigate t= o the heading or pull it up in
>>> an
>>> >>>=C2=A0 =C2=A0 agenda view, store the link with C-l= , going back to where I want to
>>> >>>=C2=A0 =C2=A0 insert the link, then insert the lin= k with C-c C-l RET. This is a
>>> bit
>>> >>>=C2=A0 =C2=A0 time consuming.
>>> >>>
>>> >>>=C2=A0 =C2=A0 Instead, I would prefer to map a key= that allows me to insert a
>>> link at
>>> >>>=C2=A0 =C2=A0 the current point using tab completi= on similar to org-refile (C-c
>>> C-w).
>>> >>>=C2=A0 =C2=A0 Looking through org-id.el, it seems = like
>>> org-id-get-with-outline-path
>>> >>>=C2=A0 =C2=A0 completion was designed for this pur= pose. I tried:
>>> >>>
>>> >>>=C2=A0 =C2=A0 (global-set-key "\C-ci" (l= ambda () (interactive) (org-id-get-with
>>> >>>=C2=A0 =C2=A0 outline-path-completion)))
>>> >>>
>>> >>>=C2=A0 =C2=A0 but it didn't work as intended. = Anyone have any ideas?
>>> >>>
>>> >>>=C2=A0 =C2=A0 Thanks!
>>> >>>=C2=A0 =C2=A0 -D
>>> >>>
>>> >>>=C2=A0 =C2=A0 For reference, I have the following = set in my configuration:
>>> >>>
>>> >>>=C2=A0 =C2=A0 ;; Use global IDs
>>> >>>=C2=A0 =C2=A0 (require 'org-id)
>>> >>>=C2=A0 =C2=A0 (setq org-id-link-to-org-use-id t) >>> >>>
>>> >>>=C2=A0 =C2=A0 ;; Update ID file .org-id-locations = on startup
>>> >>>=C2=A0 =C2=A0 (org-id-update-id-locations)
>>> >>>
>>> >>>=C2=A0 =C2=A0 ;; Targets include this file and any= file contributing to the
>>> agenda -
>>> >>>=C2=A0 =C2=A0 up to 9 levels deep
>>> >>>=C2=A0 =C2=A0 (setq org-refile-targets (quote ((ni= l :maxlevel . 9)
>>> >>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0(org-agenda-files :maxlevel .
>>> 9))))
>>> >>>=C2=A0 =C2=A0 (setq org-refile-use-outline-path &#= 39;file)
>>> >>>=C2=A0 =C2=A0 (setq org-outline-path-complete-in-s= teps t)
>>> >>>=C2=A0 =C2=A0 (setq org-refile-allow-creating-pare= nt-nodes t)
>>> >>>
>>> >>>
>>> >>>
>>> >>>
>>> >>>
>>>
>>> --
>>> Professor John Kitchin
>>> Doherty Hall A207F
>>> Department of Chemical Engineering
>>> Carnegie Mellon University
>>> Pittsburgh, PA 15213
>>> 412-268-78= 03
>>> @johnkitchin
>>> http://kitchingroup.cheme.cmu.edu
>>>
>>
>>

--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu



--
=
Dominic Surano
Email is my fastest and preferred method of contact
Phone, add= ress, etc. available upon request

--089e013cc32c050829051c44c8f3--