From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id WM1fB7ZSn15FegAA0tVLHw (envelope-from ) for ; Tue, 21 Apr 2020 20:08:22 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id YNJQHbtSn160dgAAB5/wlQ (envelope-from ) for ; Tue, 21 Apr 2020 20:08:27 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id DC04D941D35 for ; Tue, 21 Apr 2020 20:08:25 +0000 (UTC) Received: from localhost ([::1]:35688 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQzBv-0006bX-JP for larch@yhetil.org; Tue, 21 Apr 2020 16:08:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40868) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQzBL-0006ai-OS for emacs-orgmode@gnu.org; Tue, 21 Apr 2020 16:07:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jQzBK-0006lo-Py for emacs-orgmode@gnu.org; Tue, 21 Apr 2020 16:07:47 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:42533) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jQzBJ-0006g9-7d for emacs-orgmode@gnu.org; Tue, 21 Apr 2020 16:07:46 -0400 Received: by mail-wr1-x443.google.com with SMTP id j2so18015643wrs.9 for ; Tue, 21 Apr 2020 13:07:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=andrew-cmu-edu.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=nKgRVCac5PNa1L0r8qYUxwMDJkp85NtXrThk4YJWzIw=; b=rxKzolZPkiWwg5jN3CRocYFMR6Omm0hC2/5PKh4GJzGTEj40mNDH3lcoQdw3R4xSaK ezrxxBRC5vCegR+5/PlmJZrm1Jw14aA8hbgMfJfiCVI8fuCjU/zvXygOhC8mCBa6ya0z jMq4znrzn3b4leAg/p2bN6xzHHdbXqE0+s2pIDVU/VGsfG2HA8TfkZQYt79yklNE3G6e G+WAHWwaySb2m6EuHNyG4KXk9+TtGXbZQGzFkpEVi5x1dZV/IqVKn2Y1gmlrrOyA1MtX 708eYHi8EETltlT9WNAfIxCoFlLGkr8w5/pbKt+tMiBA/ccq9vqFd2s/t82+TfrxCIwB GLjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=nKgRVCac5PNa1L0r8qYUxwMDJkp85NtXrThk4YJWzIw=; b=KIAjr4H7U3I1h3+VP/LglPTm3xMFMEfOies3odocqLEGR6fQjsaNrH5q+GYotXX3vc vU+qDbZvT5YgwjAbHVVG51bdmIoih99ZmGT3+CcWd4WX3EhPLL5nMJ/beHIcv5OZ52Yf bUqaOz3kq0oJI4EDYYTDi5JgdJ+nzxGeZR0KAOI+puHe0c8oewt5UMNNtSKSW9UKaej4 vRLZwRUwaI3zpjhnqzlV6t+EEV5LRDrhRreg8yS5Trf7NSEEjjdu4nYHzu1bI2HTwpBp XmPTB1QLGtVuHW2Pu9/hiEnAezRAE8i/Twr69GU4hK/1DbcwG2s64BMSSxT/V0Fp7k/1 QKmA== X-Gm-Message-State: AGi0PubQCtzWuA+8+dBrpv1dP3nxEHu9nBY1AOKupP6kDTdzh9JsIwLh HBAsiz+D7Pegt8LlLOaOFS+r2ZfNwdMKpKJyryIWbxilV9Y= X-Google-Smtp-Source: APiQypLdTzdCgpj3sSC759qYSi3Unaklw77ifw5oibEmnreT5+ytJC7s6c/yHHCg33ysxzZVf7fhWUG2qE2Ev9iz8Sk= X-Received: by 2002:a5d:4ac6:: with SMTP id y6mr25454771wrs.212.1587499662120; Tue, 21 Apr 2020 13:07:42 -0700 (PDT) MIME-Version: 1.0 References: <87pnc0pvr5.fsf@nicolasgoaziou.fr> In-Reply-To: <87pnc0pvr5.fsf@nicolasgoaziou.fr> From: John Kitchin Date: Tue, 21 Apr 2020 16:07:30 -0400 Message-ID: Subject: Re: Public API change: How to handle function signature change gracefully To: "Benjamin Andresen via General discussions about Org-mode." , Benjamin Andresen Content-Type: multipart/alternative; boundary="000000000000711ba205a3d291cd" Received-SPF: pass client-ip=2a00:1450:4864:20::443; envelope-from=johnrkitchin@gmail.com; helo=mail-wr1-x443.google.com X-detected-operating-system: by eggs.gnu.org: Error: [-] PROGRAM ABORT : Malformed IPv6 address (bad octet value). Location : parse_addr6(), p0f-client.c:67 X-Received-From: 2a00:1450:4864:20::443 X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Scanner: scn0 X-Spam-Score: -0.21 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=andrew-cmu-edu.20150623.gappssmtp.com header.s=20150623 header.b=rxKzolZP; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=andrew.cmu.edu (policy=none); spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Scan-Result: default: False [-0.21 / 13.00]; GENERIC_REPUTATION(0.00)[-0.56827373796216]; R_SPF_ALLOW(-0.20)[+ip4:209.51.188.0/24:c]; IP_REPUTATION_HAM(0.00)[asn: 22989(0.23), country: US(-0.01), ip: 209.51.188.17(-0.57)]; URI_COUNT_ODD(1.00)[3]; TO_DN_ALL(0.00)[]; MX_GOOD(-0.50)[cached: eggs.gnu.org]; RCPT_COUNT_TWO(0.00)[2]; DKIM_TRACE(0.00)[andrew-cmu-edu.20150623.gappssmtp.com:+]; MAILLIST(-0.20)[mailman]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; RCVD_IN_DNSWL_LOW(-0.10)[209.51.188.17:from]; MIME_TRACE(0.00)[0:+,1:+,2:~]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:22989, ipnet:209.51.188.0/24, country:US]; TAGGED_FROM(0.00)[larch=yhetil.org]; FROM_NEQ_ENVFROM(0.00)[jkitchin@andrew.cmu.edu,emacs-orgmode-bounces@gnu.org]; ARC_NA(0.00)[]; RCVD_COUNT_FIVE(0.00)[6]; R_DKIM_ALLOW(-0.20)[andrew-cmu-edu.20150623.gappssmtp.com:s=20150623]; FROM_HAS_DN(0.00)[]; URIBL_BLOCKED(0.00)[nicolasgoaziou.fr:email,andrew-cmu-edu.20150623.gappssmtp.com:dkim,cmu.edu:url]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; PREVIOUSLY_DELIVERED(0.00)[emacs-orgmode@gnu.org]; HAS_LIST_UNSUB(-0.01)[]; FORGED_SENDER_MAILLIST(0.00)[]; DMARC_POLICY_SOFTFAIL(0.10)[andrew.cmu.edu : SPF not aligned (relaxed), DKIM not aligned (relaxed),none] X-TUID: +ySgY3BjxRXg --000000000000711ba205a3d291cd Content-Type: text/plain; charset="UTF-8" I think what Nicolas suggests is probably the easiest path. Here is one example that does what I think you are looking for. I use a simple string comparison on the contents, you could do something more sophisticated. #+BEGIN_SRC emacs-lisp (defun fruit-link-face (path) (let* ((ln (org-element-context)) (start (org-element-property :contents-begin ln)) (end (org-element-property :contents-end ln)) (contents (if (and start end) (buffer-substring start end) nil))) (if (and contents (stringp contents)) (if (string> contents "j") '(:foreground "red") '(:foreground "blue")) 'org-link))) (org-link-set-parameters "fruit" :face 'fruit-link-face) #+END_SRC #+RESULTS: | :face | fruit-link-face | [[fruit:mango ][test]]. # this will be red fruit:apple. # regular org link. [[fruit:apple][bera]]. # this will be blue 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 Tue, Apr 21, 2020 at 1:57 PM Nicolas Goaziou wrote: > Hello, > > Benjamin Andresen writes: > > > > I would like to change the public API of the :face part of > `org-link-set-parameters': > > > > (org-link-set-parameters "file" :face 'org-link) > > > > My ultimate goal is to have org-links be able to be have their face > changed based on the contents, not just the path of the link. > > > > I found the relevant code in org.el in the function `org-activate-links': > > > > 'face (pcase (org-link-get-parameter type :face) > > ((and (pred functionp) face) (funcall face path)) > > ((and (pred facep) face) face) > > ((and (pred consp) face) face) ;anonymous > > (_ 'org-link)) > > > > and would like to change this to > > > > 'face (pcase (org-link-get-parameter type :face) > > ((and (pred functionp) face) (funcall face path contents)) ;; this is > the change > > ((and (pred facep) face) face) > > ((and (pred consp) face) face) ;anonymous > > (_ 'org-link)) > > > > Now that will introduce a host of call issues because the callees don't > expect to the amount of arguments changed under their bottom. > > > > I would like some guidance how I could get what I think is neat: The > > contents of the bracket-style links as an additional parameter to set > > faces on and not breaking existing hookups. > > Isn't the function called with point on the link? You may just need to > extract the contents from the environment. > > Otherwise, a solution is to catch `wrong-number-of-arguments' error and > call again the function with the old calling convention. See, e.g., > `org-link-open'. > > > To make this more palatable I would suggest it's changed so that the > > 2nd argument will be a list of alists or keywords so to not have this > > function signature problem if someone else comes up with a reason to > > introduce yet more data. > > Beware the over-engineering. At this point, someone motivated enough can > put an advice to the link fontification function. > > Regards, > > -- > Nicolas Goaziou > > --000000000000711ba205a3d291cd Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I think what Nicolas suggests is probably the easiest path= . Here is one example that does what I think you are looking for. I use a s= imple string comparison on the contents, you could do something more sophis= ticated.

#+BEGIN_SRC emacs-lisp
(defun fruit-link-fac= e (path)
=C2=A0 (let* ((ln (org-element-context))
(start (org-eleme= nt-property :contents-begin ln))
(end (org-element-property :contents-= end ln))
(contents (if (and start end)
=C2=A0 =C2=A0 =C2=A0 (buf= fer-substring start end)
=C2=A0 =C2=A0 nil)))
=C2=A0 =C2=A0 (if (a= nd contents (stringp contents))
(if (string> contents "j")=
=C2=A0 =C2=A0'(:foreground "red")
=C2=A0'(:for= eground "blue"))
=C2=A0 =C2=A0 =C2=A0 'org-link)))

=
(org-link-set-parameters "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:face = 9;fruit-link-face)
#+END_SRC

#+RESULTS:
| :face | fruit-link-f= ace |

[[fruit:mango ][test]].=C2=A0 # this will be red
=C2=A0 fruit:apple. # regular org link.

=C2=A0[[fruit:apple][bera]]= . # this will be blue
Joh= n

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


On Tue, Apr 21, 2020 at 1:57 PM Nicolas Goaziou <<= a href=3D"mailto:mail@nicolasgoaziou.fr">mail@nicolasgoaziou.fr> wro= te:
Hello,

Benjamin Andresen writes:
>
> I would like to change the public API of the :face part of `org-link-s= et-parameters':
>
> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (org-link-set-parameters &q= uot;file" :face 'org-link)
>
> My ultimate goal is to have org-links be able to be have their face ch= anged based on the contents, not just the path of the link.
>
> I found the relevant code in org.el in the function `org-activate-link= s':
>
> =C2=A0=C2=A0 'face (pcase (org-link-get-parameter type :face)
> =C2=A0=C2=A0 ((and (pred functionp) face) (funcall face path))
> =C2=A0=C2=A0 ((and (pred facep) face) face)
> =C2=A0=C2=A0 ((and (pred consp) face) face) ;anonymous
> =C2=A0=C2=A0 (_ 'org-link))
>
> and would like to change this to
>
> =C2=A0=C2=A0 'face (pcase (org-link-get-parameter type :face)
> =C2=A0=C2=A0 ((and (pred functionp) face) (funcall face path contents)= ) ;; this is the change
> =C2=A0=C2=A0 ((and (pred facep) face) face)
> =C2=A0=C2=A0 ((and (pred consp) face) face) ;anonymous
> =C2=A0=C2=A0 (_ 'org-link))
>
> Now that will introduce a host of call issues because the callees don&= #39;t expect to the amount of arguments changed under their bottom.
>
> I would like some guidance how I could get what I think is neat: The > contents of the bracket-style links as an additional parameter to set<= br> > faces on and not breaking existing hookups.

Isn't the function called with point on the link? You may just need to<= br> extract the contents from the environment.

Otherwise, a solution is to catch `wrong-number-of-arguments' error and=
call again the function with the old calling convention. See, e.g.,
`org-link-open'.

> To make this more palatable I would suggest it's changed so that t= he
> 2nd argument will be a list of alists or keywords so to not have this<= br> > function signature problem if someone else comes up with a reason to > introduce yet more data.

Beware the over-engineering. At this point, someone motivated enough can put an advice to the link fontification function.

Regards,

--
Nicolas Goaziou

--000000000000711ba205a3d291cd--