comparison lisp/isearch.el @ 56303:d86ec00a8470

(isearch-mode-map): Bind C-M-w to isearch-del-char, C-M-y to isearch-yank-char. Bind M-% to isearch-query-replace, C-M-% to isearch-query-replace-regexp. (minibuffer-local-isearch-map): Add arrow key bindings. Bind C-f to isearch-yank-char-in-minibuffer. (isearch-forward): Doc fix. (isearch-edit-string): Doc fix. (isearch-query-replace, isearch-query-replace-regexp): New funs. (isearch-del-char): Add optional arg. Set isearch-yank-flag to t. (isearch-yank-char): Add optional arg. (isearch-yank-char-in-minibuffer): New fun.
author Juri Linkov <juri@jurta.org>
date Thu, 01 Jul 2004 09:54:51 +0000
parents b3821f47a6d4
children 8d4253b23d7b
comparison
equal deleted inserted replaced
56302:c857a4952b78 56303:d86ec00a8470
292 (define-key map "\C-j" 'isearch-printing-char) 292 (define-key map "\C-j" 'isearch-printing-char)
293 (define-key map "\t" 'isearch-printing-char) 293 (define-key map "\t" 'isearch-printing-char)
294 (define-key map " " 'isearch-whitespace-chars) 294 (define-key map " " 'isearch-whitespace-chars)
295 (define-key map [?\S-\ ] 'isearch-whitespace-chars) 295 (define-key map [?\S-\ ] 'isearch-whitespace-chars)
296 296
297 (define-key map "\C-w" 'isearch-yank-word-or-char) 297 (define-key map "\C-w" 'isearch-yank-word-or-char)
298 (define-key map "\C-y" 'isearch-yank-line) 298 (define-key map "\M-\C-w" 'isearch-del-char)
299 (define-key map "\M-\C-y" 'isearch-yank-char)
300 (define-key map "\C-y" 'isearch-yank-line)
299 301
300 ;; Define keys for regexp chars * ? |. 302 ;; Define keys for regexp chars * ? |.
301 ;; Nothing special for + because it matches at least once. 303 ;; Nothing special for + because it matches at least once.
302 (define-key map "*" 'isearch-*-char) 304 (define-key map "*" 'isearch-*-char)
303 (define-key map "?" 'isearch-*-char) 305 (define-key map "?" 'isearch-*-char)
334 ;; Suggest some alternates... 336 ;; Suggest some alternates...
335 (define-key map "\M-c" 'isearch-toggle-case-fold) 337 (define-key map "\M-c" 'isearch-toggle-case-fold)
336 (define-key map "\M-r" 'isearch-toggle-regexp) 338 (define-key map "\M-r" 'isearch-toggle-regexp)
337 (define-key map "\M-e" 'isearch-edit-string) 339 (define-key map "\M-e" 'isearch-edit-string)
338 340
341 (define-key map (kbd "M-%") 'isearch-query-replace)
342 (define-key map (kbd "C-M-%") 'isearch-query-replace-regexp)
343
339 map) 344 map)
340 "Keymap for `isearch-mode'.") 345 "Keymap for `isearch-mode'.")
341 346
342 (defvar minibuffer-local-isearch-map 347 (defvar minibuffer-local-isearch-map
343 (let ((map (make-sparse-keymap))) 348 (let ((map (make-sparse-keymap)))
344 (set-keymap-parent map minibuffer-local-map) 349 (set-keymap-parent map minibuffer-local-map)
345 (define-key map "\r" 'isearch-nonincremental-exit-minibuffer) 350 (define-key map "\r" 'isearch-nonincremental-exit-minibuffer)
346 (define-key map "\M-n" 'isearch-ring-advance-edit) 351 (define-key map "\M-n" 'isearch-ring-advance-edit)
347 (define-key map "\M-p" 'isearch-ring-retreat-edit) 352 (define-key map [next] 'isearch-ring-advance-edit)
353 (define-key map [down] 'isearch-ring-advance-edit)
354 (define-key map "\M-p" 'isearch-ring-retreat-edit)
355 (define-key map [prior] 'isearch-ring-retreat-edit)
356 (define-key map [up] 'isearch-ring-retreat-edit)
348 (define-key map "\M-\t" 'isearch-complete-edit) 357 (define-key map "\M-\t" 'isearch-complete-edit)
349 (define-key map "\C-s" 'isearch-forward-exit-minibuffer) 358 (define-key map "\C-s" 'isearch-forward-exit-minibuffer)
350 (define-key map "\C-r" 'isearch-reverse-exit-minibuffer) 359 (define-key map "\C-r" 'isearch-reverse-exit-minibuffer)
360 (define-key map "\C-f" 'isearch-yank-char-in-minibuffer)
361 (define-key map [right] 'isearch-yank-char-in-minibuffer)
351 map) 362 map)
352 "Keymap for editing isearch strings in the minibuffer.") 363 "Keymap for editing isearch strings in the minibuffer.")
353 364
354 ;; Internal variables declared globally for byte-compiler. 365 ;; Internal variables declared globally for byte-compiler.
355 ;; These are all set with setq while isearching 366 ;; These are all set with setq while isearching
447 \\<isearch-mode-map> 458 \\<isearch-mode-map>
448 As you type characters, they add to the search string and are found. 459 As you type characters, they add to the search string and are found.
449 The following non-printing keys are bound in `isearch-mode-map'. 460 The following non-printing keys are bound in `isearch-mode-map'.
450 461
451 Type \\[isearch-delete-char] to cancel last input item from end of search string. 462 Type \\[isearch-delete-char] to cancel last input item from end of search string.
452 Type \\[isearch-del-char] to cancel last character from end of search string.
453 Type \\[isearch-exit] to exit, leaving point at location found. 463 Type \\[isearch-exit] to exit, leaving point at location found.
454 Type LFD (C-j) to match end of line. 464 Type LFD (C-j) to match end of line.
455 Type \\[isearch-repeat-forward] to search again forward,\ 465 Type \\[isearch-repeat-forward] to search again forward,\
456 \\[isearch-repeat-backward] to search again backward. 466 \\[isearch-repeat-backward] to search again backward.
457 Type \\[isearch-yank-char] to yank character from buffer onto end of search\ 467 Type \\[isearch-yank-word-or-char] to yank word from buffer onto end of search\
458 string and search for it. 468 string and search for it.
459 Type \\[isearch-yank-word] to yank word from buffer onto end of search\ 469 Type \\[isearch-del-char] to delete character from end of search string.
470 Type \\[isearch-yank-char] to yank char from buffer onto end of search\
460 string and search for it. 471 string and search for it.
461 Type \\[isearch-yank-line] to yank rest of line onto end of search string\ 472 Type \\[isearch-yank-line] to yank rest of line onto end of search string\
462 and search for it. 473 and search for it.
463 Type \\[isearch-yank-kill] to yank last killed text onto end of search string\ 474 Type \\[isearch-yank-kill] to yank last killed text onto end of search string\
464 and search for it. 475 and search for it.
790 \\[isearch-reverse-exit-minibuffer] to resume isearching backward. 801 \\[isearch-reverse-exit-minibuffer] to resume isearching backward.
791 \\[isearch-ring-advance-edit] to replace the search string with the next item in the search ring. 802 \\[isearch-ring-advance-edit] to replace the search string with the next item in the search ring.
792 \\[isearch-ring-retreat-edit] to replace the search string with the previous item in the search ring. 803 \\[isearch-ring-retreat-edit] to replace the search string with the previous item in the search ring.
793 \\[isearch-complete-edit] to complete the search string using the search ring. 804 \\[isearch-complete-edit] to complete the search string using the search ring.
794 \\<isearch-mode-map> 805 \\<isearch-mode-map>
795 If first char entered is \\[isearch-yank-word], then do word search instead." 806 If first char entered is \\[isearch-yank-word-or-char], then do word search instead."
796 807
797 ;; This code is very hairy for several reasons, explained in the code. 808 ;; This code is very hairy for several reasons, explained in the code.
798 ;; Mainly, isearch-mode must be terminated while editing and then restarted. 809 ;; Mainly, isearch-mode must be terminated while editing and then restarted.
799 ;; If there were a way to catch any change of buffer from the minibuffer, 810 ;; If there were a way to catch any change of buffer from the minibuffer,
800 ;; this could be simplified greatly. 811 ;; this could be simplified greatly.
1046 (if isearch-case-fold-search "in" ""))) 1057 (if isearch-case-fold-search "in" "")))
1047 (setq isearch-adjusted t) 1058 (setq isearch-adjusted t)
1048 (sit-for 1) 1059 (sit-for 1)
1049 (isearch-update)) 1060 (isearch-update))
1050 1061
1062 (defun isearch-query-replace ()
1063 "Start query-replace with string to replace from last search string."
1064 (interactive)
1065 (let ((query-replace-interactive 'initial)
1066 (case-fold-search isearch-case-fold-search))
1067 ;; Put search string into the right ring
1068 (setq isearch-regexp nil)
1069 (isearch-done)
1070 (isearch-clean-overlays)
1071 (and isearch-forward isearch-other-end (goto-char isearch-other-end))
1072 (call-interactively 'query-replace)))
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 'initial)
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
1051 (defun isearch-delete-char () 1087 (defun isearch-delete-char ()
1052 "Discard last input item and move point back. 1088 "Discard last input item and move point back.
1053 If no previous match was done, just beep." 1089 If no previous match was done, just beep."
1054 (interactive) 1090 (interactive)
1055 (if (null (cdr isearch-cmds)) 1091 (if (null (cdr isearch-cmds))
1056 (ding) 1092 (ding)
1057 (isearch-pop-state)) 1093 (isearch-pop-state))
1058 (isearch-update)) 1094 (isearch-update))
1059 1095
1060 (defun isearch-del-char () 1096 (defun isearch-del-char (&optional arg)
1061 "Discard last character and move point back. 1097 "Delete character from end of search string and search again.
1062 If there is no previous character, just beep." 1098 If search string is empty, just beep."
1063 (interactive) 1099 (interactive "p")
1064 (if (equal isearch-string "") 1100 (if (= 0 (length isearch-string))
1065 (ding) 1101 (ding)
1066 (setq isearch-string (substring isearch-string 0 -1) 1102 (setq isearch-string (substring isearch-string 0 (- (or arg 1)))
1067 isearch-message (mapconcat 'isearch-text-char-description 1103 isearch-message (mapconcat 'isearch-text-char-description
1068 isearch-string ""))) 1104 isearch-string "")
1105 ;; Don't move cursor in reverse search.
1106 isearch-yank-flag t))
1069 (isearch-search-and-update)) 1107 (isearch-search-and-update))
1070 1108
1071 (defun isearch-yank-string (string) 1109 (defun isearch-yank-string (string)
1072 "Pull STRING into search string." 1110 "Pull STRING into search string."
1073 ;; Downcase the string if not supposed to case-fold yanked strings. 1111 ;; Downcase the string if not supposed to case-fold yanked strings.
1125 (save-excursion 1163 (save-excursion
1126 (and (not isearch-forward) isearch-other-end 1164 (and (not isearch-forward) isearch-other-end
1127 (goto-char isearch-other-end)) 1165 (goto-char isearch-other-end))
1128 (buffer-substring-no-properties (point) (funcall jumpform))))) 1166 (buffer-substring-no-properties (point) (funcall jumpform)))))
1129 1167
1130 (defun isearch-yank-char () 1168 (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)
1131 "Pull next character from buffer into search string." 1180 "Pull next character from buffer into search string."
1132 (interactive) 1181 (interactive "p")
1133 (isearch-yank-internal (lambda () (forward-char 1) (point)))) 1182 (isearch-yank-internal (lambda () (forward-char arg) (point))))
1134 1183
1135 (defun isearch-yank-word-or-char () 1184 (defun isearch-yank-word-or-char ()
1136 "Pull next character or word from buffer into search string." 1185 "Pull next character or word from buffer into search string."
1137 (interactive) 1186 (interactive)
1138 (isearch-yank-internal 1187 (isearch-yank-internal