-;; kkc.el -- Kana Kanji converter
+;;; kkc.el --- Kana Kanji converter
-;; Copyright (C) 1995 Free Software Foundation, Inc.
;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
+;; Licensed to the Free Software Foundation.
;; Keywords: mule, multilingual, Japanese, SKK
"Save initial setup code for KKC to a file specified by `kkc-init-file-name'"
(if (and kkc-init-file-flag
(not (eq kkc-init-file-flag t)))
- (let ((coding-system-for-write 'coding-system-iso-2022-7))
+ (let ((coding-system-for-write 'iso-2022-7bit))
(write-region (format "(setq kkc-lookup-cache '%S)\n" kkc-lookup-cache)
nil
kkc-init-file-name))))
(defvar kkc-mode-map
(let ((map (make-keymap))
(i 0))
- (while (< i ? )
- (define-key map (char-to-string i) 'undefined)
- (setq i (1+ i)))
(while (< i 128)
(define-key map (char-to-string i) 'kkc-non-kkc-command)
(setq i (1+ i)))
(define-key map "H" 'kkc-hiragana)
(define-key map "l" 'kkc-show-conversion-list-or-next-group)
(define-key map "L" 'kkc-show-conversion-list-or-prev-group)
- (define-key map [?\C-\ ] 'kkc-first-char-only)
+ (define-key map [?\C- ] 'kkc-first-char-only)
(define-key map [delete] 'kkc-cancel)
(define-key map [return] 'kkc-terminate)
- (append map '((t . kkc-non-kkc-command))))
+ (let ((meta-map (make-sparse-keymap)))
+ (define-key map (char-to-string meta-prefix-char) meta-map)
+ (define-key map [escape] meta-map))
+ (define-key map (vector meta-prefix-char t) 'kkc-non-kkc-command)
+ ;; At last, define default key binding.
+ (define-key map [t] 'kkc-non-kkc-command)
+ map)
"Keymap for KKC (Kana Kanji Conversion) mode.")
(defun kkc-mode ()
;; LEN. If no conversion is found in the dictionary, don't change
;; kkc-current-conversions and return nil.
;; Postfixes are handled only if POSTFIX is non-nil.
-(defun kkc-lookup-key (len &optional postfix)
+(defun kkc-lookup-key (len &optional postfix prefer-noun)
;; At first, prepare cache data if any.
(if (not kkc-init-file-flag)
(progn
(setq kkc-length-converted len
kkc-current-conversions-width nil
kkc-current-conversions (car entry))
- (setq entry (skkdic-lookup-key kkc-current-key len postfix))
+ (setq entry (skkdic-lookup-key kkc-current-key len postfix prefer-noun))
(if entry
(progn
(setq kkc-length-converted len
kkc-current-conversions (cons 0 nil)))))))
;;;###autoload
-(defun kkc-region (from to)
+(defun kkc-region (from to &optional kkc-mode-exit-function)
"Convert Kana string in the current region to Kanji-Kana mixed string.
After one candidate of conversion is shown in the region, users are
-put in KKC major mode to select a desirable conversion."
+put in KKC major mode to select a desirable conversion.
+Optional arg KKC-MODE-EXIT-FUNCTION if non-nil is called on exiting KKC mode."
(interactive "r")
(setq kkc-original-kana (buffer-substring from to))
(goto-char from)
;; After updating the conversion region with the first candidate of
;; conversion, jump into a recursive editing environment with KKC
- ;; mode .
+ ;; mode.
(let ((overriding-local-map nil)
(previous-local-map (current-local-map))
(minor-mode-alist nil)
(current-input-method-title kkc-input-method-title)
major-mode mode-name)
(unwind-protect
- (progn
+ (let (len)
(setq kkc-canceled nil)
(setq kkc-current-key (string-to-vector kkc-original-kana))
(setq kkc-length-head (length kkc-current-key))
+ (setq len kkc-length-head)
(setq kkc-length-converted 0)
- (while (not (kkc-lookup-key kkc-length-head))
+ (while (not (kkc-lookup-key kkc-length-head nil
+ (< kkc-length-head len)))
(setq kkc-length-head (1- kkc-length-head)))
(goto-char to)
(kkc-update-conversion 'all)
(goto-char (overlay-end kkc-overlay-tail))
(delete-overlay kkc-overlay-head)
(delete-overlay kkc-overlay-tail)
- (use-local-map previous-local-map)))
- kkc-canceled)
+ (use-local-map previous-local-map)
+ (if (and kkc-mode-exit-function
+ (fboundp kkc-mode-exit-function))
+ (funcall kkc-mode-exit-function (if kkc-canceled
+ (cons kkc-canceled (point))))))))
(defun kkc-terminate ()
"Exit from KKC mode by fixing the current conversion."
"Exit from KKC mode by fixing the current conversion.
After that, handle the event which invoked this command."
(interactive)
- (setq unread-command-events (list last-input-event))
+ (let* ((key (this-command-keys))
+ (keylist (listify-key-sequence key)))
+ (setq unread-command-events (append keylist unread-command-events)))
(kkc-terminate))
(defun kkc-cancel ()
(kkc-terminate)
(let ((newkey (make-vector kkc-length-head 0))
(idx (- (length kkc-current-key) kkc-length-head))
+ (len kkc-length-head)
(i 0))
;; For the moment, (setq kkc-original-kana (concat newkey))
;; doesn't work.
(setq i (1+ i)))
(setq kkc-current-key newkey)
(setq kkc-length-converted 0)
- (while (and (not (kkc-lookup-key kkc-length-head))
+ (while (and (not (kkc-lookup-key kkc-length-head nil
+ (< kkc-length-head len)))
(> kkc-length-head 1))
(setq kkc-length-head (1- kkc-length-head)))
(let ((pos (point))