Mercurial > emacs
comparison lisp/isearch.el @ 89966:d8411455de48
Revision: miles@gnu.org--gnu-2004/emacs--unicode--0--patch-32
Merge from emacs--cvs-trunk--0
Patches applied:
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-486
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-487
Tweak permissions
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-488
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-489
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-490
Update from CVS: man/fixit.texi (Spelling): Fix typo.
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-491
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-494
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-495
Update from CVS: Add missing lisp/mh-e files
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-496
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-499
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-500
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-513
Update from CVS
author | Miles Bader <miles@gnu.org> |
---|---|
date | Fri, 27 Aug 2004 07:00:34 +0000 |
parents | 6f6e9fe4658b 1f4ff211cbeb |
children | 3219f94257bc |
comparison
equal
deleted
inserted
replaced
89965:5e9097d1ad99 | 89966:d8411455de48 |
---|---|
151 :group 'isearch) | 151 :group 'isearch) |
152 | 152 |
153 (defcustom search-whitespace-regexp "\\(?:\\s-+\\)" | 153 (defcustom search-whitespace-regexp "\\(?:\\s-+\\)" |
154 "*If non-nil, regular expression to match a sequence of whitespace chars. | 154 "*If non-nil, regular expression to match a sequence of whitespace chars. |
155 This applies to regular expression incremental search. | 155 This applies to regular expression incremental search. |
156 You might want to use something like \"[ \\t\\r\\n]+\" instead. | 156 You might want to use something like \"\\\\(?:[ \\t\\r\\n]+\\\\)\" instead. |
157 In the Customization buffer, that is `[' followed by a space, | 157 In the Customization buffer, that is `\\(?:[' followed by a space, |
158 a tab, a carriage return (control-M), a newline, and `]+'." | 158 a tab, a carriage return (control-M), a newline, and `]+\\)'." |
159 :type 'regexp | 159 :type 'regexp |
160 :group 'isearch) | 160 :group 'isearch) |
161 | 161 |
162 (defcustom search-highlight t | 162 (defcustom search-highlight t |
163 "*Non-nil means incremental search highlights the current match." | 163 "*Non-nil means incremental search highlights the current match." |
292 (define-key map "\C-w" 'isearch-yank-word-or-char) | 292 (define-key map "\C-w" 'isearch-yank-word-or-char) |
293 (define-key map "\M-\C-w" 'isearch-del-char) | 293 (define-key map "\M-\C-w" 'isearch-del-char) |
294 (define-key map "\M-\C-y" 'isearch-yank-char) | 294 (define-key map "\M-\C-y" 'isearch-yank-char) |
295 (define-key map "\C-y" 'isearch-yank-line) | 295 (define-key map "\C-y" 'isearch-yank-line) |
296 | 296 |
297 ;; Define keys for regexp chars * ? |. | 297 ;; Define keys for regexp chars * ? } |. |
298 ;; Nothing special for + because it matches at least once. | 298 ;; Nothing special for + because it matches at least once. |
299 (define-key map "*" 'isearch-*-char) | 299 (define-key map "*" 'isearch-*-char) |
300 (define-key map "?" 'isearch-*-char) | 300 (define-key map "?" 'isearch-*-char) |
301 (define-key map "{" 'isearch-{-char) | 301 (define-key map "}" 'isearch-}-char) |
302 (define-key map "|" 'isearch-|-char) | 302 (define-key map "|" 'isearch-|-char) |
303 | 303 |
304 ;; Turned off because I find I expect to get the global definition--rms. | 304 ;; Turned off because I find I expect to get the global definition--rms. |
305 ;; ;; Instead bind C-h to special help command for isearch-mode. | 305 ;; ;; Instead bind C-h to special help command for isearch-mode. |
306 ;; (define-key map "\C-h" 'isearch-mode-help) | 306 ;; (define-key map "\C-h" 'isearch-mode-help) |
366 (defvar isearch-word nil) ; Searching for words. | 366 (defvar isearch-word nil) ; Searching for words. |
367 (defvar isearch-hidden nil) ; Non-nil if the string exists but is invisible. | 367 (defvar isearch-hidden nil) ; Non-nil if the string exists but is invisible. |
368 | 368 |
369 (defvar isearch-cmds nil | 369 (defvar isearch-cmds nil |
370 "Stack of search status sets. | 370 "Stack of search status sets. |
371 Each set is a list of the form: | 371 Each set is a vector of the form: |
372 (STRING MESSAGE POINT SUCCESS FORWARD OTHER-END WORD | 372 [STRING MESSAGE POINT SUCCESS FORWARD OTHER-END WORD |
373 INVALID-REGEXP WRAPPED BARRIER WITHIN-BRACKETS CASE-FOLD-SEARCH)") | 373 INVALID-REGEXP WRAPPED BARRIER WITHIN-BRACKETS CASE-FOLD-SEARCH]") |
374 | 374 |
375 (defvar isearch-string "") ; The current search string. | 375 (defvar isearch-string "") ; The current search string. |
376 (defvar isearch-message "") ; text-char-description version of isearch-string | 376 (defvar isearch-message "") ; text-char-description version of isearch-string |
377 | 377 |
378 (defvar isearch-success t) ; Searching is currently successful. | 378 (defvar isearch-success t) ; Searching is currently successful. |
766 ;; (interactive) ;; Is this necessary? | 766 ;; (interactive) ;; Is this necessary? |
767 ;; ;; First terminate isearch-mode. | 767 ;; ;; First terminate isearch-mode. |
768 ;; (isearch-done) | 768 ;; (isearch-done) |
769 ;; (isearch-clean-overlays) | 769 ;; (isearch-clean-overlays) |
770 ;; (handle-switch-frame (car (cdr last-command-char)))) | 770 ;; (handle-switch-frame (car (cdr last-command-char)))) |
771 | |
772 | |
773 ;; The search status structure and stack. | |
774 | |
775 (defsubst isearch-string (frame) | |
776 "Return the search string in FRAME." | |
777 (aref frame 0)) | |
778 (defsubst isearch-message-string (frame) | |
779 "Return the search string to display to the user in FRAME." | |
780 (aref frame 1)) | |
781 (defsubst isearch-point (frame) | |
782 "Return the point in FRAME." | |
783 (aref frame 2)) | |
784 (defsubst isearch-success (frame) | |
785 "Return the success flag in FRAME." | |
786 (aref frame 3)) | |
787 (defsubst isearch-forward-flag (frame) | |
788 "Return the searching-forward flag in FRAME." | |
789 (aref frame 4)) | |
790 (defsubst isearch-other-end (frame) | |
791 "Return the other end of the match in FRAME." | |
792 (aref frame 5)) | |
793 (defsubst isearch-word (frame) | |
794 "Return the search-by-word flag in FRAME." | |
795 (aref frame 6)) | |
796 (defsubst isearch-invalid-regexp (frame) | |
797 "Return the regexp error message in FRAME, or nil if its regexp is valid." | |
798 (aref frame 7)) | |
799 (defsubst isearch-wrapped (frame) | |
800 "Return the search-wrapped flag in FRAME." | |
801 (aref frame 8)) | |
802 (defsubst isearch-barrier (frame) | |
803 "Return the barrier value in FRAME." | |
804 (aref frame 9)) | |
805 (defsubst isearch-within-brackets (frame) | |
806 "Return the in-character-class flag in FRAME." | |
807 (aref frame 10)) | |
808 (defsubst isearch-case-fold-search (frame) | |
809 "Return the case-folding flag in FRAME." | |
810 (aref frame 11)) | |
811 | |
812 (defun isearch-top-state () | |
813 (let ((cmd (car isearch-cmds))) | |
814 (setq isearch-string (isearch-string cmd) | |
815 isearch-message (isearch-message-string cmd) | |
816 isearch-success (isearch-success cmd) | |
817 isearch-forward (isearch-forward-flag cmd) | |
818 isearch-other-end (isearch-other-end cmd) | |
819 isearch-word (isearch-word cmd) | |
820 isearch-invalid-regexp (isearch-invalid-regexp cmd) | |
821 isearch-wrapped (isearch-wrapped cmd) | |
822 isearch-barrier (isearch-barrier cmd) | |
823 isearch-within-brackets (isearch-within-brackets cmd) | |
824 isearch-case-fold-search (isearch-case-fold-search cmd)) | |
825 (goto-char (isearch-point cmd)))) | |
826 | |
827 (defun isearch-pop-state () | |
828 (setq isearch-cmds (cdr isearch-cmds)) | |
829 (isearch-top-state)) | |
830 | |
831 (defun isearch-push-state () | |
832 (setq isearch-cmds | |
833 (cons (vector isearch-string isearch-message (point) | |
834 isearch-success isearch-forward isearch-other-end | |
835 isearch-word | |
836 isearch-invalid-regexp isearch-wrapped isearch-barrier | |
837 isearch-within-brackets isearch-case-fold-search) | |
838 isearch-cmds))) | |
771 | 839 |
772 | 840 |
773 ;; Commands active while inside of the isearch minor mode. | 841 ;; Commands active while inside of the isearch minor mode. |
774 | 842 |
775 (defun isearch-exit () | 843 (defun isearch-exit () |
1243 (isearch-push-state) | 1311 (isearch-push-state) |
1244 (if isearch-op-fun (funcall isearch-op-fun)) | 1312 (if isearch-op-fun (funcall isearch-op-fun)) |
1245 (isearch-update)) | 1313 (isearch-update)) |
1246 | 1314 |
1247 | 1315 |
1248 (defun isearch-{-char () | 1316 ;; *, ?, }, and | chars can make a regexp more liberal. |
1249 "Handle \{ specially in regexps." | |
1250 (interactive) | |
1251 (isearch-*-char t)) | |
1252 | |
1253 ;; *, ?, and | chars can make a regexp more liberal. | |
1254 ;; They can make a regexp match sooner or make it succeed instead of failing. | 1317 ;; They can make a regexp match sooner or make it succeed instead of failing. |
1255 ;; So go back to place last successful search started | 1318 ;; So go back to place last successful search started |
1256 ;; or to the last ^S/^R (barrier), whichever is nearer. | 1319 ;; or to the last ^S/^R (barrier), whichever is nearer. |
1257 ;; + needs no special handling because the string must match at least once. | 1320 ;; + needs no special handling because the string must match at least once. |
1258 | 1321 |
1259 (defun isearch-*-char (&optional want-backslash) | 1322 (defun isearch-backslash (str) |
1260 "Handle * and ? specially in regexps. | 1323 "Return t if STR ends in an odd number of backslashes." |
1261 When WANT-BACKSLASH is non-nil, do special handling for \{." | 1324 (= (mod (- (length str) (string-match "\\\\*\\'" str)) 2) 1)) |
1262 (interactive) | 1325 |
1263 (if isearch-regexp | 1326 (defun isearch-fallback (want-backslash &optional allow-invalid to-barrier) |
1264 (let ((idx (length isearch-string))) | 1327 "Return point to previous successful match to allow regexp liberalization. |
1265 (while (and (> idx 0) | 1328 \\<isearch-mode-map> |
1266 (eq (aref isearch-string (1- idx)) ?\\)) | 1329 Respects \\[isearch-repeat-forward] and \\[isearch-repeat-backward] by |
1267 (setq idx (1- idx))) | 1330 stopping at `isearch-barrier' as needed. |
1268 ;; * and ? are special when not preceded by \. | 1331 |
1269 ;; { is special when it is preceded by \. | 1332 Do nothing if a backslash is escaping the liberalizing character. If |
1270 (when (= (mod (- (length isearch-string) idx) 2) | 1333 WANT-BACKSLASH is non-nil, invert this behavior (for \\} and \\|). |
1271 (if want-backslash 1 0)) | 1334 |
1272 (setq isearch-adjusted t) | 1335 Do nothing if regexp has recently been invalid unless optional ALLOW-INVALID |
1273 ;; Get the isearch-other-end from before the last search. | 1336 non-nil. |
1274 ;; We want to start from there, | 1337 |
1275 ;; so that we don't retreat farther than that. | 1338 If optional TO-BARRIER non-nil, ignore previous matches and go exactly to the |
1276 ;; (car isearch-cmds) is after last search; | 1339 barrier." |
1277 ;; (car (cdr isearch-cmds)) is from before it. | 1340 ;; (eq (not a) (not b)) makes all non-nil values equivalent |
1278 (let ((cs (nth 5 (car (cdr isearch-cmds))))) | 1341 (when (and isearch-regexp (eq (not (isearch-backslash isearch-string)) |
1279 (setq cs (or cs isearch-barrier)) | 1342 (not want-backslash)) |
1280 (goto-char | 1343 ;; We have to check 2 stack frames because the last might be |
1281 (if isearch-forward | 1344 ;; invalid just because of a backslash. |
1282 (max cs isearch-barrier) | 1345 (or (not isearch-invalid-regexp) |
1283 (min cs isearch-barrier))))))) | 1346 (not (isearch-invalid-regexp (cadr isearch-cmds))) |
1347 allow-invalid)) | |
1348 (if to-barrier | |
1349 (progn (goto-char isearch-barrier) | |
1350 (setq isearch-adjusted t)) | |
1351 (let* ((stack isearch-cmds) | |
1352 (previous (cdr stack)) ; lookbelow in the stack | |
1353 (frame (car stack))) | |
1354 ;; Walk down the stack looking for a valid regexp (as of course only | |
1355 ;; they can be the previous successful match); this conveniently | |
1356 ;; removes all bracket-sets and groups that might be in the way, as | |
1357 ;; well as partial \{\} constructs that the code below leaves behind. | |
1358 ;; Also skip over postfix operators -- though horrid, | |
1359 ;; 'ab?\{5,6\}+\{1,2\}*' is perfectly legal. | |
1360 (while (and previous | |
1361 (or (isearch-invalid-regexp frame) | |
1362 (let* ((string (isearch-string frame)) | |
1363 (lchar (aref string (1- (length string))))) | |
1364 ;; The operators aren't always operators; check | |
1365 ;; backslashes. This doesn't handle the case of | |
1366 ;; operators at the beginning of the regexp not | |
1367 ;; being special, but then we should fall back to | |
1368 ;; the barrier anyway because it's all optional. | |
1369 (if (isearch-backslash | |
1370 (isearch-string (car previous))) | |
1371 (eq lchar ?\}) | |
1372 (memq lchar '(?* ?? ?+)))))) | |
1373 (setq stack previous previous (cdr previous) frame (car stack))) | |
1374 (when stack | |
1375 ;; `stack' now refers the most recent valid regexp that is not at | |
1376 ;; all optional in its last term. Now dig one level deeper and find | |
1377 ;; what matched before that. | |
1378 (let ((last-other-end (or (isearch-other-end (car previous)) | |
1379 isearch-barrier))) | |
1380 (goto-char (if isearch-forward | |
1381 (max last-other-end isearch-barrier) | |
1382 (min last-other-end isearch-barrier))) | |
1383 (setq isearch-adjusted t)))))) | |
1284 (isearch-process-search-char last-command-char)) | 1384 (isearch-process-search-char last-command-char)) |
1285 | 1385 |
1286 | 1386 ;; * and ? are special when not preceded by \. |
1387 (defun isearch-*-char () | |
1388 "Maybe back up to handle * and ? specially in regexps." | |
1389 (interactive) | |
1390 (isearch-fallback nil)) | |
1391 | |
1392 ;; } is special when it is preceded by \. | |
1393 (defun isearch-}-char () | |
1394 "Handle \\} specially in regexps." | |
1395 (interactive) | |
1396 (isearch-fallback t t)) | |
1397 | |
1398 ;; | is special when it is preceded by \. | |
1287 (defun isearch-|-char () | 1399 (defun isearch-|-char () |
1288 "If in regexp search, jump to the barrier." | 1400 "If in regexp search, jump to the barrier unless in a group." |
1289 (interactive) | 1401 (interactive) |
1290 (if isearch-regexp | 1402 (isearch-fallback t nil t)) |
1291 (progn | |
1292 (setq isearch-adjusted t) | |
1293 (goto-char isearch-barrier))) | |
1294 (isearch-process-search-char last-command-char)) | |
1295 | 1403 |
1296 (defun isearch-unread-key-sequence (keylist) | 1404 (defun isearch-unread-key-sequence (keylist) |
1297 "Unread the given key-sequence KEYLIST. | 1405 "Unread the given key-sequence KEYLIST. |
1298 Scroll-bar or mode-line events are processed appropriately." | 1406 Scroll-bar or mode-line events are processed appropriately." |
1299 (cancel-kbd-macro-events) | 1407 (cancel-kbd-macro-events) |
1769 (progn | 1877 (progn |
1770 (delete-field) | 1878 (delete-field) |
1771 (insert isearch-string)))) | 1879 (insert isearch-string)))) |
1772 | 1880 |
1773 | 1881 |
1774 ;; The search status stack (and isearch window-local variables, not used). | |
1775 ;; Need a structure for this. | |
1776 | |
1777 (defun isearch-top-state () | |
1778 (let ((cmd (car isearch-cmds))) | |
1779 (setq isearch-string (car cmd) | |
1780 isearch-message (car (cdr cmd)) | |
1781 isearch-success (nth 3 cmd) | |
1782 isearch-forward (nth 4 cmd) | |
1783 isearch-other-end (nth 5 cmd) | |
1784 isearch-word (nth 6 cmd) | |
1785 isearch-invalid-regexp (nth 7 cmd) | |
1786 isearch-wrapped (nth 8 cmd) | |
1787 isearch-barrier (nth 9 cmd) | |
1788 isearch-within-brackets (nth 10 cmd) | |
1789 isearch-case-fold-search (nth 11 cmd)) | |
1790 (goto-char (car (cdr (cdr cmd)))))) | |
1791 | |
1792 (defun isearch-pop-state () | |
1793 (setq isearch-cmds (cdr isearch-cmds)) | |
1794 (isearch-top-state)) | |
1795 | |
1796 (defun isearch-push-state () | |
1797 (setq isearch-cmds | |
1798 (cons (list isearch-string isearch-message (point) | |
1799 isearch-success isearch-forward isearch-other-end | |
1800 isearch-word | |
1801 isearch-invalid-regexp isearch-wrapped isearch-barrier | |
1802 isearch-within-brackets isearch-case-fold-search) | |
1803 isearch-cmds))) | |
1804 | |
1805 | |
1806 ;; Message string | 1882 ;; Message string |
1807 | 1883 |
1808 (defun isearch-message (&optional c-q-hack ellipsis) | 1884 (defun isearch-message (&optional c-q-hack ellipsis) |
1809 ;; Generate and print the message string. | 1885 ;; Generate and print the message string. |
1810 (let ((cursor-in-echo-area ellipsis) | 1886 (let ((cursor-in-echo-area ellipsis) |
1930 (setq isearch-invalid-regexp (format "%s" lossage)))) | 2006 (setq isearch-invalid-regexp (format "%s" lossage)))) |
1931 | 2007 |
1932 (if isearch-success | 2008 (if isearch-success |
1933 nil | 2009 nil |
1934 ;; Ding if failed this time after succeeding last time. | 2010 ;; Ding if failed this time after succeeding last time. |
1935 (and (nth 3 (car isearch-cmds)) | 2011 (and (isearch-success (car isearch-cmds)) |
1936 (ding)) | 2012 (ding)) |
1937 (goto-char (nth 2 (car isearch-cmds))))) | 2013 (goto-char (isearch-point (car isearch-cmds))))) |
1938 | 2014 |
1939 | 2015 |
1940 ;; Called when opening an overlay, and we are still in isearch. | 2016 ;; Called when opening an overlay, and we are still in isearch. |
1941 (defun isearch-open-overlay-temporary (ov) | 2017 (defun isearch-open-overlay-temporary (ov) |
1942 (if (not (null (overlay-get ov 'isearch-open-invisible-temporary))) | 2018 (if (not (null (overlay-get ov 'isearch-open-invisible-temporary))) |