home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / prim / isearch-mode.el.z / isearch-mode.el
Encoding:
Text File  |  1998-05-21  |  60.5 KB  |  1,611 lines

  1. ;; Incremental search minor mode.
  2. ;; Copyright (C) 1992, 1993 Free Software Foundation, Inc.
  3.  
  4. ;; LCD Archive Entry:
  5. ;; isearch-mode|Daniel LaLiberte|liberte@cs.uiuc.edu
  6. ;; |A minor mode replacement for isearch.el.
  7.  
  8. ;; This file is part of XEmacs.
  9.  
  10. ;; XEmacs is free software; you can redistribute it and/or modify it
  11. ;; under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation; either version 2, or (at your option)
  13. ;; any later version.
  14.  
  15. ;; XEmacs is distributed in the hope that it will be useful, but
  16. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  18. ;; General Public License for more details.
  19.  
  20. ;; You should have received a copy of the GNU General Public License
  21. ;; along with XEmacs; see the file COPYING.  If not, write to the 
  22. ;; Free Software Foundation, 59 Temple Place - Suite 330,
  23. ;; Boston, MA 02111-1307, USA.
  24.  
  25. ;;; Synched up with: Not synched with FSF.
  26.  
  27. ;;;====================================================================
  28. ;; Instructions
  29.  
  30. ;; Searching with isearch-mode.el should work just like isearch.el,
  31. ;; except it is done in a temporary minor mode that terminates when
  32. ;; you finish searching.
  33.  
  34. ;; Semi-modal searching is supported, using a recursive edit. If
  35. ;; isearching is started non-interactively by calling one of the
  36. ;; isearch commands (e.g. (isearch-forward), but not like gnus does
  37. ;; it: (call-interactively 'isearch-forward)), isearch-mode does not
  38. ;; return until the search is completed.  You should still be able
  39. ;; switch buffers, so be careful not to get things confused.
  40.  
  41. ;; The key bindings active within isearch-mode are defined below in
  42. ;; `isearch-mode-map' which is given bindings close to the default
  43. ;; characters of isearch.el for version 19.  With `isearch-mode',
  44. ;; however, you can bind multi-character keys and it should be easier
  45. ;; to add new commands.  One bug though: keys with meta-prefix cannot
  46. ;; be longer than two chars.  Also see minibuffer-local-isearch-map
  47. ;; for bindings active during `isearch-edit-string'.
  48.  
  49. ;; The search ring and completion commands automatically put you in
  50. ;; the minibuffer to edit the string.  This gives you a chance to
  51. ;; modify the search string before executing the search.  There are
  52. ;; three commands to terminate the editing: C-s and C-r exit the
  53. ;; minibuffer and search forward and reverse respectively, while C-m
  54. ;; exits and does a nonincremental search.
  55.  
  56. ;; Exiting immediately from isearch uses isearch-edit-string instead
  57. ;; of nonincremental-search, if search-nonincremental-instead is non-nil.
  58. ;; The name of this option should probably be changed if we decide to
  59. ;; keep the behavior.  One difference is that isearch-edit-string does
  60. ;; not support word search yet; perhaps isearch-mode should support it
  61. ;; even for incremental searches, but how?
  62.  
  63. ;;;====================================================================
  64. ;;; Change History
  65.  
  66. ;;; Header: /import/kaplan/kaplan/liberte/Isearch/RCS/isearch-mode.el,v 1.3 92/06/29 13:10:08 liberte Exp Locker: liberte 
  67. ;;; Log:    isearch-mode.el,v 
  68. ;;;
  69. ;;; 20-aug-92  Hacked by jwz for Lucid Emacs 19.3.
  70. ;;;
  71. ;;; Revision 1.3  92/06/29  13:10:08  liberte
  72. ;;; Moved modal isearch-mode handling into isearch-mode.
  73. ;;; Got rid of buffer-local isearch variables.
  74. ;;; isearch-edit-string used by ring adjustments, completion, and
  75. ;;; nonincremental searching.  C-s and C-r are additional exit commands.
  76. ;;; Renamed all regex to regexp.
  77. ;;; Got rid of found-start and found-point globals.
  78. ;;; Generalized handling of upper-case chars.
  79.  
  80. ;;; Revision 1.2  92/05/27  11:33:57  liberte
  81. ;;; Emacs version 19 has a search ring, which is supported here.
  82. ;;; Other fixes found in the version 19 isearch are included here.
  83. ;;;
  84. ;;; Also see variables search-caps-disable-folding,
  85. ;;; search-nonincremental-instead, search-whitespace-regexp, and
  86. ;;; commands isearch-toggle-regexp, isearch-edit-string.
  87. ;;;
  88. ;;; semi-modal isearching is supported.
  89.  
  90. ;;; Changes for 1.1
  91. ;;; 3/18/92 Fixed invalid-regexp.
  92. ;;; 3/18/92 Fixed yanking in regexps.
  93.  
  94.  
  95. (defgroup isearch nil
  96.   "Incremental search"
  97.   :prefix "search-"
  98.   :group 'matching)
  99.  
  100.  
  101. (defun isearch-char-to-string (c)
  102.   (if (eventp c) 
  103.       (make-string 1 (event-to-character c nil nil t))
  104.     (make-string 1 c)))
  105.  
  106. ;(defun isearch-text-char-description (c)
  107. ;  (isearch-char-to-string c))
  108.  
  109. (define-function 'isearch-text-char-description 'text-char-description)
  110.  
  111.  
  112. ;;;=========================================================================
  113. ;;; User-accessible variables
  114.  
  115. (defvar search-last-string ""
  116.   "Last string search for by a search command.
  117. This does not include direct calls to the primitive search functions,
  118. and does not include searches that are aborted.")
  119.  
  120. (defvar search-last-regexp ""
  121.   "Last string searched for by a regexp search command.
  122. This does not include direct calls to the primitive search functions,
  123. and does not include searches that are aborted.")
  124.  
  125. (defconst search-exit-option t
  126.   "Non-nil means random control characters terminate incremental search.")
  127.  
  128. (defcustom search-slow-window-lines 1
  129.   "*Number of lines in slow search display windows.
  130. These are the short windows used during incremental search on slow terminals.
  131. Negative means put the slow search window at the top (normally it's at bottom)
  132. and the value is minus the number of lines."
  133.   :type 'integer
  134.   :group 'isearch)
  135.  
  136. (defcustom search-slow-speed 1200
  137.   "*Highest terminal speed at which to use \"slow\" style incremental search.
  138. This is the style where a one-line window is created to show the line
  139. that the search has reached."
  140.   :type 'integer
  141.   :group 'isearch)
  142.  
  143. (defcustom search-caps-disable-folding t
  144.   "*If non-nil, upper case chars disable case fold searching.
  145. This does not apply to \"yanked\" strings."
  146.   :type 'boolean
  147.   :group 'isearch)
  148.  
  149. (defcustom search-nonincremental-instead t
  150.   "*If non-nil, do a nonincremental search instead if exiting immediately."
  151.   :type 'boolean
  152.   :group 'isearch)
  153.   
  154. (defcustom search-whitespace-regexp "\\(\\s \\|[\n\r]\\)+"
  155.   "*If non-nil, regular expression to match a sequence of whitespace chars."
  156.   :type 'regexp
  157.   :group 'isearch)
  158.  
  159. ;;;==================================================================
  160. ;;; Search ring.
  161.  
  162. (defvar search-ring nil
  163.   "List of search string sequences.")
  164. (defvar regexp-search-ring nil
  165.   "List of regular expression search string sequences.")
  166.  
  167. (defcustom search-ring-max 16
  168.   "*Maximum length of search ring before oldest elements are thrown away."
  169.   :type 'integer
  170.   :group 'isearch)
  171. (defcustom regexp-search-ring-max 16
  172.   "*Maximum length of regexp search ring before oldest elements are thrown away."
  173.   :type 'integer
  174.   :group 'isearch)
  175.  
  176. (defvar search-ring-yank-pointer nil
  177.   "The tail of the search ring whose car is the last thing searched for.")
  178. (defvar regexp-search-ring-yank-pointer nil
  179.   "The tail of the regular expression search ring whose car is the last
  180. thing searched for.")
  181.  
  182. ;;;====================================================
  183. ;;; Define isearch-mode keymap.
  184.  
  185. (defvar isearch-mode-map 
  186.   (let ((map (make-keymap)))
  187.     (set-keymap-name map 'isearch-mode-map)
  188.  
  189.     ;; Bind all printing characters to `isearch-printing-char'.
  190.     ;; This isn't normally necessary, but if a printing character were 
  191.     ;; bound to something other than self-insert-command in global-map, 
  192.     ;; then it would terminate the search and be executed without this.
  193.     (let ((i 32)
  194.       (str (make-string 1 0)))
  195.       (while (< i 127)
  196.     (aset str 0 i)
  197.     (define-key map str 'isearch-printing-char)
  198.     (setq i (1+ i))))
  199.     (define-key map "\t" 'isearch-printing-char)
  200.  
  201.     ;; Several non-printing chars change the searching behavior.
  202.     ;;
  203.     (define-key map "\C-s" 'isearch-repeat-forward)
  204.     (define-key map "\M-\C-s" 'isearch-repeat-forward)
  205.     (define-key map "\C-r" 'isearch-repeat-backward)
  206.     (define-key map "\C-g" 'isearch-abort)
  207.  
  208.     (define-key map "\C-q" 'isearch-quote-char)
  209.  
  210.     (define-key map "\C-m" 'isearch-exit)
  211.     (define-key map "\C-j" 'isearch-printing-char)
  212.     (define-key map "\t" 'isearch-printing-char)
  213.  
  214.     (define-key map "\C-w" 'isearch-yank-word)
  215.     (define-key map "\C-y" 'isearch-yank-line)
  216.     (define-key map "\M-y" 'isearch-yank-kill)
  217.  
  218.     ;; Define keys for regexp chars * ? |
  219.     (define-key map "*" 'isearch-*-char)
  220.     (define-key map "?" 'isearch-*-char)
  221.     (define-key map "|" 'isearch-|-char)
  222.  
  223.     ;; Some bindings you may want to put in your isearch-mode-hook.
  224.     ;; Suggest some alternates...
  225.     ;; (define-key map "\C-t" 'isearch-toggle-regexp)
  226.     ;; (define-key map "\C-^" 'isearch-edit-string)
  227.  
  228.     ;; delete and backspace delete backward, f1 is help, and C-h can be either
  229.     (define-key map 'delete 'isearch-delete-char)
  230.     (define-key map 'backspace 'isearch-delete-char)
  231.     (define-key map '(control h) 'isearch-help-or-delete-char)
  232.     (define-key map 'f1 'isearch-mode-help)
  233.     (define-key map 'help 'isearch-mode-help)
  234.  
  235.     (define-key map "\M-n" 'isearch-ring-advance)
  236.     (define-key map "\M-p" 'isearch-ring-retreat)
  237.     (define-key map "\M- " 'isearch-whitespace-chars)
  238.     (define-key map "\M-\t" 'isearch-complete)
  239.  
  240.     (define-key map 'button2 'isearch-yank-x-selection)
  241.  
  242.     map)
  243.   "Keymap for isearch-mode.")
  244.  
  245. (defvar minibuffer-local-isearch-map 
  246.   (let ((map (make-sparse-keymap)))
  247.     ;; #### - this should also be minor-mode-ified
  248.     (set-keymap-parents map (list minibuffer-local-map))
  249.     (set-keymap-name map 'minibuffer-local-isearch-map)
  250.  
  251.     ;;#### This should just arrange to use the usual Emacs minibuffer histories
  252.     (define-key map "\r" 'isearch-nonincremental-exit-minibuffer)
  253.     (define-key map "\M-n" 'isearch-ring-advance-edit)
  254.     (define-key map "\M-p" 'isearch-ring-retreat-edit)
  255.     (define-key map "\M-\t" 'isearch-complete-edit)
  256.     (define-key map "\C-s" 'isearch-forward-exit-minibuffer)
  257.     (define-key map "\C-r" 'isearch-reverse-exit-minibuffer)
  258.     map)
  259.   "Keymap for editing isearch strings in the minibuffer.")
  260.  
  261. ;;;========================================================
  262. ;; Internal variables declared globally for byte-compiler.
  263. ;; These are all bound locally while editing the search string.
  264.  
  265. (defvar isearch-forward nil)    ; Searching in the forward direction.
  266. (defvar isearch-regexp nil)    ; Searching for a regexp.
  267. (defvar isearch-word nil)    ; Searching for words.
  268.  
  269. (defvar isearch-cmds nil)   ; Stack of search status sets.
  270. (defvar isearch-string "")  ; The current search string.
  271. (defvar isearch-message "") ; text-char-description version of isearch-string
  272.  
  273. (defvar isearch-success t)        ; Searching is currently successful.
  274. (defvar isearch-invalid-regexp nil)    ; Regexp not well formed.
  275. (defvar isearch-other-end nil)    ; Start (end) of match if forward (backward).
  276. (defvar isearch-wrapped nil)    ; Searching restarted from the top (bottom).
  277. (defvar isearch-barrier 0)
  278. (defvar isearch-buffer nil)    ; the buffer we've frobbed the keymap of
  279.  
  280. (defvar isearch-case-fold-search nil)
  281.  
  282. (defvar isearch-adjusted nil)
  283. (defvar isearch-slow-terminal-mode nil)
  284. ;;; If t, using a small window.
  285. (defvar isearch-small-window nil)
  286. (defvar isearch-opoint 0)
  287. ;;; The window configuration active at the beginning of the search.
  288. (defvar isearch-window-configuration nil)
  289. (defvar isearch-selected-frame nil)
  290.  
  291. ;; Flag to indicate a yank occurred, so don't move the cursor.
  292. (defvar isearch-yank-flag nil)
  293.  
  294. ;;; A function to be called after each input character is processed.
  295. ;;; (It is not called after characters that exit the search.)
  296. ;;; It is only set from an optional argument to `isearch-mode'.
  297. (defvar isearch-op-fun nil)
  298.  
  299. ;;;  Is isearch-mode in a recursive edit for modal searching.
  300. (defvar isearch-recursive-edit nil)
  301.  
  302. ;;; Should isearch be terminated after doing one search?
  303. (defvar isearch-nonincremental nil)
  304.  
  305. ;; New value of isearch-forward after isearch-edit-string.
  306. (defvar isearch-new-forward nil)
  307.  
  308.  
  309. (defvar isearch-mode-hook nil
  310.   "Function(s) to call after starting up an incremental search.")
  311.  
  312. (defvar isearch-mode-end-hook nil
  313.   "Function(s) to call after terminating an incremental search.")
  314.  
  315. ;;;==============================================================
  316. ;; Minor-mode-alist changes - kind of redundant with the
  317. ;; echo area, but if isearching in multiple windows, it can be useful.
  318.  
  319. (add-minor-mode 'isearch-mode 'isearch-mode)
  320.  
  321. (defvar isearch-mode nil)
  322. (make-variable-buffer-local 'isearch-mode)
  323.  
  324. ;;;===============================================================
  325. ;;; Entry points to isearch-mode.
  326. ;;; These four functions should replace those in loaddefs.el
  327. ;;; An alternative is to fset isearch-forward etc to isearch-mode,
  328. ;;; and look at the last command to set the options accordingly.
  329.  
  330. (defun isearch-forward (&optional regexp-p)
  331.   "Do incremental search forward.
  332. With a prefix argument, do an incremental regular expression search instead.
  333. \\<isearch-mode-map>
  334. As you type characters, they add to the search string and are found.
  335. The following non-printing keys are bound in `isearch-mode-map'.  
  336.  
  337. Type \\[isearch-delete-char] to cancel characters from end of search string.
  338. Type \\[isearch-exit] to exit, leaving point at location found.
  339. Type LFD (C-j) to match end of line.
  340. Type \\[isearch-repeat-forward] to search again forward,\
  341.  \\[isearch-repeat-backward] to search again backward.
  342. Type \\[isearch-yank-word] to yank word from buffer onto end of search\
  343.  string and search for it.
  344. Type \\[isearch-yank-line] to yank rest of line onto end of search string\
  345.  and search for it.
  346. Type \\[isearch-quote-char] to quote control character to search for it.
  347. Type \\[isearch-whitespace-chars] to match all whitespace chars in regexp.
  348. \\[isearch-abort] while searching or when search has failed cancels input\
  349.  back to what has
  350.  been found successfully.
  351. \\[isearch-abort] when search is successful aborts and moves point to\
  352.  starting point.
  353.  
  354. Also supported is a search ring of the previous 16 search strings.
  355. Type \\[isearch-ring-advance] to search for the next item in the search ring.
  356. Type \\[isearch-ring-retreat] to search for the previous item in the search\
  357.  ring.
  358. Type \\[isearch-complete] to complete the search string using the search ring.
  359.  
  360. The above keys are bound in the isearch-mode-map.  To change the keys which
  361.  are special to isearch-mode, simply change the bindings in that map.
  362.  
  363. Other control and meta characters terminate the search
  364.  and are then executed normally (depending on `search-exit-option').
  365.  
  366. If this function is called non-interactively, it does not return to
  367. the calling function until the search is done.
  368.  
  369. The bindings, more precisely:
  370. \\{isearch-mode-map}"
  371.  
  372. ;; Non-standard bindings
  373. ;; Type \\[isearch-toggle-regexp] to toggle regular expression with normal searching.
  374. ;; Type \\[isearch-edit-string] to edit the search string in the minibuffer.
  375. ;;  Terminate editing and return to incremental searching with CR.
  376.  
  377.   (interactive "_P")
  378.   (isearch-mode t (not (null regexp-p)) nil (not (interactive-p))))
  379.  
  380. (defun isearch-forward-regexp ()
  381.   "\
  382. Do incremental search forward for regular expression.
  383. Like ordinary incremental search except that your input
  384. is treated as a regexp.  See \\[isearch-forward] for more info."
  385.   (interactive "_")
  386.   (isearch-mode t t nil (not (interactive-p))))
  387.  
  388. (defun isearch-backward (&optional regexp-p)
  389.   "\
  390. Do incremental search backward.
  391. With a prefix argument, do an incremental regular expression search instead.
  392. See \\[isearch-forward] for more information."
  393.   (interactive "_P")
  394.   (isearch-mode nil (not (null regexp-p)) nil (not (interactive-p))))
  395.  
  396. (defun isearch-backward-regexp ()
  397.   "\
  398. Do incremental search backward for regular expression.
  399. Like ordinary incremental search except that your input
  400. is treated as a regexp.  See \\[isearch-forward] for more info."
  401.   (interactive "_")
  402.   (isearch-mode nil t nil (not (interactive-p))))
  403.  
  404. ;; This function is way wrong, because you can't scroll the help
  405. ;; screen; as soon as you press a key, it's gone.  I don't know of a
  406. ;; good way to fix it, though.  -hniksic
  407. (defun isearch-mode-help ()
  408.   (interactive "_")
  409.   (let ((w (selected-window)))
  410.     (describe-function 'isearch-forward)
  411.     (select-window w))
  412.   (isearch-update))
  413.  
  414.  
  415. ;;;==================================================================
  416. ;; isearch-mode only sets up incremental search for the minor mode.
  417. ;; All the work is done by the isearch-mode commands.
  418.  
  419. (defun isearch-mode (forward &optional regexp op-fun recursive-edit word-p)
  420.   "Start isearch minor mode.  Called by isearch-forward, etc."
  421.  
  422.   (if executing-kbd-macro (setq recursive-edit nil))
  423.  
  424.   (let ((inhibit-quit t)) ; don't leave things in an inconsistent state...
  425.  
  426.     ;; Initialize global vars.
  427.     (setq isearch-buffer (current-buffer)
  428.       isearch-forward forward
  429.       isearch-regexp regexp
  430.       isearch-word word-p
  431.       isearch-op-fun op-fun
  432.       isearch-case-fold-search case-fold-search
  433.       isearch-string ""
  434.       isearch-message ""
  435.       isearch-cmds nil
  436.       isearch-success t
  437.       isearch-wrapped nil
  438.       isearch-barrier (point)
  439.       isearch-adjusted nil
  440.       isearch-yank-flag nil
  441.       isearch-invalid-regexp nil
  442.       isearch-slow-terminal-mode (and (<= (device-baud-rate)
  443.                           search-slow-speed)
  444.                       (> (window-height)
  445.                          (* 4 search-slow-window-lines)))
  446.       isearch-other-end nil
  447.       isearch-small-window nil
  448.  
  449.       isearch-opoint (point)
  450.       isearch-window-configuration (current-window-configuration)
  451.  
  452.       ;; #### - don't do this statically: isearch-mode must be FIRST in
  453.       ;; the minor-mode-map-alist -- Stig
  454.       minor-mode-map-alist (cons (cons 'isearch-mode isearch-mode-map)
  455.                      minor-mode-map-alist)
  456.       isearch-selected-frame (selected-frame)
  457.  
  458.       isearch-mode (gettext " Isearch")
  459.       )
  460.  
  461.     ;; XEmacs change: without clearing the match data, sometimes old values
  462.     ;; of isearch-other-end get used.  Don't ask me why...
  463.     (store-match-data nil)
  464.  
  465.     (add-hook 'pre-command-hook 'isearch-pre-command-hook)
  466.     (set-buffer-modified-p (buffer-modified-p)) ; update modeline
  467.     (isearch-push-state)
  468.  
  469.     ) ; inhibit-quit is t before here
  470.  
  471.   (isearch-update)
  472.   (run-hooks 'isearch-mode-hook)
  473.  
  474.   ;; isearch-mode can be made modal (in the sense of not returning to 
  475.   ;; the calling function until searching is completed) by entering 
  476.   ;; a recursive-edit and exiting it when done isearching.
  477.   (if recursive-edit
  478.       (let ((isearch-recursive-edit t))
  479.     (recursive-edit)))
  480.   )
  481.  
  482.  
  483. ;;;====================================================
  484. ;; Some high level utilities.  Others below.
  485.  
  486. (defun isearch-update ()
  487.   ;; Called after each command to update the display.  
  488.   (if (null unread-command-event)
  489.       (progn
  490.     (if (not (input-pending-p))
  491.         (isearch-message))
  492.     (if (and isearch-slow-terminal-mode
  493.          (not (or isearch-small-window 
  494.               (pos-visible-in-window-p))))
  495.         (let ((found-point (point)))
  496.           (setq isearch-small-window t)
  497.           (move-to-window-line 0)
  498.           (let ((window-min-height 1))
  499.         (split-window nil (if (< search-slow-window-lines 0)
  500.                       (1+ (- search-slow-window-lines))
  501.                     (- (window-height)
  502.                        (1+ search-slow-window-lines)))))
  503.           (if (< search-slow-window-lines 0)
  504.           (progn (vertical-motion (- 1 search-slow-window-lines))
  505.              (set-window-start (next-window) (point))
  506.              (set-window-hscroll (next-window)
  507.                          (window-hscroll))
  508.              (set-window-hscroll (selected-window) 0))
  509.         (other-window 1))
  510.           (goto-char found-point)))
  511.     (if isearch-other-end
  512.         (if (< isearch-other-end (point))
  513.         (isearch-highlight isearch-other-end (point))
  514.           (isearch-highlight (point) isearch-other-end))
  515.       (if (extentp isearch-extent)
  516.           (isearch-dehighlight nil)))
  517.     ))
  518.   (setq ;; quit-flag nil  not for isearch-mode
  519.    isearch-adjusted nil
  520.    isearch-yank-flag nil)
  521.   )
  522.  
  523.  
  524. (defun isearch-done ()
  525.   ;; Called by all commands that terminate isearch-mode.
  526.   (let ((inhibit-quit t)) ; danger danger!
  527.     (if (and isearch-buffer (buffer-live-p isearch-buffer))
  528.     (save-excursion
  529.       ;; Some loser process filter might have switched the
  530.       ;; window's buffer, so be sure to set these variables back
  531.       ;; in the buffer we frobbed them in.  But only if the buffer
  532.       ;; is still alive.
  533.       (set-buffer isearch-buffer)
  534.       (setq minor-mode-map-alist (delq (assoc 'isearch-mode minor-mode-map-alist)
  535.                        minor-mode-map-alist))
  536.       ;; Use remove-hook instead of just setting it to our saved value
  537.       ;; in case some process filter has created a buffer and modified
  538.       ;; the pre-command-hook in that buffer...  yeah, this is obscure,
  539.       ;; and yeah, I was getting screwed by it. -jwz
  540.       (remove-hook 'pre-command-hook 'isearch-pre-command-hook)
  541.       (set-keymap-parents isearch-mode-map nil)
  542.       (setq isearch-mode nil)
  543.       (set-buffer-modified-p (buffer-modified-p));; update modeline
  544.       (isearch-dehighlight t)))
  545.  
  546.     ;; it's not critical that this be inside inhibit-quit, but leaving
  547.     ;; things in small-window-mode would be bad.
  548.     (let ((found-start (window-start (selected-window)))
  549.       (found-point (point)))
  550.       (cond ((eq (selected-frame) isearch-selected-frame)
  551.          (set-window-configuration isearch-window-configuration)
  552.  
  553.          (if isearch-small-window
  554.          (goto-char found-point)
  555.            ;; Exiting the save-window-excursion clobbers
  556.            ;; window-start; restore it.
  557.            (set-window-start (selected-window) found-start t))))
  558.       ;; If there was movement, mark the starting position.
  559.       ;; Maybe should test difference between and set mark iff > threshold.
  560.       (if (and (buffer-live-p isearch-buffer)
  561.            (/= (point isearch-buffer) isearch-opoint))
  562.       (progn
  563.         (push-mark isearch-opoint t nil isearch-buffer)
  564.         (or executing-kbd-macro (> (minibuffer-depth) 0)
  565.         (display-message 'command "Mark saved where search started"))))
  566.     )
  567.     (setq isearch-buffer nil)
  568.     ) ; inhibit-quit is t before here
  569.  
  570.   (if (> (length isearch-string) 0)
  571.       ;; Update the ring data.
  572.       (if isearch-regexp 
  573.       (if (not (setq regexp-search-ring-yank-pointer
  574.              (member isearch-string regexp-search-ring)))
  575.           (progn
  576.         (setq regexp-search-ring
  577.               (cons isearch-string regexp-search-ring)
  578.               regexp-search-ring-yank-pointer regexp-search-ring)
  579.         (if (> (length regexp-search-ring) regexp-search-ring-max)
  580.             (setcdr (nthcdr (1- search-ring-max) regexp-search-ring)
  581.                 nil))))
  582.     (if (not (setq search-ring-yank-pointer
  583.                ;; really need equal test instead of eq.
  584.                (member isearch-string search-ring)))
  585.         (progn
  586.           (setq search-ring (cons isearch-string search-ring)
  587.             search-ring-yank-pointer search-ring)
  588.           (if (> (length search-ring) search-ring-max)
  589.           (setcdr (nthcdr (1- search-ring-max) search-ring) nil))))))
  590.  
  591.   (run-hooks 'isearch-mode-end-hook)
  592.   (if isearch-recursive-edit (exit-recursive-edit)))
  593.  
  594.  
  595. ;;;====================================================
  596. ;; Commands active while inside of the isearch minor mode.
  597.  
  598. (defun isearch-exit ()
  599.   "Exit search normally.
  600. However, if this is the first command after starting incremental
  601. search and `search-nonincremental-instead' is non-nil, do an
  602. incremental search via `isearch-edit-string'."
  603.   (interactive)
  604.   (if (and search-nonincremental-instead 
  605.        (= 0 (length isearch-string)))
  606.       (let ((isearch-nonincremental t))
  607.     (isearch-edit-string))
  608.     (isearch-done)))
  609.  
  610.  
  611. (defun isearch-edit-string ()
  612.   "Edit the search string in the minibuffer.
  613. The following additional command keys are active while editing.
  614. \\<minibuffer-local-isearch-map>
  615. \\[exit-minibuffer] to exit editing and resume incremental searching.
  616. \\[isearch-forward-exit-minibuffer] to resume isearching forward.
  617. \\[isearch-backward-exit-minibuffer] to resume isearching backward.
  618. \\[isearch-ring-advance-edit] to replace the search string with the next\
  619.  item in the search ring.
  620. \\[isearch-ring-retreat-edit] to replace the search string with the next\
  621.  item in the search ring.
  622. \\[isearch-complete-edit] to complete the search string from the search ring."
  623.  
  624.   ;; Editing doesn't back up the search point.  Should it?
  625.   (interactive)
  626.  
  627.   (condition-case nil
  628.       (let ((minibuffer-local-map minibuffer-local-isearch-map)
  629.         isearch-nonincremental    ; should search nonincrementally?
  630.         isearch-new-string
  631.         isearch-new-message
  632.         (isearch-new-forward isearch-forward)
  633.  
  634.         ;; Locally bind all isearch global variables to protect them
  635.         ;; from recursive isearching.
  636.         (isearch-string isearch-string)
  637.         (isearch-message isearch-message)
  638.         (isearch-forward isearch-forward) ; set by commands below.
  639.  
  640.         (isearch-forward isearch-forward)
  641.         (isearch-regexp isearch-regexp)
  642.         (isearch-word isearch-word)
  643.         (isearch-op-fun isearch-op-fun)
  644.         (isearch-cmds isearch-cmds)
  645.         (isearch-success isearch-success)
  646.         (isearch-wrapped isearch-wrapped)
  647.         (isearch-barrier isearch-barrier)
  648.         (isearch-adjusted isearch-adjusted)
  649.         (isearch-yank-flag isearch-yank-flag)
  650.         (isearch-invalid-regexp isearch-invalid-regexp)
  651.         (isearch-other-end isearch-other-end)
  652.         (isearch-opoint isearch-opoint)
  653.         (isearch-slow-terminal-mode isearch-slow-terminal-mode)
  654.         (isearch-small-window isearch-small-window)
  655.         (isearch-recursive-edit isearch-recursive-edit)
  656.         (isearch-window-configuration (current-window-configuration))
  657.         (isearch-selected-frame (selected-frame))
  658.         )
  659.     ;; Actually terminate isearching until editing is done.
  660.     ;; This is so that the user can do anything without failure, 
  661.     ;; like switch buffers and start another isearch, and return.
  662. ;;    (condition-case nil
  663.         (isearch-done)
  664.           ;;#### What does this mean?  There is no such condition!
  665. ;;      (exit nil))            ; was recursive editing
  666.  
  667.     (unwind-protect
  668.         (let ((prompt (isearch-message-prefix nil t))
  669.                   event)
  670.           ;; If the first character the user types when we prompt them
  671.           ;; for a string is the yank-word character, then go into
  672.           ;; word-search mode.  Otherwise unread that character and
  673.           ;; read a string the normal way.
  674.           (let ((cursor-in-echo-area t))
  675.         (display-message 'prompt prompt)
  676.         (setq event (next-command-event))
  677.         (if (eq 'isearch-yank-word
  678.             (lookup-key isearch-mode-map (vector event)))
  679.             (setq isearch-word t)
  680.           (setq unread-command-event event)))
  681.           (setq isearch-new-string
  682. ;;                    (if (fboundp 'gmhist-old-read-from-minibuffer)
  683. ;;                        ;; Eschew gmhist crockery
  684. ;;            (gmhist-old-read-from-minibuffer prompt isearch-string)
  685.               (read-string
  686.                prompt isearch-string
  687.                't            ;does its own history (but shouldn't)
  688. ;;                     (if isearch-regexp
  689. ;;                         ;; The search-rings aren't exactly minibuffer
  690. ;;                         ;;  histories, but they are close enough
  691. ;;                         (cons 'regexp-search-ring
  692. ;;                               (- (length regexp-search-ring-yank-pointer)
  693. ;;                                  (length regexp-search-ring)))
  694. ;;                         (cons 'search-ring
  695. ;;                               (- (length search-ring-yank-pointer)
  696. ;;                                  (length search-ring))))
  697.                )
  698. ;;              )
  699.             isearch-new-message (mapconcat
  700.                      'isearch-text-char-description
  701.                      isearch-new-string ""))
  702.           )
  703.       ;; Always resume isearching by restarting it.
  704.       (isearch-mode isearch-forward 
  705.             isearch-regexp 
  706.             isearch-op-fun 
  707.             isearch-recursive-edit
  708.             isearch-word)
  709.       )
  710.  
  711.     ;; Copy new values in outer locals to isearch globals
  712.     (setq isearch-string isearch-new-string
  713.           isearch-message isearch-new-message
  714.           isearch-forward isearch-new-forward)
  715.  
  716.     ;; Empty isearch-string means use default.
  717.     (if (= 0 (length isearch-string))
  718.         (setq isearch-string (if isearch-regexp search-last-regexp
  719.                    search-last-string))
  720.       ;; Set last search string now so it is set even if we fail.
  721.       (if search-last-regexp
  722.           (setq search-last-regexp isearch-string)
  723.         (setq search-last-string isearch-string)))
  724.  
  725.     ;; Reinvoke the pending search.
  726.     (isearch-push-state)
  727.     (isearch-search)
  728.     (isearch-update)
  729.     (if isearch-nonincremental (isearch-done)))
  730.  
  731.     (quit  ; handle abort-recursive-edit
  732.      (isearch-abort)  ;; outside of let to restore outside global values
  733.      )))
  734.  
  735. (defun isearch-nonincremental-exit-minibuffer ()
  736.   (interactive)
  737.   (setq isearch-nonincremental t)
  738.   (exit-minibuffer))
  739.  
  740. (defun isearch-forward-exit-minibuffer ()
  741.   (interactive)
  742.   (setq isearch-new-forward t)
  743.   (exit-minibuffer))
  744.  
  745. (defun isearch-reverse-exit-minibuffer ()
  746.   (interactive)
  747.   (setq isearch-new-forward nil)
  748.   (exit-minibuffer))
  749.  
  750.  
  751. (defun isearch-abort ()
  752.   "Quit incremental search mode if searching is successful, signalling quit.
  753. Otherwise, revert to previous successful search and continue searching.
  754. Use `isearch-exit' to quit without signalling."
  755.   (interactive)
  756. ;;  (ding)  signal instead below, if quiting
  757.   (discard-input)
  758.   (if isearch-success
  759.       ;; If search is successful, move back to starting point
  760.       ;; and really do quit.
  761.       (progn (goto-char isearch-opoint)
  762.          (isearch-done)   ; exit isearch
  763.          (signal 'quit '(isearch)))  ; and pass on quit signal
  764.     ;; If search is failing, rub out until it is once more successful.
  765.     (while (not isearch-success) (isearch-pop-state))
  766.     (isearch-update)))
  767.  
  768.  
  769. (defun isearch-repeat (direction)
  770.   ;; Utility for isearch-repeat-forward and -backward.
  771.   (if (eq isearch-forward (eq direction 'forward))
  772.       ;; C-s in forward or C-r in reverse.
  773.       (if (equal isearch-string "")
  774.       ;; If search string is empty, use last one.
  775.       (setq isearch-string
  776.         (or (if isearch-regexp
  777.             (if regexp-search-ring-yank-pointer
  778.                 (car regexp-search-ring-yank-pointer)
  779.               (car regexp-search-ring))
  780.               (if search-ring-yank-pointer
  781.               (car search-ring-yank-pointer)
  782.             (car search-ring)))
  783.             "")
  784.         isearch-message
  785.         (mapconcat 'isearch-text-char-description
  786.                isearch-string ""))
  787.     ;; If already have what to search for, repeat it.
  788.     (or isearch-success
  789.         (progn 
  790.  
  791.           (goto-char (if isearch-forward (point-min) (point-max)))
  792.           (setq isearch-wrapped t))))
  793.     ;; C-s in reverse or C-r in forward, change direction.
  794.     (setq isearch-forward (not isearch-forward)))
  795.  
  796.   (setq isearch-barrier (point)) ; For subsequent \| if regexp.
  797.   (setq isearch-success t)
  798.   (or (equal isearch-string "")
  799.     ;; If repeating a search that found
  800.     ;; an empty string, ensure we advance.
  801.     (if (equal (match-end 0) (match-beginning 0))
  802.         (if (if isearch-forward (eobp) (bobp))
  803.         ;; nowhere to advance to, so fail (and wrap next time)
  804.         (progn
  805.           (setq isearch-success nil)
  806.           (and executing-kbd-macro
  807.                (not defining-kbd-macro)
  808.                (isearch-done))
  809.           (ding nil 'isearch-failed))
  810.           (forward-char (if isearch-forward 1 -1))
  811.           (isearch-search))
  812.       (isearch-search)))
  813.   (isearch-push-state)
  814.   (isearch-update))
  815.  
  816. (defun isearch-repeat-forward ()
  817.   "Repeat incremental search forwards."
  818.   (interactive)
  819.   (isearch-repeat 'forward))
  820.  
  821. (defun isearch-repeat-backward ()
  822.   "Repeat incremental search backwards."
  823.   (interactive)
  824.   (isearch-repeat 'backward))
  825.  
  826. (defun isearch-toggle-regexp ()
  827.   "Toggle regexp searching on or off."
  828.   ;; The status stack is left unchanged.
  829.   (interactive)
  830.   (setq isearch-regexp (not isearch-regexp))
  831.   (if isearch-regexp (setq isearch-word nil))
  832.   (isearch-update))
  833.  
  834. (defun isearch-toggle-case-fold ()
  835.   "Toggle case folding in searching on or off."
  836.   (interactive)
  837.   (setq isearch-case-fold-search
  838.     (if isearch-case-fold-search nil 'yes))
  839.   (message "%s%s [case %ssensitive]"
  840.        (isearch-message-prefix)
  841.        isearch-message
  842.        (if isearch-case-fold-search "in" ""))
  843.   (setq isearch-adjusted t)
  844.   (sit-for 1)
  845.   (isearch-update))
  846.  
  847. (defun isearch-delete-char ()
  848.   "Discard last input item and move point back.  
  849. If no previous match was done, just beep."
  850.   (interactive)
  851.   (if (null (cdr isearch-cmds))
  852.       (ding nil 'isearch-quit)
  853.     (isearch-pop-state))
  854.   (isearch-update))
  855.  
  856. (defun isearch-help-or-delete-char ()
  857.   "Show Isearch help or delete backward in the search string.
  858. Deletes when `delete-key-deletes-forward' is t and C-h is used for deleting
  859. backwards."
  860.   (interactive)
  861.   (if (and delete-key-deletes-forward
  862.            (case (device-type)
  863.              ('tty (eq tty-erase-char ?\C-h))
  864.              ('x (not (x-keysym-on-keyboard-sans-modifiers-p 'backspace)))))
  865.       (isearch-delete-char)
  866.     (isearch-mode-help)))
  867.  
  868. (defun isearch-yank (chunk)
  869.   ;; Helper for isearch-yank-* functions.  CHUNK can be a string or a
  870.   ;; function.
  871.   (let ((word (if (stringp chunk)
  872.           chunk
  873.         (save-excursion
  874.           (and (not isearch-forward) isearch-other-end
  875.                (goto-char isearch-other-end))
  876.           (buffer-substring
  877.            (point)
  878.            (save-excursion
  879.              (funcall chunk)
  880.              (point)))))))
  881.     ;; if configured so that typing upper-case characters turns off case
  882.     ;; folding, then downcase the string so that yanking an upper-case
  883.     ;; word doesn't mess with case-foldedness.
  884.     (if (and search-caps-disable-folding isearch-case-fold-search)
  885.     (setq word (downcase word)))
  886.     (if isearch-regexp (setq word (regexp-quote word)))
  887.     (setq isearch-string (concat isearch-string word)
  888.       isearch-message
  889.       (concat isearch-message
  890.           (mapconcat 'isearch-text-char-description
  891.                  word ""))
  892.       ;; Don't move cursor in reverse search.
  893.       isearch-yank-flag t))
  894.   (isearch-search-and-update))
  895.  
  896.  
  897. (defun isearch-yank-word ()
  898.   "Pull next word from buffer into search string."
  899.   (interactive)
  900.   (isearch-yank (function (lambda () (forward-word 1)))))
  901.  
  902. (defun isearch-yank-line ()
  903.   "Pull rest of line from buffer into search string."
  904.   (interactive)
  905.   (isearch-yank 'end-of-line))
  906.  
  907. (defun isearch-yank-kill ()
  908.   "Pull rest of line from kill ring into search string."
  909.   (interactive)
  910.   (isearch-yank (current-kill 0)))
  911.  
  912. (defun isearch-yank-sexp ()
  913.   "Pull next expression from buffer into search string."
  914.   (interactive)
  915.   (isearch-yank 'forward-sexp))
  916.  
  917. (defun isearch-yank-x-selection ()
  918.   "Pull the current X selection into the search string."
  919.   (interactive)
  920.   (isearch-yank (x-get-selection)))
  921.  
  922. (defun isearch-yank-x-clipboard ()
  923.   "Pull the current X clipboard selection into the search string."
  924.   (interactive)
  925.   (isearch-yank (x-get-clipboard)))
  926.  
  927. (defun isearch-search-and-update ()
  928.   ;; Do the search and update the display.
  929.   (if (and (not isearch-success)
  930.        ;; unsuccessful regexp search may become
  931.        ;;  successful by addition of characters which
  932.        ;;  make isearch-string valid
  933.        (not isearch-regexp))
  934.       nil
  935.     ;; In reverse search, adding stuff at
  936.     ;; the end may cause zero or many more chars to be
  937.     ;; matched, in the string following point.
  938.     ;; Allow all those possibilities without moving point as
  939.     ;; long as the match does not extend past search origin.
  940.     (if (and (not isearch-forward) (not isearch-adjusted)
  941.          (condition-case ()
  942.          (looking-at (if isearch-regexp isearch-string
  943.                    (regexp-quote isearch-string)))
  944.            (error nil))
  945.            (or isearch-yank-flag
  946.            (<= (match-end 0) 
  947.                (min isearch-opoint isearch-barrier))))
  948.     (setq isearch-success t 
  949.           isearch-invalid-regexp nil
  950.           isearch-other-end (match-end 0))
  951.       ;; Not regexp, not reverse, or no match at point.
  952.       (if (and isearch-other-end (not isearch-adjusted))
  953.       (goto-char (if isearch-forward isearch-other-end
  954.                (min isearch-opoint 
  955.                 isearch-barrier 
  956.                 (1+ isearch-other-end)))))
  957.       (isearch-search)
  958.       ))
  959.   (isearch-push-state)
  960.   (if isearch-op-fun (funcall isearch-op-fun))
  961.   (isearch-update))
  962.  
  963.  
  964. ;; *, ?, and | chars can make a regexp more liberal.
  965. ;; They can make a regexp match sooner
  966. ;; or make it succeed instead of failing.
  967. ;; So go back to place last successful search started
  968. ;; or to the last ^S/^R (barrier), whichever is nearer.
  969.  
  970. (defun isearch-*-char ()
  971.   "Handle * and ? specially in regexps."
  972.   (interactive)
  973.   (if isearch-regexp 
  974.  
  975.       (progn
  976.     (setq isearch-adjusted t)
  977.     (let ((cs (nth (if isearch-forward
  978.                5        ; isearch-other-end
  979.              2)        ; saved (point)
  980.                (car (cdr isearch-cmds)))))
  981.       ;; (car isearch-cmds) is after last search;
  982.       ;; (car (cdr isearch-cmds)) is from before it.
  983.       (setq cs (or cs isearch-barrier))
  984.       (goto-char
  985.        (if isearch-forward
  986.            (max cs isearch-barrier)
  987.          (min cs isearch-barrier))))))
  988.   (isearch-process-search-char last-command-event))
  989.   
  990.  
  991.  
  992. (defun isearch-|-char ()
  993.   "If in regexp search, jump to the barrier."
  994.   (interactive)
  995.   (if isearch-regexp
  996.       (progn
  997.     (setq isearch-adjusted t)
  998.     (goto-char isearch-barrier)))
  999.   (isearch-process-search-char last-command-event))
  1000.  
  1001. (defun isearch-quote-char ()
  1002.   "Quote special characters for incremental search."
  1003.   (interactive)
  1004.   (isearch-process-search-char (read-quoted-char (isearch-message t))))
  1005.  
  1006.  
  1007. (defun isearch-return-char ()
  1008.   "Convert return into newline for incremental search.
  1009. Obsolete."
  1010.   (interactive)
  1011.   (isearch-process-search-char ?\n))
  1012.  
  1013.  
  1014. (defun isearch-printing-char ()
  1015.   "Any other printing character => add it to the search string and search."
  1016.   (interactive)
  1017.   (isearch-process-search-char last-command-event))
  1018.  
  1019.  
  1020. (defun isearch-whitespace-chars ()
  1021.   "Match all whitespace chars, if in regexp mode."
  1022.   (interactive)
  1023.   (if (and isearch-regexp search-whitespace-regexp)
  1024.       (isearch-process-search-string search-whitespace-regexp " ")
  1025.     (beep)
  1026.     (isearch-process-search-char ?\ )
  1027. ;    (if isearch-word
  1028. ;    nil
  1029. ;      (setq isearch-word t)
  1030. ;      (goto-char isearch-other-end)
  1031. ;      (isearch-process-search-char ?\ ))
  1032.     ))
  1033.  
  1034. (defun isearch-process-search-char (char)
  1035.   ;; Append the char to the search string, update the message and re-search.
  1036.   (isearch-process-search-string (isearch-char-to-string char) 
  1037.                  (isearch-text-char-description char)))
  1038.  
  1039. (defun isearch-process-search-string (string message)
  1040.   (setq isearch-string (concat isearch-string string)
  1041.     isearch-message (concat isearch-message message))
  1042.   (isearch-search-and-update))
  1043.  
  1044.  
  1045. ;;===========================================================
  1046. ;; Search Ring
  1047.  
  1048. (defcustom search-ring-update nil
  1049.   "*Non-nil if advancing or retreating in the search ring should cause search.
  1050. Default nil means edit the string from the search ring first."
  1051.   :type 'boolean
  1052.   :group 'isearch)
  1053.   
  1054. (defun isearch-ring-adjust1 (advance)
  1055.   ;; Helper for isearch-ring-adjust
  1056.   (let* ((ring (if isearch-regexp regexp-search-ring search-ring))
  1057.      (length (length ring))
  1058.      (yank-pointer-name (if isearch-regexp
  1059.                 'regexp-search-ring-yank-pointer
  1060.                   'search-ring-yank-pointer))
  1061.      (yank-pointer (eval yank-pointer-name)))
  1062.     (if (zerop length)
  1063.     ()
  1064.       (set yank-pointer-name
  1065.        (setq yank-pointer
  1066.          (nthcdr (% (+ (- length (length yank-pointer))
  1067.                    (if advance (1- length) 1))
  1068.                 length) ring)))
  1069.       (setq isearch-string (car yank-pointer)
  1070.         isearch-message (mapconcat 'isearch-text-char-description
  1071.                        isearch-string "")))))
  1072.  
  1073. (defun isearch-ring-adjust (advance)
  1074.   ;; Helper for isearch-ring-advance and isearch-ring-retreat
  1075.   (if (cdr isearch-cmds)  ;; is there more than one thing on stack?
  1076.       (isearch-pop-state))
  1077.   (isearch-ring-adjust1 advance)
  1078.   (isearch-push-state)
  1079.   (if search-ring-update
  1080.       (progn
  1081.     (isearch-search)
  1082.     (isearch-update))
  1083.     (isearch-edit-string)
  1084.     ))
  1085.  
  1086. (defun isearch-ring-advance ()
  1087.   "Advance to the next search string in the ring."
  1088.   ;; This could be more general to handle a prefix arg, but who would use it.
  1089.   (interactive)
  1090.   (isearch-ring-adjust 'advance))
  1091.  
  1092. (defun isearch-ring-retreat ()
  1093.   "Retreat to the previous search string in the ring."
  1094.   (interactive)
  1095.   (isearch-ring-adjust nil))
  1096.  
  1097. (defun isearch-ring-adjust-edit (advance)
  1098.   "Use the next or previous search string in the ring while in minibuffer."
  1099.   (isearch-ring-adjust1 advance)
  1100.   (erase-buffer)
  1101.   (insert isearch-string))
  1102.  
  1103. (defun isearch-ring-advance-edit ()
  1104.   (interactive)
  1105.   (isearch-ring-adjust-edit 'advance))
  1106.  
  1107. (defun isearch-ring-retreat-edit ()
  1108.   "Retreat to the previous search string in the ring while in the minibuffer."
  1109.   (interactive)
  1110.   (isearch-ring-adjust-edit nil))
  1111.  
  1112.  
  1113. (defun isearch-complete1 ()
  1114.   ;; Helper for isearch-complete and isearch-complete-edit
  1115.   ;; Return t if completion OK, 
  1116.   (let* ((ring (if isearch-regexp regexp-search-ring search-ring))
  1117.          (alist (mapcar (function (lambda (string) (list string))) ring))
  1118.          (completion-ignore-case case-fold-search)
  1119.          (completion (try-completion isearch-string alist))
  1120.      )
  1121.     (cond
  1122.      ((eq completion t)
  1123.       ;; isearch-string stays the same
  1124.       t)
  1125.      ((or completion ; not nil, must be a string
  1126.       (= 0 (length isearch-string))) ; shouldn't have to say this
  1127.       (if (equal completion isearch-string)  ;; no extension?
  1128.       (if completion-auto-help
  1129.           (with-output-to-temp-buffer "*Isearch completions*"
  1130.         (display-completion-list 
  1131.          (all-completions isearch-string alist))))
  1132.     (setq isearch-string completion))
  1133.       t)
  1134.      (t
  1135.       (temp-minibuffer-message "No completion")
  1136.       nil))))
  1137.  
  1138. (defun isearch-complete ()
  1139.   "Complete the search string from the strings on the search ring.
  1140. The completed string is then editable in the minibuffer.
  1141. If there is no completion possible, say so and continue searching."
  1142.   (interactive)
  1143.   (if (isearch-complete1)
  1144.       (isearch-edit-string)
  1145.     ;; else
  1146.     (sit-for 1)
  1147.     (isearch-update)))
  1148.  
  1149. (defun isearch-complete-edit ()
  1150.   "Same as `isearch-complete' except in the minibuffer."
  1151.   (interactive)
  1152.   (setq isearch-string (buffer-string))
  1153.   (if (isearch-complete1)
  1154.       (progn
  1155.     (erase-buffer)
  1156.     (insert isearch-string))))
  1157.  
  1158.  
  1159. ;;;==============================================================
  1160. ;; The search status stack (and isearch window-local variables, not used).
  1161.  
  1162. (defun isearch-top-state ()
  1163. ;;  (fetch-window-local-variables)
  1164.   (let ((cmd (car isearch-cmds)))
  1165.     (setq isearch-string (car cmd)
  1166.       isearch-message (car (cdr cmd))
  1167.       isearch-success (nth 3 cmd)
  1168.       isearch-forward (nth 4 cmd)
  1169.       isearch-other-end (nth 5 cmd)
  1170.       isearch-invalid-regexp (nth 6 cmd)
  1171.       isearch-wrapped (nth 7 cmd)
  1172.       isearch-barrier (nth 8 cmd))
  1173.     (goto-char (car (cdr (cdr cmd))))))
  1174.  
  1175. (defun isearch-pop-state ()
  1176. ;;  (fetch-window-local-variables)
  1177.   (setq isearch-cmds (cdr isearch-cmds))
  1178.   (isearch-top-state)
  1179.   )
  1180.  
  1181. (defun isearch-push-state ()
  1182.   (setq isearch-cmds 
  1183.     (cons (list isearch-string isearch-message (point)
  1184.             isearch-success isearch-forward isearch-other-end 
  1185.             isearch-invalid-regexp isearch-wrapped isearch-barrier)
  1186.           isearch-cmds)))
  1187.  
  1188.  
  1189. ;;;==================================================================
  1190. ;; Message string
  1191.  
  1192. (defun isearch-message (&optional c-q-hack ellipsis)
  1193.   ;; Generate and print the message string.
  1194.   (let ((cursor-in-echo-area ellipsis)
  1195.     (m (concat
  1196.         (isearch-message-prefix c-q-hack)
  1197.         isearch-message
  1198.         (isearch-message-suffix c-q-hack)
  1199.         )))
  1200.     (if c-q-hack m (display-message 'progress (format "%s" m)))))
  1201.  
  1202. (defun isearch-message-prefix (&optional c-q-hack nonincremental)
  1203.   ;; If about to search, and previous search regexp was invalid,
  1204.   ;; check that it still is.  If it is valid now,
  1205.   ;; let the message we display while searching say that it is valid.
  1206.   (and isearch-invalid-regexp
  1207.        (condition-case ()
  1208.        (progn (re-search-forward isearch-string (point) t)
  1209.           (setq isearch-invalid-regexp nil))
  1210.      (error nil)))
  1211.   ;; #### - Yo!  Emacs assembles strings all over the place, they can't all
  1212.   ;; be internationalized in the manner proposed below...  Add an explicit
  1213.   ;; call to `gettext' and have the string snarfer pluck the english
  1214.   ;; strings out of the comment below.  XEmacs is on a purespace diet! -Stig
  1215.   (let ((m (concat (if isearch-success nil "failing ")
  1216.              (if isearch-wrapped "wrapped ")
  1217.              (if isearch-word "word ")
  1218.              (if isearch-regexp "regexp ")
  1219.              (if nonincremental "search" "I-search")
  1220.              (if isearch-forward nil " backward")
  1221.            ": "
  1222.              )))
  1223.     (aset m 0 (upcase (aref m 0)))
  1224.     (gettext m)))
  1225.  
  1226. (defun isearch-message-suffix (&optional c-q-hack)
  1227.   (concat (if c-q-hack "^Q" "")
  1228.       (if isearch-invalid-regexp
  1229.           (concat " [" isearch-invalid-regexp "]")
  1230.         "")))
  1231.  
  1232. ;;;;; #### - yuck...this is soooo lame.  Is this really worth 4k of purespace???
  1233. ;;;
  1234. ;;;(let ((i (logior (if isearch-success 32 0)
  1235. ;;;                (if isearch-wrapped 16 0)
  1236. ;;;                (if isearch-word     8 0)
  1237. ;;;                (if isearch-regexp   4 0)
  1238. ;;;                (if nonincremental   2 0)
  1239. ;;;                (if isearch-forward  1 0))))
  1240. ;;;  (cond
  1241. ;;;   ((= i 63) (gettext "Wrapped word regexp search: "))              ; 111111
  1242. ;;;   ((= i 62) (gettext "Wrapped word regexp search backward: "))     ; 111110
  1243. ;;;   ((= i 61) (gettext "Wrapped word regexp I-search: "))            ; 111101
  1244. ;;;   ((= i 60) (gettext "Wrapped word regexp I-search backward: "))   ; 111100
  1245. ;;;   ((= i 59) (gettext "Wrapped word search: "))                     ; 111011
  1246. ;;;   ((= i 58) (gettext "Wrapped word search backward: "))            ; 111010
  1247. ;;;   ((= i 57) (gettext "Wrapped word I-search: "))                   ; 111001
  1248. ;;;   ((= i 56) (gettext "Wrapped word I-search backward: "))          ; 111000
  1249. ;;;   ((= i 55) (gettext "Wrapped regexp search: "))                   ; 110111
  1250. ;;;   ((= i 54) (gettext "Wrapped regexp search backward: "))          ; 110110
  1251. ;;;   ((= i 53) (gettext "Wrapped regexp I-search: "))                 ; 110101
  1252. ;;;   ((= i 52) (gettext "Wrapped regexp I-search backward: "))        ; 110100
  1253. ;;;   ((= i 51) (gettext "Wrapped search: "))                          ; 110011
  1254. ;;;   ((= i 50) (gettext "Wrapped search backward: "))                 ; 110010
  1255. ;;;   ((= i 49) (gettext "Wrapped I-search: "))                        ; 110001
  1256. ;;;   ((= i 48) (gettext "Wrapped I-search backward: "))           ; 110000
  1257. ;;;   ((= i 47) (gettext "Word regexp search: "))                      ; 101111
  1258. ;;;   ((= i 46) (gettext "Word regexp search backward: "))             ; 101110
  1259. ;;;   ((= i 45) (gettext "Word regexp I-search: "))                    ; 101101
  1260. ;;;   ((= i 44) (gettext "Word regexp I-search backward: "))           ; 101100
  1261. ;;;   ((= i 43) (gettext "Word search: "))                             ; 101011
  1262. ;;;   ((= i 42) (gettext "Word search backward: "))                    ; 101010
  1263. ;;;   ((= i 41) (gettext "Word I-search: "))                           ; 101001
  1264. ;;;   ((= i 40) (gettext "Word I-search backward: "))                  ; 101000
  1265. ;;;   ((= i 39) (gettext "Regexp search: "))                           ; 100111
  1266. ;;;   ((= i 38) (gettext "Regexp search backward: "))                  ; 100110
  1267. ;;;   ((= i 37) (gettext "Regexp I-search: "))                         ; 100101
  1268. ;;;   ((= i 36) (gettext "Regexp I-search backward: "))                ; 100100
  1269. ;;;   ((= i 35) (gettext "Search: "))                                  ; 100011
  1270. ;;;   ((= i 34) (gettext "Search backward: "))                         ; 100010
  1271. ;;;   ((= i 33) (gettext "I-search: "))                                ; 100001
  1272. ;;;   ((= i 32) (gettext "I-search backward: "))               ; 100000
  1273. ;;;   ((= i 31) (gettext "Failing wrapped word regexp search: "))      ; 011111
  1274. ;;;   ((= i 30) (gettext "Failing wrapped word regexp search backward: ")) ; 011110
  1275. ;;;   ((= i 29) (gettext "Failing wrapped word regexp I-search: "))    ; 011101
  1276. ;;;   ((= i 28) (gettext "Failing wrapped word regexp I-search backward: ")) ; 011100
  1277. ;;;   ((= i 27) (gettext "Failing wrapped word search: "))             ; 011011
  1278. ;;;   ((= i 26) (gettext "Failing wrapped word search backward: "))    ; 011010
  1279. ;;;   ((= i 25) (gettext "Failing wrapped word I-search: "))           ; 011001
  1280. ;;;   ((= i 24) (gettext "Failing wrapped word I-search backward: "))  ; 011000
  1281. ;;;   ((= i 23) (gettext "Failing wrapped regexp search: "))           ; 010111
  1282. ;;;   ((= i 22) (gettext "Failing wrapped regexp search backward: "))  ; 010110
  1283. ;;;   ((= i 21) (gettext "Failing wrapped regexp I-search: "))         ; 010101
  1284. ;;;   ((= i 20) (gettext "Failing wrapped regexp I-search backward: ")) ; 010100
  1285. ;;;   ((= i 19) (gettext "Failing wrapped search: "))                  ; 010011
  1286. ;;;   ((= i 18) (gettext "Failing wrapped search backward: "))         ; 010010
  1287. ;;;   ((= i 17) (gettext "Failing wrapped I-search: "))                ; 010001
  1288. ;;;   ((= i 16) (gettext "Failing wrapped I-search backward: "))       ; 010000
  1289. ;;;   ((= i 15) (gettext "Failing word regexp search: "))              ; 001111
  1290. ;;;   ((= i 14) (gettext "Failing word regexp search backward: "))     ; 001110
  1291. ;;;   ((= i 13) (gettext "Failing word regexp I-search: "))            ; 001101
  1292. ;;;   ((= i 12) (gettext "Failing word regexp I-search backward: "))   ; 001100
  1293. ;;;   ((= i 11) (gettext "Failing word search: "))                     ; 001011
  1294. ;;;   ((= i 10) (gettext "Failing word search backward: "))            ; 001010
  1295. ;;;   ((= i  9) (gettext "Failing word I-search: "))                   ; 001001
  1296. ;;;   ((= i  8) (gettext "Failing word I-search backward: "))          ; 001000
  1297. ;;;   ((= i  7) (gettext "Failing regexp search: "))                   ; 000111
  1298. ;;;   ((= i  6) (gettext "Failing regexp search backward: "))          ; 000110
  1299. ;;;   ((= i  5) (gettext "Failing regexp I-search: "))                 ; 000101
  1300. ;;;   ((= i  4) (gettext "Failing regexp I-search backward: "))        ; 000100
  1301. ;;;   ((= i  3) (gettext "Failing search: "))                          ; 000011
  1302. ;;;   ((= i  2) (gettext "Failing search backward: "))                 ; 000010
  1303. ;;;   ((= i  1) (gettext "Failing I-search: "))                        ; 000001
  1304. ;;;   ((= i  0) (gettext "Failing I-search backward: "))           ; 000000
  1305. ;;;   (t (error "Something's rotten")))))
  1306.  
  1307.  
  1308. ;;;========================================================
  1309. ;;; Exiting
  1310.  
  1311. (put 'isearch-printing-char            'isearch-command t)
  1312. (put 'isearch-return-char            'isearch-command t)
  1313. (put 'isearch-repeat-forward            'isearch-command t)
  1314. (put 'isearch-repeat-backward            'isearch-command t)
  1315. (put 'isearch-delete-char            'isearch-command t)
  1316. (put 'isearch-help-or-delete-char        'isearch-command t)
  1317. (put 'isearch-abort                'isearch-command t)
  1318. (put 'isearch-quote-char            'isearch-command t)
  1319. (put 'isearch-exit                'isearch-command t)
  1320. (put 'isearch-printing-char            'isearch-command t)
  1321. (put 'isearch-printing-char            'isearch-command t)
  1322. (put 'isearch-yank-word                'isearch-command t)
  1323. (put 'isearch-yank-line                'isearch-command t)
  1324. (put 'isearch-yank-kill                'isearch-command t)
  1325. (put 'isearch-yank-sexp                'isearch-command t)
  1326. (put 'isearch-*-char                'isearch-command t)
  1327. (put 'isearch-*-char                'isearch-command t)
  1328. (put 'isearch-|-char                'isearch-command t)
  1329. (put 'isearch-toggle-regexp            'isearch-command t)
  1330. (put 'isearch-toggle-case-fold            'isearch-command t)
  1331. (put 'isearch-edit-string            'isearch-command t)
  1332. (put 'isearch-mode-help                'isearch-command t)
  1333. (put 'isearch-ring-advance            'isearch-command t)
  1334. (put 'isearch-ring-retreat            'isearch-command t)
  1335. (put 'isearch-ring-advance-edit            'isearch-command t)
  1336. (put 'isearch-ring-retreat-edit            'isearch-command t)
  1337. (put 'isearch-whitespace-chars            'isearch-command t)
  1338. (put 'isearch-complete                'isearch-command t)
  1339. (put 'isearch-complete-edit            'isearch-command t)
  1340. (put 'isearch-edit-string            'isearch-command t)
  1341. (put 'isearch-toggle-regexp            'isearch-command t)
  1342. (put 'isearch-forward-exit-minibuffer        'isearch-command t)
  1343. (put 'isearch-reverse-exit-minibuffer        'isearch-command t)
  1344. (put 'isearch-nonincremental-exit-minibuffer    'isearch-command t)
  1345. (put 'isearch-yank-x-selection            'isearch-command t)
  1346. (put 'isearch-yank-x-clipboard            'isearch-command t)
  1347.  
  1348. ;; scrolling the scrollbar should not terminate isearch.
  1349.  
  1350. ;; vertical scrollbar:
  1351. (put 'scrollbar-line-up                'isearch-command t)
  1352. (put 'scrollbar-line-down            'isearch-command t)
  1353. (put 'scrollbar-page-up                'isearch-command t)
  1354. (put 'scrollbar-page-down            'isearch-command t)
  1355. (put 'scrollbar-to-top                'isearch-command t)
  1356. (put 'scrollbar-to-bottom            'isearch-command t)
  1357. (put 'scrollbar-vertical-drag            'isearch-command t)
  1358.  
  1359. ;; horizontal scrollbar:
  1360. (put 'scrollbar-char-left            'isearch-command t)
  1361. (put 'scrollbar-char-right            'isearch-command t)
  1362. (put 'scrollbar-page-left            'isearch-command t)
  1363. (put 'scrollbar-page-right            'isearch-command t)
  1364. (put 'scrollbar-to-left                'isearch-command t)
  1365. (put 'scrollbar-to-right            'isearch-command t)
  1366. (put 'scrollbar-horizontal-drag            'isearch-command t)
  1367.  
  1368. (defun isearch-pre-command-hook ()
  1369.   ;;
  1370.   ;; For use as the value of `pre-command-hook' when isearch-mode is active.
  1371.   ;; If the command about to be executed is not one of the isearch commands,
  1372.   ;; then isearch-mode is turned off before that command is executed.
  1373.   ;;
  1374.   ;; If the command about to be executed is self-insert-command, or is a
  1375.   ;; keyboard macro of a single key sequence which is bound to self-insert-
  1376.   ;; command, then we add those chars to the search ring instead of inserting
  1377.   ;; them in the buffer.  In this way, the set of self-searching characters
  1378.   ;; need not be exhaustively enumerated, but is derived from other maps.
  1379.   ;;
  1380.   (cond ((not (eq (current-buffer) isearch-buffer))
  1381.      ;; If the buffer (likely meaning "frame") has changed, bail.
  1382.      ;; This can also happen if a proc filter has popped up another
  1383.      ;; buffer, which is arguably a bad thing for it to have done,
  1384.      ;; but the way in which isearch would have hosed you in that
  1385.      ;; case is unarguably even worse. -jwz
  1386.      (isearch-done))
  1387.     (t
  1388.      (isearch-maybe-frob-keyboard-macros)
  1389.      (if (and this-command
  1390.           (symbolp this-command)
  1391.           (get this-command 'isearch-command))
  1392.          nil ; then continue.
  1393.        (isearch-done)))))
  1394.  
  1395. (defun isearch-maybe-frob-keyboard-macros ()
  1396.   ;;
  1397.   ;; If the command about to be executed is `self-insert-command' then change
  1398.   ;; the command to `isearch-printing-char' instead, meaning add the last-
  1399.   ;; typed character to the search string.
  1400.   ;;
  1401.   ;; If `this-command' is a string or a vector (that is, a keyboard macro)
  1402.   ;; and it contains only one command, which is bound to self-insert-command,
  1403.   ;; then do the same thing as for self-inserting commands: arrange for that
  1404.   ;; character to be added to the search string.  If we didn't do this, then
  1405.   ;; typing a compose sequence (a la x-compose.el) would terminate the search
  1406.   ;; and insert the character, instead of searching for that character.
  1407.   ;;
  1408.   ;; We should continue doing this, since it's pretty much the behavior one
  1409.   ;; would expect, but it will stop being so necessary once key-translation-
  1410.   ;; map exists and is used by x-compose.el and things like it, since the
  1411.   ;; translation will have been done before we see the keys.
  1412.   ;;
  1413.   (cond ((eq this-command 'self-insert-command)
  1414.      (setq this-command 'isearch-printing-char))
  1415.     ((and (or (stringp this-command) (vectorp this-command))
  1416.           (eq (key-binding this-command) 'self-insert-command))
  1417.      (setq last-command-event (character-to-event (aref this-command 0))
  1418.            last-command-char (and (stringp this-command)
  1419.                       (aref this-command 0))
  1420.            this-command 'isearch-printing-char))
  1421.     ))
  1422.  
  1423.  
  1424. ;;;========================================================
  1425. ;;; Highlighting
  1426.  
  1427. (defcustom isearch-highlight t
  1428.   "*Whether isearch and query-replace should highlight the text which 
  1429. currently matches the search-string.")
  1430.  
  1431. (defvar isearch-extent nil)
  1432.  
  1433. ;; this face is initialized by x-faces.el since isearch is preloaded.
  1434. ;; this face is now created in initialize-faces
  1435. ;;(make-face 'isearch)
  1436.  
  1437. (defun isearch-make-extent (begin end)
  1438.   (let ((x (make-extent begin end (current-buffer))))
  1439.     ;; make the isearch extent always take prescedence over any mouse-
  1440.     ;; highlighted extents we may be passing through, since isearch, being
  1441.     ;; modal, is more interesting (there's nothing they could do with a
  1442.     ;; mouse-highlighted extent while in the midst of a search anyway).
  1443.     (set-extent-priority x (1+ mouse-highlight-priority))
  1444.     (set-extent-face x 'isearch)
  1445.     (setq isearch-extent x)))
  1446.  
  1447. (defun isearch-highlight (begin end)
  1448.   (if (null isearch-highlight)
  1449.       nil
  1450.     ;; make sure isearch-extent is in the current buffer
  1451.     (cond ((not (extentp isearch-extent))
  1452.        (isearch-make-extent begin end))
  1453.       ((not (eq (extent-object isearch-extent) (current-buffer)))
  1454.        (delete-extent isearch-extent)
  1455.        (isearch-make-extent begin end)))
  1456.     (set-extent-endpoints isearch-extent begin end)))
  1457.  
  1458. (defun isearch-dehighlight (totally)
  1459.   (if (and isearch-highlight isearch-extent)
  1460.       (if totally
  1461.       (let ((inhibit-quit t))
  1462.         (if (extentp isearch-extent)
  1463.         (delete-extent isearch-extent))
  1464.         (setq isearch-extent nil))
  1465.     (if (extentp isearch-extent)
  1466.         (detach-extent isearch-extent)
  1467.       (setq isearch-extent nil)))))
  1468.  
  1469.  
  1470. ;;;========================================================
  1471. ;;; Searching
  1472.  
  1473. (defun isearch-search ()
  1474.   ;; Do the search with the current search string.
  1475.   (isearch-message nil t)
  1476.   (if (and isearch-case-fold-search search-caps-disable-folding)
  1477.       (setq isearch-case-fold-search (isearch-no-upper-case-p isearch-string)))
  1478.  
  1479.   (setq isearch-mode (if case-fold-search
  1480.                          (if isearch-case-fold-search
  1481.                              " Isearch"  ;As God Intended Mode
  1482.                              " ISeARch") ;Warn about evil case via StuDLYcAps.
  1483.                  "Isearch"
  1484. ;                 (if isearch-case-fold-search
  1485. ;                            " isearch"    ;Presumably case-sensitive losers
  1486. ;                                          ;will notice this 1-char difference.
  1487. ;                            " Isearch")   ;Weenie mode.
  1488.              ))
  1489.   (condition-case lossage
  1490.       (let ((inhibit-quit nil)
  1491.         (case-fold-search isearch-case-fold-search))
  1492.     (if isearch-regexp (setq isearch-invalid-regexp nil))
  1493.     (setq isearch-success
  1494.           (funcall
  1495.            (cond (isearch-word
  1496.               (if isearch-forward
  1497.               'word-search-forward 'word-search-backward))
  1498.              (isearch-regexp
  1499.               (if isearch-forward
  1500.               're-search-forward 're-search-backward))
  1501.              (t
  1502.               (if isearch-forward 'search-forward 'search-backward)))
  1503.            isearch-string nil t))
  1504.     (if isearch-success
  1505.         (setq isearch-other-end
  1506.           (if isearch-forward (match-beginning 0) (match-end 0)))))
  1507.  
  1508.     (quit (setq unread-command-event (character-to-event (quit-char)))
  1509.       (setq isearch-success nil))
  1510.  
  1511.     (invalid-regexp 
  1512.      (setq isearch-invalid-regexp (car (cdr lossage)))
  1513.      (if (string-match
  1514.       "\\`Premature \\|\\`Unmatched \\|\\`Invalid "
  1515.       isearch-invalid-regexp)
  1516.      (setq isearch-invalid-regexp (gettext "incomplete input")))))
  1517.  
  1518.   (if isearch-success
  1519.       nil
  1520.  
  1521.     ;; If we're being run inside a keyboard macro, then the call to
  1522.     ;; ding will signal an error (to terminate the macro).  We must
  1523.     ;; turn off isearch-mode first, so that we aren't still in isearch
  1524.     ;; mode after the macro exits.  Note that isearch-recursive-edit
  1525.     ;; must not be true if a keyboard macro is executing.
  1526.     (if (and executing-kbd-macro (not defining-kbd-macro))
  1527.     (progn
  1528.       (isearch-done)
  1529.       (ding nil 'isearch-failed)))
  1530.  
  1531.     ;; Ding if failed this time after succeeding last time.
  1532.     (and (nth 3 (car isearch-cmds))
  1533.      (ding nil 'isearch-failed))
  1534.     (goto-char (nth 2 (car isearch-cmds)))))
  1535.  
  1536. ;;;=================================================
  1537. ;; This is called from incremental-search
  1538. ;; if the first input character is the exit character.
  1539.  
  1540. ;; We store the search string in `isearch-string'
  1541. ;; which has been bound already by `isearch-search'
  1542. ;; so that, when we exit, it is copied into `search-last-string'.
  1543.  
  1544. ;(defun nonincremental-search (forward regexp)
  1545. ;  ;; This may be broken.  Anyway, it is replaced by the isearch-edit-string.
  1546. ;  ;; Missing features: word search option, command history.
  1547. ;  (setq isearch-forward forward
  1548. ;    isearch-regexp regexp)
  1549. ;  (let (char function
  1550. ;    inhibit-quit
  1551. ;    (cursor-in-echo-area t))
  1552. ;    ;; Prompt assuming not word search,
  1553. ;    (setq isearch-message 
  1554. ;      (if isearch-regexp 
  1555. ;          (if isearch-forward "Regexp search: "
  1556. ;        "Regexp search backward: ")
  1557. ;        (if isearch-forward "Search: " "Search backward: ")))
  1558. ;    (message "%s" isearch-message)
  1559. ;    ;; Read 1 char and switch to word search if it is ^W.
  1560. ;    (setq char (read-char))
  1561. ;    (if (eq char search-yank-word-char)
  1562. ;    (setq isearch-message (if isearch-forward "Word search: " 
  1563. ;                "Word search backward: "))
  1564. ;      ;; Otherwise let that 1 char be part of the search string.
  1565. ;      (setq unread-command-event (character-to-event char))
  1566. ;      )
  1567. ;    (setq function
  1568. ;      (if (eq char search-yank-word-char)
  1569. ;          (if isearch-forward 'word-search-forward 'word-search-backward)
  1570. ;        (if isearch-regexp
  1571. ;        (if isearch-forward 're-search-forward 're-search-backward)
  1572. ;          (if isearch-forward 'search-forward 'search-backward))))
  1573. ;    ;; Read the search string with corrected prompt.
  1574. ;    (setq isearch-string (read-string isearch-message isearch-string))
  1575. ;    ;; Empty means use default.
  1576. ;    (if (= 0 (length isearch-string))
  1577. ;    (setq isearch-string search-last-string)
  1578. ;      ;; Set last search string now so it is set even if we fail.
  1579. ;      (setq search-last-string isearch-string))
  1580. ;    ;; Since we used the minibuffer, we should be available for redo.
  1581. ;    (setq command-history 
  1582. ;      (cons (list function isearch-string) command-history))
  1583. ;    ;; Go ahead and search.
  1584. ;    (if search-caps-disable-folding
  1585. ;    (setq isearch-case-fold-search 
  1586. ;          (isearch-no-upper-case-p isearch-string)))
  1587. ;    (let ((case-fold-search isearch-case-fold-search))
  1588. ;      (funcall function isearch-string))))
  1589.  
  1590.  
  1591. (defun isearch-no-upper-case-p (string)
  1592.   "Return t if there are no upper case chars in string.
  1593. But upper case chars preceded by \\ do not count since they
  1594. have special meaning in a regexp."
  1595.   ;; this incorrectly returns t for "\\\\A"
  1596.   (let ((case-fold-search nil))
  1597.     (not (string-match "\\(^\\|[^\\]\\)[A-Z]" string))))
  1598.  
  1599. ;; Used by etags.el and info.el
  1600. (defmacro with-caps-disable-folding (string &rest body) "\
  1601. Eval BODY with `case-fold-search' let to nil if STRING contains
  1602. uppercase letters and `search-caps-disable-folding' is t."
  1603.   `(let ((case-fold-search
  1604.           (if (and case-fold-search search-caps-disable-folding)
  1605.               (isearch-no-upper-case-p ,string)
  1606.             case-fold-search)))
  1607.      ,@body))
  1608. (put 'with-caps-disable-folding 'lisp-indent-function 1)
  1609. (put 'with-caps-disable-folding 'edebug-form-spec '(form body))
  1610.  
  1611.