Fix up comment convention on the arch-tag lines.
[bpt/emacs.git] / lisp / international / isearch-x.el
CommitLineData
4ed46869
KH
1;;; isearch-x.el --- extended isearch handling commands
2
e3fe4da0 3;; Copyright (C) 1997, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
d4877ac1 4;; Free Software Foundation, Inc.
7976eda0 5;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
e3fe4da0 6;; 2005, 2006, 2007, 2008
2fd125a3
KH
7;; National Institute of Advanced Industrial Science and Technology (AIST)
8;; Registration Number H14PRO021
4ed46869
KH
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
d7142f3e 19;; the Free Software Foundation; either version 3, or (at your option)
4ed46869
KH
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
369314dc 28;; along with GNU Emacs; see the file COPYING. If not, write to the
3a35cf56
LK
29;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
30;; Boston, MA 02110-1301, USA.
4ed46869 31
e8af40ee
PJ
32;;; Commentary:
33
4ed46869
KH
34;;; Code:
35
36;;;###autoload
37(defun isearch-toggle-specified-input-method ()
e81ed9ed 38 "Select an input method and turn it on in interactive search."
4ed46869 39 (interactive)
000028d7
KH
40 (let ((overriding-terminal-local-map nil))
41 (toggle-input-method t))
a2abd6b4
KH
42 (setq isearch-input-method-function input-method-function
43 isearch-input-method-local-p t)
44 (setq input-method-function nil)
000028d7 45 (isearch-update))
4ed46869
KH
46
47;;;###autoload
48(defun isearch-toggle-input-method ()
49 "Toggle input method in interactive search."
50 (interactive)
000028d7
KH
51 (let ((overriding-terminal-local-map nil))
52 (toggle-input-method))
a2abd6b4
KH
53 (setq isearch-input-method-function input-method-function
54 isearch-input-method-local-p t)
55 (setq input-method-function nil)
4ed46869
KH
56 (isearch-update))
57
a2abd6b4 58(defvar isearch-minibuffer-local-map
a50192e7
KH
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)
a2abd6b4 62 map)
a50192e7 63 "Keymap to use in minibuffer for multibyte character inputting in isearch.")
a2abd6b4 64
a50192e7
KH
65;; Exit from recursive edit safely. Set in `after-change-functions'
66;; by isearch-with-keyboard-coding.
c3b0c268 67(defun isearch-exit-recursive-edit (start end length)
a2abd6b4 68 (interactive)
a50192e7
KH
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))
a2abd6b4
KH
79 (exit-minibuffer))
80
a50192e7
KH
81;; Simulate the work of the current input method in the current buffer
82;; (minibuffer).
83
84(defun isearch-with-input-method ()
a2abd6b4 85 (interactive)
8aa87e06
KH
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))
a50192e7
KH
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)))
bbb398a1 97 (exit-minibuffer)))
a2abd6b4 98
000028d7 99;;;###autoload
4ed46869 100(defun isearch-process-search-multibyte-characters (last-char)
07474fef
KH
101 (if (eq this-command 'isearch-printing-char)
102 (let ((overriding-terminal-local-map nil)
57cfde4d 103 (prompt (isearch-message-prefix))
07474fef 104 (minibuffer-local-map isearch-minibuffer-local-map)
57cfde4d 105 str junk-hist)
8256bd38
MB
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
a50192e7
KH
115 (if isearch-input-method-function
116 (let (;; Let input method work rather tersely.
5cf1bf86 117 (input-method-verbose-flag nil))
a50192e7
KH
118 (setq unread-command-events
119 (cons 'with-input-method
120 (cons last-char unread-command-events))
5cf1bf86 121 ;; Inherit current-input-method in a minibuffer.
57cfde4d
JL
122 str (read-string prompt isearch-message 'junk-hist nil t))
123 (if (or (not str) (< (length str) (length isearch-message)))
a50192e7
KH
124 ;; All inputs were deleted while the input method
125 ;; was working.
126 (setq str "")
98e008e9 127 (setq str (substring str (length isearch-message)))
a50192e7 128 (if (and (= (length str) 1)
5cf1bf86
KH
129 (= (aref str 0) last-char)
130 (>= last-char 128))
a50192e7
KH
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))
57cfde4d 138 str (read-string prompt nil 'junk-hist)))
a50192e7 139
07474fef 140 (if (and str (> (length str) 0))
39d484ed
KH
141 (let ((unread-command-events nil))
142 (isearch-process-search-string str str))
143 (isearch-update)))
07474fef 144 (isearch-process-search-char last-char)))
4ed46869 145
cbee283d 146;; arch-tag: 1a90a6cf-2cb2-477a-814a-9ff895852822
4ed46869 147;;; isearch-x.el ends here