Mercurial > hg > xemacs-beta
comparison lisp/simple.el @ 5855:0bddb59072b6
Look for cased character classes when deciding on case-fold-search, #'isearch
lisp/ChangeLog addition:
2015-03-11 Aidan Kehoe <kehoea@parhasard.net>
* isearch-mode.el:
* isearch-mode.el (isearch-fix-case):
Use the new #'no-case-regexp-p function if treating ISEARCH-STRING
as a regular expression; otherwise, use the [[:upper:]] character
class.
* isearch-mode.el (isearch-no-upper-case-p): Removed.
* isearch-mode.el (with-caps-disable-folding): Removed.
These two haven't been used since 1998.
* occur.el (occur-1):
Use #'no-case-regexp-p here.
* replace.el (perform-replace):
Don't use #'no-upper-case-p, use #'no-case-regexp-p or
(string-match "[[:upper:]]" ...) as appropriate.
* simple.el:
* simple.el (no-upper-case-p): Removed. This did two different
things, and its secondary function (examining regular expressions)
just became much more complicated; move the regular expression
functionality to its own function, use character classes when
examining non-regular-expressions instead.
The code to look for character classes, and the design decision
that this should be done, are from GNU, thank you Stefan Monnier.
* simple.el (no-case-regexp-p): New.
Given a REGEXP, return non-nil if it has nothing to suggest an
interactive user wants a case-sensitive search.
* simple.el (with-search-caps-disable-folding):
* simple.el (with-interactive-search-caps-disable-folding):
Update both these macros to use #'no-case-regexp-p.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Wed, 11 Mar 2015 18:06:15 +0000 |
parents | ccb0cff115d2 |
children | 27876789edc5 |
comparison
equal
deleted
inserted
replaced
5854:ccb0cff115d2 | 5855:0bddb59072b6 |
---|---|
92 | 92 |
93 (defgroup warnings nil | 93 (defgroup warnings nil |
94 "Warnings customizations." | 94 "Warnings customizations." |
95 :group 'minibuffer) | 95 :group 'minibuffer) |
96 | 96 |
97 | |
98 (defcustom search-caps-disable-folding t | 97 (defcustom search-caps-disable-folding t |
99 "*If non-nil, upper case chars disable case fold searching. | 98 "*If non-nil, upper case chars disable case fold searching. |
100 This does not apply to \"yanked\" strings." | 99 This does not apply to \"yanked\" strings." |
101 :type 'boolean | 100 :type 'boolean |
102 :group 'editing-basics) | 101 :group 'editing-basics) |
103 | 102 |
104 ;; This is stolen (and slightly modified) from FSF emacs's | 103 (defun no-case-regexp-p (regexp) |
105 ;; `isearch-no-upper-case-p'. | 104 "Return t if there are no case-specific constructs in REGEXP. |
106 (defun no-upper-case-p (string &optional regexp-flag) | 105 |
107 "Return t if there are no upper case chars in STRING. | 106 Lower case characters are regarded as not case-specific. Upper case |
108 If REGEXP-FLAG is non-nil, disregard letters preceded by `\\' (but not `\\\\') | 107 characters are usually regarded as case-specific, but upper case characters |
109 since they have special meaning in a regexp." | 108 used in special regexp constructs, where they do not match upper case |
109 characters specifically, are regarded as not case-specific. In contrast, the | |
110 character classes [:lower:] and [:upper:] are viewed as case-specific. | |
111 | |
112 This is intended to be used by interactive searching code to decide, in a | |
113 do-what-I-mean fashion, whether a given search should be case-sensitive." | |
110 (let ((case-fold-search nil)) | 114 (let ((case-fold-search nil)) |
111 (not (string-match (if regexp-flag | 115 (save-match-data |
112 "\\(^\\|\\\\\\\\\\|[^\\]\\)[A-Z]" | 116 (not (or (string-match "\\(^\\|\\\\\\\\\\|[^\\]\\)[[:upper:]]" regexp) |
113 "[A-Z]") | 117 (and (string-match "\\[:\\(upp\\|low\\)er:]" regexp) |
114 string)) | 118 (condition-case err |
115 )) | 119 (progn |
116 | 120 (string-match (substring regexp 0 |
117 (defmacro with-search-caps-disable-folding (string regexp-flag &rest body) "\ | 121 (match-beginning 0)) "") |
118 Eval BODY with `case-fold-search' let to nil if `search-caps-disable-folding' | 122 nil) |
119 is non-nil, and if STRING (either a string or a regular expression according | 123 (invalid-regexp |
120 to REGEXP-FLAG) contains uppercase letters." | 124 (equal "Unmatched [ or [^" (cadr err)))))))))) |
125 | |
126 (defmacro* with-search-caps-disable-folding (string regexp-p &body body) | |
127 "Execute the forms in BODY, respecting `search-caps-disable-folding'. | |
128 | |
129 Within BODY, bind `case-fold-search' to nil if `search-caps-disable-folding' | |
130 is non-nil, REGEXP-P is nil, and if STRING contains any uppercase characters. | |
131 | |
132 If REGEXP-P is non-nil, treat STRING as a regular expression, and bind | |
133 `case-fold-search' to nil if it contains uppercase characters that are | |
134 not special regular expression constructs, or if it contains | |
135 case-specific character classes such as `[[:upper:]]' or | |
136 `[[:lower:]]'. See `no-case-regexp-p'." | |
121 `(let ((case-fold-search | 137 `(let ((case-fold-search |
122 (if (and case-fold-search search-caps-disable-folding) | 138 (if (and case-fold-search search-caps-disable-folding) |
123 (no-upper-case-p ,string ,regexp-flag) | 139 (if ,regexp-p |
140 (no-case-regexp-p ,string) | |
141 (save-match-data | |
142 (let (case-fold-search) | |
143 (not (string-match "[[:upper:]]" ,string))))) | |
124 case-fold-search))) | 144 case-fold-search))) |
125 ,@body)) | 145 ,@body)) |
126 (put 'with-search-caps-disable-folding 'lisp-indent-function 2) | 146 (put 'with-search-caps-disable-folding 'lisp-indent-function 2) |
127 (put 'with-search-caps-disable-folding 'edebug-form-spec | 147 (put 'with-search-caps-disable-folding 'edebug-form-spec |
128 '(sexp sexp &rest form)) | 148 '(sexp sexp &rest form)) |
129 | 149 |
130 (defmacro with-interactive-search-caps-disable-folding (string regexp-flag | 150 (defmacro* with-interactive-search-caps-disable-folding (string regexp-p |
131 &rest body) | 151 &body body) |
132 "Same as `with-search-caps-disable-folding', but only in the case of a | 152 "Like `with-search-caps-disable-folding', but only when interactive." |
133 function called interactively." | |
134 `(let ((case-fold-search | 153 `(let ((case-fold-search |
135 (if (and (interactive-p) | 154 (if (and (interactive-p) case-fold-search |
136 case-fold-search search-caps-disable-folding) | 155 search-caps-disable-folding) |
137 (no-upper-case-p ,string ,regexp-flag) | 156 (if ,regexp-p |
157 (no-case-regexp-p ,string) | |
158 (save-match-data | |
159 (let (case-fold-search) | |
160 (not (string-match "[[:upper:]]" ,string))))) | |
138 case-fold-search))) | 161 case-fold-search))) |
139 ,@body)) | 162 ,@body)) |
140 (put 'with-interactive-search-caps-disable-folding 'lisp-indent-function 2) | 163 (put 'with-interactive-search-caps-disable-folding 'lisp-indent-function 2) |
141 (put 'with-interactive-search-caps-disable-folding 'edebug-form-spec | 164 (put 'with-interactive-search-caps-disable-folding 'edebug-form-spec |
142 '(sexp sexp &rest form)) | 165 '(sexp sexp &rest form)) |