aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuri Linkov2013-10-09 02:20:12 +0300
committerJuri Linkov2013-10-09 02:20:12 +0300
commitb0949cc4c9edcfea541ad72ee5e7579fac7466e1 (patch)
treeb86ed3730e2b941d675a8532c83251a6a146231c
parent3b158d1150cbbffc77afef323008623ac5c3e169 (diff)
downloademacs-b0949cc4c9edcfea541ad72ee5e7579fac7466e1.tar.gz
emacs-b0949cc4c9edcfea541ad72ee5e7579fac7466e1.zip
* lisp/isearch.el (isearch-help-map, isearch-mode-map): Don't bind [t]
to isearch-other-control-char. (isearch-mode): Add isearch-pre-command-hook to pre-command-hook and isearch-post-command-hook to post-command-hook. (isearch-done): Remove isearch-pre-command-hook from pre-command-hook and isearch-post-command-hook from post-command-hook. (isearch-unread-key-sequence) (isearch-reread-key-sequence-naturally) (isearch-lookup-scroll-key, isearch-other-control-char) (isearch-other-meta-char): Remove functions. (isearch-pre-command-hook, isearch-post-command-hook): New functions based on isearch-other-meta-char rewritten relying on the new behavior of overriding-terminal-local-map that does not replace the local keymaps any more. Fixes: debbugs:15200
-rw-r--r--lisp/ChangeLog17
-rw-r--r--lisp/isearch.el277
2 files changed, 73 insertions, 221 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index e24ffa5893f..14d7b4f344c 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,20 @@
12013-10-08 Juri Linkov <juri@jurta.org>
2
3 * isearch.el (isearch-help-map, isearch-mode-map): Don't bind [t]
4 to isearch-other-control-char.
5 (isearch-mode): Add isearch-pre-command-hook to pre-command-hook
6 and isearch-post-command-hook to post-command-hook.
7 (isearch-done): Remove isearch-pre-command-hook from pre-command-hook
8 and isearch-post-command-hook from post-command-hook.
9 (isearch-unread-key-sequence)
10 (isearch-reread-key-sequence-naturally)
11 (isearch-lookup-scroll-key, isearch-other-control-char)
12 (isearch-other-meta-char): Remove functions.
13 (isearch-pre-command-hook, isearch-post-command-hook):
14 New functions based on isearch-other-meta-char rewritten
15 relying on the new behavior of overriding-terminal-local-map
16 that does not replace the local keymaps any more. (Bug#15200)
17
12013-10-08 Eli Zaretskii <eliz@gnu.org> 182013-10-08 Eli Zaretskii <eliz@gnu.org>
2 19
3 Support menus on text-mode terminals. 20 Support menus on text-mode terminals.
diff --git a/lisp/isearch.el b/lisp/isearch.el
index 131ab5893d4..09da9399bc8 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -349,7 +349,6 @@ A value of nil means highlight all matches."
349 349
350(defvar isearch-help-map 350(defvar isearch-help-map
351 (let ((map (make-sparse-keymap))) 351 (let ((map (make-sparse-keymap)))
352 (define-key map [t] 'isearch-other-control-char)
353 (define-key map (char-to-string help-char) 'isearch-help-for-help) 352 (define-key map (char-to-string help-char) 'isearch-help-for-help)
354 (define-key map [help] 'isearch-help-for-help) 353 (define-key map [help] 'isearch-help-for-help)
355 (define-key map [f1] 'isearch-help-for-help) 354 (define-key map [f1] 'isearch-help-for-help)
@@ -423,9 +422,6 @@ This is like `describe-bindings', but displays only Isearch keys."
423 ;; Make all multibyte characters search for themselves. 422 ;; Make all multibyte characters search for themselves.
424 (set-char-table-range (nth 1 map) (cons #x100 (max-char)) 423 (set-char-table-range (nth 1 map) (cons #x100 (max-char))
425 'isearch-printing-char) 424 'isearch-printing-char)
426 ;; Make function keys, etc, which aren't bound to a scrolling-function
427 ;; exit the search.
428 (define-key map [t] 'isearch-other-control-char)
429 425
430 ;; Single-byte printing chars extend the search string by default. 426 ;; Single-byte printing chars extend the search string by default.
431 (setq i ?\s) 427 (setq i ?\s)
@@ -440,8 +436,7 @@ This is like `describe-bindings', but displays only Isearch keys."
440 ;; default local key binding for any key not otherwise bound. 436 ;; default local key binding for any key not otherwise bound.
441 (let ((meta-map (make-sparse-keymap))) 437 (let ((meta-map (make-sparse-keymap)))
442 (define-key map (char-to-string meta-prefix-char) meta-map) 438 (define-key map (char-to-string meta-prefix-char) meta-map)
443 (define-key map [escape] meta-map) 439 (define-key map [escape] meta-map))
444 (define-key meta-map [t] 'isearch-other-meta-char))
445 440
446 ;; Several non-printing chars change the searching behavior. 441 ;; Several non-printing chars change the searching behavior.
447 (define-key map "\C-s" 'isearch-repeat-forward) 442 (define-key map "\C-s" 'isearch-repeat-forward)
@@ -521,9 +516,6 @@ This is like `describe-bindings', but displays only Isearch keys."
521 516
522 ;; The key translations defined in the C-x 8 prefix should add 517 ;; The key translations defined in the C-x 8 prefix should add
523 ;; characters to the search string. See iso-transl.el. 518 ;; characters to the search string. See iso-transl.el.
524 (define-key map "\C-x" nil)
525 (define-key map [?\C-x t] 'isearch-other-control-char)
526 (define-key map "\C-x8" nil)
527 (define-key map "\C-x8\r" 'isearch-char-by-name) 519 (define-key map "\C-x8\r" 'isearch-char-by-name)
528 520
529 map) 521 map)
@@ -920,6 +912,8 @@ convert the search string to a regexp used by regexp search functions."
920 912
921 (isearch-update) 913 (isearch-update)
922 914
915 (add-hook 'pre-command-hook 'isearch-pre-command-hook nil t)
916 (add-hook 'post-command-hook 'isearch-post-command-hook nil t)
923 (add-hook 'mouse-leave-buffer-hook 'isearch-done) 917 (add-hook 'mouse-leave-buffer-hook 'isearch-done)
924 (add-hook 'kbd-macro-termination-hook 'isearch-done) 918 (add-hook 'kbd-macro-termination-hook 'isearch-done)
925 919
@@ -998,6 +992,8 @@ NOPUSH is t and EDIT is t."
998 (unless (equal (car command-history) command) 992 (unless (equal (car command-history) command)
999 (setq command-history (cons command command-history))))) 993 (setq command-history (cons command command-history)))))
1000 994
995 (remove-hook 'pre-command-hook 'isearch-pre-command-hook t)
996 (remove-hook 'post-command-hook 'isearch-post-command-hook t)
1001 (remove-hook 'mouse-leave-buffer-hook 'isearch-done) 997 (remove-hook 'mouse-leave-buffer-hook 'isearch-done)
1002 (remove-hook 'kbd-macro-termination-hook 'isearch-done) 998 (remove-hook 'kbd-macro-termination-hook 'isearch-done)
1003 (setq isearch-lazy-highlight-start nil) 999 (setq isearch-lazy-highlight-start nil)
@@ -2100,26 +2096,6 @@ to the barrier."
2100 (min last-other-end isearch-barrier))) 2096 (min last-other-end isearch-barrier)))
2101 (setq isearch-adjusted t))))))) 2097 (setq isearch-adjusted t)))))))
2102 2098
2103(defun isearch-unread-key-sequence (keylist)
2104 "Unread the given key-sequence KEYLIST.
2105Scroll-bar or mode-line events are processed appropriately."
2106 (cancel-kbd-macro-events)
2107 (apply 'isearch-unread keylist)
2108 ;; If the event was a scroll-bar or mode-line click, the event will have
2109 ;; been prefixed by a symbol such as vertical-scroll-bar. We must remove
2110 ;; it here, because this symbol will be attached to the event again next
2111 ;; time it gets read by read-key-sequence.
2112 ;;
2113 ;; (Old comment from isearch-other-meta-char: "Note that we don't have to
2114 ;; modify the event anymore in 21 because read_key_sequence no longer
2115 ;; modifies events to produce fake prefix keys.")
2116 (if (and (> (length keylist) 1)
2117 (symbolp (car keylist))
2118 (listp (cadr keylist))
2119 (not (numberp (posn-point
2120 (event-start (cadr keylist) )))))
2121 (pop unread-command-events)))
2122
2123;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 2099;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2124;; scrolling within Isearch mode. Alan Mackenzie (acm@muc.de), 2003/2/24 2100;; scrolling within Isearch mode. Alan Mackenzie (acm@muc.de), 2003/2/24
2125;; 2101;;
@@ -2244,198 +2220,57 @@ the bottom."
2244 (recenter 0)))) 2220 (recenter 0))))
2245 (goto-char isearch-point)) 2221 (goto-char isearch-point))
2246 2222
2247(defun isearch-reread-key-sequence-naturally (keylist) 2223(defvar isearch-pre-scroll-point nil)
2248 "Reread key sequence KEYLIST with an inactive Isearch-mode keymap. 2224
2249Return the key sequence as a string/vector." 2225(defun isearch-pre-command-hook ()
2250 (isearch-unread-key-sequence keylist) 2226 "Decide whether to exit Isearch mode before executing the command.
2251 (let (overriding-terminal-local-map) 2227Don't exit Isearch if the key sequence that invoked this command
2252 ;; This will go through function-key-map, if nec. 2228is bound in `isearch-mode-map', or if the invoked command is
2253 ;; The arg DONT-DOWNCASE-LAST prevents premature shift-translation. 2229a prefix argument command (when `isearch-allow-prefix' is non-nil),
2254 (read-key-sequence nil nil t))) 2230or it is a scrolling command (when `isearch-allow-scroll' is non-nil).
2255 2231Otherwise, exit Isearch (when `search-exit-option' is non-nil)
2256(defun isearch-lookup-scroll-key (key-seq) 2232before the command is executed globally with terminated Isearch."
2257 "If KEY-SEQ is bound to a scrolling command, return it as a symbol. 2233 (let* ((key (this-command-keys))
2258Otherwise return nil." 2234 (main-event (aref key 0)))
2259 (let* ((overriding-terminal-local-map nil) 2235 (cond
2260 (binding (key-binding key-seq))) 2236 ;; Don't exit Isearch for isearch key bindings.
2261 (and binding (symbolp binding) (commandp binding) 2237 ;; FIXME: remove prefix arg to lookup key without prefix.
2262 (or (eq (get binding 'isearch-scroll) t) 2238 ((commandp (lookup-key isearch-mode-map key nil)))
2263 (eq (get binding 'scroll-command) t)) 2239 ;; Optionally edit the search string instead of exiting.
2264 binding))) 2240 ((eq search-exit-option 'edit)
2265 2241 (setq this-command 'isearch-edit-string))
2266(defalias 'isearch-other-control-char 'isearch-other-meta-char) 2242 ;; Handle a scrolling function or prefix argument.
2267 2243 ((or (and isearch-allow-prefix
2268(defun isearch-other-meta-char (&optional arg) 2244 (memq this-command '(universal-argument
2269 "Process a miscellaneous key sequence in Isearch mode. 2245 negative-argument
2270 2246 digit-argument)))
2271Try to convert the current key-sequence to something usable in Isearch 2247 (and isearch-allow-scroll
2272mode, either by converting it with `function-key-map', downcasing a 2248 (or (eq (get this-command 'isearch-scroll) t)
2273key with C-<upper case>, or finding a \"scrolling command\" bound to 2249 (eq (get this-command 'scroll-command) t))))
2274it. \(In the last case, we may have to read more events.) If so, 2250 (when isearch-allow-scroll
2275either unread the converted sequence or execute the command. 2251 (setq isearch-pre-scroll-point (point))))
2276 2252 ;; A mouse click on the isearch message starts editing the search string.
2277Otherwise, if `search-exit-option' is non-nil (the default) unread the 2253 ((and (eq (car-safe main-event) 'down-mouse-1)
2278key-sequence and exit the search normally. If it is the symbol 2254 (window-minibuffer-p (posn-window (event-start main-event))))
2279`edit', the search string is edited in the minibuffer and the meta 2255 ;; Swallow the up-event.
2280character is unread so that it applies to editing the string. 2256 (read-event)
2281 2257 (setq this-command 'isearch-edit-string))
2282ARG is the prefix argument. It will be transmitted through to the 2258 ;; Other characters terminate the search and are then executed normally.
2283scrolling command or to the command whose key-sequence exits 2259 (search-exit-option
2284Isearch mode." 2260 (isearch-done)
2285 (interactive "P") 2261 (isearch-clean-overlays))
2286 (let* ((key (if current-prefix-arg ; not nec the same as ARG 2262 ;; If search-exit-option is nil, run the command without exiting Isearch.
2287 (substring (this-command-keys) universal-argument-num-events) 2263 (t
2288 (this-command-keys))) 2264 (isearch-process-search-string key key)))))
2289 (main-event (aref key 0)) 2265
2290 (keylist (listify-key-sequence key)) 2266(defun isearch-post-command-hook ()
2291 scroll-command isearch-point) 2267 (when isearch-pre-scroll-point
2292 (cond ((and (= (length key) 1) 2268 (let ((ab-bel (isearch-string-out-of-window isearch-pre-scroll-point)))
2293 (let ((lookup (lookup-key local-function-key-map key))) 2269 (if ab-bel
2294 (not (or (null lookup) (integerp lookup) 2270 (isearch-back-into-window (eq ab-bel 'above) isearch-pre-scroll-point)
2295 (keymapp lookup))))) 2271 (goto-char isearch-pre-scroll-point)))
2296 ;; Handle a function key that translates into something else. 2272 (setq isearch-pre-scroll-point nil)
2297 ;; If the key has a global definition too, 2273 (isearch-update)))
2298 ;; exit and unread the key itself, so its global definition runs.
2299 ;; Otherwise, unread the translation,
2300 ;; so that the translated key takes effect within isearch.
2301 (cancel-kbd-macro-events)
2302 (if (lookup-key global-map key)
2303 (progn
2304 (isearch-done)
2305 (setq prefix-arg arg)
2306 (apply 'isearch-unread keylist))
2307 (setq keylist
2308 (listify-key-sequence
2309 (lookup-key local-function-key-map key)))
2310 (while keylist
2311 (setq key (car keylist))
2312 ;; Handle an undefined shifted printing character
2313 ;; by downshifting it if that makes it printing.
2314 ;; (As read-key-sequence would normally do,
2315 ;; if we didn't have a default definition.)
2316 (if (and (integerp key)
2317 (memq 'shift (event-modifiers key))
2318 (>= key (+ ?\s (- ?\S-a ?a)))
2319 (/= key (+ 127 (- ?\S-a ?a)))
2320 (< key (+ 256 (- ?\S-a ?a))))
2321 (setq key (- key (- ?\S-a ?a))))
2322 ;; If KEY is a printing char, we handle it here
2323 ;; directly to avoid the input method and keyboard
2324 ;; coding system translating it.
2325 (if (and (integerp key)
2326 (>= key ?\s) (/= key 127) (< key 256))
2327 (progn
2328 ;; Ensure that the processed char is recorded in
2329 ;; the keyboard macro, if any (Bug#4894)
2330 (store-kbd-macro-event key)
2331 (isearch-process-search-char key)
2332 (setq keylist (cdr keylist)))
2333 ;; As the remaining keys in KEYLIST can't be handled
2334 ;; here, we must reread them.
2335 (setq prefix-arg arg)
2336 (apply 'isearch-unread keylist)
2337 (setq keylist nil)))))
2338 (
2339 ;; Handle an undefined shifted control character
2340 ;; by downshifting it if that makes it defined.
2341 ;; (As read-key-sequence would normally do,
2342 ;; if we didn't have a default definition.)
2343 (let ((mods (event-modifiers main-event)))
2344 (and (integerp main-event)
2345 (memq 'shift mods)
2346 (memq 'control mods)
2347 (not (memq (lookup-key isearch-mode-map
2348 (let ((copy (copy-sequence key)))
2349 (aset copy 0
2350 (- main-event
2351 (- ?\C-\S-a ?\C-a)))
2352 copy)
2353 nil)
2354 '(nil
2355 isearch-other-control-char)))))
2356 (setcar keylist (- main-event (- ?\C-\S-a ?\C-a)))
2357 (cancel-kbd-macro-events)
2358 (setq prefix-arg arg)
2359 (apply 'isearch-unread keylist))
2360 ((eq search-exit-option 'edit)
2361 (setq prefix-arg arg)
2362 (apply 'isearch-unread keylist)
2363 (isearch-edit-string))
2364 ;; Handle a scrolling function or prefix argument.
2365 ((progn
2366 (setq key (isearch-reread-key-sequence-naturally keylist)
2367 keylist (listify-key-sequence key)
2368 main-event (aref key 0))
2369 (or (and isearch-allow-scroll
2370 (setq scroll-command (isearch-lookup-scroll-key key)))
2371 (and isearch-allow-prefix
2372 (let (overriding-terminal-local-map)
2373 (setq scroll-command (key-binding key))
2374 (memq scroll-command
2375 '(universal-argument
2376 negative-argument digit-argument))))))
2377 ;; From this point onwards, KEY, KEYLIST and MAIN-EVENT hold a
2378 ;; complete key sequence, possibly as modified by function-key-map,
2379 ;; not merely the one or two event fragment which invoked
2380 ;; isearch-other-meta-char in the first place.
2381 (setq isearch-point (point))
2382 (setq prefix-arg arg)
2383 (command-execute scroll-command)
2384 (let ((ab-bel (isearch-string-out-of-window isearch-point)))
2385 (if ab-bel
2386 (isearch-back-into-window (eq ab-bel 'above) isearch-point)
2387 (goto-char isearch-point)))
2388 (isearch-update))
2389 ;; A mouse click on the isearch message starts editing the search string
2390 ((and (eq (car-safe main-event) 'down-mouse-1)
2391 (window-minibuffer-p (posn-window (event-start main-event))))
2392 ;; Swallow the up-event.
2393 (read-event)
2394 (isearch-edit-string))
2395 (search-exit-option
2396 (let (window)
2397 (setq prefix-arg arg)
2398 (isearch-unread-key-sequence keylist)
2399 (setq main-event (car unread-command-events))
2400
2401 ;; Don't store special commands in the keyboard macro.
2402 (let (overriding-terminal-local-map)
2403 (when (memq (key-binding key)
2404 '(kmacro-start-macro
2405 kmacro-end-macro kmacro-end-and-call-macro))
2406 (cancel-kbd-macro-events)))
2407
2408 ;; If we got a mouse click event, that event contains the
2409 ;; window clicked on. maybe it was read with the buffer
2410 ;; it was clicked on. If so, that buffer, not the current one,
2411 ;; is in isearch mode. So end the search in that buffer.
2412
2413 ;; ??? I have no idea what this if checks for, but it's
2414 ;; obviously wrong for the case that a down-mouse event
2415 ;; on another window invokes this function. The event
2416 ;; will contain the window clicked on and that window's
2417 ;; buffer is certainly not always in Isearch mode.
2418 ;;
2419 ;; Leave the code in, but check for current buffer not
2420 ;; being in Isearch mode for now, until someone tells
2421 ;; what it's really supposed to do.
2422 ;;
2423 ;; --gerd 2001-08-10.
2424
2425 (if (and (not isearch-mode)
2426 (listp main-event)
2427 (setq window (posn-window (event-start main-event)))
2428 (windowp window)
2429 (or (> (minibuffer-depth) 0)
2430 (not (window-minibuffer-p window))))
2431 (with-current-buffer (window-buffer window)
2432 (isearch-done)
2433 (isearch-clean-overlays))
2434 (isearch-done)
2435 (isearch-clean-overlays)
2436 (setq prefix-arg arg))))
2437 (t;; otherwise nil
2438 (isearch-process-search-string key key)))))
2439 2274
2440(defun isearch-quote-char (&optional count) 2275(defun isearch-quote-char (&optional count)
2441 "Quote special characters for incremental search. 2276 "Quote special characters for incremental search.