annotate lisp/language/china-util.el @ 19486:31fbf3a289c1

(display-time-hook): Minor doc fix.
author Richard M. Stallman <rms@gnu.org>
date Sat, 23 Aug 1997 17:01:03 +0000
parents c42eb695ebcd
children f510736ce3d1
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
19140
a86f1b81dcf5 (setup-chinese-gb-environment): Do not
Kenichi Handa <handa@m17n.org>
parents: 19092
diff changeset
33 (set-default-coding-systems 'chinese-iso-8bit)
18553
62e17ab4e33e Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
34 (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
35 (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
36 (setq coding-category-big5 'chinese-big5)
17993
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
37
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
38 (set-coding-priority
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
39 '(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
40 coding-category-iso-7-else
17993
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
41 coding-category-iso-8-2
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
42 coding-category-big5
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
43 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
44 coding-category-emacs-mule
f98c1cb6b807 (setup-chinese-gb-environment): Adjusted for the change of coding
Kenichi Handa <handa@m17n.org>
parents: 18553
diff changeset
45 coding-category-iso-8-else))
17993
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
46
18553
62e17ab4e33e Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
47 (setq-default buffer-file-coding-system 'chinese-iso-8bit)
19140
a86f1b81dcf5 (setup-chinese-gb-environment): Do not
Kenichi Handa <handa@m17n.org>
parents: 19092
diff changeset
48 (setq default-terminal-coding-system 'chinese-iso-8bit)
a86f1b81dcf5 (setup-chinese-gb-environment): Do not
Kenichi Handa <handa@m17n.org>
parents: 19092
diff changeset
49 (setq default-keyboard-coding-system 'chinese-iso-8bit)
17993
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
50
19371
18e804fd153b (setup-chinese-gb-environment): Delete
Kenichi Handa <handa@m17n.org>
parents: 19275
diff changeset
51 (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
52
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
53 ;;;###autoload
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
54 (defun setup-chinese-big5-environment ()
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
55 "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
56 (interactive)
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
57 (setup-english-environment)
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
58
19140
a86f1b81dcf5 (setup-chinese-gb-environment): Do not
Kenichi Handa <handa@m17n.org>
parents: 19092
diff changeset
59 (set-default-coding-systems 'chinese-big5)
18553
62e17ab4e33e Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
60 (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
61 (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
62 (setq coding-category-big5 'chinese-big5)
17993
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
63
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
64 (set-coding-priority
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
65 '(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
66 coding-category-iso-7-else
17993
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
67 coding-category-big5
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
68 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
69 coding-category-emacs-mule
f98c1cb6b807 (setup-chinese-gb-environment): Adjusted for the change of coding
Kenichi Handa <handa@m17n.org>
parents: 18553
diff changeset
70 coding-category-iso-8-else))
17993
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
71
18553
62e17ab4e33e Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
72 (setq-default buffer-file-coding-system 'chinese-big5)
19140
a86f1b81dcf5 (setup-chinese-gb-environment): Do not
Kenichi Handa <handa@m17n.org>
parents: 19092
diff changeset
73 (setq default-terminal-coding-system 'chinese-big5)
a86f1b81dcf5 (setup-chinese-gb-environment): Do not
Kenichi Handa <handa@m17n.org>
parents: 19092
diff changeset
74 (setq default-keyboard-coding-system 'chinese-big5)
17993
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
75
19371
18e804fd153b (setup-chinese-gb-environment): Delete
Kenichi Handa <handa@m17n.org>
parents: 19275
diff changeset
76 (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
77
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
78 ;;;###autoload
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
79 (defun setup-chinese-cns-environment ()
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
80 "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
81 (interactive)
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
82 (setup-english-environment)
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
83
18793
f98c1cb6b807 (setup-chinese-gb-environment): Adjusted for the change of coding
Kenichi Handa <handa@m17n.org>
parents: 18553
diff changeset
84 (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
85 (setq coding-category-big5 'chinese-big5)
62e17ab4e33e Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
86 (setq coding-category-iso-8-2 'chinese-big5)
19140
a86f1b81dcf5 (setup-chinese-gb-environment): Do not
Kenichi Handa <handa@m17n.org>
parents: 19092
diff changeset
87 (set-default-coding-systems 'chinese-iso-7bit)
17993
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
88
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
89 (set-coding-priority
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
90 '(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
91 coding-category-iso-7-else
17993
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
92 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
93 coding-category-big5
f98c1cb6b807 (setup-chinese-gb-environment): Adjusted for the change of coding
Kenichi Handa <handa@m17n.org>
parents: 18553
diff changeset
94 coding-category-iso-7-else))
17993
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
95
18553
62e17ab4e33e Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
96 (setq-default buffer-file-coding-system 'chinese-iso-7bit)
19140
a86f1b81dcf5 (setup-chinese-gb-environment): Do not
Kenichi Handa <handa@m17n.org>
parents: 19092
diff changeset
97 (setq default-terminal-coding-system 'chinese-iso-7bit)
a86f1b81dcf5 (setup-chinese-gb-environment): Do not
Kenichi Handa <handa@m17n.org>
parents: 19092
diff changeset
98 (setq default-keyboard-coding-system 'chinese-iso-7bit)
17993
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
99
19371
18e804fd153b (setup-chinese-gb-environment): Delete
Kenichi Handa <handa@m17n.org>
parents: 19275
diff changeset
100 (setq default-input-method "chinese-quick-cns"))
17993
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
101
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
102 ;; Hz/ZW encoding stuffs
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
103
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
104 ;; HZ is an encoding method for Chinese character set GB2312 used
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
105 ;; widely in Internet. It is very similar to 7-bit environment of
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
106 ;; ISO-2022. The difference is that HZ uses the sequence "~{" and
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
107 ;; "~}" for designating GB2312 and ASCII respectively, hence, it
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
108 ;; doesn't uses ESC (0x1B) code.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
109
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
110 ;; ZW is another encoding method for Chinese character set GB2312. It
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
111 ;; encodes Chinese characters line by line by starting each line with
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
112 ;; the sequence "zW". It also uses only 7-bit as HZ.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
113
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
114 ;; ISO-2022 escape sequence to designate GB2312.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
115 (defvar iso2022-gb-designation "\e$A")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
116 ;; HZ escape sequence to designate GB2312.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
117 (defvar hz-gb-designnation "~{")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
118 ;; ISO-2022 escape sequence to designate ASCII.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
119 (defvar iso2022-ascii-designation "\e(B")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
120 ;; HZ escape sequence to designate ASCII.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
121 (defvar hz-ascii-designnation "~}")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
122 ;; Regexp of ZW sequence to start GB2312.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
123 (defvar zw-start-gb "^zW")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
124 ;; Regexp for start of GB2312 in an encoding mixture of HZ and ZW.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
125 (defvar hz/zw-start-gb (concat hz-gb-designnation "\\|" zw-start-gb))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
126
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
127 (defvar decode-hz-line-continuation nil
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
128 "Flag to tell if we should care line continuation convention of Hz.")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
129
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
130 ;;;###autoload
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
131 (defun decode-hz-region (beg end)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
132 "Decode HZ/ZW encoded text in the current region.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
133 Return the length of resulting text."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
134 (interactive "r")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
135 (save-excursion
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
136 (save-restriction
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
137 (narrow-to-region beg end)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
138
18553
62e17ab4e33e Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
139 ;; We, at first, convert HZ/ZW to `iso-2022-7bit',
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
140 ;; then decode it.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
141
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
142 ;; "~\n" -> "\n"
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
143 (goto-char (point-min))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
144 (while (search-forward "~" nil t)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
145 (if (= (following-char) ?\n) (delete-char -1))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
146 (if (not (eobp)) (forward-char 1)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
147
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
148 ;; "^zW...\n" -> Chinese GB2312
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
149 ;; "~{...~}" -> Chinese GB2312
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
150 (goto-char (point-min))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
151 (let ((chinese-found nil))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
152 (while (re-search-forward hz/zw-start-gb nil t)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
153 (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
154 ;; ZW -> iso-2022-7bit
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
155 (progn
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
156 (delete-char -2)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
157 (insert iso2022-gb-designation)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
158 (end-of-line)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
159 (insert iso2022-ascii-designation))
18553
62e17ab4e33e Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
160 ;; HZ -> iso-2022-7bit
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
161 (delete-char -2)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
162 (insert iso2022-gb-designation)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
163 (let ((pos (save-excursion (end-of-line) (point))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
164 (if (search-forward hz-ascii-designnation pos t)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
165 (replace-match iso2022-ascii-designation)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
166 (if (not decode-hz-line-continuation)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
167 (insert iso2022-ascii-designation)))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
168 (setq chinese-found t))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
169 (if (or chinese-found
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
170 (let ((enable-multibyte-characters nil))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
171 ;; Here we check if the text contains EUC (China) codes.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
172 ;; If any, we had better decode them also.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
173 (goto-char (point-min))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
174 (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
175 (decode-coding-region (point-min) (point-max) 'euc-china)))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
176
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
177 ;; "~~" -> "~"
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
178 (goto-char (point-min))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
179 (while (search-forward "~~" nil t) (delete-char -1))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
180 (- (point-max) (point-min)))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
181
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
182 ;;;###autoload
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
183 (defun decode-hz-buffer ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
184 "Decode HZ/ZW encoded text in the current buffer."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
185 (interactive)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
186 (decode-hz-region (point-min) (point-max)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
187
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
188 ;;;###autoload
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
189 (defun encode-hz-region (beg end)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
190 "Encode the text in the current region to HZ.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
191 Return the length of resulting text."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
192 (interactive "r")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
193 (save-excursion
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
194 (save-restriction
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
195 (narrow-to-region beg end)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
196
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
197 ;; "~" -> "~~"
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
198 (goto-char (point-min))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
199 (while (search-forward "~" nil t) (insert ?~))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
200
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
201 ;; Chinese GB2312 -> "~{...~}"
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
202 (goto-char (point-min))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
203 (if (re-search-forward "\\cc" nil t)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
204 (let ((enable-multibyte-characters nil)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
205 pos)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
206 (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
207 (encode-coding-region pos (point-max) 'iso-2022-7bit)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
208 (goto-char pos)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
209 (while (search-forward iso2022-gb-designation nil t)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
210 (delete-char -3)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
211 (insert hz-gb-designnation))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
212 (goto-char pos)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
213 (while (search-forward iso2022-ascii-designation nil t)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
214 (delete-char -3)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
215 (insert hz-ascii-designnation))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
216 (- (point-max) (point-min)))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
217
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
218 ;;;###autoload
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
219 (defun encode-hz-buffer ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
220 "Encode the text in the current buffer to HZ."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
221 (interactive)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
222 (encode-hz-region (point-min) (point-max)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
223
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
224 ;;
18309
bd8b521f5218 Provide XXX-util instead of
Kenichi Handa <handa@m17n.org>
parents: 17993
diff changeset
225 (provide 'china-util)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
226
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
227 ;;; china-util.el ends here