]> code.delx.au - gnu-emacs/blobdiff - lisp/isearch.el
(mark-c-function): Activate the mark.
[gnu-emacs] / lisp / isearch.el
index 7ab39a5dac06a83e11b61f51ac25fa8d7c5c207f..9833d7d01264c6f4a113ac11139e369aad0365f2 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: 1993/03/07 04:22:00 $|$Revision: 1.21 $|~/modes/isearch-mode.el
+;; Author: Daniel LaLiberte <liberte@cs.uiuc.edu>
+
+;; |$Date: 1993/05/14 18:02:55 $|$Revision: 1.32 $
 
 ;; 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
 
@@ -36,7 +38,7 @@
 ;; isearch-forward, etc, will then use isearch-mode instead of
 ;; isearch.
 
-;; (fset 'isearch 'isearch-mode)
+;; (defalias 'isearch 'isearch-mode)
 ;; (autoload 'isearch-mode "isearch-mode")
 
 ;; For programmed use of isearch-mode, e.g. calling (isearch-forward),
@@ -49,7 +51,7 @@
 ;; of isearch-forward, etc. found in this file instead of those in
 ;; loaddefs.el.  The simplest way to ensure this is to just load
 ;; isearch-mode explicitly in your .emacs instead of using the above
-;; fset and autoload.
+;; defalias and autoload.
 
 ;; (load "isearch-mode")
 
 ;; - 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.21 1993/03/07 04:22:00 rms Exp rms $
-;;; $Log: isearch-mode.el,v $
+;;; $Header: /gd/gnu/emacs/19.0/lisp/RCS/isearch.el,v 1.32 1993/05/14 18:02:55 rms Exp rms $
+;;; $Log: isearch.el,v $
+; Revision 1.32  1993/05/14  18:02:55  rms
+; (isearch-mode-map): Handle any length vector in keymap.
+; (isearch-char-to-string): Handle non-character events properly.
+;
+; Revision 1.31  1993/04/23  07:31:14  eric
+; Replaced all fsets with defaliases.
+;
+; Revision 1.30  1993/04/14  19:40:53  rms
+; Doc fixes.
+;
+; Revision 1.29  1993/03/30  19:42:10  rms
+; (isearch-done): Customize the message about mark.
+;
+; Revision 1.28  1993/03/30  19:38:34  rms
+; (isearch-mode-map): Delete the binding for C-h.
+;
+; Revision 1.27  1993/03/21  05:50:17  jimb
+;      * isearch.el (isearch-switch-frame-handler): Call
+;      handle-switch-frame instead of select-frame; it has been renamed.
+;
+; 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.
 ;
 ;;; 3/18/92 Fixed invalid-regexp.
 ;;; 3/18/92 Fixed yanking in regexps.
 
+;;; Code:
 
 \f
 ;;;=========================================================================
@@ -291,7 +333,9 @@ Default value, nil, means edit the string instead.")
 
       ;; Printing chars extend the selection by default.
       (setq i ?\ )
-      (while (< i 128)
+      (or (vectorp (nth 1 map))
+         (error "The initialization of isearch-mode-map must be updated"))
+      (while (< i (length (nth 1 map)))
        (define-key map (make-string 1 i) 'isearch-printing-char)
        (setq i (1+ i)))
 
@@ -303,9 +347,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)
@@ -314,35 +355,35 @@ 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)
       (define-key map "?" 'isearch-*-char)
       (define-key map "|" 'isearch-|-char)
 
-      ;; You can reenable global keys by binding them locally to nil.
-      ;; For the help char this doesnt work quite as expected because
-      ;; isearch-mode is not a major mode.  Also the echo area is not
-      ;; restored after the help command while isearch-mode is
-      ;; still active.  Furthermore, we should not assume that the
-      ;; help-command is on C-h.  But here is how it would be done:
-      ;; (define-key map "\C-h" nil)
-
-      ;; Instead bind C-h to special help command for isearch-mode.
-      (define-key map "\C-h" 'isearch-mode-help)
+;;; Turned off because I find I expect to get the global definition--rms.
+;;;      ;; Instead bind C-h to special help command for isearch-mode.
+;;;      (define-key map "\C-h" 'isearch-mode-help)
 
       ;; To handle local bindings with meta char prefix keys, define
       ;; another full keymap.  This must be done for any other prefix
       ;; 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)
@@ -443,7 +484,7 @@ Default value, nil, means edit the string instead.")
 ;;;===============================================================
 ;;; Entry points to isearch-mode.
 ;;; These four functions should replace those in loaddefs.el
-;;; An alternative is to fset isearch-forward etc to isearch-mode,
+;;; An alternative is to defalias isearch-forward etc to isearch-mode,
 ;;; and look at this-command to set the options accordingly.
 
 (defun isearch-forward (&optional regexp-p no-recursive-edit)
@@ -637,7 +678,12 @@ is treated as a regexp.  See \\[isearch-forward] for more info."
     ;; If there was movement, mark the starting position.
     ;; Maybe should test difference between and set mark iff > threshold.
     (if (/= (point) isearch-opoint)
-       (push-mark isearch-opoint)
+       (progn
+         (push-mark isearch-opoint t)
+         (if transient-mark-mode
+             (setq mark-active nil))
+         (or executing-macro (> (minibuffer-depth) 0)
+             (message "Mark saved where search started")))
       ;; (message "") why is this needed?
       )
     (if isearch-small-window
@@ -679,7 +725,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)))))
 
 ;;;========================================================
 
@@ -1039,7 +1085,7 @@ If no previous match was done, just beep."
   (isearch-process-search-char (isearch-last-command-char)))
 
 
-(fset 'isearch-other-control-char 'isearch-other-meta-char)
+(defalias 'isearch-other-control-char 'isearch-other-meta-char)
 
 (defun isearch-other-meta-char ()
   "Exit the search normally and reread this key sequence.
@@ -1049,11 +1095,11 @@ 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)))
-          (apply 'isearch-unread (append key nil)))
+          (apply 'isearch-unread (listify-key-sequence key)))
         (isearch-edit-string))
        (search-exit-option
         (let ((key (this-command-keys)))
-          (apply 'isearch-unread (append key nil)))
+          (apply 'isearch-unread (listify-key-sequence key)))
         (isearch-done))
        (t;; otherwise nil
         (isearch-process-search-string (this-command-keys)
@@ -1072,13 +1118,13 @@ Obsolete."
   (isearch-process-search-char ?\n))
 
 (defun isearch-printing-char ()
-  "Any other printing character => add it to the search string and search."
+  "Add this ordinary printing character to the search string and search."
   (interactive)
   (isearch-process-search-char (isearch-last-command-char)))
 
 (defun isearch-whitespace-chars ()
   "Match all whitespace chars, if in regexp mode.
-If not in regexp mode, activate word search."
+If you want to search for just a space, type C-q SPC."
   (interactive)
   (if isearch-regexp 
       (if search-whitespace-regexp
@@ -1401,14 +1447,14 @@ If there is no completion possible, say so and continue searching."
            (set-extent-face isearch-extent 'default)
          (isearch-dehighlight t)))))
 
-(fset 'isearch-highlight (symbol-function 'isearch-lemacs-highlight))
-(fset 'isearch-dehighlight (symbol-function 'isearch-lemacs-dehighlight))
+(defalias 'isearch-highlight (symbol-function 'isearch-lemacs-highlight))
+(defalias 'isearch-dehighlight (symbol-function 'isearch-lemacs-dehighlight))
 )
 
 ;;;===========================================================
 ;;; General utilities
 
-;; (fset 'isearch-member-equal (symbol-function 'member)) ; for emacs 19
+;; (defalias 'isearch-member-equal (symbol-function 'member)) ; for emacs 19
 
 (defun isearch-member-equal (item list)
   "Return non-nil if ITEM is `equal' to some item in LIST.
@@ -1437,16 +1483,18 @@ have special meaning in a regexp."
 (defun isearch-char-to-string (c)
   (if (integerp c)
       (make-string 1 c)
-   (make-string 1 (event-to-character c))))
+    (if (and (symbolp c) (get c 'ascii-character))
+       (make-string 1 (get c 'ascii-character))
+      (make-string 1 (event-to-character c)))))
 
 (defun isearch-text-char-description (c)
   (isearch-char-to-string c))
 
 (defun isearch-unread (&rest char-or-events)
-  (setq foo char-or-events)
   ;; General function to unread characters or events.
   (if isearch-gnu-emacs-events
-      (setq unread-command-events (listify-key-sequence char-or-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)
@@ -1567,3 +1615,4 @@ have special meaning in a regexp."
 
 ;;))
 
+;;; isearch.el ends here