aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Ingebrigtsen2022-06-13 15:31:25 +0200
committerLars Ingebrigtsen2022-06-13 15:33:12 +0200
commit027fecb24bb0a17543efb0ef63bb7b160e2630d1 (patch)
tree08df95db41ebf094dc12fb3de6f8458e7ae6d902
parent86325f960af8eb1df712e2f26e2b708f80c14ac6 (diff)
downloademacs-027fecb24bb0a17543efb0ef63bb7b160e2630d1.tar.gz
emacs-027fecb24bb0a17543efb0ef63bb7b160e2630d1.zip
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).
-rw-r--r--doc/lispref/minibuf.texi14
-rw-r--r--etc/NEWS3
-rw-r--r--lisp/replace.el57
3 files changed, 63 insertions, 11 deletions
diff --git a/doc/lispref/minibuf.texi b/doc/lispref/minibuf.texi
index 1451e59d05c..a59261cb9df 100644
--- a/doc/lispref/minibuf.texi
+++ b/doc/lispref/minibuf.texi
@@ -309,6 +309,20 @@ The optional argument @var{history}, if non-@code{nil}, is a symbol
309specifying a minibuffer history list to use (@pxref{Minibuffer 309specifying a minibuffer history list to use (@pxref{Minibuffer
310History}). If it is omitted or @code{nil}, the history list defaults 310History}). If it is omitted or @code{nil}, the history list defaults
311to @code{regexp-history}. 311to @code{regexp-history}.
312
313The user can use the @kbd{M-c} command to indicate whether case
314folding should be on or off. If the user has used this command, the
315returned string will have the text property @code{case-fold} set to
316either @code{fold} or @code{inhibit-fold}. It is up to the caller of
317@code{read-regexp} to actually use this value, and the convenience
318function @code{read-regexp-case-fold-search} is provided for that. A
319typical usage pattern here might look like:
320
321@lisp
322(let* ((regexp (read-regexp "Search for: "))
323 (case-fold-search (read-regexp-case-fold-search regexp)))
324 (re-search-forward regexp))
325@end lisp
312@end defun 326@end defun
313 327
314@defopt read-regexp-defaults-function 328@defopt read-regexp-defaults-function
diff --git a/etc/NEWS b/etc/NEWS
index 9440baee6ad..df636084dfc 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1979,6 +1979,9 @@ Previously it produced a nonsense value, -1, that was never intended.
1979* Lisp Changes in Emacs 29.1 1979* Lisp Changes in Emacs 29.1
1980 1980
1981+++ 1981+++
1982** 'read-regexp' now allows the user to indicate whether to use case folding.
1983
1984+++
1982** 'completing-read' now allows a function as its REQUIRE-MATCH argument. 1985** 'completing-read' now allows a function as its REQUIRE-MATCH argument.
1983This function is called to see whether what the user has typed in is a 1986This function is called to see whether what the user has typed in is a
1984match. This is also available from functions that call 1987match. This is also available from functions that call
diff --git a/lisp/replace.el b/lisp/replace.el
index 3d0877a9a64..b84e6eaa655 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -928,7 +928,13 @@ If the first element of DEFAULTS is non-nil (and if PROMPT does not end
928in \":\", followed by optional whitespace), DEFAULT is added to the prompt. 928in \":\", followed by optional whitespace), DEFAULT is added to the prompt.
929 929
930The optional argument HISTORY is a symbol to use for the history list. 930The optional argument HISTORY is a symbol to use for the history list.
931If nil, use `regexp-history'." 931If nil, use `regexp-history'.
932
933If the user has used the `M-c' command to specify case
934sensitivity, the returned string will have a text property named
935`case-fold' that has a value of either `fold' or
936`inhibit-fold'. (It's up to the caller of `read-regexp' to
937respect this or not; see `read-regexp-case-fold-search'.)"
932 (let* ((defaults 938 (let* ((defaults
933 (if (and defaults (symbolp defaults)) 939 (if (and defaults (symbolp defaults))
934 (cond 940 (cond
@@ -944,21 +950,50 @@ If nil, use `regexp-history'."
944 (suggestions (delete-dups (delq nil (delete "" suggestions)))) 950 (suggestions (delete-dups (delq nil (delete "" suggestions))))
945 ;; Do not automatically add default to the history for empty input. 951 ;; Do not automatically add default to the history for empty input.
946 (history-add-new-input nil) 952 (history-add-new-input nil)
953 (case-fold case-fold-search)
947 (input (read-from-minibuffer 954 (input (read-from-minibuffer
948 (if (string-match-p ":[ \t]*\\'" prompt) 955 (if (string-match-p ":[ \t]*\\'" prompt)
949 prompt 956 prompt
950 (format-prompt prompt (and (length> default 0) 957 (format-prompt prompt (and (length> default 0)
951 (query-replace-descr default)))) 958 (query-replace-descr default))))
952 nil nil nil (or history 'regexp-history) suggestions t))) 959 nil
953 (if (equal input "") 960 (define-keymap
954 ;; Return the default value when the user enters empty input. 961 :parent minibuffer-local-map
955 (prog1 (or default input) 962 "M-c" (lambda ()
956 (when default 963 (interactive)
957 (add-to-history (or history 'regexp-history) default))) 964 (setq case-fold
958 ;; Otherwise, add non-empty input to the history and return input. 965 (if (or (eq case-fold 'fold)
959 (prog1 input 966 (and case-fold
960 (add-to-history (or history 'regexp-history) input))))) 967 (not (eq case-fold
961 968 'inhibit-fold))))
969 'inhibit-fold
970 'fold))
971 (message "Case folding is now %s"
972 (if (eq case-fold 'fold)
973 "on"
974 "off"))))
975 nil (or history 'regexp-history) suggestions t))
976 (result (if (equal input "")
977 ;; Return the default value when the user enters
978 ;; empty input.
979 default
980 input)))
981 (when result
982 (add-to-history (or history 'regexp-history) result))
983 (if (and result
984 (or (eq case-fold 'fold)
985 (eq case-fold 'inhibit-fold)))
986 (propertize result 'case-fold case-fold)
987 (or result input))))
988
989(defun read-regexp-case-fold-search (regexp)
990 "Return a value for `case-fold-search' based on REGEXP and current settings.
991REGEXP is a string as returned by `read-regexp'."
992 (let ((fold (get-text-property 0 'case-fold regexp)))
993 (cond
994 ((eq fold 'fold) t)
995 ((eq fold 'inhibit-fold) nil)
996 (t case-fold-search))))
962 997
963(defalias 'delete-non-matching-lines 'keep-lines) 998(defalias 'delete-non-matching-lines 'keep-lines)
964(defalias 'delete-matching-lines 'flush-lines) 999(defalias 'delete-matching-lines 'flush-lines)