Mercurial > emacs
comparison lisp/isearch.el @ 33704:f14d787f4b33
(isearch-mode-map): Fix docstring. Init in defvar.
(minibuffer-local-isearch-map): Init in defvar. Use inheritance.
(isearch-clean-overlays, isearch-range-invisible, isearch-unread):
Use mapc rather than map.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Tue, 21 Nov 2000 21:28:05 +0000 |
parents | b8defc3b27e2 |
children | 687b166e4a49 |
comparison
equal
deleted
inserted
replaced
33703:af0f3f3533e8 | 33704:f14d787f4b33 |
---|---|
221 :type 'boolean | 221 :type 'boolean |
222 :group 'isearch) | 222 :group 'isearch) |
223 | 223 |
224 ;;; Define isearch-mode keymap. | 224 ;;; Define isearch-mode keymap. |
225 | 225 |
226 (defvar isearch-mode-map nil | 226 (defvar isearch-mode-map |
227 "Keymap for isearch-mode.") | 227 (let* ((i 0) |
228 | 228 (map (make-keymap))) |
229 (or isearch-mode-map | 229 (or (vectorp (nth 1 map)) |
230 (let* ((i 0) | 230 (char-table-p (nth 1 map)) |
231 (map (make-keymap))) | 231 (error "The initialization of isearch-mode-map must be updated")) |
232 (or (vectorp (nth 1 map)) | 232 ;; Make all multibyte characters search for themselves. |
233 (char-table-p (nth 1 map)) | 233 (let ((l (generic-character-list)) |
234 (error "The initialization of isearch-mode-map must be updated")) | 234 (table (nth 1 map))) |
235 ;; Make all multibyte characters search for themselves. | 235 (while l |
236 (let ((l (generic-character-list)) | 236 (set-char-table-default table (car l) 'isearch-printing-char) |
237 (table (nth 1 map))) | 237 (setq l (cdr l)))) |
238 (while l | 238 ;; Make function keys, etc, exit the search. |
239 (set-char-table-default table (car l) 'isearch-printing-char) | 239 (define-key map [t] 'isearch-other-control-char) |
240 (setq l (cdr l)))) | 240 ;; Control chars, by default, end isearch mode transparently. |
241 ;; Make function keys, etc, exit the search. | 241 ;; We need these explicit definitions because, in a dense keymap, |
242 (define-key map [t] 'isearch-other-control-char) | 242 ;; the binding for t does not affect characters. |
243 ;; Control chars, by default, end isearch mode transparently. | 243 ;; We use a dense keymap to save space. |
244 ;; We need these explicit definitions because, in a dense keymap, | 244 (while (< i ?\ ) |
245 ;; the binding for t does not affect characters. | 245 (define-key map (make-string 1 i) 'isearch-other-control-char) |
246 ;; We use a dense keymap to save space. | 246 (setq i (1+ i))) |
247 (while (< i ?\ ) | 247 |
248 (define-key map (make-string 1 i) 'isearch-other-control-char) | 248 ;; Single-byte printing chars extend the search string by default. |
249 (setq i (1+ i))) | 249 (setq i ?\ ) |
250 | 250 (while (< i 256) |
251 ;; Single-byte printing chars extend the search string by default. | 251 (define-key map (vector i) 'isearch-printing-char) |
252 (setq i ?\ ) | 252 (setq i (1+ i))) |
253 (while (< i 256) | 253 |
254 (define-key map (vector i) 'isearch-printing-char) | 254 ;; To handle local bindings with meta char prefix keys, define |
255 (setq i (1+ i))) | 255 ;; another full keymap. This must be done for any other prefix |
256 | 256 ;; keys as well, one full keymap per char of the prefix key. It |
257 ;; To handle local bindings with meta char prefix keys, define | 257 ;; would be simpler to disable the global keymap, and/or have a |
258 ;; another full keymap. This must be done for any other prefix | 258 ;; default local key binding for any key not otherwise bound. |
259 ;; keys as well, one full keymap per char of the prefix key. It | 259 (let ((meta-map (make-sparse-keymap))) |
260 ;; would be simpler to disable the global keymap, and/or have a | 260 (define-key map (char-to-string meta-prefix-char) meta-map) |
261 ;; default local key binding for any key not otherwise bound. | 261 (define-key map [escape] meta-map)) |
262 (let ((meta-map (make-sparse-keymap))) | 262 (define-key map (vector meta-prefix-char t) 'isearch-other-meta-char) |
263 (define-key map (char-to-string meta-prefix-char) meta-map) | 263 |
264 (define-key map [escape] meta-map)) | 264 ;; Several non-printing chars change the searching behavior. |
265 (define-key map (vector meta-prefix-char t) 'isearch-other-meta-char) | 265 (define-key map "\C-s" 'isearch-repeat-forward) |
266 | 266 (define-key map "\C-r" 'isearch-repeat-backward) |
267 ;; Several non-printing chars change the searching behavior. | 267 ;; Define M-C-s and M-C-r like C-s and C-r so that the same key |
268 (define-key map "\C-s" 'isearch-repeat-forward) | 268 ;; combinations can be used to repeat regexp isearches that can |
269 (define-key map "\C-r" 'isearch-repeat-backward) | 269 ;; be used to start these searches. |
270 ;; Define M-C-s and M-C-r like C-s and C-r so that the same key | 270 (define-key map "\M-\C-s" 'isearch-repeat-forward) |
271 ;; combinations can be used to repeat regexp isearches that can | 271 (define-key map "\M-\C-r" 'isearch-repeat-backward) |
272 ;; be used to start these searches. | 272 (define-key map "\177" 'isearch-delete-char) |
273 (define-key map "\M-\C-s" 'isearch-repeat-forward) | 273 (define-key map "\C-g" 'isearch-abort) |
274 (define-key map "\M-\C-r" 'isearch-repeat-backward) | 274 ;; This assumes \e is the meta-prefix-char. |
275 (define-key map "\177" 'isearch-delete-char) | 275 (or (= ?\e meta-prefix-char) |
276 (define-key map "\C-g" 'isearch-abort) | 276 (error "Inconsistency in isearch.el")) |
277 ;; This assumes \e is the meta-prefix-char. | 277 (define-key map "\e\e\e" 'isearch-cancel) |
278 (or (= ?\e meta-prefix-char) | 278 (define-key map [escape escape escape] 'isearch-cancel) |
279 (error "Inconsistency in isearch.el")) | |
280 (define-key map "\e\e\e" 'isearch-cancel) | |
281 (define-key map [escape escape escape] 'isearch-cancel) | |
282 | 279 |
283 (define-key map "\C-q" 'isearch-quote-char) | 280 (define-key map "\C-q" 'isearch-quote-char) |
284 | 281 |
285 (define-key map "\r" 'isearch-exit) | 282 (define-key map "\r" 'isearch-exit) |
286 (define-key map "\C-j" 'isearch-printing-char) | 283 (define-key map "\C-j" 'isearch-printing-char) |
287 (define-key map "\t" 'isearch-printing-char) | 284 (define-key map "\t" 'isearch-printing-char) |
288 (define-key map " " 'isearch-whitespace-chars) | 285 (define-key map " " 'isearch-whitespace-chars) |
289 (define-key map [?\S-\ ] 'isearch-whitespace-chars) | 286 (define-key map [?\S-\ ] 'isearch-whitespace-chars) |
290 | 287 |
291 (define-key map "\C-w" 'isearch-yank-word) | 288 (define-key map "\C-w" 'isearch-yank-word) |
292 (define-key map "\C-y" 'isearch-yank-line) | 289 (define-key map "\C-y" 'isearch-yank-line) |
293 | 290 |
294 ;; Define keys for regexp chars * ? |. | 291 ;; Define keys for regexp chars * ? |. |
295 ;; Nothing special for + because it matches at least once. | 292 ;; Nothing special for + because it matches at least once. |
296 (define-key map "*" 'isearch-*-char) | 293 (define-key map "*" 'isearch-*-char) |
297 (define-key map "?" 'isearch-*-char) | 294 (define-key map "?" 'isearch-*-char) |
298 (define-key map "|" 'isearch-|-char) | 295 (define-key map "|" 'isearch-|-char) |
299 | 296 |
300 ;;; Turned off because I find I expect to get the global definition--rms. | 297 ;;; Turned off because I find I expect to get the global definition--rms. |
301 ;;; ;; Instead bind C-h to special help command for isearch-mode. | 298 ;;; ;; Instead bind C-h to special help command for isearch-mode. |
302 ;;; (define-key map "\C-h" 'isearch-mode-help) | 299 ;;; (define-key map "\C-h" 'isearch-mode-help) |
303 | 300 |
304 (define-key map "\M-n" 'isearch-ring-advance) | 301 (define-key map "\M-n" 'isearch-ring-advance) |
305 (define-key map "\M-p" 'isearch-ring-retreat) | 302 (define-key map "\M-p" 'isearch-ring-retreat) |
306 (define-key map "\M-y" 'isearch-yank-kill) | 303 (define-key map "\M-y" 'isearch-yank-kill) |
307 | 304 |
308 (define-key map "\M-\t" 'isearch-complete) | 305 (define-key map "\M-\t" 'isearch-complete) |
309 | 306 |
310 ;; Pass frame events transparently so they won't exit the search. | 307 ;; Pass frame events transparently so they won't exit the search. |
311 ;; In particular, if we have more than one display open, then a | 308 ;; In particular, if we have more than one display open, then a |
312 ;; switch-frame might be generated by someone typing at another keyboard. | 309 ;; switch-frame might be generated by someone typing at another keyboard. |
313 (define-key map [switch-frame] nil) | 310 (define-key map [switch-frame] nil) |
314 (define-key map [delete-frame] nil) | 311 (define-key map [delete-frame] nil) |
315 (define-key map [iconify-frame] nil) | 312 (define-key map [iconify-frame] nil) |
316 (define-key map [make-frame-visible] nil) | 313 (define-key map [make-frame-visible] nil) |
317 ;; For searching multilingual text. | 314 ;; For searching multilingual text. |
318 (define-key map "\C-\\" 'isearch-toggle-input-method) | 315 (define-key map "\C-\\" 'isearch-toggle-input-method) |
319 (define-key map "\C-^" 'isearch-toggle-specified-input-method) | 316 (define-key map "\C-^" 'isearch-toggle-specified-input-method) |
320 | 317 |
321 ;; People expect to be able to paste with the mouse. | 318 ;; People expect to be able to paste with the mouse. |
322 (define-key map [mouse-2] #'isearch-mouse-yank) | 319 (define-key map [mouse-2] #'isearch-mouse-yank) |
323 (define-key map [down-mouse-2] nil) | 320 (define-key map [down-mouse-2] nil) |
324 | 321 |
325 (setq isearch-mode-map map) | 322 ;; Some bindings you may want to put in your isearch-mode-hook. |
326 )) | 323 ;; Suggest some alternates... |
327 | 324 (define-key map "\M-c" 'isearch-toggle-case-fold) |
328 ;; Some bindings you may want to put in your isearch-mode-hook. | 325 (define-key map "\M-r" 'isearch-toggle-regexp) |
329 ;; Suggest some alternates... | 326 (define-key map "\M-e" 'isearch-edit-string) |
330 ;; (define-key isearch-mode-map "\C-t" 'isearch-toggle-case-fold) | 327 |
331 ;; (define-key isearch-mode-map "\C-t" 'isearch-toggle-regexp) | 328 map) |
332 ;; (define-key isearch-mode-map "\C-^" 'isearch-edit-string) | 329 "Keymap for `isearch-mode'.") |
333 | 330 |
334 | 331 (defvar minibuffer-local-isearch-map |
335 (defvar minibuffer-local-isearch-map nil | 332 (let ((map (make-sparse-keymap))) |
333 (set-keymap-parent map minibuffer-local-map) | |
334 (define-key map "\r" 'isearch-nonincremental-exit-minibuffer) | |
335 (define-key map "\M-n" 'isearch-ring-advance-edit) | |
336 (define-key map "\M-p" 'isearch-ring-retreat-edit) | |
337 (define-key map "\M-\t" 'isearch-complete-edit) | |
338 (define-key map "\C-s" 'isearch-forward-exit-minibuffer) | |
339 (define-key map "\C-r" 'isearch-reverse-exit-minibuffer) | |
340 map) | |
336 "Keymap for editing isearch strings in the minibuffer.") | 341 "Keymap for editing isearch strings in the minibuffer.") |
337 | |
338 (or minibuffer-local-isearch-map | |
339 (let ((map (copy-keymap minibuffer-local-map))) | |
340 (define-key map "\r" 'isearch-nonincremental-exit-minibuffer) | |
341 (define-key map "\M-n" 'isearch-ring-advance-edit) | |
342 (define-key map "\M-p" 'isearch-ring-retreat-edit) | |
343 (define-key map "\M-\t" 'isearch-complete-edit) | |
344 (define-key map "\C-s" 'isearch-forward-exit-minibuffer) | |
345 (define-key map "\C-r" 'isearch-reverse-exit-minibuffer) | |
346 (setq minibuffer-local-isearch-map map) | |
347 )) | |
348 | 342 |
349 ;; Internal variables declared globally for byte-compiler. | 343 ;; Internal variables declared globally for byte-compiler. |
350 ;; These are all set with setq while isearching | 344 ;; These are all set with setq while isearching |
351 ;; and bound locally while editing the search string. | 345 ;; and bound locally while editing the search string. |
352 | 346 |
923 isearch-message | 917 isearch-message |
924 (mapconcat 'isearch-text-char-description | 918 (mapconcat 'isearch-text-char-description |
925 isearch-string "")) | 919 isearch-string "")) |
926 ;; If already have what to search for, repeat it. | 920 ;; If already have what to search for, repeat it. |
927 (or isearch-success | 921 (or isearch-success |
928 (progn | 922 (progn |
929 (goto-char (if isearch-forward (point-min) (point-max))) | 923 (goto-char (if isearch-forward (point-min) (point-max))) |
930 (setq isearch-wrapped t)))) | 924 (setq isearch-wrapped t)))) |
931 ;; C-s in reverse or C-r in forward, change direction. | 925 ;; C-s in reverse or C-r in forward, change direction. |
932 (setq isearch-forward (not isearch-forward))) | 926 (setq isearch-forward (not isearch-forward))) |
933 | 927 |
1156 ;; exit and unread the key itself, so its global definition runs. | 1150 ;; exit and unread the key itself, so its global definition runs. |
1157 ;; Otherwise, unread the translation, | 1151 ;; Otherwise, unread the translation, |
1158 ;; so that the translated key takes effect within isearch. | 1152 ;; so that the translated key takes effect within isearch. |
1159 (cancel-kbd-macro-events) | 1153 (cancel-kbd-macro-events) |
1160 (if (lookup-key global-map key) | 1154 (if (lookup-key global-map key) |
1161 (progn | 1155 (progn |
1162 (isearch-done) | 1156 (isearch-done) |
1163 (apply 'isearch-unread keylist)) | 1157 (apply 'isearch-unread keylist)) |
1164 (setq keylist | 1158 (setq keylist |
1165 (listify-key-sequence (lookup-key function-key-map key))) | 1159 (listify-key-sequence (lookup-key function-key-map key))) |
1166 (while keylist | 1160 (while keylist |
1624 | 1618 |
1625 ;;; This is called when exiting isearch. It closes the temporary | 1619 ;;; This is called when exiting isearch. It closes the temporary |
1626 ;;; opened overlays, except the ones that contain the latest match. | 1620 ;;; opened overlays, except the ones that contain the latest match. |
1627 (defun isearch-clean-overlays () | 1621 (defun isearch-clean-overlays () |
1628 (when isearch-opened-overlays | 1622 (when isearch-opened-overlays |
1629 ;; Use a cycle instead of a mapcar here? | 1623 (mapc 'isearch-open-necessary-overlays isearch-opened-overlays) |
1630 (mapcar | |
1631 (function isearch-open-necessary-overlays) isearch-opened-overlays) | |
1632 (setq isearch-opened-overlays nil))) | 1624 (setq isearch-opened-overlays nil))) |
1633 | 1625 |
1634 ;;; Verify if the current match is outside of each element of | 1626 ;;; Verify if the current match is outside of each element of |
1635 ;;; `isearch-opened-overlays', if so close that overlay. | 1627 ;;; `isearch-opened-overlays', if so close that overlay. |
1636 (defun isearch-close-unecessary-overlays (begin end) | 1628 (defun isearch-close-unecessary-overlays (begin end) |
1648 (< end (overlay-end ov))))) | 1640 (< end (overlay-end ov))))) |
1649 ;; If this exists it means that the overlay was opened using | 1641 ;; If this exists it means that the overlay was opened using |
1650 ;; this function, not by us tweaking the overlay properties. | 1642 ;; this function, not by us tweaking the overlay properties. |
1651 (setq fct-temp (overlay-get ov 'isearch-open-invisible-temporary)) | 1643 (setq fct-temp (overlay-get ov 'isearch-open-invisible-temporary)) |
1652 (if inside-overlay | 1644 (if inside-overlay |
1653 (setq isearch-opened-overlays (cons ov isearch-opened-overlays)) | 1645 (setq isearch-opened-overlays (cons ov isearch-opened-overlays)) |
1654 (if fct-temp | 1646 (if fct-temp |
1655 (funcall fct-temp ov t) | 1647 (funcall fct-temp ov t) |
1656 (overlay-put ov 'invisible (overlay-get ov 'isearch-invisible)) | 1648 (overlay-put ov 'invisible (overlay-get ov 'isearch-invisible)) |
1657 (overlay-put ov 'intangible (overlay-get ov 'isearch-intangible)) | 1649 (overlay-put ov 'intangible (overlay-get ov 'isearch-intangible)) |
1658 (overlay-put ov 'isearch-invisible nil) | 1650 (overlay-put ov 'isearch-invisible nil) |
1717 (if (>= (point) end) | 1709 (if (>= (point) end) |
1718 (if (and (not (null can-be-opened)) (consp crt-overlays)) | 1710 (if (and (not (null can-be-opened)) (consp crt-overlays)) |
1719 (progn | 1711 (progn |
1720 (setq isearch-opened-overlays | 1712 (setq isearch-opened-overlays |
1721 (append isearch-opened-overlays crt-overlays)) | 1713 (append isearch-opened-overlays crt-overlays)) |
1722 ;; maybe use a cycle instead of mapcar? | 1714 (mapc 'isearch-open-overlay-temporary crt-overlays) |
1723 (mapcar (function isearch-open-overlay-temporary) | |
1724 crt-overlays) | |
1725 nil) | 1715 nil) |
1726 t)))))) | 1716 t)))))) |
1727 | 1717 |
1728 | 1718 |
1729 ;;; Highlighting | 1719 ;;; Highlighting |
1798 (t (char-to-string c)))) | 1788 (t (char-to-string c)))) |
1799 | 1789 |
1800 ;; General function to unread characters or events. | 1790 ;; General function to unread characters or events. |
1801 ;; Also insert them in a keyboard macro being defined. | 1791 ;; Also insert them in a keyboard macro being defined. |
1802 (defun isearch-unread (&rest char-or-events) | 1792 (defun isearch-unread (&rest char-or-events) |
1803 (mapcar 'store-kbd-macro-event char-or-events) | 1793 (mapc 'store-kbd-macro-event char-or-events) |
1804 (setq unread-command-events | 1794 (setq unread-command-events |
1805 (append char-or-events unread-command-events))) | 1795 (append char-or-events unread-command-events))) |
1806 | 1796 |
1807 | 1797 |
1808 ;;; isearch-lazy-highlight feature | 1798 ;;; isearch-lazy-highlight feature |
1909 (delete-overlay (car isearch-lazy-highlight-overlays)) | 1899 (delete-overlay (car isearch-lazy-highlight-overlays)) |
1910 (setq isearch-lazy-highlight-overlays | 1900 (setq isearch-lazy-highlight-overlays |
1911 (cdr isearch-lazy-highlight-overlays)))) | 1901 (cdr isearch-lazy-highlight-overlays)))) |
1912 | 1902 |
1913 (defun isearch-lazy-highlight-new-loop () | 1903 (defun isearch-lazy-highlight-new-loop () |
1914 "Cleanup any previous isearch-lazy-highlight loop and begin a new one. | 1904 "Cleanup any previous `isearch-lazy-highlight' loop and begin a new one. |
1915 This happens when `isearch-update' is invoked (which can cause the | 1905 This happens when `isearch-update' is invoked (which can cause the |
1916 search string to change)." | 1906 search string to change)." |
1917 (if (and isearch-lazy-highlight | 1907 (if (and isearch-lazy-highlight |
1918 (not (equal isearch-string isearch-lazy-highlight-last-string))) | 1908 (not (equal isearch-string isearch-lazy-highlight-last-string))) |
1919 ;; the search string did indeed change | 1909 ;; the search string did indeed change |