From: "Philip K." <philip@warpmail.net>
To: emacs-devel@gnu.org
Subject: [PATCH] case-insenstive read-multiple-choice
Date: Fri, 29 May 2020 09:40:16 +0200 [thread overview]
Message-ID: <87blm7nq8v.fsf@warpmail.net> (raw)
[-- 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
reply other threads:[~2020-05-29 7:40 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=87blm7nq8v.fsf@warpmail.net \
--to=philip@warpmail.net \
--cc=emacs-devel@gnu.org \
/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).