Add 2012 to FSF copyright years for Emacs files (do not merge to trunk)
[bpt/emacs.git] / lisp / international / isearch-x.el
CommitLineData
4ed46869
KH
1;;; isearch-x.el --- extended isearch handling commands
2
49f70d46 3;; Copyright (C) 1997, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
d4877ac1 4;; Free Software Foundation, Inc.
7976eda0 5;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
5df4f04c 6;; 2005, 2006, 2007, 2008, 2009, 2010, 2011
2fd125a3
KH
7;; National Institute of Advanced Industrial Science and Technology (AIST)
8;; Registration Number H14PRO021
4ed46869 9
49e64228 10;; Keywords: i18n, multilingual, isearch
4ed46869
KH
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
4936186e 17;; GNU Emacs is free software: you can redistribute it and/or modify
4ed46869 18;; it under the terms of the GNU General Public License as published by
4936186e
GM
19;; the Free Software Foundation, either version 3 of the License, or
20;; (at your option) any later version.
4ed46869
KH
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
4936186e 28;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
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)
57cfde4d 101 (prompt (isearch-message-prefix))
07474fef 102 (minibuffer-local-map isearch-minibuffer-local-map)
57cfde4d 103 str junk-hist)
8256bd38
MB
104
105 ;; PROMPT contains text-properties from
106 ;; `minibuffer-prompt-properties', and some of these can screw up
107 ;; its use in `read-string' below (specifically, a read-only
108 ;; property will cause it to signal an error), so strip them here;
109 ;; read-string will add the same properties itself anyway.
110 ;;
111 (set-text-properties 0 (length prompt) nil prompt)
112
a50192e7
KH
113 (if isearch-input-method-function
114 (let (;; Let input method work rather tersely.
5cf1bf86 115 (input-method-verbose-flag nil))
a50192e7
KH
116 (setq unread-command-events
117 (cons 'with-input-method
118 (cons last-char unread-command-events))
5cf1bf86 119 ;; Inherit current-input-method in a minibuffer.
57cfde4d
JL
120 str (read-string prompt isearch-message 'junk-hist nil t))
121 (if (or (not str) (< (length str) (length isearch-message)))
a50192e7
KH
122 ;; All inputs were deleted while the input method
123 ;; was working.
124 (setq str "")
98e008e9 125 (setq str (substring str (length isearch-message)))
a50192e7 126 (if (and (= (length str) 1)
5cf1bf86
KH
127 (= (aref str 0) last-char)
128 (>= last-char 128))
a50192e7
KH
129 ;; The input method couldn't handle LAST-CHAR.
130 (setq str nil)))))
131
132 (if (and (not str) (keyboard-coding-system))
133 (setq unread-command-events
134 (cons 'with-keyboard-coding
135 (cons last-char unread-command-events))
57cfde4d 136 str (read-string prompt nil 'junk-hist)))
a50192e7 137
07474fef 138 (if (and str (> (length str) 0))
39d484ed
KH
139 (let ((unread-command-events nil))
140 (isearch-process-search-string str str))
141 (isearch-update)))
07474fef 142 (isearch-process-search-char last-char)))
4ed46869 143
cbee283d 144;; arch-tag: 1a90a6cf-2cb2-477a-814a-9ff895852822
4ed46869 145;;; isearch-x.el ends here