annotate lisp/language/china-util.el @ 93409:b705f66a40fc

(holiday-hebrew): Simplify.
author Glenn Morris <rgm@gnu.org>
date Sat, 29 Mar 2008 23:23:20 +0000
parents 4bb19b57806d
children 1e3a407766b9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
42153
ca6dbe4635da Implementing euc-tw encoding.
Werner LEMBERG <wl@gnu.org>
parents: 38414
diff changeset
1 ;;; china-util.el --- utilities for Chinese -*- coding: iso-2022-7bit -*-
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2
79711
b5d3fc1c4afe Add 2008 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 78309
diff changeset
3 ;; Copyright (C) 1995, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
62396
197607499a29 Fix copyrights.
Kenichi Handa <handa@m17n.org>
parents: 52401
diff changeset
4 ;; Free Software Foundation, Inc.
74605
6ee41fdd69ff Update AIST copyright years.
Kenichi Handa <handa@m17n.org>
parents: 74544
diff changeset
5 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
79711
b5d3fc1c4afe Add 2008 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 78309
diff changeset
6 ;; 2005, 2006, 2007, 2008
62396
197607499a29 Fix copyrights.
Kenichi Handa <handa@m17n.org>
parents: 52401
diff changeset
7 ;; National Institute of Advanced Industrial Science and Technology (AIST)
197607499a29 Fix copyrights.
Kenichi Handa <handa@m17n.org>
parents: 52401
diff changeset
8 ;; Registration Number H14PRO021
89483
2f877ed80fa6 *** empty log message ***
Kenichi Handa <handa@m17n.org>
parents: 88123 88708
diff changeset
9 ;; Copyright (C) 2003
2f877ed80fa6 *** empty log message ***
Kenichi Handa <handa@m17n.org>
parents: 88123 88708
diff changeset
10 ;; National Institute of Advanced Industrial Science and Technology (AIST)
2f877ed80fa6 *** empty log message ***
Kenichi Handa <handa@m17n.org>
parents: 88123 88708
diff changeset
11 ;; Registration Number H13PRO009
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
12
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
13 ;; Keywords: mule, multilingual, Chinese
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
14
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
15 ;; This file is part of GNU Emacs.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
16
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
17 ;; GNU Emacs is free software; you can redistribute it and/or modify
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
18 ;; it under the terms of the GNU General Public License as published by
78309
0938de05f510 Restore comma mistakenly removed in last change.
Glenn Morris <rgm@gnu.org>
parents: 78300
diff changeset
19 ;; the Free Software Foundation; either version 3, or (at your option)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
20 ;; any later version.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
21
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
22 ;; GNU Emacs is distributed in the hope that it will be useful,
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
23 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
24 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
25 ;; GNU General Public License for more details.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
26
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
27 ;; 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
28 ;; along with GNU Emacs; see the file COPYING. If not, write to the
64085
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 62396
diff changeset
29 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 62396
diff changeset
30 ;; Boston, MA 02110-1301, USA.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
31
38414
67b464da13ec Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 28906
diff changeset
32 ;;; Commentary:
67b464da13ec Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 28906
diff changeset
33
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
34 ;;; Code:
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
35
42153
ca6dbe4635da Implementing euc-tw encoding.
Werner LEMBERG <wl@gnu.org>
parents: 38414
diff changeset
36 ;; Hz/ZW/EUC-TW encoding stuff
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
37
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
38 ;; HZ is an encoding method for Chinese character set GB2312 used
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
39 ;; widely in Internet. It is very similar to 7-bit environment of
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
40 ;; ISO-2022. The difference is that HZ uses the sequence "~{" and
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
41 ;; "~}" for designating GB2312 and ASCII respectively, hence, it
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
42 ;; doesn't uses ESC (0x1B) code.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
43
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
44 ;; ZW is another encoding method for Chinese character set GB2312. It
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
45 ;; encodes Chinese characters line by line by starting each line with
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
46 ;; the sequence "zW". It also uses only 7-bit as HZ.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
47
42153
ca6dbe4635da Implementing euc-tw encoding.
Werner LEMBERG <wl@gnu.org>
parents: 38414
diff changeset
48 ;; EUC-TW is similar to EUC-KS or EUC-JP. Its main character set is
ca6dbe4635da Implementing euc-tw encoding.
Werner LEMBERG <wl@gnu.org>
parents: 38414
diff changeset
49 ;; plane 1 of CNS 11643; characters of planes 2 to 7 are accessed with
ca6dbe4635da Implementing euc-tw encoding.
Werner LEMBERG <wl@gnu.org>
parents: 38414
diff changeset
50 ;; a single shift escape followed by three bytes: the first gives the
ca6dbe4635da Implementing euc-tw encoding.
Werner LEMBERG <wl@gnu.org>
parents: 38414
diff changeset
51 ;; plane, the second and third the character code. Note that characters
ca6dbe4635da Implementing euc-tw encoding.
Werner LEMBERG <wl@gnu.org>
parents: 38414
diff changeset
52 ;; of plane 1 are (redundantly) accessible with a single shift escape
ca6dbe4635da Implementing euc-tw encoding.
Werner LEMBERG <wl@gnu.org>
parents: 38414
diff changeset
53 ;; also.
ca6dbe4635da Implementing euc-tw encoding.
Werner LEMBERG <wl@gnu.org>
parents: 38414
diff changeset
54
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
55 ;; ISO-2022 escape sequence to designate GB2312.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
56 (defvar iso2022-gb-designation "\e$A")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
57 ;; HZ escape sequence to designate GB2312.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
58 (defvar hz-gb-designnation "~{")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
59 ;; ISO-2022 escape sequence to designate ASCII.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
60 (defvar iso2022-ascii-designation "\e(B")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
61 ;; HZ escape sequence to designate ASCII.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
62 (defvar hz-ascii-designnation "~}")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
63 ;; Regexp of ZW sequence to start GB2312.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
64 (defvar zw-start-gb "^zW")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
65 ;; Regexp for start of GB2312 in an encoding mixture of HZ and ZW.
20738
f510736ce3d1 In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents: 19428
diff changeset
66 (defvar hz/zw-start-gb
f510736ce3d1 In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents: 19428
diff changeset
67 (concat hz-gb-designnation "\\|" zw-start-gb "\\|[^\0-\177]"))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
68
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
69 (defvar decode-hz-line-continuation nil
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
70 "Flag to tell if we should care line continuation convention of Hz.")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
71
20738
f510736ce3d1 In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents: 19428
diff changeset
72 (defconst hz-set-msb-table
51079
bd6dedbdc53f (hz-set-msb-table): Build when compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42153
diff changeset
73 (eval-when-compile
bd6dedbdc53f (hz-set-msb-table): Build when compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42153
diff changeset
74 (let ((chars nil)
bd6dedbdc53f (hz-set-msb-table): Build when compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42153
diff changeset
75 (i 0))
bd6dedbdc53f (hz-set-msb-table): Build when compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42153
diff changeset
76 (while (< i 33)
bd6dedbdc53f (hz-set-msb-table): Build when compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42153
diff changeset
77 (push i chars)
bd6dedbdc53f (hz-set-msb-table): Build when compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42153
diff changeset
78 (setq i (1+ i)))
bd6dedbdc53f (hz-set-msb-table): Build when compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42153
diff changeset
79 (while (< i 127)
90012
845142d93266 (hz-set-msb-table): Turn chars beyond 128
Kenichi Handa <handa@m17n.org>
parents: 89909
diff changeset
80 (push (decode-char 'eight-bit (+ i 128)) chars)
51079
bd6dedbdc53f (hz-set-msb-table): Build when compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42153
diff changeset
81 (setq i (1+ i)))
bd6dedbdc53f (hz-set-msb-table): Build when compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42153
diff changeset
82 (apply 'string (nreverse chars)))))
20738
f510736ce3d1 In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents: 19428
diff changeset
83
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
84 ;;;###autoload
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
85 (defun decode-hz-region (beg end)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
86 "Decode HZ/ZW encoded text in the current region.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
87 Return the length of resulting text."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
88 (interactive "r")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
89 (save-excursion
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
90 (save-restriction
20738
f510736ce3d1 In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents: 19428
diff changeset
91 (let (pos ch)
f510736ce3d1 In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents: 19428
diff changeset
92 (narrow-to-region beg end)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
93
20738
f510736ce3d1 In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents: 19428
diff changeset
94 ;; We, at first, convert HZ/ZW to `euc-china',
f510736ce3d1 In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents: 19428
diff changeset
95 ;; then decode it.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
96
20738
f510736ce3d1 In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents: 19428
diff changeset
97 ;; "~\n" -> "\n", "~~" -> "~"
f510736ce3d1 In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents: 19428
diff changeset
98 (goto-char (point-min))
f510736ce3d1 In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents: 19428
diff changeset
99 (while (search-forward "~" nil t)
f510736ce3d1 In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents: 19428
diff changeset
100 (setq ch (following-char))
f510736ce3d1 In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents: 19428
diff changeset
101 (if (or (= ch ?\n) (= ch ?~)) (delete-char -1)))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
102
20738
f510736ce3d1 In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents: 19428
diff changeset
103 ;; "^zW...\n" -> Chinese GB2312
f510736ce3d1 In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents: 19428
diff changeset
104 ;; "~{...~}" -> Chinese GB2312
f510736ce3d1 In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents: 19428
diff changeset
105 (goto-char (point-min))
f510736ce3d1 In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents: 19428
diff changeset
106 (setq beg nil)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
107 (while (re-search-forward hz/zw-start-gb nil t)
20738
f510736ce3d1 In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents: 19428
diff changeset
108 (setq pos (match-beginning 0)
f510736ce3d1 In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents: 19428
diff changeset
109 ch (char-after pos))
f510736ce3d1 In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents: 19428
diff changeset
110 ;; Record the first position to start conversion.
f510736ce3d1 In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents: 19428
diff changeset
111 (or beg (setq beg pos))
f510736ce3d1 In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents: 19428
diff changeset
112 (end-of-line)
f510736ce3d1 In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents: 19428
diff changeset
113 (setq end (point))
f510736ce3d1 In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents: 19428
diff changeset
114 (if (>= ch 128) ; 8bit GB2312
f510736ce3d1 In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents: 19428
diff changeset
115 nil
f510736ce3d1 In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents: 19428
diff changeset
116 (goto-char pos)
f510736ce3d1 In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents: 19428
diff changeset
117 (delete-char 2)
f510736ce3d1 In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents: 19428
diff changeset
118 (setq end (- end 2))
f510736ce3d1 In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents: 19428
diff changeset
119 (if (= ch ?z) ; ZW -> euc-china
f510736ce3d1 In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents: 19428
diff changeset
120 (progn
f510736ce3d1 In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents: 19428
diff changeset
121 (translate-region (point) end hz-set-msb-table)
f510736ce3d1 In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents: 19428
diff changeset
122 (goto-char end))
f510736ce3d1 In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents: 19428
diff changeset
123 (if (search-forward hz-ascii-designnation
f510736ce3d1 In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents: 19428
diff changeset
124 (if decode-hz-line-continuation nil end)
f510736ce3d1 In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents: 19428
diff changeset
125 t)
f510736ce3d1 In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents: 19428
diff changeset
126 (delete-char -2))
f510736ce3d1 In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents: 19428
diff changeset
127 (setq end (point))
f510736ce3d1 In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents: 19428
diff changeset
128 (translate-region pos (point) hz-set-msb-table))))
f510736ce3d1 In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents: 19428
diff changeset
129 (if beg
f510736ce3d1 In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents: 19428
diff changeset
130 (decode-coding-region beg end 'euc-china)))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
131 (- (point-max) (point-min)))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
132
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
133 ;;;###autoload
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
134 (defun decode-hz-buffer ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
135 "Decode HZ/ZW encoded text in the current buffer."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
136 (interactive)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
137 (decode-hz-region (point-min) (point-max)))
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 encode-hz-region (beg end)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
141 "Encode the text in the current region to HZ.
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
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
148 ;; "~" -> "~~"
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
149 (goto-char (point-min))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
150 (while (search-forward "~" nil t) (insert ?~))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
151
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
152 ;; Chinese GB2312 -> "~{...~}"
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
153 (goto-char (point-min))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
154 (if (re-search-forward "\\cc" nil t)
20838
3d67d591c066 (encode-hz-region): Do not bind
Kenichi Handa <handa@m17n.org>
parents: 20738
diff changeset
155 (let (pos)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
156 (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
157 (encode-coding-region pos (point-max) 'iso-2022-7bit)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
158 (goto-char pos)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
159 (while (search-forward iso2022-gb-designation nil t)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
160 (delete-char -3)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
161 (insert hz-gb-designnation))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
162 (goto-char pos)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
163 (while (search-forward iso2022-ascii-designation nil t)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
164 (delete-char -3)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
165 (insert hz-ascii-designnation))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
166 (- (point-max) (point-min)))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
167
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
168 ;;;###autoload
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
169 (defun encode-hz-buffer ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
170 "Encode the text in the current buffer to HZ."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
171 (interactive)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
172 (encode-hz-region (point-min) (point-max)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
173
88708
0816a10eb8ac (post-read-decode-hz)
Dave Love <fx@gnu.org>
parents: 42153
diff changeset
174 ;;;###autoload
0816a10eb8ac (post-read-decode-hz)
Dave Love <fx@gnu.org>
parents: 42153
diff changeset
175 (defun post-read-decode-hz (len)
0816a10eb8ac (post-read-decode-hz)
Dave Love <fx@gnu.org>
parents: 42153
diff changeset
176 (let ((pos (point))
0816a10eb8ac (post-read-decode-hz)
Dave Love <fx@gnu.org>
parents: 42153
diff changeset
177 (buffer-modified-p (buffer-modified-p))
0816a10eb8ac (post-read-decode-hz)
Dave Love <fx@gnu.org>
parents: 42153
diff changeset
178 last-coding-system-used)
0816a10eb8ac (post-read-decode-hz)
Dave Love <fx@gnu.org>
parents: 42153
diff changeset
179 (prog1
0816a10eb8ac (post-read-decode-hz)
Dave Love <fx@gnu.org>
parents: 42153
diff changeset
180 (decode-hz-region pos (+ pos len))
0816a10eb8ac (post-read-decode-hz)
Dave Love <fx@gnu.org>
parents: 42153
diff changeset
181 (set-buffer-modified-p buffer-modified-p))))
42153
ca6dbe4635da Implementing euc-tw encoding.
Werner LEMBERG <wl@gnu.org>
parents: 38414
diff changeset
182
88708
0816a10eb8ac (post-read-decode-hz)
Dave Love <fx@gnu.org>
parents: 42153
diff changeset
183 ;;;###autoload
0816a10eb8ac (post-read-decode-hz)
Dave Love <fx@gnu.org>
parents: 42153
diff changeset
184 (defun pre-write-encode-hz (from to)
0816a10eb8ac (post-read-decode-hz)
Dave Love <fx@gnu.org>
parents: 42153
diff changeset
185 (let ((buf (current-buffer)))
0816a10eb8ac (post-read-decode-hz)
Dave Love <fx@gnu.org>
parents: 42153
diff changeset
186 (set-buffer (generate-new-buffer " *temp*"))
0816a10eb8ac (post-read-decode-hz)
Dave Love <fx@gnu.org>
parents: 42153
diff changeset
187 (if (stringp from)
0816a10eb8ac (post-read-decode-hz)
Dave Love <fx@gnu.org>
parents: 42153
diff changeset
188 (insert from)
0816a10eb8ac (post-read-decode-hz)
Dave Love <fx@gnu.org>
parents: 42153
diff changeset
189 (insert-buffer-substring buf from to))
0816a10eb8ac (post-read-decode-hz)
Dave Love <fx@gnu.org>
parents: 42153
diff changeset
190 (let (last-coding-system-used)
0816a10eb8ac (post-read-decode-hz)
Dave Love <fx@gnu.org>
parents: 42153
diff changeset
191 (encode-hz-region 1 (point-max)))
0816a10eb8ac (post-read-decode-hz)
Dave Love <fx@gnu.org>
parents: 42153
diff changeset
192 nil))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
193 ;;
18309
bd8b521f5218 Provide XXX-util instead of
Kenichi Handa <handa@m17n.org>
parents: 17993
diff changeset
194 (provide 'china-util)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
195
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 51079
diff changeset
196 ;;; arch-tag: 5a47b084-b9ac-420e-8191-70c5b3a14836
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
197 ;;; china-util.el ends here