]> code.delx.au - gnu-emacs/blobdiff - lisp/international/isearch-x.el
(rmail-mail-new-frame): Doc fix.
[gnu-emacs] / lisp / international / isearch-x.el
index 0908a0a4dc98017e5b00d34597baac60edec2ee5..60736277b97c5f1ed49444a896cd63b133c2439a 100644 (file)
@@ -1,7 +1,8 @@
 ;;; isearch-x.el --- extended isearch handling commands
 
-;; Copyright (C) 1995 Free Software Foundation, Inc.
 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
+;; Licensed to the Free Software Foundation.
+;; Copyright (C) 2001 Free Software Foundation, Inc.
 
 ;; Keywords: multilingual, isearch
 
 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 ;; Boston, MA 02111-1307, USA.
 
+;;; Commentary:
+
 ;;; Code:
 
 ;;;###autoload
 (defun isearch-toggle-specified-input-method ()
-  "Select and toggle specified input method in interactive search."
+  "Select an input method and turn it on in interactive search."
   (interactive)
-  ;; Let the command `toggle-input-method' ask users to select input
-  ;; method interactively.
-  (setq default-input-method nil)
-  (isearch-toggle-input-method))
+  (let ((overriding-terminal-local-map nil))
+    (toggle-input-method t))
+  (setq isearch-input-method-function input-method-function
+       isearch-input-method-local-p t)
+  (setq input-method-function nil)
+  (isearch-update))
 
 ;;;###autoload
 (defun isearch-toggle-input-method ()
   "Toggle input method in interactive search."
   (interactive)
-  (if isearch-multibyte-characters-flag
-      (setq isearch-multibyte-characters-flag nil)
-    (condition-case nil
-       (progn
-         (if (null default-input-method)
-             (let ((overriding-terminal-local-map nil))
-               ;; No input method has ever been selected.  Select one
-               ;; interactively now.  This also sets
-               ;; `default-input-method-title' to the title of the
-               ;; selected input method.
-               (toggle-input-method)
-               ;; And, inactivate it for the moment.
-               (toggle-input-method)))
-         (setq isearch-multibyte-characters-flag t))
-      (error (ding))))
+  (let ((overriding-terminal-local-map nil))
+    (toggle-input-method))
+  (setq isearch-input-method-function input-method-function
+       isearch-input-method-local-p t)
+  (setq input-method-function nil)
   (isearch-update))
 
-(defun isearch-input-method-after-insert-chunk-function ()
-  (funcall inactivate-current-input-method-function))
+(defvar isearch-minibuffer-local-map
+  (let ((map (copy-keymap minibuffer-local-map)))
+    (define-key map [with-keyboard-coding] 'isearch-with-keyboard-coding)
+    (define-key map [with-input-method] 'isearch-with-input-method)
+    map)
+  "Keymap to use in minibuffer for multibyte character inputting in isearch.")
+
+;; Exit from recursive edit safely.  Set in `after-change-functions'
+;; by isearch-with-keyboard-coding.
+(defun isearch-exit-recursive-edit (start end length)
+  (interactive)
+  (throw 'exit nil))
+
+;; Simulate character decoding by the keyboard coding system in the
+;; current buffer (minibuffer).  As soon as a character is inserted,
+;; it exits from minibuffer.
+
+(defun isearch-with-keyboard-coding ()
+  (interactive)
+  (let ((after-change-functions '(isearch-exit-recursive-edit)))
+    (recursive-edit))
+  (exit-minibuffer))
 
+;; Simulate the work of the current input method in the current buffer
+;; (minibuffer).
+
+(defun isearch-with-input-method ()
+  (interactive)
+  (let ((key (car unread-command-events))
+       events)
+    (setq unread-command-events (cdr unread-command-events)
+         events (funcall input-method-function key))
+    ;; EVENTS is a list of events the input method has generated.  It
+    ;; contains a character event and/or the special event
+    ;; `compose-last-chars'.  We extract only character events and
+    ;; insert the corresponding characters.
+    (while events
+      (if (integerp (car events)) (insert (car events)))
+      (setq events (cdr events)))
+    (exit-minibuffer)))
+
+;;;###autoload
 (defun isearch-process-search-multibyte-characters (last-char)
-  (let* ((overriding-terminal-local-map nil)
-        ;; Let input method exit when a chunk is inserted.
-        (input-method-after-insert-chunk-hook
-         '(isearch-input-method-after-insert-chunk-function))
-        (input-method-inactivate-hook '(exit-minibuffer))
-        ;; Let input method work rather tersely.
-        (input-method-tersely-flag t)
-        str)
-    (setq unread-command-events (cons last-char unread-command-events))
-    (setq str (read-multilingual-string (concat (isearch-message-prefix)
-                                               isearch-message)))
-    (isearch-process-search-string str str)))
+  (if (eq this-command 'isearch-printing-char)
+      (let ((overriding-terminal-local-map nil)
+           (prompt (concat (isearch-message-prefix) isearch-message))
+           (minibuffer-local-map isearch-minibuffer-local-map)
+           str)
+       (if isearch-input-method-function
+           (let (;; Let input method work rather tersely.
+                 (input-method-verbose-flag nil))
+             (setq unread-command-events
+                   (cons 'with-input-method
+                         (cons last-char unread-command-events))
+                   ;; Inherit current-input-method in a minibuffer.
+                   str (read-string prompt nil nil nil t))
+             (if (not str)
+                 ;; All inputs were deleted while the input method
+                 ;; was working.
+                 (setq str "")
+               (if (and (= (length str) 1)
+                        (= (aref str 0) last-char)
+                        (>= last-char 128))
+                   ;; The input method couldn't handle LAST-CHAR.
+                   (setq str nil)))))
+
+       (if (and (not str) (keyboard-coding-system))
+           (setq unread-command-events
+                 (cons 'with-keyboard-coding
+                       (cons last-char unread-command-events))
+                 str (read-string prompt)))
+
+       (if (and str (> (length str) 0))
+           (let ((unread-command-events nil))
+             (isearch-process-search-string str str))
+         (isearch-update)))
+    (isearch-process-search-char last-char)))
 
+;;; arch-tag: 1a90a6cf-2cb2-477a-814a-9ff895852822
 ;;; isearch-x.el ends here