comparison lisp/isearch.el @ 25823:4cecefebde6f

(isearch): Add :links in defgroup. (isearch-mode-map): Bind mouse-2 to isearch-mouse-yank. (isearch-switch-frame-handler): Comment out (unused). (isearch-yank-x-selection, isearch-ring-advance-edit): Doc fix. (isearch-ring-retreat-edit): Doc fix. (isearch-mouse-yank): New command. (isearch-last-command-char): Removed. Callers changed to use last-command-char. (isearch-char-to-string): Removed. Callers changed to use char-to-string.
author Dave Love <fx@gnu.org>
date Mon, 27 Sep 1999 22:15:50 +0000
parents 2ae0f7963ccc
children e0f465df598c
comparison
equal deleted inserted replaced
25822:3a33e6b4847d 25823:4cecefebde6f
1 ;;; isearch.el --- incremental search minor mode. 1 ;;; isearch.el --- incremental search minor mode.
2 2
3 ;; Copyright (C) 1992, 93, 94, 95, 96, 1997 Free Software Foundation, Inc. 3 ;; Copyright (C) 1992, 93, 94, 95, 96, 97, 1999 Free Software Foundation, Inc.
4 4
5 ;; Author: Daniel LaLiberte <liberte@cs.uiuc.edu> 5 ;; Author: Daniel LaLiberte <liberte@cs.uiuc.edu>
6 ;; Maintainer: FSF 6 ;; Maintainer: FSF
7 ;; Keywords: matching
7 8
8 ;; This file is part of GNU Emacs. 9 ;; This file is part of GNU Emacs.
9 10
10 ;; GNU Emacs is free software; you can redistribute it and/or modify 11 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by 12 ;; it under the terms of the GNU General Public License as published by
26 27
27 ;; Instructions 28 ;; Instructions
28 29
29 ;; For programmed use of isearch-mode, e.g. calling (isearch-forward), 30 ;; For programmed use of isearch-mode, e.g. calling (isearch-forward),
30 ;; isearch-mode behaves modally and does not return until the search 31 ;; isearch-mode behaves modally and does not return until the search
31 ;; is completed. It uses a recursive-edit to behave this way. Note: 32 ;; is completed. It uses a recursive-edit to behave this way.
32 ;; gnus does it wrong: (call-interactively 'isearch-forward).
33 33
34 ;; The key bindings active within isearch-mode are defined below in 34 ;; The key bindings active within isearch-mode are defined below in
35 ;; `isearch-mode-map' which is given bindings close to the default 35 ;; `isearch-mode-map' which is given bindings close to the default
36 ;; characters of the original isearch.el. With `isearch-mode', 36 ;; characters of the original isearch.el. With `isearch-mode',
37 ;; however, you can bind multi-character keys and it should be easier 37 ;; however, you can bind multi-character keys and it should be easier
38 ;; to add new commands. One bug though: keys with meta-prefix cannot 38 ;; to add new commands. One bug though: keys with meta-prefix cannot
39 ;; be longer than two chars. Also see minibuffer-local-isearch-map 39 ;; be longer than two chars. Also see minibuffer-local-isearch-map
40 ;; for bindings active during `isearch-edit-string'. 40 ;; for bindings active during `isearch-edit-string'.
41 41
42 ;; Note to emacs version 19 users: isearch-mode should work even if 42 ;; isearch-mode should work even if you switch windows with the mouse,
43 ;; you switch windows with the mouse, in which case isearch-mode is 43 ;; in which case isearch-mode is terminated automatically before the
44 ;; terminated automatically before the switch. This is true of lemacs 44 ;; switch.
45 ;; too, with a few more cleanups I've neglected in this release.
46 ;; No one has supplied patches for epoch yet.
47 45
48 ;; The search ring and completion commands automatically put you in 46 ;; The search ring and completion commands automatically put you in
49 ;; the minibuffer to edit the string. This gives you a chance to 47 ;; the minibuffer to edit the string. This gives you a chance to
50 ;; modify the search string before executing the search. There are 48 ;; modify the search string before executing the search. There are
51 ;; three commands to terminate the editing: C-s and C-r exit the 49 ;; three commands to terminate the editing: C-s and C-r exit the
105 103
106 ;;; Some additional options and constants. 104 ;;; Some additional options and constants.
107 105
108 (defgroup isearch nil 106 (defgroup isearch nil
109 "Incremental search minor mode." 107 "Incremental search minor mode."
108 :link '(emacs-commentary-link "isearch")
109 :link '(custom-manual "(emacs)Incremental Search")
110 :prefix "isearch-" 110 :prefix "isearch-"
111 :prefix "search-" 111 :prefix "search-"
112 :group 'matching) 112 :group 'matching)
113 113
114 114
310 (define-key map [make-frame-visible] nil) 310 (define-key map [make-frame-visible] nil)
311 ;; For searching multilingual text. 311 ;; For searching multilingual text.
312 (define-key map "\C-\\" 'isearch-toggle-input-method) 312 (define-key map "\C-\\" 'isearch-toggle-input-method)
313 (define-key map "\C-^" 'isearch-toggle-specified-input-method) 313 (define-key map "\C-^" 'isearch-toggle-specified-input-method)
314 314
315 ;;; I think the normal meaning of Mouse-2 is more natural. 315 ;; People expect to be able to paste with the mouse.
316 ;;; ;; People expect to be able to paste with the mouse. 316 (define-key map [mouse-2] #'isearch-mouse-yank)
317 ;;; (define-key map [mouse-2] #'isearch-yank-kill) 317 (define-key map [down-mouse-2] nil)
318 ;;; (define-key map [down-mouse-2] nil)
319 318
320 (setq isearch-mode-map map) 319 (setq isearch-mode-map map)
321 )) 320 ))
322 321
323 ;; Some bindings you may want to put in your isearch-mode-hook. 322 ;; Some bindings you may want to put in your isearch-mode-hook.
415 (define-key esc-map "\C-s" 'isearch-forward-regexp) 414 (define-key esc-map "\C-s" 'isearch-forward-regexp)
416 (define-key global-map "\C-r" 'isearch-backward) 415 (define-key global-map "\C-r" 'isearch-backward)
417 (define-key esc-map "\C-r" 'isearch-backward-regexp) 416 (define-key esc-map "\C-r" 'isearch-backward-regexp)
418 417
419 ;;; Entry points to isearch-mode. 418 ;;; Entry points to isearch-mode.
420 ;;; These four functions should replace those in loaddefs.el
421 ;;; An alternative is to defalias isearch-forward etc to isearch-mode,
422 ;;; and look at this-command to set the options accordingly.
423 419
424 (defun isearch-forward (&optional regexp-p no-recursive-edit) 420 (defun isearch-forward (&optional regexp-p no-recursive-edit)
425 "\ 421 "\
426 Do incremental search forward. 422 Do incremental search forward.
427 With a prefix argument, do an incremental regular expression search instead. 423 With a prefix argument, do an incremental regular expression search instead.
688 (setq search-ring (cons string search-ring)) 684 (setq search-ring (cons string search-ring))
689 (if (> (length search-ring) search-ring-max) 685 (if (> (length search-ring) search-ring-max)
690 (setcdr (nthcdr (1- search-ring-max) search-ring) nil)))))) 686 (setcdr (nthcdr (1- search-ring-max) search-ring) nil))))))
691 687
692 ;;; Switching buffers should first terminate isearch-mode. 688 ;;; Switching buffers should first terminate isearch-mode.
693 ;;; This is done quite differently for each variant of emacs. 689 ;;; ;; For Emacs 19, the frame switch event is handled.
694 ;;; For lemacs, see Exiting in lemacs below 690 ;;; (defun isearch-switch-frame-handler ()
695 691 ;;; (interactive) ;; Is this necessary?
696 ;; For Emacs 19, the frame switch event is handled. 692 ;;; ;; First terminate isearch-mode.
697 (defun isearch-switch-frame-handler () 693 ;;; (isearch-done)
698 (interactive) ;; Is this necessary? 694 ;;; (isearch-clean-overlays)
699 ;; First terminate isearch-mode. 695 ;;; (handle-switch-frame (car (cdr last-command-char))))
700 (isearch-done)
701 (isearch-clean-overlays)
702 (handle-switch-frame (car (cdr (isearch-last-command-char)))))
703 696
704 697
705 ;; Commands active while inside of the isearch minor mode. 698 ;; Commands active while inside of the isearch minor mode.
706 699
707 (defun isearch-exit () 700 (defun isearch-exit ()
1003 "Pull string from kill ring into search string." 996 "Pull string from kill ring into search string."
1004 (interactive) 997 (interactive)
1005 (isearch-yank-string (current-kill 0))) 998 (isearch-yank-string (current-kill 0)))
1006 999
1007 (defun isearch-yank-x-selection () 1000 (defun isearch-yank-x-selection ()
1008 "Pull current X selection into search string. 1001 "Pull current X selection into search string."
1009 Some users like to put this command on Mouse-2.
1010 To do that, evaluate these expressions:
1011 (define-key isearch-mode-map [down-mouse-2] nil)
1012 (define-key isearch-mode-map [mouse-2] 'isearch-yank-x-selection)"
1013 (interactive) 1002 (interactive)
1014 (isearch-yank-string (x-get-selection))) 1003 (isearch-yank-string (x-get-selection)))
1004
1005 (defun isearch-mouse-yank (click arg)
1006 "Yank with the mouse in Isearch mode.
1007 For a click in the echo area, invoke `isearch-yank-x-selection'.
1008 Otherwise invoke `mouse-yank-at-click'."
1009 (interactive "e\nP")
1010 (let ((w (posn-window (event-start click))))
1011 (if (and (window-minibuffer-p w)
1012 (not (minibuffer-window-active-p w))) ; in echo area
1013 (isearch-yank-x-selection)
1014 (mouse-yank-at-click click arg))))
1015 1015
1016 (defun isearch-yank-word () 1016 (defun isearch-yank-word ()
1017 "Pull next word from buffer into search string." 1017 "Pull next word from buffer into search string."
1018 (interactive) 1018 (interactive)
1019 (isearch-yank-string 1019 (isearch-yank-string
1103 (setq cs (or cs isearch-barrier)) 1103 (setq cs (or cs isearch-barrier))
1104 (goto-char 1104 (goto-char
1105 (if isearch-forward 1105 (if isearch-forward
1106 (max cs isearch-barrier) 1106 (max cs isearch-barrier)
1107 (min cs isearch-barrier))))))) 1107 (min cs isearch-barrier)))))))
1108 (isearch-process-search-char (isearch-last-command-char))) 1108 (isearch-process-search-char last-command-char))
1109 1109
1110 1110
1111 (defun isearch-|-char () 1111 (defun isearch-|-char ()
1112 "If in regexp search, jump to the barrier." 1112 "If in regexp search, jump to the barrier."
1113 (interactive) 1113 (interactive)
1114 (if isearch-regexp 1114 (if isearch-regexp
1115 (progn 1115 (progn
1116 (setq isearch-adjusted t) 1116 (setq isearch-adjusted t)
1117 (goto-char isearch-barrier))) 1117 (goto-char isearch-barrier)))
1118 (isearch-process-search-char (isearch-last-command-char))) 1118 (isearch-process-search-char last-command-char))
1119 1119
1120 1120
1121 (defalias 'isearch-other-control-char 'isearch-other-meta-char) 1121 (defalias 'isearch-other-control-char 'isearch-other-meta-char)
1122 1122
1123 (defun isearch-other-meta-char () 1123 (defun isearch-other-meta-char ()
1221 (isearch-process-search-char ?\n)) 1221 (isearch-process-search-char ?\n))
1222 1222
1223 (defun isearch-printing-char () 1223 (defun isearch-printing-char ()
1224 "Add this ordinary printing character to the search string and search." 1224 "Add this ordinary printing character to the search string and search."
1225 (interactive) 1225 (interactive)
1226 (let ((char (isearch-last-command-char))) 1226 (let ((char last-command-char))
1227 (if (= char ?\S-\ ) 1227 (if (= char ?\S-\ )
1228 (setq char ?\ )) 1228 (setq char ?\ ))
1229 (if (and enable-multibyte-characters 1229 (if (and enable-multibyte-characters
1230 (>= char ?\200) 1230 (>= char ?\200)
1231 (<= char ?\377)) 1231 (<= char ?\377))
1234 (isearch-process-search-multibyte-characters char) 1234 (isearch-process-search-multibyte-characters char)
1235 (isearch-process-search-char char))))) 1235 (isearch-process-search-char char)))))
1236 1236
1237 (defun isearch-whitespace-chars () 1237 (defun isearch-whitespace-chars ()
1238 "Match all whitespace chars, if in regexp mode. 1238 "Match all whitespace chars, if in regexp mode.
1239 If you want to search for just a space, type C-q SPC." 1239 If you want to search for just a space, type \\[quoted-insert] SPC."
1240 (interactive) 1240 (interactive)
1241 (if isearch-regexp 1241 (if isearch-regexp
1242 (if (and search-whitespace-regexp (not isearch-within-brackets) 1242 (if (and search-whitespace-regexp (not isearch-within-brackets)
1243 (not isearch-invalid-regexp)) 1243 (not isearch-invalid-regexp))
1244 (isearch-process-search-string search-whitespace-regexp " ") 1244 (isearch-process-search-string search-whitespace-regexp " ")
1251 (isearch-printing-char)))) 1251 (isearch-printing-char))))
1252 1252
1253 (defun isearch-process-search-char (char) 1253 (defun isearch-process-search-char (char)
1254 ;; Append the char to the search string, update the message and re-search. 1254 ;; Append the char to the search string, update the message and re-search.
1255 (isearch-process-search-string 1255 (isearch-process-search-string
1256 (isearch-char-to-string char) 1256 (char-to-string char)
1257 (if (>= char ?\200) 1257 (if (>= char ?\200)
1258 (char-to-string char) 1258 (char-to-string char)
1259 (isearch-text-char-description char)))) 1259 (isearch-text-char-description char))))
1260 1260
1261 (defun isearch-process-search-string (string message) 1261 (defun isearch-process-search-string (string message)
1306 "Retreat to the previous search string in the ring." 1306 "Retreat to the previous search string in the ring."
1307 (interactive) 1307 (interactive)
1308 (isearch-ring-adjust nil)) 1308 (isearch-ring-adjust nil))
1309 1309
1310 (defun isearch-ring-advance-edit (n) 1310 (defun isearch-ring-advance-edit (n)
1311 "Insert the next element of the search history into the minibuffer." 1311 "Insert the next element of the search history into the minibuffer.
1312 With prefix arg N, insert the Nth element."
1312 (interactive "p") 1313 (interactive "p")
1313 (let* ((yank-pointer-name (if isearch-regexp 1314 (let* ((yank-pointer-name (if isearch-regexp
1314 'regexp-search-ring-yank-pointer 1315 'regexp-search-ring-yank-pointer
1315 'search-ring-yank-pointer)) 1316 'search-ring-yank-pointer))
1316 (yank-pointer (eval yank-pointer-name)) 1317 (yank-pointer (eval yank-pointer-name))
1326 (erase-buffer) 1327 (erase-buffer)
1327 (insert (nth yank-pointer ring)) 1328 (insert (nth yank-pointer ring))
1328 (goto-char (point-max))))) 1329 (goto-char (point-max)))))
1329 1330
1330 (defun isearch-ring-retreat-edit (n) 1331 (defun isearch-ring-retreat-edit (n)
1331 "Inserts the previous element of the search history into the minibuffer." 1332 "Insert the previous element of the search history into the minibuffer.
1333 With prefix arg N, insert the Nth element."
1332 (interactive "p") 1334 (interactive "p")
1333 (isearch-ring-advance-edit (- n))) 1335 (isearch-ring-advance-edit (- n)))
1334 1336
1335 ;;(defun isearch-ring-adjust-edit (advance) 1337 ;;(defun isearch-ring-adjust-edit (advance)
1336 ;; "Use the next or previous search string in the ring while in minibuffer." 1338 ;; "Use the next or previous search string in the ring while in minibuffer."
1563 (overlay-put ov 'isearch-intangible (overlay-get ov 'intangible)) 1565 (overlay-put ov 'isearch-intangible (overlay-get ov 'intangible))
1564 (overlay-put ov 'invisible nil) 1566 (overlay-put ov 'invisible nil)
1565 (overlay-put ov 'intangible nil))) 1567 (overlay-put ov 'intangible nil)))
1566 1568
1567 1569
1568 ;;; This is called at the end of isearch. I will open the overlays 1570 ;;; This is called at the end of isearch. It will open the overlays
1569 ;;; that contain the latest match. Obviously in case of a C-g the 1571 ;;; that contain the latest match. Obviously in case of a C-g the
1570 ;;; point returns to the original location which surely is not contain 1572 ;;; point returns to the original location which surely is not contain
1571 ;;; in any of these overlays, se we are safe in this case too. 1573 ;;; in any of these overlays, se we are safe in this case too.
1572 (defun isearch-open-necessary-overlays (ov) 1574 (defun isearch-open-necessary-overlays (ov)
1573 (let ((inside-overlay (and (> (point) (overlay-start ov)) 1575 (let ((inside-overlay (and (> (point) (overlay-start ov))
1574 (< (point) (overlay-end ov)))) 1576 (< (point) (overlay-end ov))))
1725 (setq i (1+ i))) 1727 (setq i (1+ i)))
1726 (not found))) 1728 (not found)))
1727 1729
1728 ;; Portability functions to support various Emacs versions. 1730 ;; Portability functions to support various Emacs versions.
1729 1731
1730 (defun isearch-char-to-string (c)
1731 (char-to-string c))
1732
1733 (defun isearch-text-char-description (c) 1732 (defun isearch-text-char-description (c)
1734 (if (and (integerp c) (or (< c ?\ ) (= c ?\^?))) 1733 (if (and (integerp c) (or (< c ?\ ) (= c ?\^?)))
1735 (text-char-description c) 1734 (text-char-description c)
1736 (isearch-char-to-string c))) 1735 (char-to-string c)))
1737 1736
1738 ;; General function to unread characters or events. 1737 ;; General function to unread characters or events.
1739 ;; Also insert them in a keyboard macro being defined. 1738 ;; Also insert them in a keyboard macro being defined.
1740 (defun isearch-unread (&rest char-or-events) 1739 (defun isearch-unread (&rest char-or-events)
1741 (mapcar 'store-kbd-macro-event char-or-events) 1740 (mapcar 'store-kbd-macro-event char-or-events)
1742 (setq unread-command-events 1741 (setq unread-command-events
1743 (append char-or-events unread-command-events))) 1742 (append char-or-events unread-command-events)))
1744 1743
1745 (defun isearch-last-command-char ()
1746 ;; General function to return the last command character.
1747 last-command-char)
1748
1749 ;;; isearch.el ends here 1744 ;;; isearch.el ends here