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