From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin Subject: Re: How to set org-make-link-description-function Date: Fri, 13 Apr 2018 13:32:08 -0700 Message-ID: References: <87bmeo53ji.fsf@ericabrahamsen.net> <87bmenu4lv.fsf@ericabrahamsen.net> <877epbt3yv.fsf@ericabrahamsen.net> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="001a113ca360305b040569c0c48a" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:53135) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f75Mi-0007WM-Cc for emacs-orgmode@gnu.org; Fri, 13 Apr 2018 16:32:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f75Mh-0004KH-8d for emacs-orgmode@gnu.org; Fri, 13 Apr 2018 16:32:12 -0400 Received: from mail-wr0-x22b.google.com ([2a00:1450:400c:c0c::22b]:44895) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f75Mg-0004Jn-T5 for emacs-orgmode@gnu.org; Fri, 13 Apr 2018 16:32:11 -0400 Received: by mail-wr0-x22b.google.com with SMTP id u46so11086560wrc.11 for ; Fri, 13 Apr 2018 13:32:10 -0700 (PDT) In-Reply-To: <877epbt3yv.fsf@ericabrahamsen.net> 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" To: Eric Abrahamsen Cc: org-mode-email --001a113ca360305b040569c0c48a Content-Type: text/plain; charset="UTF-8" Here is a globally defined version that would let you define a function for any other kind of link I think. There are probably many variations on this theme, like storing functions in some variable as an alist, etc. Something like that is what would happen if this was defined in the link parameters. #+BEGIN_SRC emacs-lisp (defun my-comp (&optional arg) (format "fruit:%s" (completing-read "Choose a fruit: " '("apple" "orange" "grapes" "kiwi")))) (org-link-set-parameters "fruit" :complete 'my-comp) (defun org-fruit-make-link-description (link desc) (replace-regexp-in-string "fruit:" "" link)) (setq org-make-link-description-function (lambda (link desc) (let* ((link-type (car (s-split ":" link))) (make-func (intern (format "org-%s-make-link-description" link-type)))) (if (fboundp make-func) (funcall make-func link desc) desc)))) #+END_SRC John ----------------------------------- 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 On Fri, Apr 13, 2018 at 10:23 AM, Eric Abrahamsen wrote: > John Kitchin writes: > > > Not with the way I wrote it. It should only affect your links and pass > everything else through I > > think. > > I just meant, you can only have one of these functions set. So if I > provide special behavior for ebdb links, no other function would be able > to do the equivalent for some other type of link. > > > --001a113ca360305b040569c0c48a Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Here is a globally defined version that would let you defi= ne a function for any other kind of link I think. There are probably many v= ariations on this theme, like storing functions in some variable as an alis= t, etc. Something like that is what would happen if this was defined in the= link parameters.

#+BEGIN_SRC emacs-lisp
= (defun my-comp (&optional arg)
=C2=A0 (format "fruit:%s&= quot;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (completing-read "C= hoose a fruit: " '("apple" "orange" "grap= es" "kiwi"))))

(org-link-set-parame= ters "fruit"=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:complete 'my-co= mp)


(defun org-fruit-make-link-desc= ription (link desc)
=C2=A0 (replace-regexp-in-string "fruit:= " "" link))


(setq or= g-make-link-description-function
=C2=A0 =C2=A0 =C2=A0 (lambda (li= nk desc)
(let* ((link-typ= e (car (s-split ":" link)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0(make-func (intern (format "or= g-%s-make-link-description" link-type))))
=C2=A0 (if (fboundp make-func)
=C2=A0 =C2=A0 =C2=A0 (funcall make-func link d= esc)
=C2=A0 =C2=A0 desc))= ))
#+END_SRC

John

------------------= -----------------
Professor John Kitchin=C2=A0
Doherty Hall A207F
= Department of Chemical Engineering
Carnegie Mellon University
Pittsbu= rgh, PA 15213
412-268-7803

On Fri, Apr 13, 2018 at 10:23 AM, Eric Abrah= amsen <eric@ericabrahamsen.net> wrote:
John Kitchin <jkitchin@andrew.cmu.edu> writes:

> Not with the way I wrote it. It should only affect your links and pass= everything else through I
> think.

I just meant, you can only have one of these functions set. So if I<= br> provide special behavior for ebdb links, no other function would be able to do the equivalent for some other type of link.



--001a113ca360305b040569c0c48a--