diff options
| author | Lars Ingebrigtsen | 2022-06-13 15:31:25 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2022-06-13 15:33:12 +0200 |
| commit | 027fecb24bb0a17543efb0ef63bb7b160e2630d1 (patch) | |
| tree | 08df95db41ebf094dc12fb3de6f8458e7ae6d902 /lisp/replace.el | |
| parent | 86325f960af8eb1df712e2f26e2b708f80c14ac6 (diff) | |
| download | emacs-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).
Diffstat (limited to 'lisp/replace.el')
| -rw-r--r-- | lisp/replace.el | 57 |
1 files changed, 46 insertions, 11 deletions
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 | |||
| 928 | in \":\", followed by optional whitespace), DEFAULT is added to the prompt. | 928 | in \":\", followed by optional whitespace), DEFAULT is added to the prompt. |
| 929 | 929 | ||
| 930 | The optional argument HISTORY is a symbol to use for the history list. | 930 | The optional argument HISTORY is a symbol to use for the history list. |
| 931 | If nil, use `regexp-history'." | 931 | If nil, use `regexp-history'. |
| 932 | |||
| 933 | If the user has used the `M-c' command to specify case | ||
| 934 | sensitivity, 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 | ||
| 937 | respect 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. | ||
| 991 | REGEXP 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) |