(VERSION): Update to 1.2.
[elisp/emacs-canna.git] / canna.el
index 715e5cf..b26a330 100644 (file)
--- a/canna.el
+++ b/canna.el
@@ -1,14 +1,16 @@
 ;;; canna.el --- Interface to the Canna input method.
 
 ;; Copyright (C) 1994 Akira Kon, NEC Corporation.
-;; Copyright (C) 1996,1997 MORIOKA Tomohiko
+;; Copyright (C) 1996,1997,1998 MORIOKA Tomohiko
+;; Copyright (C) 1997 Stephen Turnbull
 
 ;; Author: Akira Kon <kon@d1.bs2.mt.nec.co.jp>
 ;;         MORIOKA Tomohiko <morioka@jaist.ac.jp>
-;; Version: $Revision: 1.6 $
+;;         Stephen Turnbull <turnbull@sk.tsukuba.ac.jp>
+;; Version: $Revision: 1.18 $
 ;; Keywords: Canna, Japanese, input method, mule, multilingual
 
-;; This file is not a part of Emacs yet.
+;; This file is part of Emacs-Canna.
 
 ;; This program is free software; you can redistribute it and/or
 ;; modify it under the terms of the GNU General Public License as
 
 ;;; Code:
 
-;; -*-mode: emacs-lisp-*-
+(require 'poem)
+
+(defvar canna-dl-module
+  (expand-file-name "canna.so" exec-directory))
+
+(defvar canna-dl-handle
+  (and (not (boundp 'CANNA))
+       (fboundp 'dynamic-link)
+       (dynamic-link canna-dl-module)))
+
+(and canna-dl-handle
+     (dynamic-call "emacs_canna_init" canna-dl-handle))
 
-;; by \e$B<i2,\e(B \e$BCNI'\e(B <morioka@jaist.ac.jp> 1996/11/11
 (or (boundp 'CANNA)
-    (let ((handle (dynamic-link (expand-file-name "canna.so" exec-directory))))
-      (dynamic-call "emacs_canna_init" handle))
-    )
+    (featurep 'CANNA)
+    (error "Canna is not built into this Emacs"))
 
 (defvar self-insert-after-hook nil)
 ;; (defalias 'self-insert-internal 'self-insert-command)
 ;; end
 
 (defconst canna-rcs-version
-  "$Id: canna.el,v 1.6 1997-04-03 20:18:20 morioka Exp $")
+  "$Id: canna.el,v 1.18 1998-10-27 09:59:18 morioka Exp $")
 
 (defun canna-version ()
   "Display version of canna.el in mini-buffer."
                         ))
            " ...")))
 
-;; added by MORIOKA Tomohiko <morioka@jaist.ac.jp>, 1996/6/7
-(or (fboundp 'minibuffer-prompt-width)
-    (defun minibuffer-prompt-width ()
-      "Return the display width of the minibuffer prompt."
-      (save-excursion
-       (set-buffer (window-buffer (minibuffer-window)))
-       (current-column)
-       ))
-    )
-
-;; added by MORIOKA Tomohiko <morioka@jaist.ac.jp>, 1997/4/3
-(or (fboundp 'char-or-char-int-p)
-    (defalias 'char-or-char-int-p 'integerp)
-    )
+(if (featurep 'xemacs)
+    (defun canna-self-insert-string (string)
+      (let ((len (length string))
+           (i 0)
+           ;; \e$BA^F~$NESCf$G\e(B blink \e$B$,5/$-$k$H$&$C$H$*$7$$$N$G!"\e(B
+           ;; \e$B0l;~E*$K\e(B blink \e$B$rM^;_$9$k!#\e(B
+           (blink-matching-paren nil))
+       (while (< i len)
+         (self-insert-internal (aref canna-kakutei-string i))
+         (setq i (1+ i))
+         )))
+  (defalias 'canna-self-insert-string 'insert)
+  )
 
-;; added by MORIOKA Tomohiko <morioka@jaist.ac.jp>, 1996/6/18
-(defvar running-xemacs (string-match "XEmacs" emacs-version))
-
-(cond (running-xemacs
-       (require 'overlay)
-       (defun self-insert-string (string)
-        (let ((len (length string))
-              (i 0)
-              ;; \e$BA^F~$NESCf$G\e(B blink \e$B$,5/$-$k$H$&$C$H$*$7$$$N$G!"\e(B
-              ;; \e$B0l;~E*$K\e(B blink \e$B$rM^;_$9$k!#\e(B
-              (blink-matching-paren nil))
-          (while (< i len)
-            (self-insert-internal (aref canna-kakutei-string i))
-            (setq i (1+ i))
-            )))
-       )
-      (t
-       (defalias 'self-insert-string 'insert)
-       ))
 
 ;;; \e$B$+$s$J$NJQ?t\e(B
 
        (canna:memq-recursive a (cdr l)) )))
 
 (defun canna:create-mode-line ()
-  (if (not (canna:memq-recursive 'mode-line-canna-mode mode-line-format))
-      (setq-default
-       mode-line-format
-       (append (list (list 'minibuffer-window-selected
-                          (list 'display-minibuffer-mode-in-minibuffer
-                                "-" "m") "-")
-                    (list 'minibuffer-window-selected
-                          (list 'display-minibuffer-mode-in-minibuffer
-                                'mode-line-canna-mode
-                                'mode-line-canna-mode-in-minibuffer)
-                          'mode-line-canna-mode))
-              mode-line-format)))
-  (mode-line-canna-mode-update mode-line-canna-mode) )
+  "Add string of Canna status into mode-line."
+  (cond ((featurep 'xemacs)
+        (or (canna:memq-recursive 'mode-line-canna-mode
+                                  default-modeline-format)
+            (setq-default default-modeline-format
+                          (nconc '("" mode-line-canna-mode)
+                                 default-modeline-format))
+            )
+        (mapcar (function
+                 (lambda (buffer)
+                   (save-excursion
+                     (set-buffer buffer)
+                     (or (canna:memq-recursive 'mode-line-canna-mode
+                                               modeline-format)
+                         (setq modeline-format
+                               (nconc '("" mode-line-canna-mode)
+                                      modeline-format))
+                         )
+                     )))
+                (buffer-list))
+        )
+       (t
+        (or (canna:memq-recursive 'mode-line-canna-mode mode-line-format)
+            (setq-default
+             mode-line-format
+             (append (list (list 'minibuffer-window-selected
+                                 (list 'display-minibuffer-mode-in-minibuffer
+                                       "-" "m") "-")
+                           (list 'minibuffer-window-selected
+                                 (list 'display-minibuffer-mode-in-minibuffer
+                                       'mode-line-canna-mode
+                                       'mode-line-canna-mode-in-minibuffer)
+                                 'mode-line-canna-mode))
+                     mode-line-format))
+            )))
+  (mode-line-canna-mode-update mode-line-canna-mode))
 
 (defun canna:mode-line-display ()
   (mode-line-canna-mode-update mode-line-canna-mode))
@@ -282,7 +296,7 @@ t \e$B$N;~$O%G%U%)%k%H$N?'$r;HMQ$9$k!#\e(B
     (define-key canna-mode-map (make-string 1 ch) 'canna-functional-insert-command)
     (setq ch (1+ ch))))
 
-(cond (running-xemacs
+(cond ((featurep 'xemacs)
        (define-key canna-mode-map [up]             "\C-p")
        (define-key canna-mode-map [(shift up)]      "\C-p")
        (define-key canna-mode-map [(control up)]    "\C-p")
@@ -323,7 +337,7 @@ t \e$B$N;~$O%G%U%)%k%H$N?'$r;HMQ$9$k!#\e(B
     (define-key canna-minibuffer-mode-map (make-string 1 ch) 'canna-minibuffer-insert-command)
     (setq ch (1+ ch))))
 
-(cond (running-xemacs
+(cond ((featurep 'xemacs)
        (define-key canna-minibuffer-mode-map [up]              "\C-p")
        (define-key canna-minibuffer-mode-map [(shift up)]      "\C-p")
        (define-key canna-minibuffer-mode-map [(control up)]    "\C-p")
@@ -468,7 +482,7 @@ kana-to-kanji translation."
                (set-marker canna:*spos-undo-text* (point))
 ;;
 ;; update kbnes
-               (self-insert-string canna-kakutei-string)
+               (canna-self-insert-string canna-kakutei-string)
                ;; \e$BL$3NDj$NJ8;z$,$J$/!"3NDjJ8;zNs$N:G8e$,JD$83g8L$N\e(B
                ;; \e$BN`$@$C$?$H$-$O\e(B blink \e$B$5$;$k!#\e(B
                (if (and canna-empty-info
@@ -496,7 +510,7 @@ kana-to-kanji translation."
               (t
 ;;
 ;; update kbnes
-               (self-insert-string canna-kakutei-string)
+               (canna-self-insert-string canna-kakutei-string)
                ;; \e$BL$3NDj$NJ8;z$,$J$/!"3NDjJ8;zNs$N:G8e$,JD$83g8L$N\e(B
                ;; \e$BN`$@$C$?$H$-$O\e(B blink \e$B$5$;$k!#\e(B
                (if (and canna-empty-info
@@ -632,7 +646,7 @@ kana-to-kanji translation."
 ;      (set-window-buffer (minibuffer-window)
 ;                         (get-buffer-create canna:*menu-buffer*))
        ;; modified by \e$B<i2,\e(B \e$BCNI'\e(B <morioka@jaist.ac.jp>, 1996/6/7
-       (unless running-xemacs
+       (unless (featurep 'xemacs)
          ;; \e$B$H$j$"$($:\e(B XEmacs \e$B$G$OF0$+$5$J$$$3$H$K$7$F$*$3$&\e(B (^_^;
          (setq canna:*saved-redirection* (frame-focus (selected-frame)))
          (redirect-frame-focus (selected-frame) 
@@ -678,7 +692,7 @@ kana-to-kanji translation."
        (set-window-buffer (minibuffer-window) canna:*saved-minibuffer*)
 ;      (setq canna:*saved-minibuffer* nil)
        ;; modified by \e$B<i2,\e(B \e$BCNI'\e(B <morioka@jaist.ac.jp>, 1996/6/7
-       (unless running-xemacs
+       (unless (featurep 'xemacs)
          ;; \e$B$H$j$"$($:\e(B XEmacs \e$B$G$OF0$+$5$J$$$h$&$K$7$F$*$3$&\e(B (^_^;
          (redirect-frame-focus (window-frame canna:*previous-window*)
                                canna:*saved-redirection*)
@@ -719,8 +733,8 @@ kana-to-kanji translation, even if you are in the minibuffer."
 ;;; canna-functional-insert-command \e$B$r8F$V!#\e(B
 ;;;
 
-(if (not (boundp 'MULE)) ; for Nemacs
-    (defun cancel-undo-boundary ()))
+;; (if (not (boundp 'MULE)) ; for Nemacs
+;;     (defun cancel-undo-boundary ()))
 
 (defun canna-self-insert-command (arg)
   "Self insert pressed key and use it to assemble Romaji character."
@@ -755,6 +769,9 @@ kana-to-kanji translation, even if you are in the minibuffer."
                       (- (point) arg) (point)))
        (if (= last-command-char ? ) (canna:do-auto-fill))))))
 
+;; wire us into pending-delete
+(put 'canna-self-insert-command 'pending-delete t)
+
 (defun canna-toggle-japanese-mode ()
   "Toggle canna japanese mode."
   (interactive)
@@ -833,10 +850,11 @@ kana-to-kanji translation, even if you are in the minibuffer."
                                 canna:*saved-mode-string*
                               new-mode)))
                        0)))
-  (setq canna:*local-map-backup*  (current-local-map))
+  (setq canna:*local-map-backup* (current-local-map))
   (setq canna:*fence-mode* t)
   ;; XEmacs change:
-  (buffer-disable-undo (current-buffer))
+  ;; (buffer-disable-undo (current-buffer))
+  ;; Original:
   ;; (if (boundp 'disable-undo)
   ;;     (setq disable-undo canna:*fence-mode*))
   (use-local-map canna-mode-map))
@@ -858,7 +876,8 @@ kana-to-kanji translation, even if you are in the minibuffer."
                   (canna-toggle-japanese-mode)
                 (mode-line-canna-mode-update canna:*alpha-mode-string*) )))
         ;; XEmacs change:
-        (buffer-enable-undo (current-buffer))
+         ;; (buffer-enable-undo (current-buffer))
+        ;; Original:
          ;; (if (boundp 'disable-undo)
          ;;     (setq disable-undo canna:*fence-mode*))
         ))
@@ -991,7 +1010,7 @@ dictionary."
                              (eq hilit-background-mode 'dark))
                         (string-match
                          "on\\|t"
-                         (or (if running-xemacs
+                         (or (if (featurep 'xemacs)
                                  (x-get-resource "ReverseVideo"
                                                  "reverseVideo" 'string)
                                (x-get-resource "ReverseVideo" "reverseVideo"))
@@ -1048,7 +1067,14 @@ dictionary."
               (define-key global-map (make-string 1 ch) 'canna-self-insert-command)
               (setq ch (1+ ch)) ))
 
-          (cond ((let ((keys (car init-val)) (ok nil))
+          (cond
+           ;; #### I'm just guessing that this should come before the
+           ;;      init-val setting
+           ;; if registered with LEIM, no-op
+           ((featurep 'canna-leim) t)
+           ;; check to see if an X resource or the like is available in
+           ;; init-val
+           ((let ((keys (car init-val)) (ok nil))
                    (while keys
                      (cond ((< (car keys) 128)
                             (global-set-key
@@ -1057,9 +1083,13 @@ dictionary."
                             (setq ok t) ))
                      (setq keys (cdr keys))
                      ) ok))
-                (t ; \e$B%G%U%)%k%H$N@_Dj\e(B
-                 (global-set-key "\C-o" 'canna-toggle-japanese-mode) ))
+           ;; \e$B%G%U%)%k%H$N@_Dj\e(B
+           ;; Since XEmacs provides canna-leim.el, we should leave this
+           ;; as is.
+           (t (global-set-key "\C-o" 'canna-toggle-japanese-mode) ))
 
+          ;; #### should these global bindings be conditional on LEIM?
+           ;;      LEIM doesn't use kanji key yet AFAIK, so leave them.
           (if (not (keymapp (global-key-binding "\e[")))
               (global-unset-key "\e[") )
           (global-set-key "\e[210z" 'canna-toggle-japanese-mode) ; XFER