Update copyright year to 2014 by running admin/update-copyright.
[emacs.git] / lisp / international / isearch-x.el
blobbbe318f10fed38bc1ca011c3ed3b9d3a314497e8
1 ;;; isearch-x.el --- extended isearch handling commands
3 ;; Copyright (C) 1997, 2001-2014 Free Software Foundation, Inc.
4 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
5 ;; 2005, 2006, 2007, 2008, 2009, 2010, 2011
6 ;; National Institute of Advanced Industrial Science and Technology (AIST)
7 ;; Registration Number H14PRO021
9 ;; Keywords: i18n, multilingual, isearch
11 ;; Author: Kenichi HANDA <handa@etl.go.jp>
12 ;; Maintainer: Kenichi HANDA <handa@etl.go.jp>
14 ;; This file is part of GNU Emacs.
16 ;; GNU Emacs is free software: you can redistribute it and/or modify
17 ;; it under the terms of the GNU General Public License as published by
18 ;; the Free Software Foundation, either version 3 of the License, or
19 ;; (at your option) any later version.
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.
26 ;; You should have received a copy of the GNU General Public License
27 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
29 ;;; Commentary:
31 ;;; Code:
33 ;;;###autoload
34 (defun isearch-toggle-specified-input-method ()
35 "Select an input method and turn it on in interactive search."
36 (interactive)
37 (let ((overriding-terminal-local-map nil))
38 (toggle-input-method t))
39 (setq isearch-input-method-function input-method-function
40 isearch-input-method-local-p t)
41 (setq input-method-function nil)
42 (isearch-update))
44 ;;;###autoload
45 (defun isearch-toggle-input-method ()
46 "Toggle input method in interactive search."
47 (interactive)
48 (let ((overriding-terminal-local-map nil))
49 (toggle-input-method))
50 (setq isearch-input-method-function input-method-function
51 isearch-input-method-local-p t)
52 (setq input-method-function nil)
53 (isearch-update))
55 (defvar isearch-minibuffer-local-map
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)
59 map)
60 "Keymap to use in minibuffer for multibyte character inputting in isearch.")
62 ;; Exit from recursive edit safely. Set in `after-change-functions'
63 ;; by isearch-with-keyboard-coding.
64 (defun isearch-exit-recursive-edit (start end length)
65 (interactive)
66 (throw 'exit nil))
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.
72 (defun isearch-with-keyboard-coding ()
73 (interactive)
74 (let ((after-change-functions '(isearch-exit-recursive-edit)))
75 (recursive-edit))
76 (exit-minibuffer))
78 ;; Simulate the work of the current input method in the current buffer
79 ;; (minibuffer).
81 (defun isearch-with-input-method ()
82 (interactive)
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))
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)))
94 (exit-minibuffer)))
96 ;;;###autoload
97 (defun isearch-process-search-multibyte-characters (last-char &optional count)
98 (if (eq this-command 'isearch-printing-char)
99 (let ((overriding-terminal-local-map nil)
100 (prompt (isearch-message-prefix))
101 (minibuffer-local-map isearch-minibuffer-local-map)
102 str junk-hist)
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.
110 (set-text-properties 0 (length prompt) nil prompt)
112 (if isearch-input-method-function
113 (let (;; Let input method work rather tersely.
114 (input-method-verbose-flag nil))
115 (setq unread-command-events
116 (cons 'with-input-method
117 (cons last-char unread-command-events))
118 ;; Inherit current-input-method in a minibuffer.
119 str (read-string prompt isearch-message 'junk-hist nil t))
120 (if (or (not str) (< (length str) (length isearch-message)))
121 ;; All inputs were deleted while the input method
122 ;; was working.
123 (setq str "")
124 (setq str (substring str (length isearch-message)))
125 (if (and (= (length str) 1)
126 (= (aref str 0) last-char)
127 (>= last-char 128))
128 ;; The input method couldn't handle LAST-CHAR.
129 (setq str nil)))))
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))
135 str (read-string prompt nil 'junk-hist)))
137 (if (and str (> (length str) 0))
138 (let ((unread-command-events nil))
139 (if (and (integerp count) (> count 1))
140 (let ((strs (mapconcat 'identity (make-list count str) "")))
141 (isearch-process-search-string strs strs))
142 (isearch-process-search-string str str)))
143 (isearch-update)))
144 (isearch-process-search-char last-char count)))
146 ;;; isearch-x.el ends here