Merge branch 'master' into dbus
[sxemacs] / lisp / mule / japanese.el
1 ;;; japanese.el --- Japanese support -*- coding: iso-2022-7bit; -*-
2
3 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
4 ;; Licensed to the Free Software Foundation.
5 ;; Copyright (C) 1997 MORIOKA Tomohiko
6
7 ;; Keywords: multilingual, Japanese
8
9 ;; This file is part of SXEmacs.
10
11 ;; SXEmacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
15
16 ;; SXEmacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
24 ;;; Commentary:
25
26 ;; For Japanese, character sets JISX0201, JISX0208, JISX0212 are
27 ;; supported.
28
29 ;;; Code:
30
31 ;;; Syntax of Japanese characters.
32 (modify-syntax-entry 'katakana-jisx0201 "w")
33 (modify-syntax-entry 'japanese-jisx0212 "w")
34
35 (modify-syntax-entry 'japanese-jisx0208 "w")
36 (loop for row in '(33 34 40)
37       do (modify-syntax-entry `[japanese-jisx0208 ,row] "_"))
38 (loop for char in '(?\e$B!<\e(B ?\e$B!+\e(B ?\e$B!,\e(B ?\e$B!3\e(B ?\e$B!4\e(B ?\e$B!5\e(B ?\e$B!6\e(B ?\e$B!7\e(B ?\e$B!8\e(B ?\e$B!9\e(B ?\e$B!:\e(B ?\e$B!;\e(B)
39       do (modify-syntax-entry char "w"))
40 (modify-syntax-entry ?\\e$B!J\e(B "(\e$B!K\e(B")
41 (modify-syntax-entry ?\\e$B!N\e(B "(\e$B!O\e(B")
42 (modify-syntax-entry ?\\e$B!P\e(B "(\e$B!Q\e(B")
43 (modify-syntax-entry ?\\e$B!V\e(B "(\e$B!W\e(B")
44 (modify-syntax-entry ?\\e$B!X\e(B "(\e$B!Y\e(B")
45 (modify-syntax-entry ?\\e$B!K\e(B ")\e$B!J\e(B")
46 (modify-syntax-entry ?\\e$B!O\e(B ")\e$B!N\e(B")
47 (modify-syntax-entry ?\\e$B!Q\e(B ")\e$B!P\e(B")
48 (modify-syntax-entry ?\\e$B!W\e(B ")\e$B!V\e(B")
49 (modify-syntax-entry ?\\e$B!Y\e(B ")\e$B!X\e(B")
50
51 ;;; Character categories S, A, H, K, G, Y, and C
52 (define-category ?S "Japanese 2-byte symbol character.")
53 (modify-category-entry [japanese-jisx0208 33] ?S)
54 (modify-category-entry [japanese-jisx0208 34] ?S)
55 (modify-category-entry [japanese-jisx0208 40] ?S)
56 (define-category ?A "Japanese 2-byte Alphanumeric character.")
57 (modify-category-entry [japanese-jisx0208 35] ?A)
58 (define-category ?H "Japanese 2-byte Hiragana character.")
59 (modify-category-entry [japanese-jisx0208 36] ?H)
60 (define-category ?K "Japanese 2-byte Katakana character.")
61 (modify-category-entry [japanese-jisx0208 37] ?K)
62 (define-category ?G "Japanese 2-byte Greek character.")
63 (modify-category-entry [japanese-jisx0208 38] ?G)
64 (define-category ?Y "Japanese 2-byte Cyrillic character.")
65 (modify-category-entry [japanese-jisx0208 39] ?Y)
66 (define-category ?C "Japanese 2-byte Kanji characters.")
67 (loop for row from 48 to 126
68       do (modify-category-entry `[japanese-jisx0208 ,row] ?C))
69 (loop for char in '(?\e$B!<\e(B ?\e$B!+\e(B ?\e$B!,\e(B)
70       do (modify-category-entry char ?K)
71          (modify-category-entry char ?H))
72 (loop for char in '(?\e$B!3\e(B ?\e$B!4\e(B ?\e$B!5\e(B ?\e$B!6\e(B ?\e$B!7\e(B ?\e$B!8\e(B ?\e$B!9\e(B ?\e$B!:\e(B ?\e$B!;\e(B)
73       do (modify-category-entry char ?C))
74 (modify-category-entry 'japanese-jisx0212 ?C)
75
76 (defvar japanese-word-regexp
77   "\\cA+\\cH*\\|\\cK+\\cH*\\|\\cC+\\cH*\\|\\cH+\\|\\ck+\\|\\sw+"
78   "Regular expression used to match a Japanese word.")
79
80 (set-word-regexp japanese-word-regexp)
81 (setq forward-word-regexp  "\\w\\>")
82 (setq backward-word-regexp "\\<\\w")
83
84 ;;; Paragraph setting
85 (setq sentence-end
86       (concat
87        "\\("
88        "\\("
89        "[.?!][]\"')}]*"
90        "\\|"
91        "[\e$B!%!)!*\e(B][\e$B!O!I!G!K!Q!M!S!U!W!Y\e(B]*"
92        "\\)"
93        "\\($\\|\t\\|  \\)"
94        "\\|"
95        "\e$B!#\e(B"
96        "\\)"
97        "[ \t\n]*"))
98
99 ;; allow paragraphs to start with a zenkaku space
100 (setq paragraph-start    "[ \e$B!!\e(B\t\n\f]")
101 (setq paragraph-separate "[ \e$B!!\e(B\t\f]*$")
102
103 ;; EGG specific setup
104 (define-egg-environment 'japanese
105   "Japanese settings for egg."
106   (lambda ()
107     (with-boundp '(its:*standard-modes* its:*current-map* wnn-server-type)
108       (with-fboundp 'its:get-mode-map
109         (when (not (featurep 'egg-jpn))
110           (load "its-hira")
111           (load "its-kata")
112           (load "its-hankaku")
113           (load "its-zenkaku")
114           (setq its:*standard-modes*
115                 (append
116                  (list (its:get-mode-map "roma-kana")
117                        (its:get-mode-map "roma-kata")
118                        (its:get-mode-map "downcase")
119                        (its:get-mode-map "upcase")
120                        (its:get-mode-map "zenkaku-downcase")
121                        (its:get-mode-map "zenkaku-upcase"))
122                  its:*standard-modes*))
123           (provide 'egg-jpn))
124         (setq wnn-server-type 'jserver)
125         ;; Can't do this here any more.  Must do it when selecting egg-wnn
126         ;; or egg-sj3
127         ;; (setq egg-default-startup-file "eggrc-wnn")
128         (setq-default its:*current-map* (its:get-mode-map "roma-kana"))))))
129
130 ;; stuff for providing grammatic processing of Japanese text
131 ;; something like this should probably be created for all environments...
132 ;; #### Arrgh.  This stuff should defvar'd in either fill.el or kinsoku.el.
133 ;; Then the language environment should set these things, probably buffer-
134 ;; locally.
135
136 (defvar aletter (concat "\\(" ascii-char "\\|" kanji-char "\\)"))
137 (defvar kanji-space-insertable (concat
138            "\e$B!"\e(B" aletter                   "\\|"
139            "\e$B!#\e(B" aletter                   "\\|"
140            aletter "\e$B!J\e(B"                   "\\|"
141            "\e$B!K\e(B" aletter                   "\\|"
142            ascii-alphanumeric  kanji-kanji-char "\\|"
143            kanji-kanji-char    ascii-alphanumeric ))
144
145 ;; #### will be moved to fill.el
146 (defvar space-insertable (concat " " aletter "\\|" kanji-space-insertable)
147   "Regexp for finding points that can have spaces inserted into them for justification")
148 \f
149 ;; (make-coding-system
150 ;;  'iso-2022-jp 2 ?J
151 ;;  "ISO 2022 based 7bit encoding for Japanese (MIME:ISO-2022-JP)"
152 ;;  '((ascii japanese-jisx0208-1978 japanese-jisx0208
153 ;;           latin-jisx0201 japanese-jisx0212 katakana-jisx0201) nil nil nil
154 ;;    short ascii-eol ascii-cntl seven)
155 ;;  '((safe-charsets ascii japanese-jisx0208-1978 japanese-jisx0208
156 ;;                   latin-jisx0201 japanese-jisx0212 katakana-jisx0201)
157 ;;    (mime-charset . iso-2022-jp)))
158
159 (make-coding-system
160  'iso-2022-jp 'iso2022
161  "Coding-system used for communication with mail and news in Japan."
162  '(charset-g0 ascii
163    short t
164    seven t
165    input-charset-conversion ((latin-jisx0201 ascii)
166                              (japanese-jisx0208-1978 japanese-jisx0208))
167    mnemonic "MULE/7bit"
168    ))
169
170 (define-coding-system-alias 'junet 'iso-2022-jp)
171
172 ;; (make-coding-system
173 ;;  'iso-2022-jp-2 2 ?J
174 ;;  "ISO 2022 based 7bit encoding for CJK, Latin-1, and Greek (MIME:ISO-2022-JP-2)"
175 ;;  '((ascii japanese-jisx0208-1978 japanese-jisx0208
176 ;;           latin-jisx0201 japanese-jisx0212 katakana-jisx0201
177 ;;           chinese-gb2312 korean-ksc5601) nil
178 ;;           (nil latin-iso8859-1 greek-iso8859-7) nil
179 ;;  short ascii-eol ascii-cntl seven nil single-shift)
180 ;;  '((safe-charsets ascii japanese-jisx0208-1978 japanese-jisx0208
181 ;;                   latin-jisx0201 japanese-jisx0212 katakana-jisx0201
182 ;;                   chinese-gb2312 korean-ksc5601
183 ;;                   latin-iso8859-1 greek-iso8859-7)
184 ;;    (mime-charset . iso-2022-jp-2)))
185
186 ;; (make-coding-system
187 ;;  'japanese-shift-jis 1 ?S
188 ;;  "Shift-JIS 8-bit encoding for Japanese (MIME:SHIFT_JIS)"
189 ;;  nil
190 ;;  '((safe-charsets ascii japanese-jisx0208 japanese-jisx0208-1978
191 ;;                   latin-jisx0201 katakana-jisx0201)
192 ;;    (mime-charset . shift_jis)
193 ;;    (charset-origin-alist (japanese-jisx0208 "SJIS" encode-sjis-char)
194 ;;                          (katakana-jisx0201 "SJIS" encode-sjis-char))))
195
196 (make-coding-system
197  'shift_jis 'shift-jis
198  "Coding-system of Shift-JIS used in Japan."
199  '(mnemonic "Ja/SJIS"))
200
201 ;; (define-coding-system-alias 'shift_jis 'japanese-shift-jis)
202 ;; (define-coding-system-alias 'sjis 'japanese-shift-jis)
203
204 ;; (make-coding-system
205 ;;  'japanese-iso-7bit-1978-irv 2 ?j
206 ;;  "ISO 2022 based 7-bit encoding for Japanese JISX0208-1978 and JISX0201-Roman"
207 ;;  '((ascii japanese-jisx0208-1978 japanese-jisx0208
208 ;;           latin-jisx0201 japanese-jisx0212 katakana-jisx0201 t) nil nil nil
209 ;;    short ascii-eol ascii-cntl seven nil nil use-roman use-oldjis)
210 ;;  '(ascii japanese-jisx0208-1978 japanese-jisx0208 latin-jisx0201))
211
212 (make-coding-system
213  'iso-2022-jp-1978-irv 'iso2022
214  "Coding-system used for old JIS terminal."
215  '(charset-g0 ascii
216    short t
217    seven t
218    output-charset-conversion ((ascii latin-jisx0201)
219                               (japanese-jisx0208 japanese-jisx0208-1978))
220    mnemonic "Ja-78/7bit"
221    ))
222
223 ;; (define-coding-system-alias 'iso-2022-jp-1978-irv 'japanese-iso-7bit-1978-irv)
224 ;; (define-coding-system-alias 'old-jis 'japanese-iso-7bit-1978-irv)
225
226 (define-coding-system-alias 'old-jis 'iso-2022-jp-1978-irv)
227
228 ;; (make-coding-system
229 ;;  'japanese-iso-8bit 2 ?E
230 ;;  "ISO 2022 based EUC encoding for Japanese (MIME:EUC-JP)"
231 ;;  '(ascii japanese-jisx0208 katakana-jisx0201 japanese-jisx0212
232 ;;    short ascii-eol ascii-cntl nil nil single-shift)
233 ;;  '((safe-charsets ascii latin-jisx0201 japanese-jisx0208 japanese-jisx0208-1978
234 ;;                  katakana-jisx0201 japanese-jisx0212)
235 ;;    (mime-charset . euc-jp)))
236
237 (make-coding-system
238  'euc-jp 'iso2022
239  "Coding-system of Japanese EUC (Extended Unix Code)."
240  '(charset-g0 ascii
241    charset-g1 japanese-jisx0208
242    charset-g2 katakana-jisx0201
243    charset-g3 japanese-jisx0212
244    short t
245    mnemonic "Ja/EUC"
246    ))
247
248 ;; (define-coding-system-alias 'euc-japan-1990 'japanese-iso-8bit)
249 ;; (define-coding-system-alias 'euc-japan 'japanese-iso-8bit)
250 ;; (define-coding-system-alias 'euc-jp 'japanese-iso-8bit)
251
252 (define-coding-system-alias 'euc-japan 'euc-jp) ; only for w3
253 (define-coding-system-alias 'japanese-euc 'euc-jp)
254
255 (set-language-info-alist
256  "Japanese" '((setup-function . setup-japanese-environment-internal)
257               (exit-function . exit-japanese-environment)
258               (tutorial . "TUTORIAL.ja")
259               (charset japanese-jisx0208 japanese-jisx0208-1978
260                        japanese-jisx0212 latin-jisx0201 katakana-jisx0201)
261               (coding-system iso-2022-jp euc-jp
262                              shift_jis iso-2022-jp-2)
263               (coding-priority iso-2022-jp euc-jp
264                                shift_jis iso-2022-jp-2)
265 ;;            (input-method . "japanese")
266               (features japan-util)
267               (sample-text . "Japanese (\e$BF|K\8l\e(B)   \e$B$3$s$K$A$O\e(B, \e(I:]FAJ\e(B")
268               (documentation . t)))
269
270 ;;; japanese.el ends here