unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Daniel Mendler <mail@daniel-mendler.de>
To: 53012@debbugs.gnu.org
Cc: Stefan Monnier <monnier@iro.umontreal.ca>
Subject: bug#53012: 28.0.90; completion--nth-completion: Throw a meaningful error
Date: Tue, 4 Jan 2022 21:12:47 +0100	[thread overview]
Message-ID: <9908ba86-2117-9025-559c-dc7bc868b371@daniel-mendler.de> (raw)

In the context of the GNU ELPA Vertico/Mct/Orderless/Embark ecosystem we
teach users to adjust the completion style. Unfortunately
completion--nth-completion is not very robust against misconfiguration.
I propose to throw a more meaningful error instead of the nil error.
Patch follows.

---

From da92169572e375facabb28b6d3c14cb2158ab1c9 Mon Sep 17 00:00:00 2001
From: Daniel Mendler <mail@daniel-mendler.de>
Date: Tue, 4 Jan 2022 21:08:04 +0100
Subject: [PATCH] completion--nth-completion: Throw meaningful error

If a configured completion style does not exist, throw a meaningful
error. Also make completion-styles-alist a defvar, since completion
styles like orderless extend it.
---
 lisp/minibuffer.el | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 1d596694e4..ab760a42d1 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -900,7 +900,7 @@ completion-auto-help
 the second failed attempt to complete."
   :type '(choice (const nil) (const t) (const lazy)))

-(defconst completion-styles-alist
+(defvar completion-styles-alist
   '((emacs21
      completion-emacs21-try-completion completion-emacs21-all-completions
      "Simple prefix-based completion.
@@ -1076,9 +1076,10 @@ completion--nth-completion
          (result-and-style
           (completion--some
            (lambda (style)
-             (let ((probe (funcall (nth n (assq style
-                                                completion-styles-alist))
-                                   string table pred point)))
+             (let ((probe (funcall
+                           (or (nth n (assq style completion-styles-alist))
+                               (error "Invalid completion style %s" style))
+                           string table pred point)))
                (and probe (cons probe style))))
            (completion--styles md)))
          (adjust-fn (get (cdr result-and-style)
'completion--adjust-metadata)))
-- 
2.20.1






             reply	other threads:[~2022-01-04 20:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-04 20:12 Daniel Mendler [this message]
2022-01-05  0:19 ` bug#53012: 28.0.90; completion--nth-completion: Throw a meaningful error Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-01-05  0:42   ` Daniel Mendler
2022-01-09 15:31     ` Stefan Kangas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9908ba86-2117-9025-559c-dc7bc868b371@daniel-mendler.de \
    --to=mail@daniel-mendler.de \
    --cc=53012@debbugs.gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).