From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?B?Sm/Do28gVMOhdm9yYQ==?= Newsgroups: gmane.emacs.devel Subject: Re: master 7fc0292: Allow completion styles to adjust completion metadata Date: Sat, 26 Oct 2019 17:59:20 +0100 Message-ID: References: <20191026121258.26047.33907@vcs0.savannah.gnu.org> <20191026121259.B54E720664@vcs0.savannah.gnu.org> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000b6ee490595d3308e" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="224299"; mail-complaints-to="usenet@blaine.gmane.org" Cc: emacs-devel To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Oct 26 19:01:46 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iOPRf-000wCD-Jo for ged-emacs-devel@m.gmane.org; Sat, 26 Oct 2019 19:01:43 +0200 Original-Received: from localhost ([::1]:40982 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iOPRd-0000mg-Vv for ged-emacs-devel@m.gmane.org; Sat, 26 Oct 2019 13:01:42 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34554) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iOPPa-0007F6-Me for emacs-devel@gnu.org; Sat, 26 Oct 2019 12:59:35 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iOPPZ-0007fN-37 for emacs-devel@gnu.org; Sat, 26 Oct 2019 12:59:34 -0400 Original-Received: from mail-io1-xd31.google.com ([2607:f8b0:4864:20::d31]:41117) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iOPPY-0007em-UR for emacs-devel@gnu.org; Sat, 26 Oct 2019 12:59:33 -0400 Original-Received: by mail-io1-xd31.google.com with SMTP id r144so5950293iod.8 for ; Sat, 26 Oct 2019 09:59:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=otaT1SE+ve3DkGy/4ckWaWvRFUf6dayhDz9X+QqF9RE=; b=DPblzI/PNP3TP7pDJ0QC5mHtNv1qH71DynSXCH9jMom/rCrM6wEfbIBtKwsoQs42IJ RwYO8kdj0hQoaNcDKrm6FVdUWSYSgECOS4YcFS+yz2CT+eu8xWD3ItjWxD8HRdnUVYjM yslyuItjY3oR0cSgMxObKQtmJEaP6anSXKW1YZD7jX31CskFRpEk2Gb4HII8eVHnT7gN AXtFw7S9jBXAVtOG0JrF4PfIOa8NPIhd05ITV7MGkNU+IHK4X/nLpCozMjbvuy5iWu+x FULfGU807gcqH9Yl7E5wb6Bzh028hFwncotHTNZ2CD5OQMu1oSKssXKNVUSu9IZbYNHn ySyQ== 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:cc; bh=otaT1SE+ve3DkGy/4ckWaWvRFUf6dayhDz9X+QqF9RE=; b=RyTU4Na8r19njnWj++ZnmvoAY4uPGLI20lztF07/rASUpX+0X/1kPpTEWAj+MRpXP+ lX/BVuHmURIxFUXhRi/PPJTpcrdT1/gVeZPGca1x+akbkdamxkvLh8zd4Ccwsp7F1oa8 Q+yEygEJpVL7Hb42+eoJ17rN7GtCSNeyHLmLYwRk2hlCx+cHHTxGO52lwJmeGVOEhuJo pKQIjYCTQgbujN3XejzoZZpFezHhJwCKUsldBlKR0bb6kBTgGWcTDaTqXGpOv+kNjmpx 1M8/qvgzicY1RRhrLPOtt3nru3REDpM9IP92am2euWYk0YOMTd1z8a8TX1qtqMDhL2Jl g9Ng== X-Gm-Message-State: APjAAAU0rYCURg/hKQNj1MtIMGPdmeQKADswOIYLJzg/Jj1KTVK3MxRu GI+edsepajmlb1cFIHWTfgFo9aUOdmNV9eBoMKboGA== X-Google-Smtp-Source: APXvYqwRQfcmyl7D6O+BCiuy6ZZmqHND/0Dn9zsIjHqWG8zm2rERfi3EJbdz90pLH9tjnOkWry4xXFxfQASBCOhtVDQ= X-Received: by 2002:a6b:ea0b:: with SMTP id m11mr9393821ioc.97.1572109171484; Sat, 26 Oct 2019 09:59:31 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::d31 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:241472 Archived-At: --000000000000b6ee490595d3308e Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable You're right, this version didn't work for many reasons. Once we get cl-defgeneric to work, we can fix it to work by return value, as you suggest... Jo=C3=A3o On Sat, Oct 26, 2019, 17:12 Stefan Monnier wrote= : > > +(cl-defgeneric completion-adjust-metadata-for-style (style metadata) > > + "Adjust METADATA of current completion according to STYLE." > > + (:method (_style _metadata) nil) ; nop by default > > Hmm... if "nop" is to return nil, it means it works by side-effect, but > if the metadata is `nil` to start with, there's no side-effect that can > turn it into a non-nil value, right? > > So I think it should work by returning a new metadata and hence "nop" > should be to return `metadata` unmodified. > > > + (let ((alist (cdr metadata))) > > + (setf (alist-get 'display-sort-function alist) > > + (compose-flex-sort-fn (alist-get 'display-sort-function > alist))) > > + (setf (alist-get 'cycle-sort-function alist) > > + (compose-flex-sort-fn (alist-get 'cycle-sort-function > alist))) > > This works by side-effecting the alist, but those entries may (and > usually) come from immediate constants in the code, so this is > like "self-modifying code" :-( > > > + metadata)))) > > I see here you do return the metadata, good. > > > + (result-and-style > > + (completion--some > > + (lambda (style) > > + (let ((probe (funcall (nth n (assq style > > + completion-styles-alist= )) > > + string table pred point))) > > + (and probe (cons probe style)))) > > + (completion--styles metadata)))) > > + (completion-adjust-metadata-for-style (cdr result-and-style) > metadata) > > (if requote > > But here it appears you're not using the return value, unless I'm > missing something. > > > Stefan > > --000000000000b6ee490595d3308e Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
You're right, this version didn't work for many r= easons. Once we get cl-defgeneric to work, we can fix it to work by return = value, as you suggest...

Jo=C3= =A3o

On Sat, Oct 26, 2019, 17:12 Stefan Monnier <monnier@iro.umontreal.ca> wrote:
=
> +(cl-defgeneric completion-adjust-metad= ata-for-style (style metadata)
> +=C2=A0 "Adjust METADATA of current completion according to STYLE= ."
> +=C2=A0 (:method (_style _metadata) nil) ; nop by default

Hmm... if "nop" is to return nil, it means it works by side-effec= t, but
if the metadata is `nil` to start with, there's no side-effect that can=
turn it into a non-nil value, right?

So I think it should work by returning a new metadata and hence "nop&q= uot;
should be to return `metadata` unmodified.

> +=C2=A0 =C2=A0 =C2=A0(let ((alist (cdr metadata)))
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0(setf (alist-get 'display-sort-functio= n alist)
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(compose-flex-sort-fn= (alist-get 'display-sort-function alist)))
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0(setf (alist-get 'cycle-sort-function = alist)
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(compose-flex-sort-fn= (alist-get 'cycle-sort-function alist)))

This works by side-effecting the alist, but those entries may (and
usually) come from immediate constants in the code, so this is
like "self-modifying code" :-(

> +=C2=A0 =C2=A0 =C2=A0 =C2=A0metadata))))

I see here you do return the metadata, good.

> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 (result-and-style
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(completion--some
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (lambda (style)
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (let ((probe (funcall (nth = n (assq style
> +=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 =C2=A0completion-styles-alist))
> +=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 string table pred point))= )
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (and probe (cons pro= be style))))
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (completion--styles metadata)))) > +=C2=A0 =C2=A0 (completion-adjust-metadata-for-style (cdr result-and-s= tyle) metadata)
>=C2=A0 =C2=A0 =C2=A0 (if requote

But here it appears you're not using the return value, unless I'm missing something.


=C2=A0 =C2=A0 =C2=A0 =C2=A0 Stefan

--000000000000b6ee490595d3308e--