]> code.delx.au - gnu-emacs/blobdiff - lisp/isearch.el
* isearch.el (isearch-switch-frame-handler): Call
[gnu-emacs] / lisp / isearch.el
index 0f7fcc65b5a181a843e9eab7d9163ca10040ab8f..85b8924ac0d97a7f7c87f406a4c846af0a6d970e 100644 (file)
@@ -1,10 +1,10 @@
-;; Incremental search minor mode.
+;;; isearch.el --- incremental search minor mode.
+
 ;; Copyright (C) 1992 Free Software Foundation, Inc.
 
-;; LCD Archive Entry:
-;; isearch-mode|Daniel LaLiberte|liberte@cs.uiuc.edu
-;; |A minor mode replacement for isearch.el.
-;; |$Date: 1992/10/27 04:11:46 $|$Revision: 1.13 $|~/modes/isearch-mode.el
+;; Author: Daniel LaLiberte <liberte@cs.uiuc.edu>
+
+;; |$Date: 1993/03/17 17:17:05 $|$Revision: 1.26 $
 
 ;; This file is not yet part of GNU Emacs, but it is based almost
 ;; entirely on isearch.el which is part of GNU Emacs.
@@ -24,6 +24,8 @@
 ;; file named COPYING.  Among other things, the copyright notice
 ;; and this notice must be preserved on all copies.
 
+;;; Commentary:
+
 ;;;====================================================================
 ;; Instructions
 
 ;; - Think about incorporating query-replace.
 ;; - Hooks and options for failed search.
 
+;;; Change Log:
+
 ;;;====================================================================
 ;;; Change History
 
-;;; $Header: /gd/gnu/emacs/19.0/lisp/RCS/isearch-mode.el,v 1.13 1992/10/27 04:11:46 rms Exp rms $
-;;; $Log: isearch-mode.el,v $
+;;; $Header: /home/gd/gnu/emacs/19.0/lisp/RCS/isearch.el,v 1.26 1993/03/17 17:17:05 eric Exp jimb $
+;;; $Log: isearch.el,v $
+; Revision 1.26  1993/03/17  17:17:05  eric
+; Add standard library headers.
+;
+; Revision 1.25  1993/03/17  16:44:50  eric
+; Add standard library headers.
+;
+; Revision 1.24  1993/03/17  15:58:09  eric
+; Add standard library headers.
+;
+; Revision 1.23  1993/03/07  20:17:27  rms
+; (isearch-other-meta-char): Call listify-key-sequence.
+; (isearch-unread): Don't call it here.
+; (isearch-mode-map): Bind the ASCII-equivalent function keys.
+;
+; Revision 1.22  1993/03/07  08:43:57  rms
+; (isearch-mode): Don't make a pre-command-hook.
+;
+; Revision 1.21  1993/03/07  04:22:00  rms
+; (isearch-unread): Find last list element by hand.
+;
+; Revision 1.20  1993/03/06  06:15:05  rms
+; (isearch-unread): Handle multiple args.
+; For Emacs 19, use listify-key-sequence.
+; If not Emacs 19, assume they are a meta sequence.
+; (isearch-other-meta-char): Pass the whole key sequence.
+; (isearch-other-control-char): Make this alias for ...-meta-char.
+;
+; Revision 1.19  1993/02/17  21:30:25  rms
+; Fix minor bugs in previous change.
+;
+; Revision 1.18  1993/02/17  20:34:20  rms
+; (isearch-backward-regexp):
+; New arg no-recursive-edit, always non-nil for interactive call.
+; Rename first arg, and set it right in interactive call.
+; (isearch-forward-regexp): Likewise.
+; (isearch-forward, isearch-backward): Likewise no-recursive-edit.
+;
+; Revision 1.17  1993/01/26  01:48:27  jimb
+; JimB's changes since January 18th
+;
+; Revision 1.16  1992/11/16  01:37:06  jimb
+;      * bytecomp.el: Declare unread-command-char an obsolete variable.
+;      * vip.el (vip-escape-to-emacs, vip-prefix-arg-value,
+;      vip-prefix-arg-com): Use unread-command-event instead of
+;      unread-command-char; respect its new semantics.
+;      * isearch-mode.el (isearch-update, isearch-unread): Same.
+;
+; Revision 1.15  1992/11/07  06:17:04  jimb
+;         * isearch.el (isearch-frames-exist): This isn't what we want -
+;      replaced by...
+;      (isearch-gnu-emacs-events): non-nil if should expect events in the
+;      style generated by GNU Emacs 19.  Set if set-frame-height is
+;      fboundp; this is true on any GNU Emacs 19, whether or not it was
+;      compiled with multiple frame support.
+;      (isearch-mode-map): Test isearch-gnu-emacs-events instead of
+;      isearch-frames-exist to see if we should bind switch-frame events.
+;      (isearch-update): Test isearch-gnu-emacs-events instead of
+;      isearch-frames-exist to see if unread-command-char's quiescent
+;      value is nil or -1.
+;
+; Revision 1.14  1992/11/01  22:10:59  rms
+; (isearch-search): Handle all sorts of errors from regexp search.
+;
 ; Revision 1.13  1992/10/27  04:11:46  rms
 ; (isearch-edit-string):
 ; Bind cursor-in-echo-area only around read-char/allocate-event.
 ;;; 3/18/92 Fixed invalid-regexp.
 ;;; 3/18/92 Fixed yanking in regexps.
 
+;;; Code:
 
 \f
 ;;;=========================================================================
 ;; Each of the tests below must work on any version of emacs.
 ;; (Perhaps provide and featurep could be used for this purpose.)
 
-(defconst isearch-frames-exist (fboundp 'select-frame)) ;; emacs 19
+(defconst isearch-gnu-emacs-events (fboundp 'set-frame-height)) ;; emacs 19
 (defconst isearch-pre-command-hook-exists (boundp 'pre-command-hook)) ;; lemacs
 (defconst isearch-event-data-type nil)  ;; lemacs
 
@@ -257,9 +325,6 @@ Default value, nil, means edit the string instead.")
     
       (define-key map "\C-q" 'isearch-quote-char)
 
-      ;;  (define-key map "\r" 'isearch-return-char)
-      ;; For version 19, RET (C-m) terminates search and LFD (C-j) matches eol.
-      ;; We could make this conditional.
       (define-key map "\r" 'isearch-exit)
       (define-key map "\C-j" 'isearch-printing-char)
       (define-key map "\t" 'isearch-printing-char)
@@ -268,6 +333,16 @@ Default value, nil, means edit the string instead.")
       (define-key map "\C-w" 'isearch-yank-word)
       (define-key map "\C-y" 'isearch-yank-line)
 
+      ;; Bind the ASCII-equivalent "function keys" explicitly
+      ;; if we bind their equivalents, 
+      ;; since otherwise the default binding would override.
+      ;; We bind [escape] below.
+      (define-key map [tab] 'isearch-printing-char)
+      (define-key map [delete] 'isearch-delete-char)
+      (define-key map [backspace] 'isearch-delete-char)
+      (define-key map [return] 'isearch-exit)
+      (define-key map [newline] 'isearch-printing-char)
+
       ;; Define keys for regexp chars * ? |.
       ;; Nothing special for + because it matches at least once.
       (define-key map "*" 'isearch-*-char)
@@ -290,20 +365,18 @@ Default value, nil, means edit the string instead.")
       ;; keys as well, one full keymap per char of the prefix key.  It
       ;; would be simpler to disable the global keymap, and/or have a
       ;; default local key binding for any key not otherwise bound.
-      (define-key map (char-to-string meta-prefix-char) (make-sparse-keymap))
+      (let ((meta-map (make-sparse-keymap)))
+       (define-key map (char-to-string meta-prefix-char) meta-map)
+       (define-key map [escape] meta-map))
       (define-key map (vector meta-prefix-char t) 'isearch-other-meta-char)
-;;;      (setq i 0)
-;;;      (while (< i 128)
-;;;    (define-key map (char-to-string (+ 128 i));; Needs to be generalized.
-;;;      'isearch-other-meta-char)
-;;;    (setq i (1+ i)))
 
       (define-key map "\M-n" 'isearch-ring-advance)
       (define-key map "\M-p" 'isearch-ring-retreat)
+
       (define-key map "\M-\t" 'isearch-complete)
 
       ;; For emacs 19, switching frames should terminate isearch-mode
-      (if isearch-frames-exist
+      (if isearch-gnu-emacs-events
          (define-key map [switch-frame] 'isearch-switch-frame-handler))
       
       (setq isearch-mode-map map)
@@ -399,7 +472,7 @@ Default value, nil, means edit the string instead.")
 ;;; An alternative is to fset isearch-forward etc to isearch-mode,
 ;;; and look at this-command to set the options accordingly.
 
-(defun isearch-forward (&optional regexp-p)
+(defun isearch-forward (&optional regexp-p no-recursive-edit)
   "\
 Do incremental search forward.
 With a prefix argument, do an incremental regular expression search instead.
@@ -438,34 +511,34 @@ Other control and meta characters terminate the search
 If this function is called non-interactively, it does not return to
 the calling function until the search is done."
 
-  (interactive "P")
-  (isearch-mode t (not (null regexp-p)) nil (not (interactive-p))))
+  (interactive "P\np")
+  (isearch-mode t (not (null regexp-p)) nil (not no-recursive-edit)))
 
-(defun isearch-forward-regexp (&optional regexp-p)
+(defun isearch-forward-regexp (&optional not-regexp no-recursive-edit)
   "\
 Do incremental search forward for regular expression.
 With a prefix argument, do a regular string search instead.
 Like ordinary incremental search except that your input
 is treated as a regexp.  See \\[isearch-forward] for more info."
-  (interactive)
-  (isearch-mode t (null regexp-p) nil (not (interactive-p))))
+  (interactive "P\np")
+  (isearch-mode t (null not-regexp) nil (not no-recursive-edit)))
 
-(defun isearch-backward (&optional regexp-p)
+(defun isearch-backward (&optional regexp-p no-recursive-edit)
   "\
 Do incremental search backward.
 With a prefix argument, do a regular expression search instead.
 See \\[isearch-forward] for more information."
-  (interactive)
-  (isearch-mode nil (not (null regexp-p)) nil (not (interactive-p))))
+  (interactive "P\np")
+  (isearch-mode nil (not (null regexp-p)) nil (not no-recursive-edit)))
 
-(defun isearch-backward-regexp (&optional regexp-p)
+(defun isearch-backward-regexp (&optional not-regexp no-recursive-edit)
   "\
 Do incremental search backward for regular expression.
 With a prefix argument, do a regular string search instead.
 Like ordinary incremental search except that your input
 is treated as a regexp.  See \\[isearch-forward] for more info."
-  (interactive)
-  (isearch-mode nil (null regexp-p) nil (not (interactive-p))))
+  (interactive "P\np")
+  (isearch-mode nil (null not-regexp) nil (not no-recursive-edit)))
 
 
 (defun isearch-mode-help ()
@@ -514,8 +587,10 @@ is treated as a regexp.  See \\[isearch-forward] for more info."
        isearch-old-local-map (current-local-map)
        search-ring-yank-pointer nil
        regexp-search-ring-yank-pointer nil)
-  (if isearch-pre-command-hook-exists
-      (add-hook 'pre-command-hook 'isearch-pre-command-hook))
+;; This was for Lucid Emacs.  But now that we have pre-command-hook,
+;; it causes trouble.
+;;  (if isearch-pre-command-hook-exists
+;;      (add-hook 'pre-command-hook 'isearch-pre-command-hook))
   (setq        isearch-mode " Isearch")  ;; forward? regexp?
   (set-buffer-modified-p (buffer-modified-p)) ; update modeline
 
@@ -539,8 +614,8 @@ is treated as a regexp.  See \\[isearch-forward] for more info."
   ;; Called after each command to update the display.  
   (if (if isearch-event-data-type
          (null unread-command-event)
-       (if isearch-frames-exist
-           (null unread-command-char)
+       (if isearch-gnu-emacs-events
+           (null unread-command-events)
          (< unread-command-char 0)))
       (progn
        (if (not (input-pending-p))
@@ -630,7 +705,7 @@ is treated as a regexp.  See \\[isearch-forward] for more info."
   (interactive) ;; Is this necessary?
   ;; First terminate isearch-mode.
   (isearch-done)
-  (select-frame (car (cdr (isearch-last-command-char)))))
+  (handle-switch-frame (car (cdr (isearch-last-command-char)))))
 
 ;;;========================================================
 
@@ -990,35 +1065,21 @@ If no previous match was done, just beep."
   (isearch-process-search-char (isearch-last-command-char)))
 
 
-(defun isearch-other-control-char ()
-  "Any other control char => unread it and exit the search normally.
-But only if `search-exit-option' is non-nil, the default.
-If it is the symbol `edit', the search string is edited in the minibuffer
-and the control char is unread so that it applies to editing the string."
-  (interactive)
-  (cond ((eq search-exit-option 'edit)
-        (isearch-unread (isearch-last-command-char))
-        (isearch-edit-string))
-       (search-exit-option;; any other non-nil value
-        (isearch-unread (isearch-last-command-char))
-        (isearch-done))
-       (t;; search-exit-option is nil
-        (isearch-process-search-char (isearch-last-command-char)))))
-
+(fset 'isearch-other-control-char 'isearch-other-meta-char)
 
 (defun isearch-other-meta-char ()
-  "Any other meta char => exit the search normally and reread the character.
+  "Exit the search normally and reread this key sequence.
 But only if `search-exit-option' is non-nil, the default.
 If it is the symbol `edit', the search string is edited in the minibuffer
 and the meta character is unread so that it applies to editing the string."
   (interactive)
   (cond ((eq search-exit-option 'edit)
         (let ((key (this-command-keys)))
-          (isearch-unread (+ 128 (aref key (1- (length key))))))
+          (apply 'isearch-unread (listify-key-sequence key)))
         (isearch-edit-string))
        (search-exit-option
         (let ((key (this-command-keys)))
-          (isearch-unread (+ 128 (aref key (1- (length key))))))
+          (apply 'isearch-unread (listify-key-sequence key)))
         (isearch-done))
        (t;; otherwise nil
         (isearch-process-search-string (this-command-keys)
@@ -1396,6 +1457,7 @@ have special meaning in a regexp."
 
 ;; To quiet the byte-compiler.
 (defvar unread-command-event)
+(defvar unread-command-events)
 (defvar last-command-event)
 
 (defun isearch-char-to-string (c)
@@ -1406,11 +1468,20 @@ have special meaning in a regexp."
 (defun isearch-text-char-description (c)
   (isearch-char-to-string c))
 
-(defun isearch-unread (char-or-event)
-  ;; General function to unread a character or event.
-  (if isearch-event-data-type
-      (setq unread-command-event char-or-event)
-    (setq unread-command-char char-or-event)))
+(defun isearch-unread (&rest char-or-events)
+  ;; General function to unread characters or events.
+  (if isearch-gnu-emacs-events
+      (setq unread-command-events
+           (append char-or-events unread-command-events))
+    (let ((char (if (cdr char-or-events)
+                   (progn
+                     (while (cdr char-or-events)
+                       (setq char-or-events (cdr char-or-events)))
+                     (+ 128 (car char-or-events)))
+                 (car char-or-events))))
+      (if isearch-event-data-type
+         (setq unread-command-event char)
+       (setq unread-command-char char)))))
 
 (defun isearch-last-command-char ()
   ;; General function to return the last command character.
@@ -1521,3 +1592,5 @@ have special meaning in a regexp."
 ;;     ))
 
 ;;))
+
+;;; isearch.el ends here