Mercurial > emacs
annotate lisp/international/kkc.el @ 37678:ebec0594dece
(compile-files): Redirect output of chmod to
/dev/null.
| author | Gerd Moellmann <gerd@gnu.org> |
|---|---|
| date | Fri, 11 May 2001 10:53:56 +0000 |
| parents | 7472ec46ab91 |
| children | 67b464da13ec |
| rev | line source |
|---|---|
|
36683
b82a6fbaae16
Add coding: iso-2022-7bit tag.
Kenichi Handa <handa@m17n.org>
parents:
31218
diff
changeset
|
1 ;;; kkc.el --- Kana Kanji converter -*- coding: iso-2022-7bit; -*- |
| 17052 | 2 |
| 3 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN. | |
|
18377
8b4a66c66dd6
Change copyright notice.
Richard M. Stallman <rms@gnu.org>
parents:
18198
diff
changeset
|
4 ;; Licensed to the Free Software Foundation. |
| 17052 | 5 |
|
31165
6c51a4e8bf88
Remove SKK from Keywords. Require ja-dic-utl instead of skkdic-utl.
Kenichi Handa <handa@m17n.org>
parents:
30256
diff
changeset
|
6 ;; Keywords: mule, multilingual, Japanese |
| 17052 | 7 |
| 8 ;; This file is part of GNU Emacs. | |
| 9 | |
| 10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
| 11 ;; it under the terms of the GNU General Public License as published by | |
| 12 ;; the Free Software Foundation; either version 2, or (at your option) | |
| 13 ;; any later version. | |
| 14 | |
| 15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
| 16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 18 ;; GNU General Public License for more details. | |
| 19 | |
| 20 ;; You should have received a copy of the GNU General Public License | |
| 17071 | 21 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
| 22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
| 23 ;; Boston, MA 02111-1307, USA. | |
| 17052 | 24 |
| 25 ;;; Commentary: | |
| 26 | |
| 27 ;; These routines provide a simple and easy-to-use converter from | |
| 28 ;; Kana-string to Kana-Kanji-mixed-string. This converter (here after | |
| 29 ;; KKC) uses a SKK dictionary to get information how to convert | |
| 30 ;; Kana-string. Since KKC can't be fully automated, we need an | |
| 31 ;; interaction with a user to decide the correct conversion. For | |
| 32 ;; that, we provide KKC major mode. | |
| 33 | |
| 34 ;;; Code: | |
| 35 | |
|
31165
6c51a4e8bf88
Remove SKK from Keywords. Require ja-dic-utl instead of skkdic-utl.
Kenichi Handa <handa@m17n.org>
parents:
30256
diff
changeset
|
36 (require 'ja-dic-utl) |
| 17052 | 37 |
| 38 (defvar kkc-input-method-title "漢" | |
| 39 "String denoting KKC input method. | |
| 40 This string is shown at mode line when users are in KKC mode.") | |
| 41 | |
| 42 (defvar kkc-init-file-name "~/.kkcrc" | |
| 43 "Name of a file which contains user's initial setup code for KKC.") | |
| 44 | |
| 45 ;; A flag to control a file specified by `kkc-init-file-name'. | |
| 46 ;; The value nil means the file is not yet consulted. | |
| 47 ;; The value t means the file has already been consulted but there's | |
| 48 ;; no need of updating it yet. | |
| 49 ;; Any other value means that we must update the file before exiting Emacs. | |
| 50 (defvar kkc-init-file-flag nil) | |
| 51 | |
| 52 ;; Cash data for `kkc-lookup-key'. This may be initialized by loading | |
| 53 ;; a file specified by `kkc-init-file-name'. If any elements are | |
| 54 ;; modified, the data is written out to the file when exiting Emacs. | |
|
22888
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
55 (defvar kkc-lookup-cache nil) |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
56 |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
57 ;; Tag symbol of `kkc-lookup-cache'. |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
58 (defconst kkc-lookup-cache-tag 'kkc-lookup-cache-2) |
| 17052 | 59 |
| 60 (defun kkc-save-init-file () | |
| 61 "Save initial setup code for KKC to a file specified by `kkc-init-file-name'" | |
| 62 (if (and kkc-init-file-flag | |
| 63 (not (eq kkc-init-file-flag t))) | |
|
37016
7472ec46ab91
(kkc-save-init-file): Locally bind print-length to nil.
Kenichi Handa <handa@m17n.org>
parents:
36683
diff
changeset
|
64 (let ((coding-system-for-write 'iso-2022-7bit) |
|
7472ec46ab91
(kkc-save-init-file): Locally bind print-length to nil.
Kenichi Handa <handa@m17n.org>
parents:
36683
diff
changeset
|
65 (print-length nil)) |
| 17052 | 66 (write-region (format "(setq kkc-lookup-cache '%S)\n" kkc-lookup-cache) |
| 67 nil | |
| 68 kkc-init-file-name)))) | |
| 69 | |
| 70 ;; Sequence of characters to be used for indexes for shown list. The | |
| 71 ;; Nth character is for the Nth conversion in the list currently shown. | |
| 72 (defvar kkc-show-conversion-list-index-chars | |
|
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
73 "1234567890") |
| 17052 | 74 |
| 23032 | 75 (defun kkc-help () |
| 76 "Show key bindings available while converting by KKC." | |
| 77 (interactive) | |
| 78 (with-output-to-temp-buffer "*Help*" | |
| 79 (princ (substitute-command-keys "\\{kkc-keymap}")))) | |
| 80 | |
|
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
81 (defvar kkc-keymap |
| 23032 | 82 (let ((map (make-sparse-keymap)) |
|
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
83 (len (length kkc-show-conversion-list-index-chars)) |
| 17052 | 84 (i 0)) |
|
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
85 (while (< i len) |
|
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
86 (define-key map |
|
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
87 (char-to-string (aref kkc-show-conversion-list-index-chars i)) |
|
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
88 'kkc-select-from-list) |
| 17052 | 89 (setq i (1+ i))) |
| 90 (define-key map " " 'kkc-next) | |
| 91 (define-key map "\r" 'kkc-terminate) | |
| 92 (define-key map "\C-@" 'kkc-first-char-only) | |
| 93 (define-key map "\C-n" 'kkc-next) | |
| 94 (define-key map "\C-p" 'kkc-prev) | |
| 95 (define-key map "\C-i" 'kkc-shorter) | |
| 96 (define-key map "\C-o" 'kkc-longer) | |
|
22888
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
97 (define-key map "I" 'kkc-shorter-conversion) |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
98 (define-key map "O" 'kkc-longer-phrase) |
| 17052 | 99 (define-key map "\C-c" 'kkc-cancel) |
| 100 (define-key map "\C-?" 'kkc-cancel) | |
| 101 (define-key map "\C-f" 'kkc-next-phrase) | |
| 102 (define-key map "K" 'kkc-katakana) | |
| 103 (define-key map "H" 'kkc-hiragana) | |
| 104 (define-key map "l" 'kkc-show-conversion-list-or-next-group) | |
| 105 (define-key map "L" 'kkc-show-conversion-list-or-prev-group) | |
|
20638
c3360a392ae4
Change "?\C-\ " to "?\C- " because "\ " is changed
Kenichi Handa <handa@m17n.org>
parents:
19931
diff
changeset
|
106 (define-key map [?\C- ] 'kkc-first-char-only) |
| 17052 | 107 (define-key map [delete] 'kkc-cancel) |
| 108 (define-key map [return] 'kkc-terminate) | |
| 23032 | 109 (define-key map "\C-h" 'kkc-help) |
|
19869
3c4025f3be8f
(kkc-mode-map): Bind meta-prefix-char to a
Kenichi Handa <handa@m17n.org>
parents:
19406
diff
changeset
|
110 map) |
|
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
111 "Keymap for KKC (Kana Kanji Converter).") |
| 17052 | 112 |
| 113 ;;; Internal variables used in KKC. | |
| 114 | |
| 115 ;; The current Kana string to be converted. | |
| 116 (defvar kkc-original-kana nil) | |
| 117 | |
| 118 ;; The current key sequence (vector of Kana characters) generated from | |
| 119 ;; `kkc-original-kana'. | |
| 120 (defvar kkc-current-key nil) | |
| 121 | |
| 122 ;; List of the current conversions for `kkc-current-key'. | |
| 123 (defvar kkc-current-conversions nil) | |
| 124 | |
| 125 ;; Vector of the same length as `kkc-current-conversion'. The first | |
| 126 ;; element is a vector of: | |
| 127 ;; o index number of the first conversion shown previously, | |
| 128 ;; o index number of a conversion next of the last one shown previously, | |
| 129 ;; o the shown string itself. | |
| 130 ;; The remaining elements are widths (including columns for index | |
| 131 ;; numbers) of conversions stored in the same order as in | |
| 132 ;; `kkc-current-conversion'. | |
| 133 (defvar kkc-current-conversions-width nil) | |
| 134 | |
|
30251
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
135 (defcustom kkc-show-conversion-list-count 4 |
|
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
136 "*Count of successive `kkc-next' or `kkc-prev' to show conversion list. |
|
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
137 When you type SPC or C-p successively this count while using the input |
|
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
138 method `japanese', the conversion candidates are shown in the echo |
|
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
139 area while indicating the current selection by `<N>'." |
|
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
140 :group 'mule |
|
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
141 :type 'integer) |
|
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
142 |
|
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
143 ;; Count of successive invocations of `kkc-next'. |
|
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
144 (defvar kkc-next-count nil) |
|
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
145 |
|
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
146 ;; Count of successive invocations of `kkc-prev'. |
|
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
147 (defvar kkc-prev-count nil) |
| 17052 | 148 |
| 149 ;; Provided that `kkc-current-key' is [A B C D E F G H I], the current | |
|
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
150 ;; conversion target is [A B C D E F], and the sequence of which |
| 17052 | 151 ;; conversion is found is [A B C D]: |
| 152 ;; | |
| 153 ;; A B C D E F G H I | |
| 154 ;; kkc-overlay-head (black): |<--------->| | |
| 155 ;; kkc-overlay-tail (underline): |<------->| | |
| 156 ;; kkc-length-head: |<--------->| | |
| 157 ;; kkc-length-converted: |<----->| | |
| 158 ;; | |
| 159 (defvar kkc-overlay-head nil) | |
| 160 (defvar kkc-overlay-tail nil) | |
| 161 (defvar kkc-length-head nil) | |
| 162 (defvar kkc-length-converted nil) | |
| 163 | |
| 164 ;; Cursor type (`box' or `bar') of the current frame. | |
| 165 (defvar kkc-cursor-type nil) | |
| 166 | |
|
31165
6c51a4e8bf88
Remove SKK from Keywords. Require ja-dic-utl instead of skkdic-utl.
Kenichi Handa <handa@m17n.org>
parents:
30256
diff
changeset
|
167 ;; Lookup Japanese dictionary to set list of conversions in |
| 17052 | 168 ;; kkc-current-conversions for key sequence kkc-current-key of length |
| 169 ;; LEN. If no conversion is found in the dictionary, don't change | |
| 170 ;; kkc-current-conversions and return nil. | |
| 171 ;; Postfixes are handled only if POSTFIX is non-nil. | |
|
18644
69c91eee7ba1
(kkc-region): Call skkdic-lookup-key with
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
172 (defun kkc-lookup-key (len &optional postfix prefer-noun) |
| 17052 | 173 ;; At first, prepare cache data if any. |
|
22888
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
174 (unless kkc-init-file-flag |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
175 (setq kkc-init-file-flag t |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
176 kkc-lookup-cache nil) |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
177 (add-hook 'kill-emacs-hook 'kkc-save-init-file) |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
178 (if (file-readable-p kkc-init-file-name) |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
179 (condition-case nil |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
180 (load-file kkc-init-file-name) |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
181 (kkc-error "Invalid data in %s" kkc-init-file-name)))) |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
182 (or (and (nested-alist-p kkc-lookup-cache) |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
183 (eq (car kkc-lookup-cache) kkc-lookup-cache-tag)) |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
184 (setq kkc-lookup-cache (list kkc-lookup-cache-tag) |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
185 kkc-init-file-flag 'kkc-lookup-cache)) |
| 17052 | 186 (let ((entry (lookup-nested-alist kkc-current-key kkc-lookup-cache len 0 t))) |
| 187 (if (consp (car entry)) | |
| 188 (setq kkc-length-converted len | |
| 189 kkc-current-conversions-width nil | |
| 190 kkc-current-conversions (car entry)) | |
|
18644
69c91eee7ba1
(kkc-region): Call skkdic-lookup-key with
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
191 (setq entry (skkdic-lookup-key kkc-current-key len postfix prefer-noun)) |
| 17052 | 192 (if entry |
| 193 (progn | |
| 194 (setq kkc-length-converted len | |
| 195 kkc-current-conversions-width nil | |
| 196 kkc-current-conversions (cons 1 entry)) | |
| 197 (if postfix | |
| 198 ;; Store this conversions in the cache. | |
| 199 (progn | |
| 200 (set-nested-alist kkc-current-key kkc-current-conversions | |
| 201 kkc-lookup-cache kkc-length-converted) | |
| 202 (setq kkc-init-file-flag 'kkc-lookup-cache))) | |
| 203 t) | |
| 204 (if (= len 1) | |
| 205 (setq kkc-length-converted 1 | |
| 206 kkc-current-conversions-width nil | |
| 207 kkc-current-conversions (cons 0 nil))))))) | |
| 208 | |
|
22888
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
209 (put 'kkc-error 'error-conditions '(kkc-error error)) |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
210 (defun kkc-error (&rest args) |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
211 (signal 'kkc-error (apply 'format args))) |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
212 |
|
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
213 (defvar kkc-converting nil) |
|
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
214 |
| 17052 | 215 ;;;###autoload |
|
30256
e4b4bca5087a
(kkc-after-update-conversion-functions): New variable.
Kenichi Handa <handa@m17n.org>
parents:
30251
diff
changeset
|
216 (defvar kkc-after-update-conversion-functions nil |
|
e4b4bca5087a
(kkc-after-update-conversion-functions): New variable.
Kenichi Handa <handa@m17n.org>
parents:
30251
diff
changeset
|
217 "Functions to run after a conversion is selected in `japanese' input method. |
|
e4b4bca5087a
(kkc-after-update-conversion-functions): New variable.
Kenichi Handa <handa@m17n.org>
parents:
30251
diff
changeset
|
218 With this input method, a user can select a proper conversion from |
|
e4b4bca5087a
(kkc-after-update-conversion-functions): New variable.
Kenichi Handa <handa@m17n.org>
parents:
30251
diff
changeset
|
219 candidate list. Each time he changes the selection, functions in this |
|
e4b4bca5087a
(kkc-after-update-conversion-functions): New variable.
Kenichi Handa <handa@m17n.org>
parents:
30251
diff
changeset
|
220 list are called with two arguments; starting and ending buffer |
|
e4b4bca5087a
(kkc-after-update-conversion-functions): New variable.
Kenichi Handa <handa@m17n.org>
parents:
30251
diff
changeset
|
221 positions that contains the current selection.") |
|
e4b4bca5087a
(kkc-after-update-conversion-functions): New variable.
Kenichi Handa <handa@m17n.org>
parents:
30251
diff
changeset
|
222 |
|
e4b4bca5087a
(kkc-after-update-conversion-functions): New variable.
Kenichi Handa <handa@m17n.org>
parents:
30251
diff
changeset
|
223 ;;;###autoload |
|
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
224 (defun kkc-region (from to) |
| 17052 | 225 "Convert Kana string in the current region to Kanji-Kana mixed string. |
|
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
226 Users can select a desirable conversion interactively. |
|
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
227 When called from a program, expects two arguments, |
|
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
228 positions FROM and TO (integers or markers) specifying the target region. |
|
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
229 When it returns, the point is at the tail of the selected conversion, |
|
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
230 and the return value is the length of the conversion." |
| 17052 | 231 (interactive "r") |
| 232 (setq kkc-original-kana (buffer-substring from to)) | |
| 233 (goto-char from) | |
| 234 | |
| 235 ;; Setup overlays. | |
| 236 (if (overlayp kkc-overlay-head) | |
| 237 (move-overlay kkc-overlay-head from to) | |
| 238 (setq kkc-overlay-head (make-overlay from to nil nil t)) | |
| 239 (overlay-put kkc-overlay-head 'face 'highlight)) | |
| 240 (if (overlayp kkc-overlay-tail) | |
| 241 (move-overlay kkc-overlay-tail to to) | |
| 242 (setq kkc-overlay-tail (make-overlay to to nil nil t)) | |
| 243 (overlay-put kkc-overlay-tail 'face 'underline)) | |
| 244 | |
|
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
245 (setq kkc-current-key (string-to-vector kkc-original-kana)) |
|
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
246 (setq kkc-length-head (length kkc-current-key)) |
|
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
247 (setq kkc-length-converted 0) |
|
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
248 |
|
22888
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
249 (unwind-protect |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
250 ;; At first convert the region to the first candidate. |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
251 (let ((current-input-method-title kkc-input-method-title) |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
252 (input-method-function nil) |
|
29146
ded7fa3de6db
(kkc-region): Don't change modified-p of
Kenichi Handa <handa@m17n.org>
parents:
23196
diff
changeset
|
253 (modified-p (buffer-modified-p)) |
|
22888
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
254 (first t)) |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
255 (while (not (kkc-lookup-key kkc-length-head nil first)) |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
256 (setq kkc-length-head (1- kkc-length-head) |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
257 first nil)) |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
258 (goto-char to) |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
259 (kkc-update-conversion 'all) |
|
30251
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
260 (setq kkc-next-count 1 kkc-prev-count 0) |
|
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
261 (if (and (>= kkc-next-count kkc-show-conversion-list-count) |
|
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
262 (>= (length kkc-current-conversions) 3)) |
|
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
263 (kkc-show-conversion-list-or-next-group)) |
|
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
264 |
| 23196 | 265 ;; Then, ask users to select a desirable conversion. |
|
22816
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
266 (force-mode-line-update) |
|
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
267 (setq kkc-converting t) |
|
31218
6828c3827297
(kkc-region): Hide "... loaded" message.
Kenichi Handa <handa@m17n.org>
parents:
31165
diff
changeset
|
268 ;; Hide "... loaded" message. |
|
6828c3827297
(kkc-region): Hide "... loaded" message.
Kenichi Handa <handa@m17n.org>
parents:
31165
diff
changeset
|
269 (message nil) |
|
22816
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
270 (while kkc-converting |
|
29146
ded7fa3de6db
(kkc-region): Don't change modified-p of
Kenichi Handa <handa@m17n.org>
parents:
23196
diff
changeset
|
271 (set-buffer-modified-p modified-p) |
|
22919
95d147bbdce0
(kkc-region): Don't bind echo-keystrokes.
Kenichi Handa <handa@m17n.org>
parents:
22888
diff
changeset
|
272 (let* ((overriding-terminal-local-map kkc-keymap) |
| 23032 | 273 (help-char nil) |
|
22816
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
274 (keyseq (read-key-sequence nil)) |
|
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
275 (cmd (lookup-key kkc-keymap keyseq))) |
|
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
276 (if (commandp cmd) |
|
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
277 (condition-case err |
|
30251
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
278 (progn |
|
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
279 (cond ((eq cmd 'kkc-next) |
|
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
280 (setq kkc-next-count (1+ kkc-next-count) |
|
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
281 kkc-prev-count 0)) |
|
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
282 ((eq cmd 'kkc-prev) |
|
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
283 (setq kkc-prev-count (1+ kkc-prev-count) |
|
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
284 kkc-next-count 0)) |
|
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
285 (t |
|
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
286 (setq kkc-next-count 0 kkc-prev-count 0))) |
|
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
287 (call-interactively cmd)) |
|
22816
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
288 (kkc-error (message "%s" (cdr err)) (beep))) |
|
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
289 ;; KEYSEQ is not defined in KKC keymap. |
|
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
290 ;; Let's put the event back. |
|
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
291 (setq unread-input-method-events |
|
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
292 (append (string-to-list keyseq) |
|
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
293 unread-input-method-events)) |
|
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
294 (kkc-terminate)))) |
|
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
295 |
|
22816
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
296 (force-mode-line-update) |
|
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
297 (goto-char (overlay-end kkc-overlay-tail)) |
|
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
298 (- (overlay-start kkc-overlay-head) from)) |
|
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
299 (delete-overlay kkc-overlay-head) |
|
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
300 (delete-overlay kkc-overlay-tail))) |
| 17052 | 301 |
| 302 (defun kkc-terminate () | |
| 303 "Exit from KKC mode by fixing the current conversion." | |
| 304 (interactive) | |
|
22794
9ace35333789
(kkc-region): Handled the case that
Kenichi Handa <handa@m17n.org>
parents:
22779
diff
changeset
|
305 (goto-char (overlay-end kkc-overlay-tail)) |
|
9ace35333789
(kkc-region): Handled the case that
Kenichi Handa <handa@m17n.org>
parents:
22779
diff
changeset
|
306 (move-overlay kkc-overlay-head (point) (point)) |
|
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
307 (setq kkc-converting nil)) |
| 17052 | 308 |
| 309 (defun kkc-cancel () | |
| 310 "Exit from KKC mode by canceling any conversions." | |
| 311 (interactive) | |
|
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
312 (goto-char (overlay-start kkc-overlay-head)) |
| 17052 | 313 (delete-region (overlay-start kkc-overlay-head) |
| 314 (overlay-end kkc-overlay-tail)) | |
| 315 (insert kkc-original-kana) | |
|
22794
9ace35333789
(kkc-region): Handled the case that
Kenichi Handa <handa@m17n.org>
parents:
22779
diff
changeset
|
316 (setq kkc-converting nil)) |
| 17052 | 317 |
| 318 (defun kkc-first-char-only () | |
| 319 "Select only the first character currently converted." | |
| 320 (interactive) | |
| 321 (goto-char (overlay-start kkc-overlay-head)) | |
| 322 (forward-char 1) | |
| 323 (delete-region (point) (overlay-end kkc-overlay-tail)) | |
| 324 (kkc-terminate)) | |
| 325 | |
| 326 (defun kkc-next () | |
| 327 "Select the next candidate of conversion." | |
| 328 (interactive) | |
| 329 (let ((idx (1+ (car kkc-current-conversions)))) | |
| 330 (if (< idx 0) | |
| 331 (setq idx 1)) | |
| 332 (if (>= idx (length kkc-current-conversions)) | |
| 333 (setq idx 0)) | |
| 334 (setcar kkc-current-conversions idx) | |
| 335 (if (> idx 1) | |
| 336 (progn | |
| 337 (set-nested-alist kkc-current-key kkc-current-conversions | |
| 338 kkc-lookup-cache kkc-length-converted) | |
| 339 (setq kkc-init-file-flag 'kkc-lookup-cache))) | |
| 340 (if (or kkc-current-conversions-width | |
| 341 (>= kkc-next-count kkc-show-conversion-list-count)) | |
| 342 (kkc-show-conversion-list-update)) | |
| 343 (kkc-update-conversion))) | |
| 344 | |
| 345 (defun kkc-prev () | |
| 346 "Select the previous candidate of conversion." | |
| 347 (interactive) | |
| 348 (let ((idx (1- (car kkc-current-conversions)))) | |
| 349 (if (< idx 0) | |
| 350 (setq idx (1- (length kkc-current-conversions)))) | |
| 351 (setcar kkc-current-conversions idx) | |
| 352 (if (> idx 1) | |
| 353 (progn | |
| 354 (set-nested-alist kkc-current-key kkc-current-conversions | |
| 355 kkc-lookup-cache kkc-length-converted) | |
| 356 (setq kkc-init-file-flag 'kkc-lookup-cache))) | |
| 357 (if (or kkc-current-conversions-width | |
| 358 (>= kkc-prev-count kkc-show-conversion-list-count)) | |
| 359 (kkc-show-conversion-list-update)) | |
| 360 (kkc-update-conversion))) | |
| 361 | |
| 362 (defun kkc-select-from-list () | |
| 363 "Select one candidate from the list currently shown in echo area." | |
| 364 (interactive) | |
| 365 (let (idx) | |
| 366 (if kkc-current-conversions-width | |
| 367 (let ((len (length kkc-show-conversion-list-index-chars)) | |
| 368 (maxlen (- (aref (aref kkc-current-conversions-width 0) 1) | |
| 369 (aref (aref kkc-current-conversions-width 0) 0))) | |
| 370 (i 0)) | |
| 371 (if (> len maxlen) | |
| 372 (setq len maxlen)) | |
| 373 (while (< i len) | |
| 374 (if (= (aref kkc-show-conversion-list-index-chars i) | |
|
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
375 last-input-event) |
| 17052 | 376 (setq idx i i len) |
| 377 (setq i (1+ i)))))) | |
| 378 (if idx | |
| 379 (progn | |
| 380 (setcar kkc-current-conversions | |
| 381 (+ (aref (aref kkc-current-conversions-width 0) 0) idx)) | |
| 382 (kkc-show-conversion-list-update) | |
| 383 (kkc-update-conversion)) | |
|
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
384 (setq unread-input-method-events |
|
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
385 (cons last-input-event unread-input-method-events)) |
| 17052 | 386 (kkc-terminate)))) |
| 387 | |
| 388 (defun kkc-katakana () | |
| 389 "Convert to Katakana." | |
| 390 (interactive) | |
| 391 (setcar kkc-current-conversions -1) | |
| 392 (kkc-update-conversion 'all)) | |
| 393 | |
| 394 (defun kkc-hiragana () | |
| 395 "Convert to hiragana." | |
| 396 (interactive) | |
| 397 (setcar kkc-current-conversions 0) | |
| 398 (kkc-update-conversion)) | |
| 399 | |
| 400 (defun kkc-shorter () | |
| 401 "Make the Kana string to be converted shorter." | |
| 402 (interactive) | |
| 403 (if (<= kkc-length-head 1) | |
|
22888
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
404 (kkc-error "Can't be shorter")) |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
405 (setq kkc-length-head (1- kkc-length-head)) |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
406 (if (> kkc-length-converted kkc-length-head) |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
407 (let ((len kkc-length-head)) |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
408 (setq kkc-length-converted 0) |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
409 (while (not (kkc-lookup-key len)) |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
410 (setq len (1- len))))) |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
411 (kkc-update-conversion 'all)) |
| 17052 | 412 |
| 413 (defun kkc-longer () | |
| 414 "Make the Kana string to be converted longer." | |
| 415 (interactive) | |
| 416 (if (>= kkc-length-head (length kkc-current-key)) | |
|
22888
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
417 (kkc-error "Can't be longer")) |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
418 (setq kkc-length-head (1+ kkc-length-head)) |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
419 ;; This time, try also entries with postfixes. |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
420 (kkc-lookup-key kkc-length-head 'postfix) |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
421 (kkc-update-conversion 'all)) |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
422 |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
423 (defun kkc-shorter-conversion () |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
424 "Make the Kana string to be converted shorter." |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
425 (interactive) |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
426 (if (<= kkc-length-converted 1) |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
427 (kkc-error "Can't be shorter")) |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
428 (let ((len (1- kkc-length-converted))) |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
429 (setq kkc-length-converted 0) |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
430 (while (not (kkc-lookup-key len)) |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
431 (setq len (1- len)))) |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
432 (kkc-update-conversion 'all)) |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
433 |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
434 (defun kkc-longer-phrase () |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
435 "Make the current phrase (BUNSETSU) longer without looking up dictionary." |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
436 (interactive) |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
437 (if (>= kkc-length-head (length kkc-current-key)) |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
438 (kkc-error "Can't be longer")) |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
439 (setq kkc-length-head (1+ kkc-length-head)) |
|
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
440 (kkc-update-conversion 'all)) |
| 17052 | 441 |
| 442 (defun kkc-next-phrase () | |
| 443 "Fix the currently converted string and try to convert the remaining string." | |
| 444 (interactive) | |
| 445 (if (>= kkc-length-head (length kkc-current-key)) | |
| 446 (kkc-terminate) | |
| 447 (setq kkc-length-head (- (length kkc-current-key) kkc-length-head)) | |
| 448 (goto-char (overlay-end kkc-overlay-head)) | |
| 449 (while (and (< (point) (overlay-end kkc-overlay-tail)) | |
| 450 (looking-at "\\CH")) | |
| 451 (goto-char (match-end 0)) | |
| 452 (setq kkc-length-head (1- kkc-length-head))) | |
| 453 (if (= kkc-length-head 0) | |
| 454 (kkc-terminate) | |
| 455 (let ((newkey (make-vector kkc-length-head 0)) | |
| 456 (idx (- (length kkc-current-key) kkc-length-head)) | |
|
18644
69c91eee7ba1
(kkc-region): Call skkdic-lookup-key with
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
457 (len kkc-length-head) |
| 17052 | 458 (i 0)) |
| 459 ;; For the moment, (setq kkc-original-kana (concat newkey)) | |
| 460 ;; doesn't work. | |
| 461 (setq kkc-original-kana "") | |
| 462 (while (< i kkc-length-head) | |
| 463 (aset newkey i (aref kkc-current-key (+ idx i))) | |
| 464 (setq kkc-original-kana | |
| 465 (concat kkc-original-kana (char-to-string (aref newkey i)))) | |
| 466 (setq i (1+ i))) | |
| 467 (setq kkc-current-key newkey) | |
| 468 (setq kkc-length-converted 0) | |
|
18644
69c91eee7ba1
(kkc-region): Call skkdic-lookup-key with
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
469 (while (and (not (kkc-lookup-key kkc-length-head nil |
|
69c91eee7ba1
(kkc-region): Call skkdic-lookup-key with
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
470 (< kkc-length-head len))) |
| 17052 | 471 (> kkc-length-head 1)) |
| 472 (setq kkc-length-head (1- kkc-length-head))) | |
| 473 (let ((pos (point)) | |
| 474 (tail (overlay-end kkc-overlay-tail))) | |
| 475 (move-overlay kkc-overlay-head pos tail) | |
| 476 (move-overlay kkc-overlay-tail tail tail)) | |
| 477 (kkc-update-conversion 'all))))) | |
| 478 | |
| 479 ;; We'll show users a list of available conversions in echo area with | |
| 480 ;; index numbers so that users can select one conversion with the | |
| 481 ;; number. | |
| 482 | |
| 483 ;; Set `kkc-current-conversions-width'. | |
| 484 (defun kkc-setup-current-conversions-width () | |
| 485 (let ((convs (cdr kkc-current-conversions)) | |
| 486 (len (length kkc-current-conversions)) | |
| 487 (idx 1)) | |
| 488 (setq kkc-current-conversions-width (make-vector len nil)) | |
| 489 ;; To tell `kkc-show-conversion-list-update' to generate | |
| 490 ;; message from scratch. | |
| 491 (aset kkc-current-conversions-width 0 (vector len -2 nil)) | |
| 492 ;; Fill the remaining slots. | |
| 493 (while convs | |
| 494 (aset kkc-current-conversions-width idx | |
| 495 (+ (string-width (car convs)) 4)) | |
| 496 (setq convs (cdr convs) | |
| 497 idx (1+ idx))))) | |
| 498 | |
| 499 (defun kkc-show-conversion-list-or-next-group () | |
| 500 "Show list of available conversions in echo area with index numbers. | |
| 501 If the list is already shown, show the next group of conversions, | |
| 502 and change the current conversion to the first one in the group." | |
| 503 (interactive) | |
| 504 (if (< (length kkc-current-conversions) 3) | |
|
22888
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
505 (kkc-error "No alternative")) |
| 17052 | 506 (if kkc-current-conversions-width |
| 507 (let ((next-idx (aref (aref kkc-current-conversions-width 0) 1))) | |
| 508 (if (< next-idx (length kkc-current-conversions-width)) | |
| 509 (setcar kkc-current-conversions next-idx) | |
| 510 (setcar kkc-current-conversions 1)) | |
| 511 (kkc-show-conversion-list-update) | |
| 512 (kkc-update-conversion)) | |
| 513 (kkc-setup-current-conversions-width) | |
| 514 (kkc-show-conversion-list-update))) | |
| 515 | |
| 516 (defun kkc-show-conversion-list-or-prev-group () | |
| 517 "Show list of available conversions in echo area with index numbers. | |
| 518 If the list is already shown, show the previous group of conversions, | |
| 519 and change the current conversion to the last one in the group." | |
| 520 (interactive) | |
| 521 (if (< (length kkc-current-conversions) 3) | |
|
22888
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
522 (kkc-error "No alternative")) |
| 17052 | 523 (if kkc-current-conversions-width |
| 524 (let ((this-idx (aref (aref kkc-current-conversions-width 0) 0))) | |
| 525 (if (> this-idx 1) | |
| 526 (setcar kkc-current-conversions (1- this-idx)) | |
| 527 (setcar kkc-current-conversions | |
| 528 (1- (length kkc-current-conversions-width)))) | |
| 529 (kkc-show-conversion-list-update) | |
| 530 (kkc-update-conversion)) | |
| 531 (kkc-setup-current-conversions-width) | |
| 532 (kkc-show-conversion-list-update))) | |
| 533 | |
| 534 ;; Update the conversion list shown in echo area. | |
| 535 (defun kkc-show-conversion-list-update () | |
| 536 (or kkc-current-conversions-width | |
| 537 (kkc-setup-current-conversions-width)) | |
| 538 (let* ((current-idx (car kkc-current-conversions)) | |
| 539 (first-slot (aref kkc-current-conversions-width 0)) | |
| 540 (this-idx (aref first-slot 0)) | |
| 541 (next-idx (aref first-slot 1)) | |
| 542 (msg (aref first-slot 2))) | |
| 543 (if (< current-idx this-idx) | |
| 544 ;; The currently selected conversion is before the list shown | |
| 545 ;; previously. We must start calculation of message width | |
| 546 ;; from the start again. | |
| 547 (setq this-idx 1 msg nil) | |
| 548 (if (>= current-idx next-idx) | |
| 549 ;; The currently selected conversion is after the list shown | |
| 550 ;; previously. We start calculation of message width from | |
| 551 ;; the conversion next of TO. | |
| 552 (setq this-idx next-idx msg nil) | |
| 553 ;; The current conversion is in MSG. Just clear brackets | |
| 554 ;; around index number. | |
| 555 (if (string-match "<.>" msg) | |
| 556 (progn | |
| 557 (aset msg (match-beginning 0) ?\ ) | |
| 558 (aset msg (1- (match-end 0)) ?\ ))))) | |
| 559 (if (not msg) | |
| 560 (let ((len (length kkc-current-conversions)) | |
| 561 (max-width (window-width (minibuffer-window))) | |
| 562 (width-table kkc-current-conversions-width) | |
| 563 (width 0) | |
| 564 (idx this-idx) | |
|
22816
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
565 (max-items (length kkc-show-conversion-list-index-chars)) |
| 17052 | 566 l) |
|
30251
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
567 ;; Set THIS-IDX to the first index of conversion to be shown |
|
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
568 ;; in MSG, and reflect it in kkc-current-conversions-width. |
|
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
569 (while (<= idx current-idx) |
|
22816
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
570 (if (and (<= (+ width (aref width-table idx)) max-width) |
|
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
571 (< (- idx this-idx) max-items)) |
| 17052 | 572 (setq width (+ width (aref width-table idx))) |
| 573 (setq this-idx idx width (aref width-table idx))) | |
| 574 (setq idx (1+ idx) | |
| 575 l (cdr l))) | |
| 576 (aset first-slot 0 this-idx) | |
|
30251
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
577 ;; Set NEXT-IDX to the next index of the last conversion |
|
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
578 ;; shown in MSG, and reflect it in |
|
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
579 ;; kkc-current-conversions-width. |
| 17052 | 580 (while (and (< idx len) |
|
22816
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
581 (<= (+ width (aref width-table idx)) max-width) |
|
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
582 (< (- idx this-idx) max-items)) |
| 17052 | 583 (setq width (+ width (aref width-table idx)) |
| 584 idx (1+ idx) | |
| 585 l (cdr l))) | |
| 586 (aset first-slot 1 (setq next-idx idx)) | |
| 587 (setq l (nthcdr this-idx kkc-current-conversions)) | |
|
30251
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
588 (setq msg (format " %c %s" |
|
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
589 (aref kkc-show-conversion-list-index-chars 0) |
|
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
590 (car l)) |
|
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
591 idx (1+ this-idx) |
|
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
592 l (cdr l)) |
| 17052 | 593 (while (< idx next-idx) |
|
30251
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
594 (setq msg (format "%s %c %s" |
| 17052 | 595 msg |
| 596 (aref kkc-show-conversion-list-index-chars | |
| 597 (- idx this-idx)) | |
| 598 (car l))) | |
| 599 (setq idx (1+ idx) | |
| 600 l (cdr l))) | |
| 601 (aset first-slot 2 msg))) | |
| 602 (if (> current-idx 0) | |
| 603 (progn | |
| 604 ;; Highlight the current conversion by brackets. | |
| 605 (string-match (format " \\(%c\\) " | |
| 606 (aref kkc-show-conversion-list-index-chars | |
| 607 (- current-idx this-idx))) | |
| 608 msg) | |
| 609 (aset msg (match-beginning 0) ?<) | |
| 610 (aset msg (1- (match-end 0)) ?>))) | |
| 611 (message "%s" msg))) | |
| 612 | |
| 613 ;; Update the conversion area with the latest conversion selected. | |
| 614 ;; ALL if non nil means to update the whole area, else update only | |
| 615 ;; inside quail-overlay-head. | |
| 616 | |
| 617 (defun kkc-update-conversion (&optional all) | |
| 618 (goto-char (overlay-start kkc-overlay-head)) | |
| 619 (cond ((= (car kkc-current-conversions) 0) ; Hiragana | |
| 620 (let ((i 0)) | |
| 621 (while (< i kkc-length-converted) | |
| 622 (insert (aref kkc-current-key i)) | |
| 623 (setq i (1+ i))))) | |
| 624 ((= (car kkc-current-conversions) -1) ; Katakana | |
| 625 (let ((i 0)) | |
| 626 (while (< i kkc-length-converted) | |
| 627 (insert (japanese-katakana (aref kkc-current-key i))) | |
| 628 (setq i (1+ i))))) | |
| 629 (t | |
| 630 (insert (nth (car kkc-current-conversions) kkc-current-conversions)))) | |
| 631 (delete-region (point) (overlay-start kkc-overlay-tail)) | |
| 632 (if all | |
| 633 (let ((len (length kkc-current-key)) | |
| 634 (i kkc-length-converted)) | |
| 635 (delete-region (overlay-start kkc-overlay-tail) | |
| 636 (overlay-end kkc-overlay-head)) | |
| 637 (while (< i kkc-length-head) | |
| 638 (if (= (car kkc-current-conversions) -1) | |
| 639 (insert (japanese-katakana (aref kkc-current-key i))) | |
| 640 (insert (aref kkc-current-key i))) | |
| 641 (setq i (1+ i))) | |
| 642 (let ((pos (point))) | |
| 643 (while (< i len) | |
| 644 (insert (aref kkc-current-key i)) | |
| 645 (setq i (1+ i))) | |
| 646 (move-overlay kkc-overlay-head | |
| 647 (overlay-start kkc-overlay-head) pos) | |
| 648 (delete-region (point) (overlay-end kkc-overlay-tail))))) | |
|
30256
e4b4bca5087a
(kkc-after-update-conversion-functions): New variable.
Kenichi Handa <handa@m17n.org>
parents:
30251
diff
changeset
|
649 (unwind-protect |
|
e4b4bca5087a
(kkc-after-update-conversion-functions): New variable.
Kenichi Handa <handa@m17n.org>
parents:
30251
diff
changeset
|
650 (run-hook-with-args 'kkc-after-update-conversion-functions |
|
e4b4bca5087a
(kkc-after-update-conversion-functions): New variable.
Kenichi Handa <handa@m17n.org>
parents:
30251
diff
changeset
|
651 (overlay-start kkc-overlay-head) |
|
e4b4bca5087a
(kkc-after-update-conversion-functions): New variable.
Kenichi Handa <handa@m17n.org>
parents:
30251
diff
changeset
|
652 (overlay-end kkc-overlay-head)) |
|
e4b4bca5087a
(kkc-after-update-conversion-functions): New variable.
Kenichi Handa <handa@m17n.org>
parents:
30251
diff
changeset
|
653 (goto-char (overlay-end kkc-overlay-tail)))) |
| 17052 | 654 |
| 655 ;; | |
| 656 (provide 'kkc) | |
| 657 | |
| 658 ;; kkc.el ends here |
