/[emacs]/emacs/lisp/isearch.el
ViewVC logotype

Diff of /emacs/lisp/isearch.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.221.2.4 by miles, Tue Jul 6 02:56:04 2004 UTC revision 1.221.2.5 by miles, Fri Aug 27 07:00:26 2004 UTC
# Line 153  string, and RET terminates editing and d Line 153  string, and RET terminates editing and d
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    
# Line 294  Default value, nil, means edit the strin Line 294  Default value, nil, means edit the strin
294      (define-key map "\M-\C-y" 'isearch-yank-char)      (define-key map "\M-\C-y" 'isearch-yank-char)
295      (define-key map    "\C-y" 'isearch-yank-line)      (define-key map    "\C-y" 'isearch-yank-line)
296    
297      ;; Define keys for regexp chars * ? |.      ;; Define keys for regexp chars * ? } |.
298      ;; Nothing special for + because it matches at least once.      ;; Nothing special for + because it matches at least once.
299      (define-key map "*" 'isearch-*-char)      (define-key map "*" 'isearch-*-char)
300      (define-key map "?" 'isearch-*-char)      (define-key map "?" 'isearch-*-char)
301      (define-key map "{" 'isearch-{-char)      (define-key map "}" 'isearch-}-char)
302      (define-key map "|" 'isearch-|-char)      (define-key map "|" 'isearch-|-char)
303    
304      ;; 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.
# Line 368  Default value, nil, means edit the strin Line 368  Default value, nil, means edit the strin
368    
369  (defvar isearch-cmds nil  (defvar isearch-cmds nil
370    "Stack of search status sets.    "Stack of search status sets.
371  Each set is a list of the form:  Each set is a vector of the form:
372   (STRING MESSAGE POINT SUCCESS FORWARD OTHER-END WORD   [STRING MESSAGE POINT SUCCESS FORWARD OTHER-END WORD
373    INVALID-REGEXP WRAPPED BARRIER WITHIN-BRACKETS CASE-FOLD-SEARCH)")    INVALID-REGEXP WRAPPED BARRIER WITHIN-BRACKETS CASE-FOLD-SEARCH]")
374    
375  (defvar isearch-string "")  ; The current search string.  (defvar isearch-string "")  ; The current search string.
376  (defvar isearch-message "") ; text-char-description version of isearch-string  (defvar isearch-message "") ; text-char-description version of isearch-string
# Line 770  REGEXP says which ring to use." Line 770  REGEXP says which ring to use."
770  ;;   (handle-switch-frame (car (cdr last-command-char))))  ;;   (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)))
839    
840    
841  ;; Commands active while inside of the isearch minor mode.  ;; Commands active while inside of the isearch minor mode.
842    
843  (defun isearch-exit ()  (defun isearch-exit ()
# Line 1245  might return the position of the end of Line 1313  might return the position of the end of
1313    (isearch-update))    (isearch-update))
1314    
1315    
1316  (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.  
1317  ;; 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.
1318  ;; So go back to place last successful search started  ;; So go back to place last successful search started
1319  ;; or to the last ^S/^R (barrier), whichever is nearer.  ;; or to the last ^S/^R (barrier), whichever is nearer.
1320  ;; + needs no special handling because the string must match at least once.  ;; + needs no special handling because the string must match at least once.
1321    
1322  (defun isearch-*-char (&optional want-backslash)  (defun isearch-backslash (str)
1323    "Handle * and ? specially in regexps.    "Return t if STR ends in an odd number of backslashes."
1324  When WANT-BACKSLASH is non-nil, do special handling for \{."    (= (mod (- (length str) (string-match "\\\\*\\'" str)) 2) 1))
1325    (interactive)  
1326    (if isearch-regexp  (defun isearch-fallback (want-backslash &optional allow-invalid to-barrier)
1327        (let ((idx (length isearch-string)))    "Return point to previous successful match to allow regexp liberalization.
1328          (while (and (> idx 0)  \\<isearch-mode-map>
1329                      (eq (aref isearch-string (1- idx)) ?\\))  Respects \\[isearch-repeat-forward] and \\[isearch-repeat-backward] by
1330            (setq idx (1- idx)))  stopping at `isearch-barrier' as needed.
1331          ;; * and ? are special when not preceded by \.  
1332          ;; { is special when it is preceded by \.  Do nothing if a backslash is escaping the liberalizing character.  If
1333          (when (= (mod (- (length isearch-string) idx) 2)  WANT-BACKSLASH is non-nil, invert this behavior (for \\} and \\|).
1334                   (if want-backslash 1 0))  
1335            (setq isearch-adjusted t)  Do nothing if regexp has recently been invalid unless optional ALLOW-INVALID
1336            ;; Get the isearch-other-end from before the last search.  non-nil.
1337            ;; We want to start from there,  
1338            ;; so that we don't retreat farther than that.  If optional TO-BARRIER non-nil, ignore previous matches and go exactly to the
1339            ;; (car isearch-cmds) is after last search;  barrier."
1340            ;; (car (cdr isearch-cmds)) is from before it.    ;; (eq (not a) (not b)) makes all non-nil values equivalent
1341            (let ((cs (nth 5 (car (cdr isearch-cmds)))))    (when (and isearch-regexp (eq (not (isearch-backslash isearch-string))
1342              (setq cs (or cs isearch-barrier))                                  (not want-backslash))
1343              (goto-char               ;; We have to check 2 stack frames because the last might be
1344               (if isearch-forward               ;; invalid just because of a backslash.
1345                   (max cs isearch-barrier)               (or (not isearch-invalid-regexp)
1346                 (min cs isearch-barrier)))))))                   (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))))))
1384    (isearch-process-search-char last-command-char))    (isearch-process-search-char last-command-char))
1385    
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 \.
1399  (defun isearch-|-char ()  (defun isearch-|-char ()
1400    "If in regexp search, jump to the barrier."    "If in regexp search, jump to the barrier unless in a group."
1401    (interactive)    (interactive)
1402    (if isearch-regexp    (isearch-fallback t nil t))
       (progn  
         (setq isearch-adjusted t)  
         (goto-char isearch-barrier)))  
   (isearch-process-search-char last-command-char))  
1403    
1404  (defun isearch-unread-key-sequence (keylist)  (defun isearch-unread-key-sequence (keylist)
1405    "Unread the given key-sequence KEYLIST.    "Unread the given key-sequence KEYLIST.
# Line 1771  If there is no completion possible, say Line 1879  If there is no completion possible, say
1879          (insert isearch-string))))          (insert isearch-string))))
1880    
1881    
 ;; 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)))  
   
   
1882  ;; Message string  ;; Message string
1883    
1884  (defun isearch-message (&optional c-q-hack ellipsis)  (defun isearch-message (&optional c-q-hack ellipsis)
# Line 1932  Can be changed via `isearch-search-fun-f Line 2008  Can be changed via `isearch-search-fun-f
2008    (if isearch-success    (if isearch-success
2009        nil        nil
2010      ;; Ding if failed this time after succeeding last time.      ;; Ding if failed this time after succeeding last time.
2011      (and (nth 3 (car isearch-cmds))      (and (isearch-success (car isearch-cmds))
2012           (ding))           (ding))
2013      (goto-char (nth 2 (car isearch-cmds)))))      (goto-char (isearch-point (car isearch-cmds)))))
2014    
2015    
2016  ;; Called when opening an overlay, and we are still in isearch.  ;; Called when opening an overlay, and we are still in isearch.

Legend:
Removed from v.1.221.2.4  
changed lines
  Added in v.1.221.2.5

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26