add autoload setting for egg-mode.
[elisp/egg.git] / egg.el
1 ;;; egg.el --- EGG Input Method Architecture
2
3 ;; Copyright (C) 1997 Mule Project, Powered by Electrotechnical
4 ;; Laboratory, JAPAN.
5 ;; Project Leader: Satoru Tomura <tomura@etl.go.jp>
6
7 ;; Author: NIIBE Yutaka <gniibe@mri.co.jp>
8 ;; Maintainer: NIIBE Yutaka <gniibe@mri.co.jp>
9 ;; Keywords: mule, multilingual, input method
10
11 ;; This file will be part of GNU Emacs (in future).
12
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; any later version.
17
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 ;; GNU General Public License for more details.
22
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 ;; Boston, MA 02111-1307, USA.
27
28 ;;; Commentary:
29
30 ;;; Code:
31 (defvar egg-mode-preference t
32   "Non-nil if modefull.")
33
34 ;;;###autoload
35 (defun egg-mode (&optional arg)
36   "Toggle EGG  mode.
37 \\[describe-bindings]
38 "
39   (interactive "P")
40   (if (null arg)
41       ;; Turn off
42       (progn
43         (setq describe-current-input-method-function nil)
44         (setq current-input-method nil)
45         (let ((orig-local-map (keymap-parent (current-local-map))))
46           (use-local-map orig-local-map))
47         (run-hooks 'input-method-inactivate-hook))
48     ;; Turn on
49     (use-local-map (if egg-mode-preference
50                        (egg-modefull-map)
51                      (egg-modeless-map)))
52     (setq inactivate-current-input-method-function 'egg-mode)
53     (setq describe-current-input-method-function 'egg-help)
54     (run-hooks 'input-method-activate-hook))
55   (force-mode-line-update))
56
57 (defun egg-modefull-map ()
58   "Generate modefull keymap for EGG mode."  
59   (let ((map (make-sparse-keymap))
60         (i 33))
61     (define-key map "\C-_" 'egg-jis-code-input)
62     (while (< i 127)
63       (define-key map (vector i) 'egg-self-insert-char)
64       (setq i (1+ i)))
65     (set-keymap-parent map (current-local-map))
66     map))
67
68 (defun egg-modeless-map ()
69   "Generate modeless keymap for EGG mode."
70   (let ((map (make-sparse-keymap)))
71     (define-key map " " 'mlh-space-bar-backward-henkan)
72     (define-key map "\C-_" 'egg-jis-code-input)
73     (set-keymap-parent map (current-local-map))
74     map))
75
76 (defun egg-self-insert-char ()
77   (interactive)
78   (its-start last-command-char))
79 \f
80 (defun egg-hinshi-select ()
81  (menudiag-select ; Should generate at initialization time
82   '(menu  "\e$BIJ;lL>\e(B:"
83           (("\e$BIaDLL>;l\e(B" .
84             (menu  "\e$BIJ;lL>\e(B[\e$BIaDLL>;l\e(B]:"
85                    ("\e$BL>;l\e(B" "\e$B%59T\e(B(\e$B$9$k\e(B)&\e$BL>;l\e(B" "\e$B0lCJ\e(B&\e$BL>;l\e(B"
86                     "\e$B7AMFF0;l\e(B&\e$BL>;l\e(B" "\e$B?t;l\e(B")))
87            ("\e$B8GM-L>;l\e(B" .
88             (menu  "\e$BIJ;lL>\e(B[\e$B8GM-L>;l\e(B]:"
89                    ("\e$B?ML>\e(B" "\e$BCOL>\e(B" "\e$B?ML>\e(B&\e$BCOL>\e(B" "\e$B8GM-L>;l\e(B")))
90            ("\e$BF0;l\e(B" .
91             (menu  "\e$BIJ;lL>\e(B[\e$BF0;l\e(B]:"
92                    ("\e$B0lCJ\e(B" "\e$B0lCJ\e(B&\e$BL>;l\e(B" "\e$B%+9T8^CJ\e(B" "\e$B%,9T8^CJ\e(B"
93                     "\e$B%59T8^CJ\e(B" "\e$B%?9T8^CJ\e(B")))
94            ("\e$BFC<l$JF0;l\e(B" .
95             (menu  "\e$BIJ;lL>\e(B[\e$BFC<l$JF0;l\e(B]:"
96                    ("\e$B%+9T\e(B(\e$B9T$/\e(B)" "\e$B%i9T\e(B(\e$B2<$5$$\e(B)" "\e$BMh\e(B(\e$B$3\e(B)"
97                     "\e$BMh\e(B(\e$B$-\e(B)" "\e$BMh\e(B(\e$B$/\e(B)" "\e$B0Y\e(B(\e$B$7\e(B)")))
98            ("\e$BF0;l0J30$NMQ8@\e(B" .
99             (menu  "\e$BIJ;lL>\e(B[\e$BF0;l0J30$NMQ8@\e(B]:"
100                    ("\e$B7AMF;l\e(B" "\e$B7AMFF0;l\e(B" "\e$B7AMFF0;l\e(B&\e$BL>;l\e(B"
101                     "\e$B7AMFF0;l\e(B(\e$B$?$k\e(B)")))))))
102
103 ;; XXX: Should use backend interface
104 (defun egg-toroku-region (start end)
105   (interactive "r")
106   (let* ((env (wnn-get-environment))    ; XXX
107          (kanji (buffer-substring start end))
108          (yomi (read-multilingual-string 
109                 (format "\e$B<-=qEPO?!X\e(B%s\e$B!Y\e(B  \e$BFI$_\e(B:" kanji)))
110          (dic (menudiag-select (list 'menu "\e$BEPO?<-=qL>\e(B:"
111                                  ;; XXX
112                                  (wnn-list-writable-dictionaries-byname env))))
113          (dic-name (wnn-dict-name dic))
114          (hinshi (egg-hinshi-select))
115          (hinshi-id (wnn-hinshi-number env hinshi)))
116     (if (y-or-n-p
117          (format "\e$B<-=q9`L\!X\e(B%s\e$B!Y\e(B(%s: %s)\e$B$r\e(B %s \e$B$KEPO?$7$^$9\e(B"
118                  kanji yomi hinshi dic-name))
119         (let ((r (wnn-add-word env dic yomi kanji "" hinshi-id 0)))
120           (if (< r 0)
121             (error "\e$B<-=qEPO?!X\e(B%s\e$B!Y\e(B(%s: %s) %s \e$B$K<:GT$7$^$7$?\e(B: %s"
122                    kanji yomi hinshi dic-name
123                    (wnnrpc-get-error-message (- r)))
124             (message 
125              "\e$B<-=q9`L\!X\e(B%s\e$B!Y\e(B(%s: %s)\e$B$r\e(B %s \e$B$KEPO?$7$^$7$?\e(B" 
126              kanji yomi hinshi dic-name))))))
127 \f
128 ;;;
129 ;;; auto fill controll
130 ;;;
131
132 (defun egg-do-auto-fill ()
133   (if (and auto-fill-function (> (current-column) fill-column))
134       (let ((ocolumn (current-column)))
135         (funcall auto-fill-function)
136         (while (and (< fill-column (current-column))
137                     (< (current-column) ocolumn))
138           (setq ocolumn (current-column))
139           (funcall auto-fill-function)))))
140
141 (setq its-hira-period "\e$B!#\e(B")    ; ". " "\e$B!%\e(B" "\e$B!#\e(B"
142 (setq its-hira-comma  ", ")    ; ", " "\e$B!$\e(B" "\e$B!"\e(B"
143
144 (require 'its)
145 (require 'menudiag)
146 (require 'egg-mlh)
147 (require 'egg-cnv)
148 (require 'egg-com)
149
150 (load-library "its/hira")
151 (setq-default its-current-map its-hira-map)
152
153 (load-library "egg/wnn")
154 (load-library "egg/wnnrpc")
155 (setq egg-conversion-backend wnn-conversion-backend)
156
157 ;;(load-library "egg/sj3rpc")
158 ;;(load-library "egg/sj3")
159 ;;(setq egg-conversion-backend sj3-conversion-backend)
160
161 (add-hook 'kill-emacs-hook 'egg-kill-emacs-function)
162 (defun egg-kill-emacs-function ()
163   (egg-finalize-backend))
164
165 (provide 'egg)
166
167 ;;; egg.el ends here