aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenichi Handa1998-07-16 00:14:44 +0000
committerKenichi Handa1998-07-16 00:14:44 +0000
commit9045dc7e0a80512389d59d7d9b61c499f668d342 (patch)
treeb5972eed06e21bd13decd57cc8859284415a3905
parentb58fc490b4085519055c3daae372bb43ec5889a9 (diff)
downloademacs-9045dc7e0a80512389d59d7d9b61c499f668d342.tar.gz
emacs-9045dc7e0a80512389d59d7d9b61c499f668d342.zip
(kkc-show-conversion-list-index-chars):
Default value changed. (kkc-keymap): Renamed from kkc-mode-map. Key binding for kkc-non-kkc-command are deleted. (kkc-mode): This function deleted. (kkc-canceled): This variable deleted. (kkc-converting): New variable. (kkc-region): 3rd optional arg is deleted. Completely rewritten to adjust for the change in quail.el. (kkc-terminate, kkc-cancel): Adjusted for the change of kkc-region. (kkc-non-kkc-command): This function deleted. (kkc-select-from-list): Use last-input-event instead of last-input-char. Put an unknown event back to unread-input-method-events.
-rw-r--r--lisp/international/kkc.el141
1 files changed, 58 insertions, 83 deletions
diff --git a/lisp/international/kkc.el b/lisp/international/kkc.el
index 7d2baf80e02..05889322fd9 100644
--- a/lisp/international/kkc.el
+++ b/lisp/international/kkc.el
@@ -66,23 +66,18 @@ This string is shown at mode line when users are in KKC mode.")
66;; Sequence of characters to be used for indexes for shown list. The 66;; Sequence of characters to be used for indexes for shown list. The
67;; Nth character is for the Nth conversion in the list currently shown. 67;; Nth character is for the Nth conversion in the list currently shown.
68(defvar kkc-show-conversion-list-index-chars 68(defvar kkc-show-conversion-list-index-chars
69 "1234567890abcdefghijklmnopqrsuvwxyz") 69 "1234567890")
70 70
71(defvar kkc-mode-map 71(defvar kkc-keymap
72 (let ((map (make-keymap)) 72 (let ((map (make-keymap))
73 (len (length kkc-show-conversion-list-index-chars))
73 (i 0)) 74 (i 0))
74 (while (< i 128) 75 (while (< i len)
75 (define-key map (char-to-string i) 'kkc-non-kkc-command) 76 (define-key map
77 (char-to-string (aref kkc-show-conversion-list-index-chars i))
78 'kkc-select-from-list)
76 (setq i (1+ i))) 79 (setq i (1+ i)))
77 (setq i 0)
78 (let ((len (length kkc-show-conversion-list-index-chars)))
79 (while (< i len)
80 (define-key map
81 (char-to-string (aref kkc-show-conversion-list-index-chars i))
82 'kkc-select-from-list)
83 (setq i (1+ i))))
84 (define-key map " " 'kkc-next) 80 (define-key map " " 'kkc-next)
85 (define-key map (char-to-string help-char) 'help-command)
86 (define-key map "\r" 'kkc-terminate) 81 (define-key map "\r" 'kkc-terminate)
87 (define-key map "\C-@" 'kkc-first-char-only) 82 (define-key map "\C-@" 'kkc-first-char-only)
88 (define-key map "\C-n" 'kkc-next) 83 (define-key map "\C-n" 'kkc-next)
@@ -99,23 +94,8 @@ This string is shown at mode line when users are in KKC mode.")
99 (define-key map [?\C- ] 'kkc-first-char-only) 94 (define-key map [?\C- ] 'kkc-first-char-only)
100 (define-key map [delete] 'kkc-cancel) 95 (define-key map [delete] 'kkc-cancel)
101 (define-key map [return] 'kkc-terminate) 96 (define-key map [return] 'kkc-terminate)
102 (let ((meta-map (make-sparse-keymap)))
103 (define-key map (char-to-string meta-prefix-char) meta-map)
104 (define-key map [escape] meta-map))
105 (define-key map (vector meta-prefix-char t) 'kkc-non-kkc-command)
106 ;; At last, define default key binding.
107 (define-key map [t] 'kkc-non-kkc-command)
108 map) 97 map)
109 "Keymap for KKC (Kana Kanji Conversion) mode.") 98 "Keymap for KKC (Kana Kanji Converter).")
110
111(defun kkc-mode ()
112 "Major mode for converting Kana string to Kanji-Kana mixed string.
113Commands:
114\\{kkc-mode-map}"
115 (setq major-mode 'kkc-mode)
116 (setq mode-name "KKC")
117 (use-local-map kkc-mode-map)
118 (run-hooks 'kkc-mode-hook))
119 99
120;;; Internal variables used in KKC. 100;;; Internal variables used in KKC.
121 101
@@ -143,7 +123,7 @@ Commands:
143 "Count of successive `kkc-next' or `kkc-prev' to show conversion list.") 123 "Count of successive `kkc-next' or `kkc-prev' to show conversion list.")
144 124
145;; Provided that `kkc-current-key' is [A B C D E F G H I], the current 125;; Provided that `kkc-current-key' is [A B C D E F G H I], the current
146;; conversion target is [A B C D E F], the sequence of which 126;; conversion target is [A B C D E F], and the sequence of which
147;; conversion is found is [A B C D]: 127;; conversion is found is [A B C D]:
148;; 128;;
149;; A B C D E F G H I 129;; A B C D E F G H I
@@ -160,11 +140,6 @@ Commands:
160;; Cursor type (`box' or `bar') of the current frame. 140;; Cursor type (`box' or `bar') of the current frame.
161(defvar kkc-cursor-type nil) 141(defvar kkc-cursor-type nil)
162 142
163;; Flag to tell if the current conversion is canceled. If non-nil,
164;; the value is a buffer position of the head of currently active
165;; conversion region.
166(defvar kkc-canceled nil)
167
168;; Lookup SKK dictionary to set list of conversions in 143;; Lookup SKK dictionary to set list of conversions in
169;; kkc-current-conversions for key sequence kkc-current-key of length 144;; kkc-current-conversions for key sequence kkc-current-key of length
170;; LEN. If no conversion is found in the dictionary, don't change 145;; LEN. If no conversion is found in the dictionary, don't change
@@ -204,12 +179,16 @@ Commands:
204 kkc-current-conversions-width nil 179 kkc-current-conversions-width nil
205 kkc-current-conversions (cons 0 nil))))))) 180 kkc-current-conversions (cons 0 nil)))))))
206 181
182(defvar kkc-converting nil)
183
207;;;###autoload 184;;;###autoload
208(defun kkc-region (from to &optional kkc-mode-exit-function) 185(defun kkc-region (from to)
209 "Convert Kana string in the current region to Kanji-Kana mixed string. 186 "Convert Kana string in the current region to Kanji-Kana mixed string.
210After one candidate of conversion is shown in the region, users are 187Users can select a desirable conversion interactively.
211put in KKC major mode to select a desirable conversion. 188When called from a program, expects two arguments,
212Optional arg KKC-MODE-EXIT-FUNCTION if non-nil is called on exiting KKC mode." 189positions FROM and TO (integers or markers) specifying the target region.
190When it returns, the point is at the tail of the selected conversion,
191and the return value is the length of the conversion."
213 (interactive "r") 192 (interactive "r")
214 (setq kkc-original-kana (buffer-substring from to)) 193 (setq kkc-original-kana (buffer-substring from to))
215 (goto-char from) 194 (goto-char from)
@@ -224,57 +203,52 @@ Optional arg KKC-MODE-EXIT-FUNCTION if non-nil is called on exiting KKC mode."
224 (setq kkc-overlay-tail (make-overlay to to nil nil t)) 203 (setq kkc-overlay-tail (make-overlay to to nil nil t))
225 (overlay-put kkc-overlay-tail 'face 'underline)) 204 (overlay-put kkc-overlay-tail 'face 'underline))
226 205
227 ;; After updating the conversion region with the first candidate of 206 (setq kkc-current-key (string-to-vector kkc-original-kana))
228 ;; conversion, jump into a recursive editing environment with KKC 207 (setq kkc-length-head (length kkc-current-key))
229 ;; mode. 208 (setq kkc-length-converted 0)
230 (let ((overriding-local-map nil) 209
231 (previous-local-map (current-local-map)) 210 ;; At first convert the region to the first candidate.
232 (minor-mode-alist nil) 211 (let ((first t))
233 (minor-mode-map-alist nil) 212 (while (not (kkc-lookup-key kkc-length-head nil first))
234 (current-input-method-title kkc-input-method-title) 213 (setq kkc-length-head (1- kkc-length-head)
235 major-mode mode-name) 214 first nil))
236 (unwind-protect 215 (goto-char to)
237 (let (len) 216 (kkc-update-conversion 'all))
238 (setq kkc-canceled nil) 217
239 (setq kkc-current-key (string-to-vector kkc-original-kana)) 218 ;; Then, ask users to selecte a desirable conversoin.
240 (setq kkc-length-head (length kkc-current-key)) 219 (let ((current-input-method-title kkc-input-method-title)
241 (setq len kkc-length-head) 220 (input-method-function nil))
242 (setq kkc-length-converted 0) 221 (force-mode-line-update)
243 (while (not (kkc-lookup-key kkc-length-head nil 222 (setq kkc-converting t)
244 (< kkc-length-head len))) 223 (while kkc-converting
245 (setq kkc-length-head (1- kkc-length-head))) 224 (let* ((echo-keystrokes 0)
246 (goto-char to) 225 (keyseq (read-key-sequence nil))
247 (kkc-update-conversion 'all) 226 (cmd (lookup-key kkc-keymap keyseq)))
248 (kkc-mode) 227 (if (commandp cmd)
249 (recursive-edit)) 228 (condition-case err
250 (goto-char (overlay-end kkc-overlay-tail)) 229 (call-interactively cmd)
251 (delete-overlay kkc-overlay-head) 230 (kkc-error (message "%s" (cdr err)) (beep)))
252 (delete-overlay kkc-overlay-tail) 231 ;; KEYSEQ is not defined in KKC keymap.
253 (use-local-map previous-local-map) 232 ;; Let's put the event back.
254 (if (and kkc-mode-exit-function 233 (setq unread-input-method-events
255 (fboundp kkc-mode-exit-function)) 234 (append (string-to-list keyseq) unread-input-method-events))
256 (funcall kkc-mode-exit-function (if kkc-canceled 235 (setq kkc-converting nil)))))
257 (cons kkc-canceled (point)))))))) 236
237 (force-mode-line-update)
238 (goto-char (overlay-end kkc-overlay-tail))
239 (prog1 (- (overlay-start kkc-overlay-head) from)
240 (delete-overlay kkc-overlay-head)
241 (delete-overlay kkc-overlay-tail)))
258 242
259(defun kkc-terminate () 243(defun kkc-terminate ()
260 "Exit from KKC mode by fixing the current conversion." 244 "Exit from KKC mode by fixing the current conversion."
261 (interactive) 245 (interactive)
262 (throw 'exit nil)) 246 (setq kkc-converting nil))
263
264(defun kkc-non-kkc-command ()
265 "Exit from KKC mode by fixing the current conversion.
266After that, handle the event which invoked this command."
267 (interactive)
268 (let* ((key (this-command-keys))
269 (keylist (listify-key-sequence key)))
270 (setq unread-command-events (append keylist unread-command-events)))
271 (kkc-terminate))
272 247
273(defun kkc-cancel () 248(defun kkc-cancel ()
274 "Exit from KKC mode by canceling any conversions." 249 "Exit from KKC mode by canceling any conversions."
275 (interactive) 250 (interactive)
276 (setq kkc-canceled (overlay-start kkc-overlay-head)) 251 (goto-char (overlay-start kkc-overlay-head))
277 (goto-char kkc-canceled)
278 (delete-region (overlay-start kkc-overlay-head) 252 (delete-region (overlay-start kkc-overlay-head)
279 (overlay-end kkc-overlay-tail)) 253 (overlay-end kkc-overlay-tail))
280 (insert kkc-original-kana) 254 (insert kkc-original-kana)
@@ -349,7 +323,7 @@ After that, handle the event which invoked this command."
349 (setq len maxlen)) 323 (setq len maxlen))
350 (while (< i len) 324 (while (< i len)
351 (if (= (aref kkc-show-conversion-list-index-chars i) 325 (if (= (aref kkc-show-conversion-list-index-chars i)
352 last-input-char) 326 last-input-event)
353 (setq idx i i len) 327 (setq idx i i len)
354 (setq i (1+ i)))))) 328 (setq i (1+ i))))))
355 (if idx 329 (if idx
@@ -358,7 +332,8 @@ After that, handle the event which invoked this command."
358 (+ (aref (aref kkc-current-conversions-width 0) 0) idx)) 332 (+ (aref (aref kkc-current-conversions-width 0) 0) idx))
359 (kkc-show-conversion-list-update) 333 (kkc-show-conversion-list-update)
360 (kkc-update-conversion)) 334 (kkc-update-conversion))
361 (setq unread-command-events (list last-input-event)) 335 (setq unread-input-method-events
336 (cons last-input-event unread-input-method-events))
362 (kkc-terminate)))) 337 (kkc-terminate))))
363 338
364(defun kkc-katakana () 339(defun kkc-katakana ()