1 ;;; isearch-ext.el --- incremental search with front-end inputting method
3 ;; Author: SAKAI Kiyotaka <ksakai@mtl.t.u-tokyo.ac.jp>
6 ;; !Id: isearch-ext.el,v 1.41 1994/12/16 15:33:34 ksakai Exp !
8 ;; This file is part of XEmacs.
10 ;; XEmacs is free software; you can redistribute it and/or modify it
11 ;; under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; XEmacs is distributed in the hope that it will be useful, but
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ;; General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with XEmacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;; This program is extension of isearch.el to support multi-lingal
28 ;; incremental search with front-end input method.
30 ;; If you want to use this program, simply put C-\ or C-o or C-[ when
31 ;; doing incremental search, and you can input search words with
34 ;; For backward compatibility with mule-1.x, you can also use C-k, but
35 ;; isearch-edit-string may be more suitable for this use. If you
36 ;; think so, put the following code in your .emacs.
38 ;; (define-key isearch-mode-map "\C-k" 'isearch-edit-string)
41 ;; Following people contributed modifications to isearch-ext.el:
42 ;; Kenichi Handa <handa@etlken.etl.go.jp>
43 ;; YAMAMOTO Mitsuharu <mituharu@is.s.u-tokyo.ac.jp>
44 ;; A. Sasaki <beckun@cis.canon.co.jp>
45 ;; Atsuo Ohki <ohki@gssm.otsuka.tsukuba.ac.jp>
49 ;; #### This is far from working in XEmacs.
51 ;; If this file *really* must have these packages to bytecompile, then
52 ;; it can't be in mule-base.
53 ;; (eval-when-compile (require 'quail))
54 ;; (eval-when-compile (require 'egg))
58 (defvar search-string-char-prompt "*Enter string... ")
60 (defvar isearch-fep-prompt "" "Prompt for isearch-fep mode.")
61 (defvar isearch-fep-mode nil "If t, isearch-fep-mode is invoked.")
63 (defconst isearch-fep-table
64 '((isearch-fep-string isearch-fep-prompt-string isearch-fep-read-string)
65 (isearch-fep-egg isearch-fep-prompt-egg isearch-fep-read-egg)
66 (isearch-fep-canna isearch-fep-prompt-canna isearch-fep-read-canna)
67 (isearch-fep-quail isearch-fep-prompt-quail isearch-fep-read-quail)))
69 ;; the followings are defined in isearch.el
70 (define-key isearch-mode-map "\C-k" 'isearch-fep-string)
71 (define-key isearch-mode-map "\C-\\" 'isearch-fep-egg)
72 (define-key isearch-mode-map "\M-k" 'isearch-fep-egg)
73 (define-key isearch-mode-map "\C-o" 'isearch-fep-canna)
74 ;(define-key isearch-mode-map "\C-\]" 'isearch-fep-quail)
76 (put 'isearch-fep-string 'isearch-command t)
77 (put 'isearch-fep-egg 'isearch-command t)
78 (put 'isearch-fep-canna 'isearch-command t)
79 (put 'isearch-fep-prompt-string 'isearch-command t)
80 (put 'isearch-fep-prompt-egg 'isearch-command t)
81 (put 'isearch-fep-prompt-canna 'isearch-comnand t)
82 (put 'isearch-fep-read-string 'isearch-command t)
83 (put 'isearch-fep-read-egg 'isearch-command t)
84 (put 'isearch-fep-read-canna 'isearch-command t)
85 ;(put 'isearch-fep-quail 'isearch-command t)
87 (defun isearch-fep-mode ()
88 (let ((command this-command)
91 (while isearch-fep-mode
92 (setq table (assq command isearch-fep-table))
93 (setq isearch-fep-prompt (funcall (car (cdr table))))
94 (message "%s%s" isearch-fep-prompt (isearch-message))
95 (if (eq command 'isearch-fep-string) ;; \C-k
97 (setq str (funcall (nth 2 table)))
98 (setq isearch-fep-mode nil)
99 (isearch-process-search-string str str))
100 (let* ((keys (read-key-sequence nil))
101 (current-command (key-binding keys t)))
102 (setq isearch-fep-mode (not (eq command current-command)))
104 (if (assq current-command isearch-fep-table)
105 (setq command current-command)
106 (cond ((eq current-command 'isearch-printing-char)
107 (setq str (funcall (nth 2 table) keys))
108 (isearch-process-search-string str str))
109 ((or (eq current-command 'isearch-other-control-char)
110 (eq current-command 'isearch-other-meta-char))
111 (call-interactively current-command)
112 (setq isearch-fep-mode nil))
113 ((eq current-command 'isearch-exit)
114 (setq isearch-fep-mode nil)
116 (isearch-message-prefix) isearch-message))
119 (call-interactively current-command))))
120 (setq isearch-fep-prompt nil)
121 (message "%s%s" (isearch-message-prefix) isearch-message)))))))
124 ;; Read string from minibuffer for incremental search.
128 (defun isearch-fep-string ()
129 "Read string from minibuffer for incremental search."
133 (defun isearch-fep-prompt-string ()
134 search-string-char-prompt)
136 (defun exit-minibuffer-and-isearch-backward ()
138 (setq unread-command-events
139 (nconc unread-command-events
140 (list (character-to-event ?\r) (character-to-event ?\r))))
143 (defun isearch-fep-read-string ()
145 (set-buffer (window-buffer (minibuffer-window)))
146 (let* ((overriding-local-map nil)
147 (minibuffer-local-map (cons 'keymap minibuffer-local-map)))
148 ;; Some program overwrites "\C-m"'s default binding.
149 (define-key minibuffer-local-map "\C-m" 'exit-minibuffer)
150 (define-key minibuffer-local-map "\C-s" 'exit-minibuffer)
151 (define-key minibuffer-local-map "\C-r"
152 'exit-minibuffer-and-isearch-backward)
153 (condition-case condition
154 (read-from-minibuffer (concat isearch-fep-prompt (isearch-message)))
164 (defun isearch-fep-egg ()
165 "Read string for incremental search by using egg."
169 (defun isearch-fep-prompt-egg ()
171 (format "[%s]->" (map-indicator its:*current-map*))
172 (setq isearch-fep-mode nil)
173 (message "No EGG!! ")
177 (defun isearch-exit-minibuffer-egg (from to)
180 (defvar isearch-fep-egg-its-map nil)
181 (defvar isearch-fep-egg-server-type nil)
183 (defun isearch-minibuffer-setup-egg ()
184 (setq its:*current-map* isearch-fep-egg-its-map)
185 (setq wnn-server-type isearch-fep-egg-server-type))
187 (defun isearch-fep-read-egg (first-str)
188 (if (and (featurep 'egg) (= (minibuffer-depth) 0))
189 (let ((isearch-fep-egg-its-map its:*current-map*)
190 (isearch-fep-egg-server-type wnn-server-type)
191 (minibuffer-setup-hook 'isearch-minibuffer-setup-egg))
193 (set-buffer (window-buffer (minibuffer-window)))
194 (let ((display-minibuffer-mode-in-minibuffer t)
197 (self-insert-after-hook 'isearch-exit-minibuffer-egg))
198 (setq unread-command-events (mil-listify-key-sequence first-str))
200 (read-from-minibuffer (isearch-message))
201 (setq egg:henkan-mode-in-use nil)
202 ;;(setq disable-undo nil)
212 (defun isearch-fep-canna ()
213 "Read string for incremental search by using canna."
217 (defun isearch-fep-prompt-canna ()
218 (if (and (featurep 'canna) canna:*initialized*)
219 (format "%s" canna:*kanji-mode-string*)
220 (setq isearch-fep-mode nil)
221 (message "No Canna!! ")
225 (defun isearch-exit-minibuffer-canna (from to)
228 (defun isearch-fep-read-canna (first-str)
229 (if (and (featurep 'canna) (= (minibuffer-depth) 0))
231 (set-buffer (window-buffer (minibuffer-window)))
232 (let ((display-minibuffer-mode-in-minibuffer t)
233 (canna:*japanese-mode* t)
234 (canna:*japanese-mode-in-minibuffer* t)
235 (canna:*fence-mode* nil)
236 (self-insert-after-hook 'isearch-exit-minibuffer-canna))
237 (setq unread-command-events (mil-listify-key-sequence first-str))
239 (read-from-minibuffer (isearch-message))
241 (buffer-enable-undo (current-buffer)))))
250 (defun isearch-fep-quail ()
251 "Read string for incremental search by using quail."
256 (defun isearch-fep-prompt-quail ()
259 (defun isearch-exit-minibuffer-quail ()
260 (if (or quail-current-key quail-current-str)
264 (defun isearch-fep-read-quail (first-str)
265 (let ((quail-self-insert-after-hook 'isearch-exit-minibuffer-quail))
266 (setq unread-command-events
267 (nconc unread-command-events
268 (cons (character-to-event ?\\)
269 (mil-listify-key-sequence first-str))))
271 (read-from-minibuffer
272 (concat isearch-fep-prompt (isearch-message)))
274 (buffer-enable-undo (current-buffer))
278 (provide 'isearch-ext)
279 ;;; isearch-ext.el ends here