1 |
;;; isearch.el --- incremental search minor mode |
;;; isearch.el --- incremental search minor mode |
2 |
|
|
3 |
;; Copyright (C) 1992, 93, 94, 95, 96, 97, 1999, 2000, 01, 2003, 2004 |
;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1999, |
4 |
;; Free Software Foundation, Inc. |
;; 2000, 2001, 2003, 2004 Free Software Foundation, Inc. |
5 |
|
|
6 |
;; Author: Daniel LaLiberte <liberte@cs.uiuc.edu> |
;; Author: Daniel LaLiberte <liberte@cs.uiuc.edu> |
7 |
;; Maintainer: FSF |
;; Maintainer: FSF |
59 |
|
|
60 |
;; TODO |
;; TODO |
61 |
;; - Integrate the emacs 19 generalized command history. |
;; - Integrate the emacs 19 generalized command history. |
|
;; - Think about incorporating query-replace. |
|
62 |
;; - Hooks and options for failed search. |
;; - Hooks and options for failed search. |
63 |
|
|
64 |
;;; Change Log: |
;;; Change Log: |
293 |
(define-key map " " 'isearch-whitespace-chars) |
(define-key map " " 'isearch-whitespace-chars) |
294 |
(define-key map [?\S-\ ] 'isearch-whitespace-chars) |
(define-key map [?\S-\ ] 'isearch-whitespace-chars) |
295 |
|
|
296 |
(define-key map "\C-w" 'isearch-yank-word-or-char) |
(define-key map "\C-w" 'isearch-yank-word-or-char) |
297 |
(define-key map "\C-y" 'isearch-yank-line) |
(define-key map "\M-\C-w" 'isearch-del-char) |
298 |
|
(define-key map "\M-\C-y" 'isearch-yank-char) |
299 |
|
(define-key map "\C-y" 'isearch-yank-line) |
300 |
|
|
301 |
;; Define keys for regexp chars * ? |. |
;; Define keys for regexp chars * ? |. |
302 |
;; Nothing special for + because it matches at least once. |
;; Nothing special for + because it matches at least once. |
337 |
(define-key map "\M-r" 'isearch-toggle-regexp) |
(define-key map "\M-r" 'isearch-toggle-regexp) |
338 |
(define-key map "\M-e" 'isearch-edit-string) |
(define-key map "\M-e" 'isearch-edit-string) |
339 |
|
|
340 |
|
(define-key map [?\M-%] 'isearch-query-replace) |
341 |
|
(define-key map [?\C-\M-%] 'isearch-query-replace-regexp) |
342 |
|
|
343 |
map) |
map) |
344 |
"Keymap for `isearch-mode'.") |
"Keymap for `isearch-mode'.") |
345 |
|
|
346 |
(defvar minibuffer-local-isearch-map |
(defvar minibuffer-local-isearch-map |
347 |
(let ((map (make-sparse-keymap))) |
(let ((map (make-sparse-keymap))) |
348 |
(set-keymap-parent map minibuffer-local-map) |
(set-keymap-parent map minibuffer-local-map) |
349 |
(define-key map "\r" 'isearch-nonincremental-exit-minibuffer) |
(define-key map "\r" 'isearch-nonincremental-exit-minibuffer) |
350 |
(define-key map "\M-n" 'isearch-ring-advance-edit) |
(define-key map "\M-n" 'isearch-ring-advance-edit) |
351 |
(define-key map "\M-p" 'isearch-ring-retreat-edit) |
(define-key map [next] 'isearch-ring-advance-edit) |
352 |
|
(define-key map [down] 'isearch-ring-advance-edit) |
353 |
|
(define-key map "\M-p" 'isearch-ring-retreat-edit) |
354 |
|
(define-key map [prior] 'isearch-ring-retreat-edit) |
355 |
|
(define-key map [up] 'isearch-ring-retreat-edit) |
356 |
(define-key map "\M-\t" 'isearch-complete-edit) |
(define-key map "\M-\t" 'isearch-complete-edit) |
357 |
(define-key map "\C-s" 'isearch-forward-exit-minibuffer) |
(define-key map "\C-s" 'isearch-forward-exit-minibuffer) |
358 |
(define-key map "\C-r" 'isearch-reverse-exit-minibuffer) |
(define-key map "\C-r" 'isearch-reverse-exit-minibuffer) |
359 |
|
(define-key map "\C-f" 'isearch-yank-char-in-minibuffer) |
360 |
|
(define-key map [right] 'isearch-yank-char-in-minibuffer) |
361 |
map) |
map) |
362 |
"Keymap for editing isearch strings in the minibuffer.") |
"Keymap for editing isearch strings in the minibuffer.") |
363 |
|
|
459 |
The following non-printing keys are bound in `isearch-mode-map'. |
The following non-printing keys are bound in `isearch-mode-map'. |
460 |
|
|
461 |
Type \\[isearch-delete-char] to cancel last input item from end of search string. |
Type \\[isearch-delete-char] to cancel last input item from end of search string. |
|
Type \\[isearch-del-char] to cancel last character from end of search string. |
|
462 |
Type \\[isearch-exit] to exit, leaving point at location found. |
Type \\[isearch-exit] to exit, leaving point at location found. |
463 |
Type LFD (C-j) to match end of line. |
Type LFD (C-j) to match end of line. |
464 |
Type \\[isearch-repeat-forward] to search again forward,\ |
Type \\[isearch-repeat-forward] to search again forward,\ |
465 |
\\[isearch-repeat-backward] to search again backward. |
\\[isearch-repeat-backward] to search again backward. |
466 |
Type \\[isearch-yank-char] to yank character from buffer onto end of search\ |
Type \\[isearch-yank-word-or-char] to yank word from buffer onto end of search\ |
467 |
string and search for it. |
string and search for it. |
468 |
Type \\[isearch-yank-word] to yank word from buffer onto end of search\ |
Type \\[isearch-del-char] to delete character from end of search string. |
469 |
|
Type \\[isearch-yank-char] to yank char from buffer onto end of search\ |
470 |
string and search for it. |
string and search for it. |
471 |
Type \\[isearch-yank-line] to yank rest of line onto end of search string\ |
Type \\[isearch-yank-line] to yank rest of line onto end of search string\ |
472 |
and search for it. |
and search for it. |
802 |
\\[isearch-ring-retreat-edit] to replace the search string with the previous item in the search ring. |
\\[isearch-ring-retreat-edit] to replace the search string with the previous item in the search ring. |
803 |
\\[isearch-complete-edit] to complete the search string using the search ring. |
\\[isearch-complete-edit] to complete the search string using the search ring. |
804 |
\\<isearch-mode-map> |
\\<isearch-mode-map> |
805 |
If first char entered is \\[isearch-yank-word], then do word search instead." |
If first char entered is \\[isearch-yank-word-or-char], then do word search instead." |
806 |
|
|
807 |
;; This code is very hairy for several reasons, explained in the code. |
;; This code is very hairy for several reasons, explained in the code. |
808 |
;; Mainly, isearch-mode must be terminated while editing and then restarted. |
;; Mainly, isearch-mode must be terminated while editing and then restarted. |
1058 |
(sit-for 1) |
(sit-for 1) |
1059 |
(isearch-update)) |
(isearch-update)) |
1060 |
|
|
1061 |
|
(defun isearch-query-replace () |
1062 |
|
"Start query-replace with string to replace from last search string." |
1063 |
|
(interactive) |
1064 |
|
(barf-if-buffer-read-only) |
1065 |
|
(let ((case-fold-search isearch-case-fold-search)) |
1066 |
|
(isearch-done) |
1067 |
|
(isearch-clean-overlays) |
1068 |
|
(and isearch-forward isearch-other-end (goto-char isearch-other-end)) |
1069 |
|
(perform-replace |
1070 |
|
isearch-string |
1071 |
|
(query-replace-read-to isearch-string "Query replace" isearch-regexp) |
1072 |
|
t isearch-regexp isearch-word))) |
1073 |
|
|
1074 |
|
(defun isearch-query-replace-regexp () |
1075 |
|
"Start query-replace-regexp with string to replace from last search string." |
1076 |
|
(interactive) |
1077 |
|
(let ((query-replace-interactive t) |
1078 |
|
(case-fold-search isearch-case-fold-search)) |
1079 |
|
;; Put search string into the right ring |
1080 |
|
(setq isearch-regexp t) |
1081 |
|
(isearch-done) |
1082 |
|
(isearch-clean-overlays) |
1083 |
|
(and isearch-forward isearch-other-end (goto-char isearch-other-end)) |
1084 |
|
(call-interactively 'query-replace-regexp))) |
1085 |
|
|
1086 |
|
|
1087 |
(defun isearch-delete-char () |
(defun isearch-delete-char () |
1088 |
"Discard last input item and move point back. |
"Discard last input item and move point back. |
1089 |
If no previous match was done, just beep." |
If no previous match was done, just beep." |
1093 |
(isearch-pop-state)) |
(isearch-pop-state)) |
1094 |
(isearch-update)) |
(isearch-update)) |
1095 |
|
|
1096 |
(defun isearch-del-char () |
(defun isearch-del-char (&optional arg) |
1097 |
"Discard last character and move point back. |
"Delete character from end of search string and search again. |
1098 |
If there is no previous character, just beep." |
If search string is empty, just beep." |
1099 |
(interactive) |
(interactive "p") |
1100 |
(if (equal isearch-string "") |
(if (= 0 (length isearch-string)) |
1101 |
(ding) |
(ding) |
1102 |
(setq isearch-string (substring isearch-string 0 -1) |
(setq isearch-string (substring isearch-string 0 (- (or arg 1))) |
1103 |
isearch-message (mapconcat 'isearch-text-char-description |
isearch-message (mapconcat 'isearch-text-char-description |
1104 |
isearch-string ""))) |
isearch-string "") |
1105 |
|
;; Don't move cursor in reverse search. |
1106 |
|
isearch-yank-flag t)) |
1107 |
(isearch-search-and-update)) |
(isearch-search-and-update)) |
1108 |
|
|
1109 |
(defun isearch-yank-string (string) |
(defun isearch-yank-string (string) |
1165 |
(goto-char isearch-other-end)) |
(goto-char isearch-other-end)) |
1166 |
(buffer-substring-no-properties (point) (funcall jumpform))))) |
(buffer-substring-no-properties (point) (funcall jumpform))))) |
1167 |
|
|
1168 |
(defun isearch-yank-char () |
(defun isearch-yank-char-in-minibuffer (&optional arg) |
1169 |
|
"Pull next character from buffer into end of search string in minibuffer." |
1170 |
|
(interactive "p") |
1171 |
|
(if (eobp) |
1172 |
|
(insert |
1173 |
|
(save-excursion |
1174 |
|
(set-buffer (cadr (buffer-list))) |
1175 |
|
(buffer-substring-no-properties |
1176 |
|
(point) (progn (forward-char arg) (point))))) |
1177 |
|
(forward-char arg))) |
1178 |
|
|
1179 |
|
(defun isearch-yank-char (&optional arg) |
1180 |
"Pull next character from buffer into search string." |
"Pull next character from buffer into search string." |
1181 |
(interactive) |
(interactive "p") |
1182 |
(isearch-yank-internal (lambda () (forward-char 1) (point)))) |
(isearch-yank-internal (lambda () (forward-char arg) (point)))) |
1183 |
|
|
1184 |
(defun isearch-yank-word-or-char () |
(defun isearch-yank-word-or-char () |
1185 |
"Pull next character or word from buffer into search string." |
"Pull next character or word from buffer into search string." |
2380 |
isearch-case-fold-search case-fold) |
isearch-case-fold-search case-fold) |
2381 |
(isearch-search)) |
(isearch-search)) |
2382 |
|
|
2383 |
;;; arch-tag: 74850515-f7d8-43a6-8a2c-ca90a4c1e675 |
;; arch-tag: 74850515-f7d8-43a6-8a2c-ca90a4c1e675 |
2384 |
;;; isearch.el ends here |
;;; isearch.el ends here |