annotate lisp/language/china-util.el @ 18975:06204358e78f

(CODING_REQUIRE_TEXT_CONVERSION, CODING_REQUIRE_EOL_CONVERSION, CODING_REQUIRE_CONVERSION): Deleted. (CODING_REQUIRE_NO_CONVERSION): New macro. (CODING_MAY_REQUIRE_NO_CONVERSION): New macro.
author Kenichi Handa <handa@m17n.org>
date Fri, 25 Jul 1997 07:46:51 +0000
parents f98c1cb6b807
children 6835f9c00ff5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17315
a3ca5e15c82a Fix the format of the first line.
Kenichi Handa <handa@m17n.org>
parents: 17098
diff changeset
1 ;;; china-util.el --- utilities for Chinese
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
18377
8b4a66c66dd6 Change copyright notice.
Richard M. Stallman <rms@gnu.org>
parents: 18309
diff changeset
4 ;; Licensed to the Free Software Foundation.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6 ;; Keywords: mule, multilingual, Chinese
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
9
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
13 ;; any later version.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
14
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
19
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
17071
70194012fb3a Fix FSF address in comment.
Karl Heuer <kwzh@gnu.org>
parents: 17052
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
70194012fb3a Fix FSF address in comment.
Karl Heuer <kwzh@gnu.org>
parents: 17052
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
70194012fb3a Fix FSF address in comment.
Karl Heuer <kwzh@gnu.org>
parents: 17052
diff changeset
23 ;; Boston, MA 02111-1307, USA.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
24
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
25 ;;; Code:
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
26
17993
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
27 ;;;###autoload
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
28 (defun setup-chinese-gb-environment ()
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
29 "Setup multilingual environment (MULE) for Chinese GB2312 users."
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
30 (interactive)
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
31 (setup-english-environment)
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
32
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
33 (setq primary-language "Chinese-GB")
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
34
18553
62e17ab4e33e Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
35 (setq coding-category-iso-8-2 'chinese-iso-8bit)
18793
f98c1cb6b807 (setup-chinese-gb-environment): Adjusted for the change of coding
Kenichi Handa <handa@m17n.org>
parents: 18553
diff changeset
36 (setq coding-category-iso-7-else 'chinese-iso-7bit)
18553
62e17ab4e33e Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
37 (setq coding-category-big5 'chinese-big5)
17993
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
38
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
39 (set-coding-priority
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
40 '(coding-category-iso-7
18793
f98c1cb6b807 (setup-chinese-gb-environment): Adjusted for the change of coding
Kenichi Handa <handa@m17n.org>
parents: 18553
diff changeset
41 coding-category-iso-7-else
17993
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
42 coding-category-iso-8-2
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
43 coding-category-big5
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
44 coding-category-iso-8-1
18793
f98c1cb6b807 (setup-chinese-gb-environment): Adjusted for the change of coding
Kenichi Handa <handa@m17n.org>
parents: 18553
diff changeset
45 coding-category-emacs-mule
f98c1cb6b807 (setup-chinese-gb-environment): Adjusted for the change of coding
Kenichi Handa <handa@m17n.org>
parents: 18553
diff changeset
46 coding-category-iso-8-else))
17993
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
47
18553
62e17ab4e33e Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
48 (setq-default buffer-file-coding-system 'chinese-iso-8bit)
62e17ab4e33e Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
49 (set-terminal-coding-system-internal 'chinese-iso-8bit)
62e17ab4e33e Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
50 (set-keyboard-coding-system-internal 'chinese-iso-8bit)
17993
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
51 (setq sendmail-coding-system nil
18553
62e17ab4e33e Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
52 rmail-file-coding-system 'chinese-iso-7bit)
17993
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
53
18793
f98c1cb6b807 (setup-chinese-gb-environment): Adjusted for the change of coding
Kenichi Handa <handa@m17n.org>
parents: 18553
diff changeset
54 (setq default-input-method "chinese-py-punct"))
17993
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
55
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
56 ;;;###autoload
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
57 (defun setup-chinese-big5-environment ()
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
58 "Setup multilingual environment (MULE) for Chinese Big5 users."
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
59 (interactive)
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
60 (setup-english-environment)
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
61
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
62 (setq primary-language "Chinese-BIG5")
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
63
18553
62e17ab4e33e Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
64 (setq coding-category-iso-8-2 'chinese-big5)
18793
f98c1cb6b807 (setup-chinese-gb-environment): Adjusted for the change of coding
Kenichi Handa <handa@m17n.org>
parents: 18553
diff changeset
65 (setq coding-category-iso-7-else 'chinese-iso-7bit)
18553
62e17ab4e33e Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
66 (setq coding-category-big5 'chinese-big5)
17993
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
67
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
68 (set-coding-priority
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
69 '(coding-category-iso-7
18793
f98c1cb6b807 (setup-chinese-gb-environment): Adjusted for the change of coding
Kenichi Handa <handa@m17n.org>
parents: 18553
diff changeset
70 coding-category-iso-7-else
17993
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
71 coding-category-big5
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
72 coding-category-iso-8-2
18793
f98c1cb6b807 (setup-chinese-gb-environment): Adjusted for the change of coding
Kenichi Handa <handa@m17n.org>
parents: 18553
diff changeset
73 coding-category-emacs-mule
f98c1cb6b807 (setup-chinese-gb-environment): Adjusted for the change of coding
Kenichi Handa <handa@m17n.org>
parents: 18553
diff changeset
74 coding-category-iso-8-else))
17993
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
75
18553
62e17ab4e33e Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
76 (setq-default buffer-file-coding-system 'chinese-big5)
62e17ab4e33e Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
77 (set-terminal-coding-system-internal 'chinese-big5)
62e17ab4e33e Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
78 (set-keyboard-coding-system-internal 'chinese-big5)
17993
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
79 (setq sendmail-coding-system nil
18553
62e17ab4e33e Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
80 rmail-file-coding-system 'chienese-iso-7bit)
17993
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
81
18793
f98c1cb6b807 (setup-chinese-gb-environment): Adjusted for the change of coding
Kenichi Handa <handa@m17n.org>
parents: 18553
diff changeset
82 (setq default-input-method "chinese-py-punct-b5"))
17993
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
83
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
84 ;;;###autoload
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
85 (defun setup-chinese-cns-environment ()
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
86 "Setup multilingual environment (MULE) for Chinese CNS11643 family users."
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
87 (interactive)
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
88 (setup-english-environment)
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
89
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
90 (setq primary-language "Chinese-CNS")
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
91
18793
f98c1cb6b807 (setup-chinese-gb-environment): Adjusted for the change of coding
Kenichi Handa <handa@m17n.org>
parents: 18553
diff changeset
92 (setq coding-category-iso-7-else 'chinese-iso-7bit)
18553
62e17ab4e33e Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
93 (setq coding-category-big5 'chinese-big5)
62e17ab4e33e Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
94 (setq coding-category-iso-8-2 'chinese-big5)
17993
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
95
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
96 (set-coding-priority
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
97 '(coding-category-iso-7
18793
f98c1cb6b807 (setup-chinese-gb-environment): Adjusted for the change of coding
Kenichi Handa <handa@m17n.org>
parents: 18553
diff changeset
98 coding-category-iso-7-else
17993
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
99 coding-category-iso-8-2
18793
f98c1cb6b807 (setup-chinese-gb-environment): Adjusted for the change of coding
Kenichi Handa <handa@m17n.org>
parents: 18553
diff changeset
100 coding-category-big5
f98c1cb6b807 (setup-chinese-gb-environment): Adjusted for the change of coding
Kenichi Handa <handa@m17n.org>
parents: 18553
diff changeset
101 coding-category-iso-7-else))
17993
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
102
18553
62e17ab4e33e Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
103 (setq-default buffer-file-coding-system 'chinese-iso-7bit)
62e17ab4e33e Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
104 (set-terminal-coding-system-internal 'chinese-iso-7bit)
62e17ab4e33e Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
105 (set-keyboard-coding-system-internal 'chinese-iso-7bit)
17993
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
106 (setq sendmail-coding-system nil
18553
62e17ab4e33e Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
107 rmail-file-coding-system 'chinese-iso-7bit)
17993
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
108
18793
f98c1cb6b807 (setup-chinese-gb-environment): Adjusted for the change of coding
Kenichi Handa <handa@m17n.org>
parents: 18553
diff changeset
109 (setq default-input-method "quail-quick-cns"))
17993
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
110
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
111 ;; Hz/ZW encoding stuffs
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
112
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
113 ;; HZ is an encoding method for Chinese character set GB2312 used
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
114 ;; widely in Internet. It is very similar to 7-bit environment of
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
115 ;; ISO-2022. The difference is that HZ uses the sequence "~{" and
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
116 ;; "~}" for designating GB2312 and ASCII respectively, hence, it
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
117 ;; doesn't uses ESC (0x1B) code.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
118
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
119 ;; ZW is another encoding method for Chinese character set GB2312. It
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
120 ;; encodes Chinese characters line by line by starting each line with
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
121 ;; the sequence "zW". It also uses only 7-bit as HZ.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
122
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
123 ;; ISO-2022 escape sequence to designate GB2312.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
124 (defvar iso2022-gb-designation "\e$A")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
125 ;; HZ escape sequence to designate GB2312.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
126 (defvar hz-gb-designnation "~{")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
127 ;; ISO-2022 escape sequence to designate ASCII.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
128 (defvar iso2022-ascii-designation "\e(B")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
129 ;; HZ escape sequence to designate ASCII.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
130 (defvar hz-ascii-designnation "~}")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
131 ;; Regexp of ZW sequence to start GB2312.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
132 (defvar zw-start-gb "^zW")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
133 ;; Regexp for start of GB2312 in an encoding mixture of HZ and ZW.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
134 (defvar hz/zw-start-gb (concat hz-gb-designnation "\\|" zw-start-gb))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
135
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
136 (defvar decode-hz-line-continuation nil
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
137 "Flag to tell if we should care line continuation convention of Hz.")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
138
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
139 ;;;###autoload
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
140 (defun decode-hz-region (beg end)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
141 "Decode HZ/ZW encoded text in the current region.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
142 Return the length of resulting text."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
143 (interactive "r")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
144 (save-excursion
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
145 (save-restriction
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
146 (narrow-to-region beg end)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
147
18553
62e17ab4e33e Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
148 ;; We, at first, convert HZ/ZW to `iso-2022-7bit',
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
149 ;; then decode it.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
150
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
151 ;; "~\n" -> "\n"
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
152 (goto-char (point-min))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
153 (while (search-forward "~" nil t)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
154 (if (= (following-char) ?\n) (delete-char -1))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
155 (if (not (eobp)) (forward-char 1)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
156
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
157 ;; "^zW...\n" -> Chinese GB2312
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
158 ;; "~{...~}" -> Chinese GB2312
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
159 (goto-char (point-min))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
160 (let ((chinese-found nil))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
161 (while (re-search-forward hz/zw-start-gb nil t)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
162 (if (= (char-after (match-beginning 0)) ?z)
18553
62e17ab4e33e Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
163 ;; ZW -> iso-2022-7bit
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
164 (progn
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
165 (delete-char -2)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
166 (insert iso2022-gb-designation)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
167 (end-of-line)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
168 (insert iso2022-ascii-designation))
18553
62e17ab4e33e Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
169 ;; HZ -> iso-2022-7bit
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
170 (delete-char -2)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
171 (insert iso2022-gb-designation)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
172 (let ((pos (save-excursion (end-of-line) (point))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
173 (if (search-forward hz-ascii-designnation pos t)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
174 (replace-match iso2022-ascii-designation)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
175 (if (not decode-hz-line-continuation)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
176 (insert iso2022-ascii-designation)))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
177 (setq chinese-found t))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
178 (if (or chinese-found
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
179 (let ((enable-multibyte-characters nil))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
180 ;; Here we check if the text contains EUC (China) codes.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
181 ;; If any, we had better decode them also.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
182 (goto-char (point-min))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
183 (re-search-forward "[\240-\377]" nil t)))
17098
8917133b7e82 Remove prefix "coding-system-" from coding system symbol names.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
184 (decode-coding-region (point-min) (point-max) 'euc-china)))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
185
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
186 ;; "~~" -> "~"
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
187 (goto-char (point-min))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
188 (while (search-forward "~~" nil t) (delete-char -1))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
189 (- (point-max) (point-min)))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
190
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
191 ;;;###autoload
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
192 (defun decode-hz-buffer ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
193 "Decode HZ/ZW encoded text in the current buffer."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
194 (interactive)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
195 (decode-hz-region (point-min) (point-max)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
196
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
197 ;;;###autoload
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
198 (defun encode-hz-region (beg end)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
199 "Encode the text in the current region to HZ.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
200 Return the length of resulting text."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
201 (interactive "r")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
202 (save-excursion
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
203 (save-restriction
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
204 (narrow-to-region beg end)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
205
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
206 ;; "~" -> "~~"
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
207 (goto-char (point-min))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
208 (while (search-forward "~" nil t) (insert ?~))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
209
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
210 ;; Chinese GB2312 -> "~{...~}"
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
211 (goto-char (point-min))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
212 (if (re-search-forward "\\cc" nil t)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
213 (let ((enable-multibyte-characters nil)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
214 pos)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
215 (goto-char (setq pos (match-beginning 0)))
18553
62e17ab4e33e Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
216 (encode-coding-region pos (point-max) 'iso-2022-7bit)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
217 (goto-char pos)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
218 (while (search-forward iso2022-gb-designation nil t)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
219 (delete-char -3)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
220 (insert hz-gb-designnation))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
221 (goto-char pos)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
222 (while (search-forward iso2022-ascii-designation nil t)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
223 (delete-char -3)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
224 (insert hz-ascii-designnation))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
225 (- (point-max) (point-min)))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
226
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
227 ;;;###autoload
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
228 (defun encode-hz-buffer ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
229 "Encode the text in the current buffer to HZ."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
230 (interactive)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
231 (encode-hz-region (point-min) (point-max)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
232
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
233 ;;
18309
bd8b521f5218 Provide XXX-util instead of
Kenichi Handa <handa@m17n.org>
parents: 17993
diff changeset
234 (provide 'china-util)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
235
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
236 ;;; china-util.el ends here