unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] case-insenstive read-multiple-choice
@ 2020-05-29  7:40 Philip K.
  0 siblings, 0 replies; only message in thread
From: Philip K. @ 2020-05-29  7:40 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 806 bytes --]


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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-case-insenstive-option-to-read-multiple-choice.patch --]
[-- Type: text/x-diff, Size: 1815 bytes --]

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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2020-05-29  7:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-29  7:40 [PATCH] case-insenstive read-multiple-choice Philip K.

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).