annotate lisp/mule/chinese.el @ 70:131b0175ea99 r20-0b30

Import from CVS: tag r20-0b30
author cvs
date Mon, 13 Aug 2007 09:02:59 +0200
parents
children 3bb7ccffb0c0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1 ;;; chinese.el --- Chinese specific setup for XEmacs/Mule (not pre-loaded).
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3 ;; Copyright (C) 1992 Free Software Foundation, Inc.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
5 ;; This file is part of XEmacs.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
6
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
7 ;; XEmacs is free software; you can redistribute it and/or modify it
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
8 ;; under the terms of the GNU General Public License as published by
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
9 ;; the Free Software Foundation; either version 2, or (at your option)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
10 ;; any later version.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
11
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
12 ;; XEmacs is distributed in the hope that it will be useful, but
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
15 ;; General Public License for more details.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
16
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
17 ;; You should have received a copy of the GNU General Public License
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
18 ;; along with XEmacs; see the file COPYING. If not, write to the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
19 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
20 ;; Boston, MA 02111-1307, USA.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
21
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
22 ;;; Synched up with: Mule 2.3.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
23
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
24 ;;; 92.3.5 Created for Mule Ver.0.9.0 by K.Handa <handa@etl.go.jp>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
25
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
26 ;; #### This does not work yet in XEmacs.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
27
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
28 ;; Hz/ZW encoding stuffs
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
29 (defvar hz2gb-gb-designation "\e$A")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
30 (defvar hz2gb-ascii-designation "\e(B")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
31 (defvar hz2gb-line-continuation nil)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
32
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
33 ;;;###autoload
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
34 (defun hz2gb-buffer ()
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
35 "Decode the text in the current buffer, assumed to be HZ/ZW-encoded."
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
36 (interactive)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
37 (hz2gb-region (point-min) (point-max)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
38
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
39 ;;;###autoload
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
40 (defun hz2gb-region (beg end)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
41 "Decode HZ/ZW-encoded text between point and mark.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
42 When called from a program, expects two arguments,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
43 positions (integers or markers) specifying the stretch to be decoded."
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
44 (interactive "r")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
45 (save-excursion
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
46 (save-restriction
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
47 (narrow-to-region beg end)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
48 ;; "~\n" -> "\n"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
49 (goto-char (point-min))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
50 (while (search-forward "~" nil t)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
51 (if (= (following-char) ?\n) (delete-char -1))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
52 (if (not (eobp)) (forward-char 1)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
53 ;; "^zW...\n" -> Chinese text
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
54 ;; "~{...~}" -> Chinese Text
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
55 (goto-char (point-min))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
56 (let (chinese-found)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
57 (while (re-search-forward "~{\\|^zW" nil t)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
58 (if (= (char-after (match-beginning 0)) ?z)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
59 ;; ZW -> junet
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
60 (progn
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
61 (delete-char -2)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
62 (insert hz2gb-gb-designation)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
63 (end-of-line)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
64 (insert hz2gb-ascii-designation))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
65 ;; Hz -> junet
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
66 (delete-char -2)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
67 (insert hz2gb-gb-designation)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
68 (if (re-search-forward "\\(~}\\)\\|\\(\n\\)" nil t)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
69 (if (match-beginning 1)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
70 (replace-match hz2gb-ascii-designation)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
71 (if (not hz2gb-line-continuation)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
72 (progn
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
73 (goto-char (match-beginning 2))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
74 (insert hz2gb-ascii-designation))))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
75 (setq chinese-found t))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
76 (if chinese-found
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
77 (decode-coding-region (point-min) (point-max) 'junet)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
78 ;; "~~" -> "~"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
79 (goto-char (point-min))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
80 (while (search-forward "~~" nil t) (delete-char -1)))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
81
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
82 ;;;###autoload
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
83 (defun gb2hz-buffer ()
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
84 "Convert whole text in the current buffer
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
85 from mule internal encoding to HZ encoding."
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
86 (interactive) (gb2hz-region (point-min) (point-max)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
87
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
88 ;;;###autoload
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
89 (defun gb2hz-region (beg end)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
90 "Encode text between point and mark in HZ/ZW encoding.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
91 When called from a program, expects two arguments,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
92 positions (integers or markers) specifying the stretch to be encoded."
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
93 (interactive "r")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
94 (save-excursion
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
95 (save-restriction
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
96 (narrow-to-region beg end)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
97 ;; "~" -> "~~"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
98 (goto-char (point-min))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
99 (while (search-forward "~" nil t) (insert ?~))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
100 ;; Chinese text -> "~{...~}"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
101 (goto-char (point-min))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
102 (if (re-search-forward "\\cc" nil t)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
103 (let (p)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
104 (goto-char (match-beginning 0))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
105 (setq p (point))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
106 (encode-coding-region p (point-max) 'junet)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
107 (goto-char p)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
108 (while (search-forward hz2gb-gb-designation nil t)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
109 (delete-char -3)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
110 (insert "~{"))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
111 (goto-char p)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
112 (while (search-forward hz2gb-ascii-designation nil t)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
113 (delete-char -3)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
114 (insert "~}"))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
115 (goto-char p)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
116 )))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
117
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
118 ;;;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
119 (provide 'chinese)