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