From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Daniel Mendler Newsgroups: gmane.emacs.devel Subject: [PATCH] `affixation-function`: Allow only three-element lists Date: Sun, 25 Apr 2021 02:39:53 +0200 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------9BB8A4D36EB7C9B224D2D685" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="23759"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Stefan Monnier , Juri Linkov To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Apr 25 02:41:14 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1laSpm-000643-Gy for ged-emacs-devel@m.gmane-mx.org; Sun, 25 Apr 2021 02:41:14 +0200 Original-Received: from localhost ([::1]:36500 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1laSpl-00049j-Ji for ged-emacs-devel@m.gmane-mx.org; Sat, 24 Apr 2021 20:41:13 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45602) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1laSoc-0003e6-MJ for emacs-devel@gnu.org; Sat, 24 Apr 2021 20:40:02 -0400 Original-Received: from server.qxqx.de ([2a01:4f8:121:346::180]:60235 helo=mail.qxqx.de) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1laSoZ-0007pK-Rk for emacs-devel@gnu.org; Sat, 24 Apr 2021 20:40:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=qxqx.de; s=mail1392553390; h=Content-Type:MIME-Version:Date:Message-ID:Subject:From:Cc :To:Sender:Reply-To:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=dYk5yORRDDEhtl646rmN5kuAy5SXNWSUuXh8eP07hQk=; b=n0Ol2ThPm5s44MUkvE7ProJ1QU jksejsnUcj3ZYBdF6eV8LBc1rzVnSuNOSDjkVqGJU/iasqDpVnIy1vmJMu0H3TJREsAUC9gtG8OAp atDiRRcf7h0RXhZoC1DeEu8kySDMfai3FCoW27NaU3Q/yEmt6h99S5y/Amj5w/q5FzlA=; Content-Language: en-US Received-SPF: pass client-ip=2a01:4f8:121:346::180; envelope-from=mail@daniel-mendler.de; helo=mail.qxqx.de X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:268356 Archived-At: This is a multi-part message in MIME format. --------------9BB8A4D36EB7C9B224D2D685 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Regarding our previous discussion: I attached a patch which restricts the definition of the `affixation-function` such that the returned list must consist only of three-element lists. Since the `affixation-function` is part of the widely used `completing-read` API a simplification is helpful for both authors of completion UIs and authors of completion tables. Daniel --------------9BB8A4D36EB7C9B224D2D685 Content-Type: text/x-diff; charset=UTF-8; name="0001-affixation-function-Allow-only-three-element-list-el.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-affixation-function-Allow-only-three-element-list-el.pa"; filename*1="tch" >From 82583ee3afbb1278e664a3e5858a93bc698c370b Mon Sep 17 00:00:00 2001 From: Daniel Mendler Date: Sun, 25 Apr 2021 02:04:23 +0200 Subject: [PATCH] (affixation-function): Allow only three-element list elements Restrict the definition of the `affixation-function`. The function must return a list of three element lists. Since the `affixation-function` is part of the widely used `completing-read` API a simplification is helpful for both authors of completion UIs and authors of completion tables. * doc/lispref/minibuf.texi: Update documentation. * lisp/minibuffer.el: Update documentation. (minibuffer-completion-help): Add assertion. * lisp/simple.el (read-extended-command--affixation): Return three-element lists. --- doc/lispref/minibuf.texi | 10 ++++------ lisp/minibuffer.el | 22 ++++++++++++---------- lisp/simple.el | 7 +++++-- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/doc/lispref/minibuf.texi b/doc/lispref/minibuf.texi index 7cf2fcf68f..28d3afac22 100644 --- a/doc/lispref/minibuf.texi +++ b/doc/lispref/minibuf.texi @@ -1819,12 +1819,10 @@ Completion Variables @item :affixation-function The value should be a function to add prefixes and suffixes to completions. This function must accept one argument, a list of -completions, and should return such a list of completions where -each element contains a list of three elements: a completion, -a prefix string, and a suffix string. When this function -returns a list of two elements, it is interpreted as a list -of a completion and a suffix string like in @code{:annotation-function}. -This function takes priority over @code{:annotation-function}. +completions, and should return a list of annotated completions. Each +element of the returned list must be a three-element list, the +completion, a prefix string, and a suffix string. This function takes +priority over @code{:annotation-function}. @item :exit-function The value should be a function to run after performing completion. diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 98691c2ede..f76ce37030 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -122,10 +122,10 @@ completion-metadata returns a string to append to STRING. - `affixation-function': function to prepend/append a prefix/suffix to entries. Takes one argument (COMPLETIONS) and should return a list - of completions with a list of either two elements: completion - and suffix, or three elements: completion, its prefix - and suffix. This function takes priority over `annotation-function' - when both are provided, so only this function is used. + of annotated completions. The elements of the list must be + three-element lists: completion, its prefix and suffix. This + function takes priority over `annotation-function' when both are + provided, so only this function is used. - `display-sort-function': function to sort entries in *Completions*. Takes one argument (COMPLETIONS) and should return a new list of completions. Can operate destructively. @@ -1972,11 +1972,11 @@ completion-extra-properties `:affixation-function': Function to prepend/append a prefix/suffix to completions. The function must accept one argument, a list of - completions, and return a list where each element is a list of - either two elements: a completion, and a suffix, or - three elements: a completion, a prefix and a suffix. - This function takes priority over `:annotation-function' - when both are provided, so only this function is used. + completions, and return a list of annotated completions. The + elements of the list must be three-element lists: completion, its + prefix and suffix. This function takes priority over + `:annotation-function' when both are provided, so only this + function is used. `:exit-function': Function to run after completion is performed. @@ -2110,7 +2110,9 @@ minibuffer-completion-help (cond (aff-fun (setq completions - (funcall aff-fun completions))) + (funcall aff-fun completions)) + (cl-assert (or (not completions) + (= 3 (length (car completions)))))) (ann-fun (setq completions (mapcar (lambda (s) diff --git a/lisp/simple.el b/lisp/simple.el index 999755a642..26eb8cad7f 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -2080,8 +2080,11 @@ read-extended-command--affixation (obsolete (format " (%s)" (car obsolete))) ((and binding (not (stringp binding))) - (format " (%s)" (key-description binding)))))) - (if suffix (list command-name suffix) command-name))) + (format " (%s)" (key-description binding))) + (t "")))) + (put-text-property 0 (length suffix) + 'face 'completions-annotations suffix) + (list command-name "" suffix))) command-names))) (defcustom suggest-key-bindings t -- 2.20.1 --------------9BB8A4D36EB7C9B224D2D685--