From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#15200: isearch-other-meta-char and shift Date: Tue, 17 Sep 2013 01:09:36 +0300 Organization: JURTA Message-ID: <87txhko1mb.fsf@mail.jurta.org> References: <8761urkssh.fsf@mail.jurta.org> <87fvtvgk00.fsf@mail.jurta.org> <877gf5rcoz.fsf@mail.jurta.org> <87wqn53sac.fsf@mail.jurta.org> <87vc2k7556.fsf@mail.jurta.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1379369927 14643 80.91.229.3 (16 Sep 2013 22:18:47 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 16 Sep 2013 22:18:47 +0000 (UTC) Cc: 15200@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Sep 17 00:18:49 2013 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1VLh84-0000cD-Be for geb-bug-gnu-emacs@m.gmane.org; Tue, 17 Sep 2013 00:18:48 +0200 Original-Received: from localhost ([::1]:37279 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VLh83-0005FU-Tv for geb-bug-gnu-emacs@m.gmane.org; Mon, 16 Sep 2013 18:18:47 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44762) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VLh7O-0004Sa-Uj for bug-gnu-emacs@gnu.org; Mon, 16 Sep 2013 18:18:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VLh7K-0002lU-5I for bug-gnu-emacs@gnu.org; Mon, 16 Sep 2013 18:18:06 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:33747) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VLh7K-0002lQ-14 for bug-gnu-emacs@gnu.org; Mon, 16 Sep 2013 18:18:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1VLh7J-0005vY-NM for bug-gnu-emacs@gnu.org; Mon, 16 Sep 2013 18:18:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 16 Sep 2013 22:18:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 15200 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 15200-submit@debbugs.gnu.org id=B15200.137936983422726 (code B ref 15200); Mon, 16 Sep 2013 22:18:01 +0000 Original-Received: (at 15200) by debbugs.gnu.org; 16 Sep 2013 22:17:14 +0000 Original-Received: from localhost ([127.0.0.1]:42038 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VLh6W-0005uT-PO for submit@debbugs.gnu.org; Mon, 16 Sep 2013 18:17:13 -0400 Original-Received: from ps18281.dreamhost.com ([69.163.218.105]:41970 helo=ps18281.dreamhostps.com) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VLh6S-0005uF-UO for 15200@debbugs.gnu.org; Mon, 16 Sep 2013 18:17:10 -0400 Original-Received: from localhost.jurta.org (ps18281.dreamhostps.com [69.163.218.105]) by ps18281.dreamhostps.com (Postfix) with ESMTP id DECBE258B9E935; Mon, 16 Sep 2013 15:17:06 -0700 (PDT) In-Reply-To: (Stefan Monnier's message of "Mon, 02 Sep 2013 22:12:14 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (x86_64-pc-linux-gnu) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:78471 Archived-At: >> Surprisingly, I see no problems with this approach. > > Oh, right without using set-temporary-overlay-map at all, but only > relying on the new behavior of overriding-terminal-local-map. > Yes, that should work fine. set-temporary-overlay-map could be added later too if possible. >> + (cond ((lookup-key isearch-mode-map key nil)) >> + ((and (= (length key) 1) >> (let ((lookup (lookup-key local-function-key-map key))) >> (not (or (null lookup) (integerp lookup) >> (keymapp lookup))))) > > We should not need to consider local-function-key-map any more. Maybe I'm missing something, but it seems working without local-function-key-map and without much of other legacy code. Also I removed `universal-argument-num-events' in the patch, but now typing: `C-s C-3 C-l' doubles the arg 3 in prefix-arg to 33, `C-s C-4 C-l' doubles the arg 4 in prefix-arg to 44, etc. This happens after this code: (memq scroll-command '(universal-argument negative-argument digit-argument)))))) (command-execute scroll-command) Perhaps `command-execute' should be removed here. It's not yet removed in this patch since I'm not sure because after moving its post-processing code: (let ((ab-bel (isearch-string-out-of-window isearch-point))) (if ab-bel (isearch-back-into-window (eq ab-bel 'above) isearch-point) (goto-char isearch-point))) to `post-command-hook' will make impossible to use later `set-temporary-overlay-map' (that doesn't use `post-command-hook' but maybe this is not a problem). === modified file 'lisp/isearch.el' --- lisp/isearch.el 2013-08-28 16:39:51 +0000 +++ lisp/isearch.el 2013-09-16 22:08:10 +0000 @@ -349,7 +349,6 @@ (defvar lazy-highlight-face 'lazy-highli (defvar isearch-help-map (let ((map (make-sparse-keymap))) - (define-key map [t] 'isearch-other-control-char) (define-key map (char-to-string help-char) 'isearch-help-for-help) (define-key map [help] 'isearch-help-for-help) (define-key map [f1] 'isearch-help-for-help) @@ -423,9 +422,6 @@ (defvar isearch-mode-map ;; Make all multibyte characters search for themselves. (set-char-table-range (nth 1 map) (cons #x100 (max-char)) 'isearch-printing-char) - ;; Make function keys, etc, which aren't bound to a scrolling-function - ;; exit the search. - (define-key map [t] 'isearch-other-control-char) ;; Single-byte printing chars extend the search string by default. (setq i ?\s) @@ -440,8 +436,7 @@ (defvar isearch-mode-map ;; default local key binding for any key not otherwise bound. (let ((meta-map (make-sparse-keymap))) (define-key map (char-to-string meta-prefix-char) meta-map) - (define-key map [escape] meta-map) - (define-key meta-map [t] 'isearch-other-meta-char)) + (define-key map [escape] meta-map)) ;; Several non-printing chars change the searching behavior. (define-key map "\C-s" 'isearch-repeat-forward) @@ -521,9 +516,6 @@ (defvar isearch-mode-map ;; The key translations defined in the C-x 8 prefix should add ;; characters to the search string. See iso-transl.el. - (define-key map "\C-x" nil) - (define-key map [?\C-x t] 'isearch-other-control-char) - (define-key map "\C-x8" nil) (define-key map "\C-x8\r" 'isearch-char-by-name) map) @@ -920,6 +912,7 @@ (defun isearch-mode (forward &optional r (isearch-update) + (add-hook 'pre-command-hook 'isearch-mode-keep-pred) (add-hook 'mouse-leave-buffer-hook 'isearch-done) (add-hook 'kbd-macro-termination-hook 'isearch-done) @@ -998,6 +991,7 @@ (defun isearch-done (&optional nopush ed (unless (equal (car command-history) command) (setq command-history (cons command command-history))))) + (remove-hook 'pre-command-hook 'isearch-mode-keep-pred) (remove-hook 'mouse-leave-buffer-hook 'isearch-done) (remove-hook 'kbd-macro-termination-hook 'isearch-done) (setq isearch-lazy-highlight-start nil) @@ -2100,26 +2094,6 @@ (defun isearch-fallback (want-backslash (min last-other-end isearch-barrier))) (setq isearch-adjusted t))))))) -(defun isearch-unread-key-sequence (keylist) - "Unread the given key-sequence KEYLIST. -Scroll-bar or mode-line events are processed appropriately." - (cancel-kbd-macro-events) - (apply 'isearch-unread keylist) - ;; If the event was a scroll-bar or mode-line click, the event will have - ;; been prefixed by a symbol such as vertical-scroll-bar. We must remove - ;; it here, because this symbol will be attached to the event again next - ;; time it gets read by read-key-sequence. - ;; - ;; (Old comment from isearch-other-meta-char: "Note that we don't have to - ;; modify the event anymore in 21 because read_key_sequence no longer - ;; modifies events to produce fake prefix keys.") - (if (and (> (length keylist) 1) - (symbolp (car keylist)) - (listp (cadr keylist)) - (not (numberp (posn-point - (event-start (cadr keylist) ))))) - (pop unread-command-events))) - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; scrolling within Isearch mode. Alan Mackenzie (acm@muc.de), 2003/2/24 ;; @@ -2244,15 +2218,6 @@ (defun isearch-back-into-window (above i (recenter 0)))) (goto-char isearch-point)) -(defun isearch-reread-key-sequence-naturally (keylist) - "Reread key sequence KEYLIST with an inactive Isearch-mode keymap. -Return the key sequence as a string/vector." - (isearch-unread-key-sequence keylist) - (let (overriding-terminal-local-map) - ;; This will go through function-key-map, if nec. - ;; The arg DONT-DOWNCASE-LAST prevents premature shift-translation. - (read-key-sequence nil nil t))) - (defun isearch-lookup-scroll-key (key-seq) "If KEY-SEQ is bound to a scrolling command, return it as a symbol. Otherwise return nil." @@ -2263,109 +2228,16 @@ (defun isearch-lookup-scroll-key (key-se (eq (get binding 'scroll-command) t)) binding))) -(defalias 'isearch-other-control-char 'isearch-other-meta-char) - -(defun isearch-other-meta-char (&optional arg) - "Process a miscellaneous key sequence in Isearch mode. - -Try to convert the current key-sequence to something usable in Isearch -mode, either by converting it with `function-key-map', downcasing a -key with C-, or finding a \"scrolling command\" bound to -it. \(In the last case, we may have to read more events.) If so, -either unread the converted sequence or execute the command. - -Otherwise, if `search-exit-option' is non-nil (the default) unread the -key-sequence and exit the search normally. If it is the symbol -`edit', the search string is edited in the minibuffer and the meta -character is unread so that it applies to editing the string. - -ARG is the prefix argument. It will be transmitted through to the -scrolling command or to the command whose key-sequence exits -Isearch mode." - (interactive "P") - (let* ((key (if current-prefix-arg ; not nec the same as ARG - (substring (this-command-keys) universal-argument-num-events) - (this-command-keys))) +(defun isearch-mode-keep-pred () + (let* ((key (this-command-keys)) (main-event (aref key 0)) (keylist (listify-key-sequence key)) scroll-command isearch-point) - (cond ((and (= (length key) 1) - (let ((lookup (lookup-key local-function-key-map key))) - (not (or (null lookup) (integerp lookup) - (keymapp lookup))))) - ;; Handle a function key that translates into something else. - ;; If the key has a global definition too, - ;; exit and unread the key itself, so its global definition runs. - ;; Otherwise, unread the translation, - ;; so that the translated key takes effect within isearch. - (cancel-kbd-macro-events) - (if (lookup-key global-map key) - (progn - (isearch-done) - (setq prefix-arg arg) - (apply 'isearch-unread keylist)) - (setq keylist - (listify-key-sequence - (lookup-key local-function-key-map key))) - (while keylist - (setq key (car keylist)) - ;; Handle an undefined shifted printing character - ;; by downshifting it if that makes it printing. - ;; (As read-key-sequence would normally do, - ;; if we didn't have a default definition.) - (if (and (integerp key) - (memq 'shift (event-modifiers key)) - (>= key (+ ?\s (- ?\S-a ?a))) - (/= key (+ 127 (- ?\S-a ?a))) - (< key (+ 256 (- ?\S-a ?a)))) - (setq key (- key (- ?\S-a ?a)))) - ;; If KEY is a printing char, we handle it here - ;; directly to avoid the input method and keyboard - ;; coding system translating it. - (if (and (integerp key) - (>= key ?\s) (/= key 127) (< key 256)) - (progn - ;; Ensure that the processed char is recorded in - ;; the keyboard macro, if any (Bug#4894) - (store-kbd-macro-event key) - (isearch-process-search-char key) - (setq keylist (cdr keylist))) - ;; As the remaining keys in KEYLIST can't be handled - ;; here, we must reread them. - (setq prefix-arg arg) - (apply 'isearch-unread keylist) - (setq keylist nil))))) - ( - ;; Handle an undefined shifted control character - ;; by downshifting it if that makes it defined. - ;; (As read-key-sequence would normally do, - ;; if we didn't have a default definition.) - (let ((mods (event-modifiers main-event))) - (and (integerp main-event) - (memq 'shift mods) - (memq 'control mods) - (not (memq (lookup-key isearch-mode-map - (let ((copy (copy-sequence key))) - (aset copy 0 - (- main-event - (- ?\C-\S-a ?\C-a))) - copy) - nil) - '(nil - isearch-other-control-char))))) - (setcar keylist (- main-event (- ?\C-\S-a ?\C-a))) - (cancel-kbd-macro-events) - (setq prefix-arg arg) - (apply 'isearch-unread keylist)) + (cond ((lookup-key isearch-mode-map key nil)) ((eq search-exit-option 'edit) - (setq prefix-arg arg) - (apply 'isearch-unread keylist) (isearch-edit-string)) ;; Handle a scrolling function or prefix argument. ((progn - (setq key (isearch-reread-key-sequence-naturally keylist) - keylist (listify-key-sequence key) - main-event (aref key 0)) (or (and isearch-allow-scroll (setq scroll-command (isearch-lookup-scroll-key key))) (and isearch-allow-prefix @@ -2374,12 +2246,7 @@ (defun isearch-other-meta-char (&optiona (memq scroll-command '(universal-argument negative-argument digit-argument)))))) - ;; From this point onwards, KEY, KEYLIST and MAIN-EVENT hold a - ;; complete key sequence, possibly as modified by function-key-map, - ;; not merely the one or two event fragment which invoked - ;; isearch-other-meta-char in the first place. (setq isearch-point (point)) - (setq prefix-arg arg) (command-execute scroll-command) (let ((ab-bel (isearch-string-out-of-window isearch-point))) (if ab-bel @@ -2394,16 +2261,6 @@ (defun isearch-other-meta-char (&optiona (isearch-edit-string)) (search-exit-option (let (window) - (setq prefix-arg arg) - (isearch-unread-key-sequence keylist) - (setq main-event (car unread-command-events)) - - ;; Don't store special commands in the keyboard macro. - (let (overriding-terminal-local-map) - (when (memq (key-binding key) - '(kmacro-start-macro - kmacro-end-macro kmacro-end-and-call-macro)) - (cancel-kbd-macro-events))) ;; If we got a mouse click event, that event contains the ;; window clicked on. maybe it was read with the buffer @@ -2432,8 +2289,7 @@ (defun isearch-other-meta-char (&optiona (isearch-done) (isearch-clean-overlays)) (isearch-done) - (isearch-clean-overlays) - (setq prefix-arg arg)))) + (isearch-clean-overlays)))) (t;; otherwise nil (isearch-process-search-string key key)))))