mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-01-31 04:41:23 -08:00
Add a M-c' command to read-regexp'
* doc/lispref/minibuf.texi (Text from Minibuffer): Document it. * lisp/replace.el (read-regexp): Add a `M-c' command to indicate case folding (bug#16913).
This commit is contained in:
parent
86325f960a
commit
027fecb24b
3 changed files with 62 additions and 10 deletions
|
|
@ -309,6 +309,20 @@ The optional argument @var{history}, if non-@code{nil}, is a symbol
|
|||
specifying a minibuffer history list to use (@pxref{Minibuffer
|
||||
History}). If it is omitted or @code{nil}, the history list defaults
|
||||
to @code{regexp-history}.
|
||||
|
||||
The user can use the @kbd{M-c} command to indicate whether case
|
||||
folding should be on or off. If the user has used this command, the
|
||||
returned string will have the text property @code{case-fold} set to
|
||||
either @code{fold} or @code{inhibit-fold}. It is up to the caller of
|
||||
@code{read-regexp} to actually use this value, and the convenience
|
||||
function @code{read-regexp-case-fold-search} is provided for that. A
|
||||
typical usage pattern here might look like:
|
||||
|
||||
@lisp
|
||||
(let* ((regexp (read-regexp "Search for: "))
|
||||
(case-fold-search (read-regexp-case-fold-search regexp)))
|
||||
(re-search-forward regexp))
|
||||
@end lisp
|
||||
@end defun
|
||||
|
||||
@defopt read-regexp-defaults-function
|
||||
|
|
|
|||
3
etc/NEWS
3
etc/NEWS
|
|
@ -1978,6 +1978,9 @@ Previously it produced a nonsense value, -1, that was never intended.
|
|||
|
||||
* Lisp Changes in Emacs 29.1
|
||||
|
||||
+++
|
||||
** 'read-regexp' now allows the user to indicate whether to use case folding.
|
||||
|
||||
+++
|
||||
** 'completing-read' now allows a function as its REQUIRE-MATCH argument.
|
||||
This function is called to see whether what the user has typed in is a
|
||||
|
|
|
|||
|
|
@ -928,7 +928,13 @@ If the first element of DEFAULTS is non-nil (and if PROMPT does not end
|
|||
in \":\", followed by optional whitespace), DEFAULT is added to the prompt.
|
||||
|
||||
The optional argument HISTORY is a symbol to use for the history list.
|
||||
If nil, use `regexp-history'."
|
||||
If nil, use `regexp-history'.
|
||||
|
||||
If the user has used the `M-c' 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'.)"
|
||||
(let* ((defaults
|
||||
(if (and defaults (symbolp defaults))
|
||||
(cond
|
||||
|
|
@ -944,21 +950,50 @@ If nil, use `regexp-history'."
|
|||
(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)
|
||||
(input (read-from-minibuffer
|
||||
(if (string-match-p ":[ \t]*\\'" prompt)
|
||||
prompt
|
||||
(format-prompt prompt (and (length> default 0)
|
||||
(query-replace-descr default))))
|
||||
nil nil nil (or history 'regexp-history) suggestions t)))
|
||||
(if (equal input "")
|
||||
;; Return the default value when the user enters empty input.
|
||||
(prog1 (or default input)
|
||||
(when default
|
||||
(add-to-history (or history 'regexp-history) default)))
|
||||
;; Otherwise, add non-empty input to the history and return input.
|
||||
(prog1 input
|
||||
(add-to-history (or history 'regexp-history) input)))))
|
||||
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))
|
||||
(message "Case folding is now %s"
|
||||
(if (eq case-fold 'fold)
|
||||
"on"
|
||||
"off"))))
|
||||
nil (or history 'regexp-history) suggestions t))
|
||||
(result (if (equal input "")
|
||||
;; Return the default value when the user enters
|
||||
;; empty input.
|
||||
default
|
||||
input)))
|
||||
(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 result input))))
|
||||
|
||||
(defun read-regexp-case-fold-search (regexp)
|
||||
"Return a value for `case-fold-search' based on REGEXP and current settings.
|
||||
REGEXP is a string as returned by `read-regexp'."
|
||||
(let ((fold (get-text-property 0 'case-fold regexp)))
|
||||
(cond
|
||||
((eq fold 'fold) t)
|
||||
((eq fold 'inhibit-fold) nil)
|
||||
(t case-fold-search))))
|
||||
|
||||
(defalias 'delete-non-matching-lines 'keep-lines)
|
||||
(defalias 'delete-matching-lines 'flush-lines)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue