diff lisp/isearch-mode.el @ 5371:6f10ac29bf40

Be better about searching for chars typed via XIM and x-compose.el, isearch lisp/ChangeLog addition: 2011-03-12 Aidan Kehoe <kehoea@parhasard.net> * isearch-mode.el (isearch-mode-map): Document why we bind the ASCII characters to isearch-printing-char in more detail. * isearch-mode.el (isearch-maybe-frob-keyboard-macros): If `this-command' is nil and the keys typed would normally be bound to `self-insert-command' in the global map, force `isearch-printing-char' to be called with an appropriate value for last-command-event. Addresses an issue where searching for characters generated from x-compose.el and XIM threw errors for me in dired. src/ChangeLog addition: 2011-03-12 Aidan Kehoe <kehoea@parhasard.net> * event-stream.c (Fdispatch_event): As documented, allow pre-command-hook to usefully modify this-command even when this-command is nil (that is, we would normally throw an undefined-keystroke-sequence error). Don't throw that error if this-command was modified, instead try to execute the new value. Allow pre-command-hook to modify last-command-event in this specific context. Don't document this, for the moment.
author Aidan Kehoe <kehoea@parhasard.net>
date Sat, 12 Mar 2011 13:11:31 +0000
parents f00192e1cd49
children ac37a5f7e5be
line wrap: on
line diff
--- a/lisp/isearch-mode.el	Fri Mar 11 20:40:01 2011 +0000
+++ b/lisp/isearch-mode.el	Sat Mar 12 13:11:31 2011 +0000
@@ -239,10 +239,18 @@
   (let ((map (make-keymap)))
     (set-keymap-name map 'isearch-mode-map)
 
-    ;; Bind all printing characters to `isearch-printing-char'.
-    ;; This isn't normally necessary, but if a printing character were
-    ;; bound to something other than self-insert-command in global-map,
-    ;; then it would terminate the search and be executed without this.
+    ;; Bind ASCII printing characters to `isearch-printing-char'.  This
+    ;; isn't normally necessary, but if a printing character were bound to
+    ;; something other than self-insert-command in global-map, then it would
+    ;; terminate the search and be executed without this.
+
+    ;; This is also relevant when other modes (notably dired and gnus) call
+    ;; `suppress-keymap' on their major mode maps; this means that
+    ;; `isearch-maybe-frob-keyboard-macros' won't pick up that the command
+    ;; that would normally be executed is `self-insert-command' and do its
+    ;; thing of transforming that to `isearch-printing-char'. This is less
+    ;; of an issue for the non-ASCII characters, because they rarely have
+    ;; specific bindings in major modes.
     (let ((i 32)
 	  (str (make-string 1 0)))
       (while (< i 127)
@@ -1609,8 +1617,27 @@
 	       last-command-char (and (stringp this-command)
 				      (aref this-command 0))
 	       this-command 'isearch-printing-char))
-	))
-
+	((and (null this-command)
+              (eq 'key-press (event-type last-command-event))
+              (current-local-map)
+              (let* ((this-command-keys (this-command-keys))
+                     (this-command-keys (or (lookup-key function-key-map
+                                                        this-command-keys)
+                                            this-command-keys))
+                     (lookup-key (lookup-key global-map this-command-keys)))
+                (and (eq 'self-insert-command lookup-key)
+                     ;; The feature here that a modification of
+                     ;; last-command-event is respected is undocumented, and
+                     ;; only applies when this-command is nil. The design
+                     ;; isn't reat, and I welcome suggestions for a better
+                     ;; one.
+                     (setq last-command-event
+                           (find-if 'key-press-event-p this-command-keys
+                                    :from-end t)
+                           last-command-char
+                           (event-to-character last-command-event)
+                           this-command 'isearch-printing-char)))))))
+                           
 
 ;;;========================================================
 ;;; Highlighting