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