emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] case-insenstive read-multiple-choice


From: Philip K.
Subject: [PATCH] case-insenstive read-multiple-choice
Date: Fri, 29 May 2020 09:40:16 +0200

Hi,

I wrote this patch for project-switch-project, becasue it kept
highlighting the "wrong" charachters when using read-multiple-choice.

To take the example from the docstring: When evalutating

(read-multiple-choice "Continue connecting?"
                      '((?a "Always")
                        (?s "Session only")
                        (?n "No")))

with upper-case names instead of "always", "session only" and "no",
read-multiple-choice decides to highlight

        Always          Session only            No
           ^              ^                (nothing here)

which I don't think it is always intended, just because one wanted to
capitalize the words. With this patch applied and a non-nil value passed
as the third argument, the first letters get highlighted as expected.

-- 
        Philip K.

>From 9237a00f2ac98a401245aa3fd9a0cdcb6ef5ea79 Mon Sep 17 00:00:00 2001
From: Philip K <philip@warpmail.net>
Date: Fri, 29 May 2020 09:35:23 +0200
Subject: [PATCH] Add case-insenstive option to read-multiple-choice

---
 lisp/emacs-lisp/rmc.el | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/lisp/emacs-lisp/rmc.el b/lisp/emacs-lisp/rmc.el
index 9b253b8857..9a26d94e9b 100644
--- a/lisp/emacs-lisp/rmc.el
+++ b/lisp/emacs-lisp/rmc.el
@@ -26,7 +26,7 @@
 (require 'seq)
 
 ;;;###autoload
-(defun read-multiple-choice (prompt choices)
+(defun read-multiple-choice (prompt choices &optional case-insenstive)
   "Ask user a multiple choice question.
 PROMPT should be a string that will be displayed as the prompt.
 
@@ -37,6 +37,9 @@ read-multiple-choice
 will be displayed in a help buffer if the user requests more
 help.
 
+If CASE-INSENSTIVE is non-nil, KEY will highlight the first
+instance of that letter in NAME, regardless of case.
+
 This function translates user input into responses by consulting
 the bindings in `query-replace-map'; see the documentation of
 that variable for more information.  In this case, the useful
@@ -59,6 +62,7 @@ read-multiple-choice
                         (?s \"session only\")
                         (?n \"no\")))"
   (let* ((altered-names nil)
+         (case-fold-search case-insenstive)
          (full-prompt
           (format
            "%s (%s): "
@@ -66,7 +70,7 @@ read-multiple-choice
            (mapconcat
             (lambda (elem)
               (let* ((name (cadr elem))
-                     (pos (seq-position name (car elem)))
+                     (pos (seq-position name (car elem) #'char-equal))
                      (altered-name
                       (cond
                        ;; Not in the name string.
-- 
2.20.1


reply via email to

[Prev in Thread] Current Thread [Next in Thread]