annotate lisp/international/kkc.el @ 74872:789e50a3feec

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