Remove non-free old and crusty clearcase pkg
[packages] / mule-packages / mule-base / isearch-mule.el
1 ;;; isearch-ext.el --- incremental search with front-end inputting method
2
3 ;; Author: SAKAI Kiyotaka <ksakai@mtl.t.u-tokyo.ac.jp>
4 ;; Keywords: search
5
6 ;; !Id: isearch-ext.el,v 1.41 1994/12/16 15:33:34 ksakai Exp !
7
8 ;; This file is part of XEmacs.
9
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)
13 ;; any later version.
14
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.
19
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.
24
25 ;;; Commentary:
26
27 ;; This program is extension of isearch.el to support multi-lingal
28 ;; incremental search with front-end input method.
29 ;;
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
32 ;; inputting method.
33 ;;
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.
37 ;;
38 ;;   (define-key isearch-mode-map "\C-k" 'isearch-edit-string)
39 ;;
40
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>
46
47 ;;; Code:
48
49 ;; #### This is far from working in XEmacs.
50
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))
55
56 \f
57 ;;;###autoload
58 (defvar search-string-char-prompt "*Enter string... ")
59
60 (defvar isearch-fep-prompt "" "Prompt for isearch-fep mode.")
61 (defvar isearch-fep-mode nil "If t, isearch-fep-mode is invoked.")
62
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)))
68
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)
75
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)
86
87 (defun isearch-fep-mode ()
88   (let ((command this-command)
89         (isearch-fep-mode t)
90         table str)
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
96           (progn
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)))
103           (if isearch-fep-mode
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)
115                        (message "%s%s"
116                                 (isearch-message-prefix) isearch-message))
117                       (t
118                        (ding)
119                        (call-interactively current-command))))
120             (setq isearch-fep-prompt nil)
121             (message "%s%s" (isearch-message-prefix) isearch-message)))))))
122 \f
123 ;;
124 ;;  Read string from minibuffer for incremental search.
125 ;;
126
127 ;;;###autoload
128 (defun isearch-fep-string ()
129   "Read string from minibuffer for incremental search."
130   (interactive)
131   (isearch-fep-mode))
132
133 (defun isearch-fep-prompt-string ()
134   search-string-char-prompt)
135
136 (defun exit-minibuffer-and-isearch-backward ()
137   (interactive)
138   (setq unread-command-events
139         (nconc unread-command-events
140                (list (character-to-event ?\r) (character-to-event ?\r))))
141   (exit-minibuffer))
142
143 (defun isearch-fep-read-string ()
144   (save-excursion
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)))
155         (quit
156          (isearch-abort))))))
157
158 \f
159 ;;
160 ;;  For EGG
161 ;;
162
163 ;;;###autoload
164 (defun isearch-fep-egg ()
165   "Read string for incremental search by using egg."
166   (interactive)
167   (isearch-fep-mode))
168
169 (defun isearch-fep-prompt-egg ()
170   (if (featurep 'egg)
171       (format "[%s]->" (map-indicator its:*current-map*))
172     (setq isearch-fep-mode nil)
173     (message "No EGG!! ")
174     (sit-for 1)
175     ""))
176
177 (defun isearch-exit-minibuffer-egg (from to)
178   (exit-minibuffer))
179
180 (defvar isearch-fep-egg-its-map nil)
181 (defvar isearch-fep-egg-server-type nil)
182
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))
186
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))
192         (save-excursion
193           (set-buffer (window-buffer (minibuffer-window)))
194           (let ((display-minibuffer-mode-in-minibuffer t)
195                 (egg:*input-mode* t)
196                 (egg:*mode-on* t)
197                 (self-insert-after-hook 'isearch-exit-minibuffer-egg))
198             (setq unread-command-events (mil-listify-key-sequence first-str))
199             (unwind-protect
200                 (read-from-minibuffer (isearch-message))
201               (setq egg:henkan-mode-in-use nil)
202               ;;(setq disable-undo nil)
203               ))))
204     ""))
205
206 \f
207 ;;
208 ;;  For Canna
209 ;;
210
211 ;;;###autoload
212 (defun isearch-fep-canna ()
213   "Read string for incremental search by using canna."
214   (interactive)
215   (isearch-fep-mode))
216
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!! ")
222     (sit-for 1)
223     ""))
224
225 (defun isearch-exit-minibuffer-canna (from to)
226   (exit-minibuffer))
227
228 (defun isearch-fep-read-canna (first-str)
229   (if (and (featurep 'canna) (= (minibuffer-depth) 0))
230       (save-excursion
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))
238           (unwind-protect
239               (read-from-minibuffer (isearch-message))
240             ;XEmacs change:
241             (buffer-enable-undo (current-buffer)))))
242     ""))
243
244 \f
245 ;;
246 ;;  For QUAIL
247 ;;
248
249 ;;;###autoload
250 (defun isearch-fep-quail ()
251   "Read string for incremental search by using quail."
252   (interactive)
253   (require 'quail)
254   (isearch-fep-mode))
255
256 (defun isearch-fep-prompt-quail ()
257   "[QUAIL]")
258
259 (defun isearch-exit-minibuffer-quail ()
260   (if (or quail-current-key quail-current-str)
261       nil
262     (exit-minibuffer)))
263
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))))
270     (unwind-protect
271         (read-from-minibuffer
272          (concat isearch-fep-prompt (isearch-message)))
273       ;; XEmacs change:
274       (buffer-enable-undo (current-buffer))
275       )))
276
277 \f
278 (provide 'isearch-ext)
279 ;;; isearch-ext.el ends here
280