From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: master 7fc0292: Allow completion styles to adjust completion metadata Date: Sat, 26 Oct 2019 12:12:50 -0400 Message-ID: References: <20191026121258.26047.33907@vcs0.savannah.gnu.org> <20191026121259.B54E720664@vcs0.savannah.gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="264104"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: =?windows-1252?B?Sm/jbyBU4XZvcmE=?= To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Oct 26 18:14:08 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 1iOOhY-0016W0-15 for ged-emacs-devel@m.gmane.org; Sat, 26 Oct 2019 18:14:04 +0200 Original-Received: from localhost ([::1]:40678 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iOOhW-0001AU-SS for ged-emacs-devel@m.gmane.org; Sat, 26 Oct 2019 12:14:02 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58381) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iOOgT-0000sM-MT for emacs-devel@gnu.org; Sat, 26 Oct 2019 12:12:58 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iOOgR-00047r-SC for emacs-devel@gnu.org; Sat, 26 Oct 2019 12:12:56 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:16060) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iOOgR-000476-M5 for emacs-devel@gnu.org; Sat, 26 Oct 2019 12:12:55 -0400 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id CE65881155; Sat, 26 Oct 2019 12:12:53 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 3AF4E80AC6; Sat, 26 Oct 2019 12:12:52 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1572106372; bh=S2mejyQXM9CHDfxarbYDiDxvT4Ir8XCcH/S03Y1GVEw=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=oN6YxY9O5245ghteuYTPHa6o6xG2ShdyUsvnqpxRScv9dbV/lJcn0HxKUM2wXcylc mUE3Ecn8Tp7INT7WeYovbnV7qnESaWkq37YcioEMaA0kryqAcWdO7BS7xSw/VOdpSK pJJWwKOKgjUvi87CnzVK+yZ3U5hx2K2P8TF+yOGcbleNNOuoDv/TIiVxhjuwiV6K2C rX3EcUZfJe9TmkPZL3EZi3e2ozildacY8OnB2FM7TW9uOl6m5c6s6ggseRV9mn40kK 8Wx8BJuSSC3cZMs1GIPJHGC8ECt9HRniGvDOmNIAn4Wj8/v+bnseCYGcfpepJBx+8f tVobjPTiSWdUg== Original-Received: from pastel (unknown [216.154.30.71]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id D744A120130; Sat, 26 Oct 2019 12:12:51 -0400 (EDT) In-Reply-To: <20191026121259.B54E720664@vcs0.savannah.gnu.org> (=?windows-1252?Q?=22Jo=E3o=09T=E1vora=22's?= message of "Sat, 26 Oct 2019 08:12:59 -0400 (EDT)") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 132.204.25.50 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:241467 Archived-At: > +(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