(regexp-quote (or (car search-ring) ""))
(car (symbol-value query-replace-from-history-variable))))
+(defvar-keymap read-regexp-map
+ :parent minibuffer-local-map
+ "M-c" #'read-regexp-toggle-case-folding)
+
+(defvar read-regexp--case-fold nil)
+
+(defun read-regexp-toggle-case-folding ()
+ (interactive)
+ (setq read-regexp--case-fold
+ (if (or (eq read-regexp--case-fold 'fold)
+ (and read-regexp--case-fold
+ (not (eq read-regexp--case-fold 'inhibit-fold))))
+ 'inhibit-fold
+ 'fold))
+ (minibuffer-message "Case folding is now %s"
+ (if (eq read-regexp--case-fold 'fold) "on" "off")))
+
(defun read-regexp (prompt &optional defaults history)
"Read and return a regular expression as a string.
Prompt with the string PROMPT. If PROMPT ends in \":\" (followed by
The optional argument HISTORY is a symbol to use for the history list.
If nil, use `regexp-history'.
-If the user has used the \\`M-c' command to specify case
+If the user has used the \\<read-regexp-map>\\[read-regexp-toggle-case-folding] command to specify case
sensitivity, the returned string will have a text property named
`case-fold' that has a value of either `fold' or
`inhibit-fold'. (It's up to the caller of `read-regexp' to
-respect this or not; see `read-regexp-case-fold-search'.)"
+respect this or not; see `read-regexp-case-fold-search'.)
+
+This command uses the `read-regexp-map' keymap while reading the
+regexp from the user."
(let* ((defaults
(if (and defaults (symbolp defaults))
(cond
(suggestions (delete-dups (delq nil (delete "" suggestions))))
;; Do not automatically add default to the history for empty input.
(history-add-new-input nil)
- (case-fold case-fold-search)
+ ;; `read-regexp--case-fold' dynamically bound and may be
+ ;; altered by `M-c'.
+ (read-regexp--case-fold case-fold-search)
(input (read-from-minibuffer
(if (string-match-p ":[ \t]*\\'" prompt)
prompt
(format-prompt prompt (and (length> default 0)
(query-replace-descr default))))
- nil
- (define-keymap
- :parent minibuffer-local-map
- "M-c" (lambda ()
- (interactive)
- (setq case-fold
- (if (or (eq case-fold 'fold)
- (and case-fold
- (not (eq case-fold
- 'inhibit-fold))))
- 'inhibit-fold
- 'fold))
- (minibuffer-message
- "Case folding is now %s"
- (if (eq case-fold 'fold)
- "on"
- "off"))))
+ nil read-regexp-map
nil (or history 'regexp-history) suggestions t))
(result (if (equal input "")
;; Return the default value when the user enters
(when result
(add-to-history (or history 'regexp-history) result))
(if (and result
- (or (eq case-fold 'fold)
- (eq case-fold 'inhibit-fold)))
- (propertize result 'case-fold case-fold)
+ (or (eq read-regexp--case-fold 'fold)
+ (eq read-regexp--case-fold 'inhibit-fold)))
+ (propertize result 'case-fold read-regexp--case-fold)
(or result input))))
(defun read-regexp-case-fold-search (regexp)