comparison lisp/mule/chinese.el @ 159:3bb7ccffb0c0 r20-3b6

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