153 |
(defcustom search-whitespace-regexp "\\(?:\\s-+\\)" |
(defcustom search-whitespace-regexp "\\(?:\\s-+\\)" |
154 |
"*If non-nil, regular expression to match a sequence of whitespace chars. |
"*If non-nil, regular expression to match a sequence of whitespace chars. |
155 |
This applies to regular expression incremental search. |
This applies to regular expression incremental search. |
156 |
You might want to use something like \"[ \\t\\r\\n]+\" instead. |
You might want to use something like \"\\\\(?:[ \\t\\r\\n]+\\\\)\" instead. |
157 |
In the Customization buffer, that is `[' followed by a space, |
In the Customization buffer, that is `\\(?:[' followed by a space, |
158 |
a tab, a carriage return (control-M), a newline, and `]+'." |
a tab, a carriage return (control-M), a newline, and `]+\\)'." |
159 |
:type 'regexp |
:type 'regexp |
160 |
:group 'isearch) |
:group 'isearch) |
161 |
|
|
298 |
(define-key map "\M-\C-y" 'isearch-yank-char) |
(define-key map "\M-\C-y" 'isearch-yank-char) |
299 |
(define-key map "\C-y" 'isearch-yank-line) |
(define-key map "\C-y" 'isearch-yank-line) |
300 |
|
|
301 |
;; Define keys for regexp chars * ? |. |
;; Define keys for regexp chars * ? } |. |
302 |
;; Nothing special for + because it matches at least once. |
;; Nothing special for + because it matches at least once. |
303 |
(define-key map "*" 'isearch-*-char) |
(define-key map "*" 'isearch-*-char) |
304 |
(define-key map "?" 'isearch-*-char) |
(define-key map "?" 'isearch-*-char) |
305 |
(define-key map "{" 'isearch-{-char) |
(define-key map "}" 'isearch-}-char) |
306 |
(define-key map "|" 'isearch-|-char) |
(define-key map "|" 'isearch-|-char) |
307 |
|
|
308 |
;; Turned off because I find I expect to get the global definition--rms. |
;; Turned off because I find I expect to get the global definition--rms. |
372 |
|
|
373 |
(defvar isearch-cmds nil |
(defvar isearch-cmds nil |
374 |
"Stack of search status sets. |
"Stack of search status sets. |
375 |
Each set is a list of the form: |
Each set is a vector of the form: |
376 |
(STRING MESSAGE POINT SUCCESS FORWARD OTHER-END WORD |
[STRING MESSAGE POINT SUCCESS FORWARD OTHER-END WORD |
377 |
INVALID-REGEXP WRAPPED BARRIER WITHIN-BRACKETS CASE-FOLD-SEARCH)") |
INVALID-REGEXP WRAPPED BARRIER WITHIN-BRACKETS CASE-FOLD-SEARCH]") |
378 |
|
|
379 |
(defvar isearch-string "") ; The current search string. |
(defvar isearch-string "") ; The current search string. |
380 |
(defvar isearch-message "") ; text-char-description version of isearch-string |
(defvar isearch-message "") ; text-char-description version of isearch-string |
774 |
;; (handle-switch-frame (car (cdr last-command-char)))) |
;; (handle-switch-frame (car (cdr last-command-char)))) |
775 |
|
|
776 |
|
|
777 |
|
;; The search status structure and stack. |
778 |
|
|
779 |
|
(defsubst isearch-string (frame) |
780 |
|
"Return the search string in FRAME." |
781 |
|
(aref 0 frame)) |
782 |
|
(defsubst isearch-message-string (frame) |
783 |
|
"Return the search string to display to the user in FRAME." |
784 |
|
(aref 1 frame)) |
785 |
|
(defsubst isearch-point (frame) |
786 |
|
"Return the point in FRAME." |
787 |
|
(aref 2 frame)) |
788 |
|
(defsubst isearch-success (frame) |
789 |
|
"Return the success flag in FRAME." |
790 |
|
(aref 3 frame)) |
791 |
|
(defsubst isearch-forward-flag (frame) |
792 |
|
"Return the searching-forward flag in FRAME." |
793 |
|
(aref 4 frame)) |
794 |
|
(defsubst isearch-other-end (frame) |
795 |
|
"Return the other end of the match in FRAME." |
796 |
|
(aref 5 frame)) |
797 |
|
(defsubst isearch-word (frame) |
798 |
|
"Return the search-by-word flag in FRAME." |
799 |
|
(aref 6 frame)) |
800 |
|
(defsubst isearch-invalid-regexp (frame) |
801 |
|
"Return the regexp error message in FRAME, or nil if its regexp is valid." |
802 |
|
(aref 7 frame)) |
803 |
|
(defsubst isearch-wrapped (frame) |
804 |
|
"Return the search-wrapped flag in FRAME." |
805 |
|
(aref 8 frame)) |
806 |
|
(defsubst isearch-barrier (frame) |
807 |
|
"Return the barrier value in FRAME." |
808 |
|
(aref 9 frame)) |
809 |
|
(defsubst isearch-within-brackets (frame) |
810 |
|
"Return the in-character-class flag in FRAME." |
811 |
|
(aref 10 frame)) |
812 |
|
(defsubst isearch-case-fold-search (frame) |
813 |
|
"Return the case-folding flag in FRAME." |
814 |
|
(aref 11 frame)) |
815 |
|
|
816 |
|
(defun isearch-top-state () |
817 |
|
(let ((cmd (car isearch-cmds))) |
818 |
|
(setq isearch-string (isearch-string cmd) |
819 |
|
isearch-message (isearch-message-string cmd) |
820 |
|
isearch-success (isearch-success cmd) |
821 |
|
isearch-forward (isearch-forward-flag cmd) |
822 |
|
isearch-other-end (isearch-other-end cmd) |
823 |
|
isearch-word (isearch-word cmd) |
824 |
|
isearch-invalid-regexp (isearch-invalid-regexp cmd) |
825 |
|
isearch-wrapped (isearch-wrapped cmd) |
826 |
|
isearch-barrier (isearch-barrier cmd) |
827 |
|
isearch-within-brackets (isearch-within-brackets cmd) |
828 |
|
isearch-case-fold-search (isearch-case-fold-search cmd)) |
829 |
|
(goto-char (isearch-point cmd)))) |
830 |
|
|
831 |
|
(defun isearch-pop-state () |
832 |
|
(setq isearch-cmds (cdr isearch-cmds)) |
833 |
|
(isearch-top-state)) |
834 |
|
|
835 |
|
(defun isearch-push-state () |
836 |
|
(setq isearch-cmds |
837 |
|
(cons (vector isearch-string isearch-message (point) |
838 |
|
isearch-success isearch-forward isearch-other-end |
839 |
|
isearch-word |
840 |
|
isearch-invalid-regexp isearch-wrapped isearch-barrier |
841 |
|
isearch-within-brackets isearch-case-fold-search) |
842 |
|
isearch-cmds))) |
843 |
|
|
844 |
|
|
845 |
;; Commands active while inside of the isearch minor mode. |
;; Commands active while inside of the isearch minor mode. |
846 |
|
|
847 |
(defun isearch-exit () |
(defun isearch-exit () |
1317 |
(isearch-update)) |
(isearch-update)) |
1318 |
|
|
1319 |
|
|
1320 |
(defun isearch-{-char () |
;; *, ?, }, and | chars can make a regexp more liberal. |
|
"Handle \{ specially in regexps." |
|
|
(interactive) |
|
|
(isearch-*-char t)) |
|
|
|
|
|
;; *, ?, and | chars can make a regexp more liberal. |
|
1321 |
;; They can make a regexp match sooner or make it succeed instead of failing. |
;; They can make a regexp match sooner or make it succeed instead of failing. |
1322 |
;; So go back to place last successful search started |
;; So go back to place last successful search started |
1323 |
;; or to the last ^S/^R (barrier), whichever is nearer. |
;; or to the last ^S/^R (barrier), whichever is nearer. |
1324 |
;; + needs no special handling because the string must match at least once. |
;; + needs no special handling because the string must match at least once. |
1325 |
|
|
1326 |
(defun isearch-*-char (&optional want-backslash) |
(defun isearch-backslash (str) |
1327 |
"Handle * and ? specially in regexps. |
"Return t if STR ends in an odd number of backslashes." |
1328 |
When WANT-BACKSLASH is non-nil, do special handling for \{." |
(= (mod (- (length str) (string-match "\\\\*\\'" str)) 2) 1)) |
1329 |
(interactive) |
|
1330 |
(if isearch-regexp |
(defun isearch-fallback (want-backslash &optional allow-invalid to-barrier) |
1331 |
(let ((idx (length isearch-string))) |
"Return point to previous successful match to allow regexp liberalization. |
1332 |
(while (and (> idx 0) |
\\<isearch-mode-map> |
1333 |
(eq (aref isearch-string (1- idx)) ?\\)) |
Respects \\[isearch-repeat-forward] and \\[isearch-repeat-backward] by |
1334 |
(setq idx (1- idx))) |
stopping at `isearch-barrier' as needed. |
1335 |
;; * and ? are special when not preceded by \. |
|
1336 |
;; { is special when it is preceded by \. |
Do nothing if a backslash is escaping the liberalizing character. If |
1337 |
(when (= (mod (- (length isearch-string) idx) 2) |
WANT-BACKSLASH is non-nil, invert this behavior (for \\} and \\|). |
1338 |
(if want-backslash 1 0)) |
|
1339 |
(setq isearch-adjusted t) |
Do nothing if regexp has recently been invalid unless optional ALLOW-INVALID |
1340 |
;; Get the isearch-other-end from before the last search. |
non-nil. |
1341 |
;; We want to start from there, |
|
1342 |
;; so that we don't retreat farther than that. |
If optional TO-BARRIER non-nil, ignore previous matches and go exactly to the |
1343 |
;; (car isearch-cmds) is after last search; |
barrier." |
1344 |
;; (car (cdr isearch-cmds)) is from before it. |
;; (eq (not a) (not b)) makes all non-nil values equivalent |
1345 |
(let ((cs (nth 5 (car (cdr isearch-cmds))))) |
(when (and isearch-regexp (eq (not (isearch-backslash isearch-string)) |
1346 |
(setq cs (or cs isearch-barrier)) |
(not want-backslash)) |
1347 |
(goto-char |
;; We have to check 2 stack frames because the last might be |
1348 |
(if isearch-forward |
;; invalid just because of a backslash. |
1349 |
(max cs isearch-barrier) |
(or (not isearch-invalid-regexp) |
1350 |
(min cs isearch-barrier))))))) |
(not (isearch-invalid-regexp (cadr isearch-cmds))) |
1351 |
|
allow-invalid)) |
1352 |
|
(if to-barrier |
1353 |
|
(progn (goto-char isearch-barrier) |
1354 |
|
(setq isearch-adjusted t)) |
1355 |
|
(let* ((stack isearch-cmds) |
1356 |
|
(previous (cdr stack)) ; lookbelow in the stack |
1357 |
|
(frame (car stack))) |
1358 |
|
;; Walk down the stack looking for a valid regexp (as of course only |
1359 |
|
;; they can be the previous successful match); this conveniently |
1360 |
|
;; removes all bracket-sets and groups that might be in the way, as |
1361 |
|
;; well as partial \{\} constructs that the code below leaves behind. |
1362 |
|
;; Also skip over postfix operators -- though horrid, |
1363 |
|
;; 'ab?\{5,6\}+\{1,2\}*' is perfectly legal. |
1364 |
|
(while (and previous |
1365 |
|
(or (isearch-invalid-regexp frame) |
1366 |
|
(let* ((string (isearch-string frame)) |
1367 |
|
(lchar (aref string (1- (length string))))) |
1368 |
|
;; The operators aren't always operators; check |
1369 |
|
;; backslashes. This doesn't handle the case of |
1370 |
|
;; operators at the beginning of the regexp not |
1371 |
|
;; being special, but then we should fall back to |
1372 |
|
;; the barrier anyway because it's all optional. |
1373 |
|
(if (isearch-backslash |
1374 |
|
(isearch-string (car previous))) |
1375 |
|
(eq lchar ?\}) |
1376 |
|
(memq lchar '(?* ?? ?+)))))) |
1377 |
|
(setq stack previous previous (cdr previous) frame (car stack))) |
1378 |
|
(when stack |
1379 |
|
;; `stack' now refers the most recent valid regexp that is not at |
1380 |
|
;; all optional in its last term. Now dig one level deeper and find |
1381 |
|
;; what matched before that. |
1382 |
|
(let ((last-other-end (or (isearch-other-end (car previous)) |
1383 |
|
isearch-barrier))) |
1384 |
|
(goto-char (if isearch-forward |
1385 |
|
(max last-other-end isearch-barrier) |
1386 |
|
(min last-other-end isearch-barrier))) |
1387 |
|
(setq isearch-adjusted t)))))) |
1388 |
(isearch-process-search-char last-command-char)) |
(isearch-process-search-char last-command-char)) |
1389 |
|
|
1390 |
|
;; * and ? are special when not preceded by \. |
1391 |
|
(defun isearch-*-char () |
1392 |
|
"Maybe back up to handle * and ? specially in regexps." |
1393 |
|
(interactive) |
1394 |
|
(isearch-fallback nil)) |
1395 |
|
|
1396 |
|
;; } is special when it is preceded by \. |
1397 |
|
(defun isearch-}-char () |
1398 |
|
"Handle \\} specially in regexps." |
1399 |
|
(interactive) |
1400 |
|
(isearch-fallback t t)) |
1401 |
|
|
1402 |
|
;; | is special when it is preceded by \. |
1403 |
(defun isearch-|-char () |
(defun isearch-|-char () |
1404 |
"If in regexp search, jump to the barrier." |
"If in regexp search, jump to the barrier unless in a group." |
1405 |
(interactive) |
(interactive) |
1406 |
(if isearch-regexp |
(isearch-fallback t nil t)) |
|
(progn |
|
|
(setq isearch-adjusted t) |
|
|
(goto-char isearch-barrier))) |
|
|
(isearch-process-search-char last-command-char)) |
|
1407 |
|
|
1408 |
(defun isearch-unread-key-sequence (keylist) |
(defun isearch-unread-key-sequence (keylist) |
1409 |
"Unread the given key-sequence KEYLIST. |
"Unread the given key-sequence KEYLIST. |
1883 |
(insert isearch-string)))) |
(insert isearch-string)))) |
1884 |
|
|
1885 |
|
|
|
;; The search status stack (and isearch window-local variables, not used). |
|
|
;; Need a structure for this. |
|
|
|
|
|
(defun isearch-top-state () |
|
|
(let ((cmd (car isearch-cmds))) |
|
|
(setq isearch-string (car cmd) |
|
|
isearch-message (car (cdr cmd)) |
|
|
isearch-success (nth 3 cmd) |
|
|
isearch-forward (nth 4 cmd) |
|
|
isearch-other-end (nth 5 cmd) |
|
|
isearch-word (nth 6 cmd) |
|
|
isearch-invalid-regexp (nth 7 cmd) |
|
|
isearch-wrapped (nth 8 cmd) |
|
|
isearch-barrier (nth 9 cmd) |
|
|
isearch-within-brackets (nth 10 cmd) |
|
|
isearch-case-fold-search (nth 11 cmd)) |
|
|
(goto-char (car (cdr (cdr cmd)))))) |
|
|
|
|
|
(defun isearch-pop-state () |
|
|
(setq isearch-cmds (cdr isearch-cmds)) |
|
|
(isearch-top-state)) |
|
|
|
|
|
(defun isearch-push-state () |
|
|
(setq isearch-cmds |
|
|
(cons (list isearch-string isearch-message (point) |
|
|
isearch-success isearch-forward isearch-other-end |
|
|
isearch-word |
|
|
isearch-invalid-regexp isearch-wrapped isearch-barrier |
|
|
isearch-within-brackets isearch-case-fold-search) |
|
|
isearch-cmds))) |
|
|
|
|
|
|
|
1886 |
;; Message string |
;; Message string |
1887 |
|
|
1888 |
(defun isearch-message (&optional c-q-hack ellipsis) |
(defun isearch-message (&optional c-q-hack ellipsis) |
2012 |
(if isearch-success |
(if isearch-success |
2013 |
nil |
nil |
2014 |
;; Ding if failed this time after succeeding last time. |
;; Ding if failed this time after succeeding last time. |
2015 |
(and (nth 3 (car isearch-cmds)) |
(and (isearch-success (car isearch-cmds)) |
2016 |
(ding)) |
(ding)) |
2017 |
(goto-char (nth 2 (car isearch-cmds))))) |
(goto-char (isearch-point (car isearch-cmds))))) |
2018 |
|
|
2019 |
|
|
2020 |
;; Called when opening an overlay, and we are still in isearch. |
;; Called when opening an overlay, and we are still in isearch. |