Fix Bug#22736
[emacs.git] / lisp / international / isearch-x.el
blob09d6d0a1d0b7565045e2b33603d2c620f15d900a
1 ;;; isearch-x.el --- extended isearch handling commands
3 ;; Copyright (C) 1997, 2001-2016 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 ;; FIXME: What does this after-change-functions binding do here?
75 (let ((after-change-functions '(isearch-exit-recursive-edit)))
76 (recursive-edit))
77 (exit-minibuffer))
79 ;; Simulate the work of the current input method in the current buffer
80 ;; (minibuffer).
82 (defun isearch-with-input-method ()
83 (interactive)
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))
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)))
95 (exit-minibuffer)))
97 ;;;###autoload
98 (defun isearch-process-search-multibyte-characters (last-char &optional count)
99 (if (eq this-command 'isearch-printing-char)
100 (let ((overriding-terminal-local-map nil)
101 (prompt (isearch-message-prefix))
102 (minibuffer-local-map isearch-minibuffer-local-map)
103 str junk-hist)
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.
111 (set-text-properties 0 (length prompt) nil prompt)
113 (if isearch-input-method-function
114 (let (;; Let input method work rather tersely.
115 (input-method-verbose-flag nil))
116 (setq unread-command-events
117 (cons 'with-input-method
118 (cons last-char unread-command-events))
119 ;; Inherit current-input-method in a minibuffer.
120 str (read-string prompt isearch-message 'junk-hist nil t))
121 (if (or (not str) (< (length str) (length isearch-message)))
122 ;; All inputs were deleted while the input method
123 ;; was working.
124 (setq str "")
125 (setq str (substring str (length isearch-message)))
126 (if (and (= (length str) 1)
127 (= (aref str 0) last-char)
128 (>= last-char 128))
129 ;; The input method couldn't handle LAST-CHAR.
130 (setq str nil)))))
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))
136 str (read-string prompt nil 'junk-hist)))
138 (if (and str (> (length str) 0))
139 (let ((unread-command-events nil))
140 (if (and (integerp count) (> count 1))
141 (let ((strs (mapconcat 'identity (make-list count str) "")))
142 (isearch-process-search-string strs strs))
143 (isearch-process-search-string str str)))
144 (isearch-update)))
145 (isearch-process-search-char last-char count)))
147 ;;; isearch-x.el ends here