unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@jurta.org>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 15200@debbugs.gnu.org
Subject: bug#15200: isearch-other-meta-char and shift
Date: Sun, 01 Sep 2013 21:45:09 +0300	[thread overview]
Message-ID: <87vc2k7556.fsf@mail.jurta.org> (raw)
In-Reply-To: <jwvtxi8znlp.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Thu, 29 Aug 2013 08:30:52 -0400")

>> Maybe the arg KEEP-PRED set-temporary-overlay-map
>> can be used to decide whether to exit Isearch and
>> apply the key sequence to global keymaps?
>
> Of course:
>
>    KEEP-PRED can also be a function of no arguments: if it returns
>    non-nil then MAP stays active.
>
> KEEP-PRED is run in pre-command-hook, so it can check this-command.

Surprisingly, I see no problems with this approach.
First I tried to implement the logic of KEEP-PRED
without using set-temporary-overlay-map, i.e.
by adding a new function isearch-mode-keep-pred
to pre-command-hook.  isearch-mode-keep-pred is created
from isearch-other-meta-char by removing all re-reading,
and adding a new condition

  ((lookup-key isearch-mode-map key nil))

to not exit Isearch mode for Isearch key bindings.
Otherwise, Isearch mode is exited by isearch-done
and this-command is executed in global context.

Later isearch-mode-keep-pred could be further simplified,
e.g. instead of calling command-execute for
isearch-allow-scroll, it could pass execution
to global key binding and add isearch post-processing
of isearch-back-into-window to post-command-hook, etc.

=== modified file 'lisp/isearch.el'
--- lisp/isearch.el	2013-08-28 16:39:51 +0000
+++ lisp/isearch.el	2013-09-01 18:42:04 +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,47 +2228,25 @@ (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-<upper case>, 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")
+(defun isearch-mode-keep-pred ()
   (let* ((key (if current-prefix-arg    ; not nec the same as ARG
                   (substring (this-command-keys) universal-argument-num-events)
                 (this-command-keys)))
 	 (main-event (aref key 0))
 	 (keylist (listify-key-sequence key))
          scroll-command isearch-point)
-    (cond ((and (= (length key) 1)
+    (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)))))
 	   ;; 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)
+	   ;; exit, so its global definition runs.
+	   ;; Otherwise, translated key takes effect within isearch.
 	   (if (lookup-key global-map key)
 	       (progn
-		 (isearch-done)
-		 (setq prefix-arg arg)
-		 (apply 'isearch-unread keylist))
+		 (isearch-done))
 	     (setq keylist
 		   (listify-key-sequence
 		    (lookup-key local-function-key-map key)))
@@ -2311,8 +2254,6 @@ (defun isearch-other-meta-char (&optiona
 	       (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)))
@@ -2331,15 +2272,11 @@ (defun isearch-other-meta-char (&optiona
 		     (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)))))
+		 ;; here, exit.
+		 (isearch-done)))))
 	  (
 	   ;; 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)
@@ -2352,20 +2289,13 @@ (defun isearch-other-meta-char (&optiona
 					   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))
+	   (isearch-done))
 	  ((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 +2304,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 +2319,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 +2347,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)))))
 





  reply	other threads:[~2013-09-01 18:45 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-27 16:28 bug#15200: isearch-other-meta-char and shift Juri Linkov
2013-08-27 16:45 ` Juri Linkov
2013-08-28  0:27   ` Stefan Monnier
2013-08-28 16:42     ` Juri Linkov
2013-08-28 18:33       ` Stefan Monnier
2013-08-29  6:49         ` Juri Linkov
2013-08-29 12:30           ` Stefan Monnier
2013-09-01 18:45             ` Juri Linkov [this message]
2013-09-03  2:12               ` Stefan Monnier
2013-09-03  2:22                 ` Drew Adams
2013-09-16 22:09                 ` Juri Linkov
2013-09-17  1:21                   ` Stefan Monnier
2013-09-17  2:19                   ` Stefan Monnier
2013-10-07 23:35                     ` Juri Linkov
2013-10-08  3:07                       ` Stefan Monnier
2013-10-08 23:29                         ` Juri Linkov
2013-10-09  2:43                           ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87vc2k7556.fsf@mail.jurta.org \
    --to=juri@jurta.org \
    --cc=15200@debbugs.gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).