From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id QOJSIW5sn15rWwAA0tVLHw (envelope-from ) for ; Tue, 21 Apr 2020 21:58:06 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id gCbmBHRsn15YVAAA1q6Kng (envelope-from ) for ; Tue, 21 Apr 2020 21:58:12 +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 B2279941A4C for ; Tue, 21 Apr 2020 21:58:10 +0000 (UTC) Received: from localhost ([::1]:36690 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jR0u9-0008Ii-67 for larch@yhetil.org; Tue, 21 Apr 2020 17:58:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49820) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jR0sd-0007aF-8d for emacs-orgmode@gnu.org; Tue, 21 Apr 2020 17:56:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jR0sc-0000HR-3A for emacs-orgmode@gnu.org; Tue, 21 Apr 2020 17:56:34 -0400 Received: from w4.tutanota.de ([81.3.6.165]:52690) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jR0sb-0008TR-7z for emacs-orgmode@gnu.org; Tue, 21 Apr 2020 17:56:33 -0400 Received: from w3.tutanota.de (unknown [192.168.1.164]) by w4.tutanota.de (Postfix) with ESMTP id 584141060159 for ; Tue, 21 Apr 2020 21:56:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1587506189; s=s1; d=lambda.icu; h=From:From:To:To:Subject:Subject:Content-Description:Content-ID:Content-Type:Content-Type:Content-Transfer-Encoding:Content-Transfer-Encoding:Cc:Date:Date:In-Reply-To:In-Reply-To:MIME-Version:MIME-Version:Message-ID:Message-ID:Reply-To:References:References:Sender; bh=vv9AcWMt0h5lJk0qlJfaeU4DAEmT2fgPj0HAN4GdGgw=; b=hrSmmoTk6PBlCH9jUoi8i6AtDaNNS4tl60NUHmmb3060ZTKpzEAegwjG0b5K3wmn hJGDaByCwEr0xWrGx7u2rYrUxXDZAt2vAhDQWujoPGqwKqYnfRS9gSG6SYYh5zyzB81 3nEzucFf3UMkOsFTcOPbWQPZivDOtQRbc72uVG1GfBBOtSB+stL9SjbiXM8X+4+WzcJ cIwD03UVLDutdVoW/7cafNc5m/jgUnkdgwBr8VU98FKuAjyB5b3O3sXva0vmJMNyWS2 jYq2N3EfNV/Z4BpFEEaQY7p+mY/jURX6tr2JDa2NaBz/4O5krdkV32IPTs7w4YCSst6 loE0DKS6Ug== Date: Tue, 21 Apr 2020 23:56:29 +0200 (CEST) To: Emacs Orgmode Message-ID: In-Reply-To: References: <87pnc0pvr5.fsf@nicolasgoaziou.fr> Subject: Re: Public API change: How to handle function signature change gracefully MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=81.3.6.165; envelope-from=benny@lambda.icu; helo=w4.tutanota.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/21 17:56:29 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 81.3.6.165 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" Reply-to: Benjamin Andresen From: Benjamin Andresen via "General discussions about Org-mode." X-Scanner: scn0 X-Spam-Score: -0.11 Authentication-Results: aspmx1.migadu.com; dkim=fail (rsa verify failed) header.d=lambda.icu header.s=s1 header.b=hrSmmoTk; dmarc=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.11 / 13.00]; HAS_REPLYTO(0.00)[benny@lambda.icu]; GENERIC_REPUTATION(0.00)[-0.56800701271185]; 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)]; R_DKIM_REJECT(1.00)[lambda.icu:s=s1]; TO_DN_ALL(0.00)[]; MX_GOOD(-0.50)[cached: eggs.gnu.org]; DKIM_TRACE(0.00)[lambda.icu:-]; MAILLIST(-0.20)[mailman]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; RCVD_IN_DNSWL_LOW(-0.10)[209.51.188.17:from]; TO_EQ_FROM(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:22989, ipnet:209.51.188.0/24, country:US]; RCVD_TLS_LAST(0.00)[]; TAGGED_FROM(0.00)[larch=yhetil.org]; FROM_NEQ_ENVFROM(0.00)[emacs-orgmode@gnu.org,emacs-orgmode-bounces@gnu.org]; ARC_NA(0.00)[]; RCVD_COUNT_FIVE(0.00)[6]; URIBL_BLOCKED(0.00)[cmu.edu:email,nicolasgoaziou.fr:email]; FROM_HAS_DN(0.00)[]; MIME_GOOD(-0.10)[text/plain]; REPLYTO_DOM_NEQ_FROM_DOM(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[emacs-orgmode@gnu.org]; HAS_LIST_UNSUB(-0.01)[]; RCPT_COUNT_ONE(0.00)[1]; DMARC_NA(0.00)[gnu.org]; FORGED_SENDER_MAILLIST(0.00)[] X-TUID: N151AGobyuUX Thanks John and Nicolas. I sort of arrived at the same point with my over-engineered approach and ch= ange of public API. modified=C2=A0=C2=A0 lisp/org.el @@ -5081,10 +5081,18 @@ This includes angle, plain, and bracket links." (link (org-element-property :raw-link link-object)) (type (org-element-property :type link-object)) (path (org-element-property :path link-object)) +=09=09 (cbeg (org-element-property :contents-begin link-object)) +=09=09 (cend (org-element-property :contents-end link-object)) +=09=09 (contents (if (and cbeg cend) +=09=09=09=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (buffer-substring-no-propert= ies cbeg cend))) (properties=09=09;for link's visible part =C2=A0 (list =C2=A0=C2=A0 'face (pcase (org-link-get-parameter type :face) -=09=09=09=C2=A0=C2=A0 ((and (pred functionp) face) (funcall face path)) +=09=09=09=C2=A0=C2=A0 ((and (pred functionp) face) (let* ((number-of-args = (cdr (func-arity face))) +=09=09=09=09=09=09=09=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (kws (plist-put = '() :contents contents))) +=09=09=09=09=09=09=09=C2=A0 (if (equal number-of-args 1) +=09=09=09=09=09=09=09=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (funcall face path) +=09=09=09=09=09=09=09=C2=A0=C2=A0=C2=A0 (funcall face path kws)))) =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)) This in turn resulted in more complexity on the callee side as I had to res= olve the keywords. So thanks for this simple fix I get rid of my over-engineered proposal: Hav= ing access to `org-element-context' is great for my usecase, because it mea= ns it will work on versions of Org that are already released. Yay! Best regards, Benny Apr 21, 2020, 22:07 by jkitchin@andrew.cmu.edu: > I think what Nicolas suggests is probably the easiest path. Here is one e= xample that does what I think you are looking for. I use a simple string co= mparison on the contents, you could do something more sophisticated. > > #+BEGIN_SRC emacs-lisp > (defun fruit-link-face (path) > =C2=A0 (let* ((ln (org-element-context)) > (start (org-element-property :contents-begin ln)) > (end (org-element-property :contents-end ln)) > (contents (if (and start end) > =C2=A0 =C2=A0 =C2=A0 (buffer-substring start end) > =C2=A0 =C2=A0 nil))) > =C2=A0 =C2=A0 (if (and contents (stringp contents)) > (if (string> contents "j") > =C2=A0 =C2=A0'(:foreground "red") > =C2=A0'(:foreground "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 'fruit-link-face) > #+END_SRC > > #+RESULTS: > | :face | fruit-link-face | > > [[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 > John > > ----------------------------------- > Professor John Kitchin=C2=A0 > 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 <> mail@nicolasgoaziou.fr= > > wrote: > >> Hello, >> =20 >> Benjamin Andresen writes: >> > >> > I would like to change the public API of the :face part of `org-link-= set-parameters': >> > >> > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (org-link-set-parameters "= file" :face 'org-link) >> > >> > My ultimate goal is to have org-links be able to be have their face c= hanged based on the contents, not just the path of the link. >> > >> > I found the relevant code in org.el in the function `org-activate-lin= ks': >> > >> > =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=20 >> > >> > =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= '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. >> =20 >> Isn't the function called with point on the link? You may just need to >> extract the contents from the environment. >> =20 >> 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'. >> =20 >> > 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. >> =20 >> Beware the over-engineering. At this point, someone motivated enough ca= n >> put an advice to the link fontification function. >> =20 >> Regards, >> =20 >> --=20 >> Nicolas Goaziou >> =20 >>