comparison lisp/isearch.el @ 89952:6f6e9fe4658b

Revision: miles@gnu.org--gnu-2004/emacs--unicode--0--patch-22 Merge from emacs--cvs-trunk--0 Patches applied: * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-431 - miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-441 Update from CVS
author Miles Bader <miles@gnu.org>
date Tue, 06 Jul 2004 02:57:15 +0000
parents 4c90ffeb71c5 f0e5e08dd63e
children d8411455de48
comparison
equal deleted inserted replaced
89951:aafd98bcc2ac 89952:6f6e9fe4658b
1 ;;; isearch.el --- incremental search minor mode 1 ;;; isearch.el --- incremental search minor mode
2 2
3 ;; Copyright (C) 1992, 93, 94, 95, 96, 97, 1999, 2000, 01, 2003, 2004 3 ;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1999,
4 ;; Free Software Foundation, Inc. 4 ;; 2000, 2001, 2003, 2004 Free Software Foundation, Inc.
5 5
6 ;; Author: Daniel LaLiberte <liberte@cs.uiuc.edu> 6 ;; Author: Daniel LaLiberte <liberte@cs.uiuc.edu>
7 ;; Maintainer: FSF 7 ;; Maintainer: FSF
8 ;; Keywords: matching 8 ;; Keywords: matching
9 9
57 ;; keep the behavior. No point in forcing nonincremental search until 57 ;; keep the behavior. No point in forcing nonincremental search until
58 ;; the last possible moment. 58 ;; the last possible moment.
59 59
60 ;; TODO 60 ;; TODO
61 ;; - Integrate the emacs 19 generalized command history. 61 ;; - Integrate the emacs 19 generalized command history.
62 ;; - Think about incorporating query-replace.
63 ;; - Hooks and options for failed search. 62 ;; - Hooks and options for failed search.
64 63
65 ;;; Change Log: 64 ;;; Change Log:
66 65
67 ;; Changes before those recorded in ChangeLog: 66 ;; Changes before those recorded in ChangeLog:
288 (define-key map "\C-j" 'isearch-printing-char) 287 (define-key map "\C-j" 'isearch-printing-char)
289 (define-key map "\t" 'isearch-printing-char) 288 (define-key map "\t" 'isearch-printing-char)
290 (define-key map " " 'isearch-whitespace-chars) 289 (define-key map " " 'isearch-whitespace-chars)
291 (define-key map [?\S-\ ] 'isearch-whitespace-chars) 290 (define-key map [?\S-\ ] 'isearch-whitespace-chars)
292 291
293 (define-key map "\C-w" 'isearch-yank-word-or-char) 292 (define-key map "\C-w" 'isearch-yank-word-or-char)
294 (define-key map "\C-y" 'isearch-yank-line) 293 (define-key map "\M-\C-w" 'isearch-del-char)
294 (define-key map "\M-\C-y" 'isearch-yank-char)
295 (define-key map "\C-y" 'isearch-yank-line)
295 296
296 ;; Define keys for regexp chars * ? |. 297 ;; Define keys for regexp chars * ? |.
297 ;; Nothing special for + because it matches at least once. 298 ;; Nothing special for + because it matches at least once.
298 (define-key map "*" 'isearch-*-char) 299 (define-key map "*" 'isearch-*-char)
299 (define-key map "?" 'isearch-*-char) 300 (define-key map "?" 'isearch-*-char)
330 ;; Suggest some alternates... 331 ;; Suggest some alternates...
331 (define-key map "\M-c" 'isearch-toggle-case-fold) 332 (define-key map "\M-c" 'isearch-toggle-case-fold)
332 (define-key map "\M-r" 'isearch-toggle-regexp) 333 (define-key map "\M-r" 'isearch-toggle-regexp)
333 (define-key map "\M-e" 'isearch-edit-string) 334 (define-key map "\M-e" 'isearch-edit-string)
334 335
336 (define-key map [?\M-%] 'isearch-query-replace)
337 (define-key map [?\C-\M-%] 'isearch-query-replace-regexp)
338
335 map) 339 map)
336 "Keymap for `isearch-mode'.") 340 "Keymap for `isearch-mode'.")
337 341
338 (defvar minibuffer-local-isearch-map 342 (defvar minibuffer-local-isearch-map
339 (let ((map (make-sparse-keymap))) 343 (let ((map (make-sparse-keymap)))
340 (set-keymap-parent map minibuffer-local-map) 344 (set-keymap-parent map minibuffer-local-map)
341 (define-key map "\r" 'isearch-nonincremental-exit-minibuffer) 345 (define-key map "\r" 'isearch-nonincremental-exit-minibuffer)
342 (define-key map "\M-n" 'isearch-ring-advance-edit) 346 (define-key map "\M-n" 'isearch-ring-advance-edit)
343 (define-key map "\M-p" 'isearch-ring-retreat-edit) 347 (define-key map [next] 'isearch-ring-advance-edit)
348 (define-key map [down] 'isearch-ring-advance-edit)
349 (define-key map "\M-p" 'isearch-ring-retreat-edit)
350 (define-key map [prior] 'isearch-ring-retreat-edit)
351 (define-key map [up] 'isearch-ring-retreat-edit)
344 (define-key map "\M-\t" 'isearch-complete-edit) 352 (define-key map "\M-\t" 'isearch-complete-edit)
345 (define-key map "\C-s" 'isearch-forward-exit-minibuffer) 353 (define-key map "\C-s" 'isearch-forward-exit-minibuffer)
346 (define-key map "\C-r" 'isearch-reverse-exit-minibuffer) 354 (define-key map "\C-r" 'isearch-reverse-exit-minibuffer)
355 (define-key map "\C-f" 'isearch-yank-char-in-minibuffer)
356 (define-key map [right] 'isearch-yank-char-in-minibuffer)
347 map) 357 map)
348 "Keymap for editing isearch strings in the minibuffer.") 358 "Keymap for editing isearch strings in the minibuffer.")
349 359
350 ;; Internal variables declared globally for byte-compiler. 360 ;; Internal variables declared globally for byte-compiler.
351 ;; These are all set with setq while isearching 361 ;; These are all set with setq while isearching
443 \\<isearch-mode-map> 453 \\<isearch-mode-map>
444 As you type characters, they add to the search string and are found. 454 As you type characters, they add to the search string and are found.
445 The following non-printing keys are bound in `isearch-mode-map'. 455 The following non-printing keys are bound in `isearch-mode-map'.
446 456
447 Type \\[isearch-delete-char] to cancel last input item from end of search string. 457 Type \\[isearch-delete-char] to cancel last input item from end of search string.
448 Type \\[isearch-del-char] to cancel last character from end of search string.
449 Type \\[isearch-exit] to exit, leaving point at location found. 458 Type \\[isearch-exit] to exit, leaving point at location found.
450 Type LFD (C-j) to match end of line. 459 Type LFD (C-j) to match end of line.
451 Type \\[isearch-repeat-forward] to search again forward,\ 460 Type \\[isearch-repeat-forward] to search again forward,\
452 \\[isearch-repeat-backward] to search again backward. 461 \\[isearch-repeat-backward] to search again backward.
453 Type \\[isearch-yank-char] to yank character from buffer onto end of search\ 462 Type \\[isearch-yank-word-or-char] to yank word from buffer onto end of search\
454 string and search for it. 463 string and search for it.
455 Type \\[isearch-yank-word] to yank word from buffer onto end of search\ 464 Type \\[isearch-del-char] to delete character from end of search string.
465 Type \\[isearch-yank-char] to yank char from buffer onto end of search\
456 string and search for it. 466 string and search for it.
457 Type \\[isearch-yank-line] to yank rest of line onto end of search string\ 467 Type \\[isearch-yank-line] to yank rest of line onto end of search string\
458 and search for it. 468 and search for it.
459 Type \\[isearch-yank-kill] to yank last killed text onto end of search string\ 469 Type \\[isearch-yank-kill] to yank last killed text onto end of search string\
460 and search for it. 470 and search for it.
786 \\[isearch-reverse-exit-minibuffer] to resume isearching backward. 796 \\[isearch-reverse-exit-minibuffer] to resume isearching backward.
787 \\[isearch-ring-advance-edit] to replace the search string with the next item in the search ring. 797 \\[isearch-ring-advance-edit] to replace the search string with the next item in the search ring.
788 \\[isearch-ring-retreat-edit] to replace the search string with the previous item in the search ring. 798 \\[isearch-ring-retreat-edit] to replace the search string with the previous item in the search ring.
789 \\[isearch-complete-edit] to complete the search string using the search ring. 799 \\[isearch-complete-edit] to complete the search string using the search ring.
790 \\<isearch-mode-map> 800 \\<isearch-mode-map>
791 If first char entered is \\[isearch-yank-word], then do word search instead." 801 If first char entered is \\[isearch-yank-word-or-char], then do word search instead."
792 802
793 ;; This code is very hairy for several reasons, explained in the code. 803 ;; This code is very hairy for several reasons, explained in the code.
794 ;; Mainly, isearch-mode must be terminated while editing and then restarted. 804 ;; Mainly, isearch-mode must be terminated while editing and then restarted.
795 ;; If there were a way to catch any change of buffer from the minibuffer, 805 ;; If there were a way to catch any change of buffer from the minibuffer,
796 ;; this could be simplified greatly. 806 ;; this could be simplified greatly.
1042 (if isearch-case-fold-search "in" ""))) 1052 (if isearch-case-fold-search "in" "")))
1043 (setq isearch-adjusted t) 1053 (setq isearch-adjusted t)
1044 (sit-for 1) 1054 (sit-for 1)
1045 (isearch-update)) 1055 (isearch-update))
1046 1056
1057 (defun isearch-query-replace ()
1058 "Start query-replace with string to replace from last search string."
1059 (interactive)
1060 (barf-if-buffer-read-only)
1061 (let ((case-fold-search isearch-case-fold-search))
1062 (isearch-done)
1063 (isearch-clean-overlays)
1064 (and isearch-forward isearch-other-end (goto-char isearch-other-end))
1065 (perform-replace
1066 isearch-string
1067 (query-replace-read-to isearch-string "Query replace" isearch-regexp)
1068 t isearch-regexp isearch-word)))
1069
1070 (defun isearch-query-replace-regexp ()
1071 "Start query-replace-regexp with string to replace from last search string."
1072 (interactive)
1073 (let ((query-replace-interactive t)
1074 (case-fold-search isearch-case-fold-search))
1075 ;; Put search string into the right ring
1076 (setq isearch-regexp t)
1077 (isearch-done)
1078 (isearch-clean-overlays)
1079 (and isearch-forward isearch-other-end (goto-char isearch-other-end))
1080 (call-interactively 'query-replace-regexp)))
1081
1082
1047 (defun isearch-delete-char () 1083 (defun isearch-delete-char ()
1048 "Discard last input item and move point back. 1084 "Discard last input item and move point back.
1049 If no previous match was done, just beep." 1085 If no previous match was done, just beep."
1050 (interactive) 1086 (interactive)
1051 (if (null (cdr isearch-cmds)) 1087 (if (null (cdr isearch-cmds))
1052 (ding) 1088 (ding)
1053 (isearch-pop-state)) 1089 (isearch-pop-state))
1054 (isearch-update)) 1090 (isearch-update))
1055 1091
1056 (defun isearch-del-char () 1092 (defun isearch-del-char (&optional arg)
1057 "Discard last character and move point back. 1093 "Delete character from end of search string and search again.
1058 If there is no previous character, just beep." 1094 If search string is empty, just beep."
1059 (interactive) 1095 (interactive "p")
1060 (if (equal isearch-string "") 1096 (if (= 0 (length isearch-string))
1061 (ding) 1097 (ding)
1062 (setq isearch-string (substring isearch-string 0 -1) 1098 (setq isearch-string (substring isearch-string 0 (- (or arg 1)))
1063 isearch-message (mapconcat 'isearch-text-char-description 1099 isearch-message (mapconcat 'isearch-text-char-description
1064 isearch-string ""))) 1100 isearch-string "")
1101 ;; Don't move cursor in reverse search.
1102 isearch-yank-flag t))
1065 (isearch-search-and-update)) 1103 (isearch-search-and-update))
1066 1104
1067 (defun isearch-yank-string (string) 1105 (defun isearch-yank-string (string)
1068 "Pull STRING into search string." 1106 "Pull STRING into search string."
1069 ;; Downcase the string if not supposed to case-fold yanked strings. 1107 ;; Downcase the string if not supposed to case-fold yanked strings.
1121 (save-excursion 1159 (save-excursion
1122 (and (not isearch-forward) isearch-other-end 1160 (and (not isearch-forward) isearch-other-end
1123 (goto-char isearch-other-end)) 1161 (goto-char isearch-other-end))
1124 (buffer-substring-no-properties (point) (funcall jumpform))))) 1162 (buffer-substring-no-properties (point) (funcall jumpform)))))
1125 1163
1126 (defun isearch-yank-char () 1164 (defun isearch-yank-char-in-minibuffer (&optional arg)
1165 "Pull next character from buffer into end of search string in minibuffer."
1166 (interactive "p")
1167 (if (eobp)
1168 (insert
1169 (save-excursion
1170 (set-buffer (cadr (buffer-list)))
1171 (buffer-substring-no-properties
1172 (point) (progn (forward-char arg) (point)))))
1173 (forward-char arg)))
1174
1175 (defun isearch-yank-char (&optional arg)
1127 "Pull next character from buffer into search string." 1176 "Pull next character from buffer into search string."
1128 (interactive) 1177 (interactive "p")
1129 (isearch-yank-internal (lambda () (forward-char 1) (point)))) 1178 (isearch-yank-internal (lambda () (forward-char arg) (point))))
1130 1179
1131 (defun isearch-yank-word-or-char () 1180 (defun isearch-yank-word-or-char ()
1132 "Pull next character or word from buffer into search string." 1181 "Pull next character or word from buffer into search string."
1133 (interactive) 1182 (interactive)
1134 (isearch-yank-internal 1183 (isearch-yank-internal
2325 (setq isearch-string search 2374 (setq isearch-string search
2326 isearch-message message 2375 isearch-message message
2327 isearch-case-fold-search case-fold) 2376 isearch-case-fold-search case-fold)
2328 (isearch-search)) 2377 (isearch-search))
2329 2378
2330 ;;; arch-tag: 74850515-f7d8-43a6-8a2c-ca90a4c1e675 2379 ;; arch-tag: 74850515-f7d8-43a6-8a2c-ca90a4c1e675
2331 ;;; isearch.el ends here 2380 ;;; isearch.el ends here