*** empty log message ***
[bpt/emacs.git] / lisp / international / isearch-x.el
CommitLineData
4ed46869
KH
1;;; isearch-x.el --- extended isearch handling commands
2
4ed46869 3;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
fa526c4a 4;; Licensed to the Free Software Foundation.
4ed46869
KH
5
6;; Keywords: multilingual, isearch
7
8;; Author: Kenichi HANDA <handa@etl.go.jp>
9;; Maintainer: Kenichi HANDA <handa@etl.go.jp>
10
11;; This file is part of GNU Emacs.
12
13;; GNU Emacs is free software; you can redistribute it and/or modify
14;; it under the terms of the GNU General Public License as published by
15;; the Free Software Foundation; either version 2, or (at your option)
16;; any later version.
17
18;; GNU Emacs is distributed in the hope that it will be useful,
19;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21;; GNU General Public License for more details.
22
23;; You should have received a copy of the GNU General Public License
369314dc
KH
24;; along with GNU Emacs; see the file COPYING. If not, write to the
25;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26;; Boston, MA 02111-1307, USA.
4ed46869
KH
27
28;;; Code:
29
30;;;###autoload
31(defun isearch-toggle-specified-input-method ()
e81ed9ed 32 "Select an input method and turn it on in interactive search."
4ed46869 33 (interactive)
000028d7
KH
34 (let ((overriding-terminal-local-map nil))
35 (toggle-input-method t))
a2abd6b4
KH
36 (setq isearch-input-method-function input-method-function
37 isearch-input-method-local-p t)
38 (setq input-method-function nil)
000028d7 39 (isearch-update))
4ed46869
KH
40
41;;;###autoload
42(defun isearch-toggle-input-method ()
43 "Toggle input method in interactive search."
44 (interactive)
000028d7
KH
45 (let ((overriding-terminal-local-map nil))
46 (toggle-input-method))
a2abd6b4
KH
47 (setq isearch-input-method-function input-method-function
48 isearch-input-method-local-p t)
49 (setq input-method-function nil)
4ed46869
KH
50 (isearch-update))
51
a2abd6b4 52(defvar isearch-minibuffer-local-map
a50192e7
KH
53 (let ((map (copy-keymap minibuffer-local-map)))
54 (define-key map [with-keyboard-coding] 'isearch-with-keyboard-coding)
55 (define-key map [with-input-method] 'isearch-with-input-method)
a2abd6b4 56 map)
a50192e7 57 "Keymap to use in minibuffer for multibyte character inputting in isearch.")
a2abd6b4 58
a50192e7
KH
59
60;; These two variables are used to refer to the values of
61;; `current-input-method' and `input-method-function' of the original
62;; buffer in the function isearch-with-input-method which runs in a
63;; minibuffer.
64
65(defvar isearch-minibuffer-input-method nil)
66(defvar isearch-minibuffer-input-method-function nil)
67
68;; Exit from recursive edit safely. Set in `after-change-functions'
69;; by isearch-with-keyboard-coding.
70(defun isearch-exit-recursive-edit ()
a2abd6b4 71 (interactive)
a50192e7
KH
72 (throw 'exit nil))
73
74;; Simulate character decoding by the keyboard coding system in the
75;; current buffer (minibuffer). As soon as a character is inserted,
76;; it exits from minibuffer.
77
78(defun isearch-with-keyboard-coding ()
79 (interactive)
80 (let ((after-change-functions '(isearch-exit-recursive-edit)))
81 (recursive-edit))
a2abd6b4
KH
82 (exit-minibuffer))
83
a50192e7
KH
84;; Simulate the work of the current input method in the current buffer
85;; (minibuffer).
86
87(defun isearch-with-input-method ()
a2abd6b4 88 (interactive)
a50192e7
KH
89 (let* ((current-input-method isearch-minibuffer-input-method)
90 (events (funcall isearch-minibuffer-input-method-function nil)))
91 ;; EVENTS is a list of events the input method has generated. It
92 ;; contains a character event and/or the special event
93 ;; `compose-last-chars'. We extract only character events and
94 ;; insert the corresponding characters.
95 (while events
96 (if (integerp (car events)) (insert (car events)))
97 (setq events (cdr events)))
bbb398a1 98 (exit-minibuffer)))
a2abd6b4 99
000028d7 100;;;###autoload
4ed46869 101(defun isearch-process-search-multibyte-characters (last-char)
07474fef
KH
102 (if (eq this-command 'isearch-printing-char)
103 (let ((overriding-terminal-local-map nil)
a50192e7 104 (prompt (concat (isearch-message-prefix) isearch-message))
07474fef
KH
105 (minibuffer-local-map isearch-minibuffer-local-map)
106 str)
a50192e7
KH
107 (if isearch-input-method-function
108 (let (;; Let input method work rather tersely.
109 (input-method-verbose-flag nil)
110 (isearch-minibuffer-input-method current-input-method)
111 (isearch-minibuffer-input-method-function
112 isearch-input-method-function))
113 (setq unread-command-events
114 (cons 'with-input-method
115 (cons last-char unread-command-events))
116 str (read-string prompt))
117 (if (not str)
118 ;; All inputs were deleted while the input method
119 ;; was working.
120 (setq str "")
121 (if (and (= (length str) 1)
122 (= (aref str 0) last-char))
123 ;; The input method couldn't handle LAST-CHAR.
124 (setq str nil)))))
125
126 (if (and (not str) (keyboard-coding-system))
127 (setq unread-command-events
128 (cons 'with-keyboard-coding
129 (cons last-char unread-command-events))
130 str (read-string prompt)))
131
07474fef 132 (if (and str (> (length str) 0))
39d484ed
KH
133 (let ((unread-command-events nil))
134 (isearch-process-search-string str str))
135 (isearch-update)))
07474fef 136 (isearch-process-search-char last-char)))
4ed46869
KH
137
138;;; isearch-x.el ends here