Mercurial > hg > xemacs-beta
comparison lisp/mule/kinsoku.el @ 110:fe104dbd9147 r20-1b7
Import from CVS: tag r20-1b7
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:19:45 +0200 |
parents | |
children | 7d55a9ba150c |
comparison
equal
deleted
inserted
replaced
109:e183fc049578 | 110:fe104dbd9147 |
---|---|
1 ;; kinsoku.el -- Kinsoku (line wrap) processing for XEmacs/Mule | |
2 | |
3 ;; Copyright (C) 1997 Free Software Foundation, Inc. | |
4 ;; This file is part of Mule (MULtilingual Enhancement of XEmacs). | |
5 ;; This file contains Japanese and Chinese characters. | |
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 ;; Written by Jareth Hein (jhod@po.iijnet.or.jp) based off of | |
23 ;; code by S.Tomura, Electrotechnical Lab. (tomura@etl.go.jp) from | |
24 ;; Mule-2.3 | |
25 | |
26 ;;; Special characters for JIS code | |
27 ;;; "$B!!!"!#!$!%!&!'!'!(!)!*!+!,!-!.!/(B" | |
28 ;;; "$B!0!1!2!3!4!5!6!7!8!9!:!;!<!=!>!?(B" | |
29 ;;; "$B!@!A!B!C!D!E!F!G!H!I!J!K!L!M!N!O(B" | |
30 ;;; "$B!P!Q!R!S!T!U!V!W!X!Y!Z![!\!]!^!_(B" | |
31 ;;; "$B!`!a!b!c!d!e!f!g!h!i!j!k!l!m!n!o(B" | |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"O(B | |
108 ;;;$(0"P"Q"R"S"T"U"V"W"X"Y"Z"["\"]"^"_(B | |
109 ;;;$(0"`"a"b"c"d"e"f"g"h"i"j"k"l"m"n"o(B | |
110 ;;;$(0"p"q"r"s"t"u"v"w"x"y"z"{"|"}"~(B | |
111 ;;; $(0#!#"###$#%#&#'#(#)#*#+#,#-#.#/(B | |
112 ;;;$(0#0#1#2#3#4#5#6#7#8#9#:#;#<#=#>#?(B | |
113 ;;;$(0#@#A#B#C#D#E#F#G#H#I#J#K#L#M#N#O(B | |
114 ;;;$(0#P#Q#R#S#T#U#V#W#X#Y#Z#[#\#]#^#_(B | |
115 ;;;$(0#`#a#b#c#d#e#f#g#h#i#j#k#l#m#n#o(B | |
116 ;;;$(0#p#q#r#s#t#u#v#w#x#y#z#{#|#}#~(B | |
117 ;;; $(0$!$"$#$$$%$&$'$($)$*$+$,$-$.$/(B | |
118 ;;;$(0$0$1$2$3$4$5$6$7$8$9$:$;$<$=$>$?(B | |
119 ;;;$(0$@$A$B$C$D$E$F$G$H$I$J$K$L$M$N$O(B | |
120 ;;;$(0$P$Q$R$S$T$U$V$W$X$Y$Z$[$\$]$^$_(B | |
121 ;;;$(0$`$a$b$c$d$e$f$g$h$i$j$k$l$m$n$o(B | |
122 ;;;$(0$p$q$r$s$t$u$v$w$x$y$z${$|$}$~(B | |
123 ;;; $(0%!%"%#%$%%%&%'%(%)%*%+%,%-%.%/(B | |
124 ;;;$(0%0%1%2%3%4%5%6%7%8%9%:%;%<%=%>%?(B | |
125 | |
126 (defvar kinsoku-ascii nil "Do kinsoku-processing for ASCII.") | |
127 (make-variable-buffer-local 'kinsoku-ascii) | |
128 (set-default 'kinsoku-ascii nil) | |
129 (defvar kinsoku-jis t "Do kinsoku-processing for JISX0208.") | |
130 (make-variable-buffer-local 'kinsoku-jis) | |
131 (set-default 'kinsoku-jis t) | |
132 (defvar kinsoku-gb t "Do kinsoku-processing for GB2312.") | |
133 (make-variable-buffer-local 'kinsoku-gb) | |
134 (set-default 'kinsoku-gb t) | |
135 (defvar kinsoku-big5 t "Do kinsoku-processing for Big5..") | |
136 (make-variable-buffer-local 'kinsoku-big5) | |
137 (set-default 'kinsoku-big5 t) | |
138 | |
139 (defvar kinsoku-ascii-bol "!)-_~}]:;',.?" "BOL kinsoku for ASCII.") | |
140 (defvar kinsoku-ascii-eol "({[" "EOL kinsoku for ASCII.") | |
141 (defvar kinsoku-jis-bol | |
142 (concat "$B!"!#!$!%!&!'!(!)!*!+!,!-!.!/!0!1!2!3!4!5!6!7!8!9!:!;!<!=!>(B" | |
143 "$B!?!@!A!B!C!D!E!G!I!K!M!O!Q!S!U!W!Y![!k!l!m!n(B" | |
144 "$B$!$#$%$'$)$C$c$e$g$n%!%#%%%'%)%C%c%e%g%n%u%v(B") | |
145 "BOL kinsoku for JISX0208.") | |
146 (defvar kinsoku-jis-eol | |
147 "$B!F!H!J!L!N!P!R!T!V!X!Z!k!l!m!n!w!x(B" | |
148 "EOL kinsoku for JISX0208.") | |
149 (defvar kinsoku-gb-bol | |
150 (concat "$A!"!##.#,!$!%!&!'!(!)!*!+!,!-!/!1#)!3!5!7!9!;!=(B" | |
151 "$A!?#;#:#?#!!@!A!B!C!c!d!e!f#/#\#"#_#~#|(e(B") | |
152 "BOL kinsoku for GB2312.") | |
153 (defvar kinsoku-gb-eol | |
154 (concat "$A!.!0#"#(!2!4!6!8!:!<!>!c!d!e#@!f!l(B" | |
155 "$A(E(F(G(H(I(J(K(L(M(N(O(P(Q(R(S(T(U(V(W(X(Y(h(B") | |
156 "EOL kinsoku for GB2312.") | |
157 (defvar kinsoku-big5-bol | |
158 (concat "$(0!"!#!$!%!&!'!(!)!*!+!,!-!.!/!0!1!2(B" | |
159 "$(0!3!4!5!6!7!8!9!:!;!<!=!?!A!C!E!G!I!K(B" | |
160 "$(0!M!O!Q(B $(0!S!U!W!Y![!]!_!a!c!e!g!i!k!q(B" | |
161 "$(0"#"$"%"&"'"(")"*"+","2"3"4"j"k"l"x%7(B") | |
162 "BOL kinsoku for BIG5.") | |
163 (defvar kinsoku-big5-eol | |
164 (concat "$(0!>!@!B!D!F!H!J!L!N!P!R!T!V!X!Z!\!^!`!b(B" | |
165 "$(0!d!f!h!j!k!q!p"i"j"k"n"x$u$v$w$x$y$z${(B" | |
166 "$(0$|$}$~%!%"%#%$%%%&%'%(%)%*%+%:(B") | |
167 "EOL kinsoku for BIG5.") | |
168 | |
169 (define-category ?s "Kinsoku forbidden start of line characters") | |
170 (define-category ?e "Kinsoku forbidden end of line characters") | |
171 | |
172 ;; kinsoku ascii | |
173 (loop for char in (string-to-char-list kinsoku-ascii-bol) | |
174 do (modify-category-entry char ?s)) | |
175 (loop for char in kinsoku-ascii-eol | |
176 do (modify-category-entry char ?e)) | |
177 ;; kinsoku-jis | |
178 (loop for char in (string-to-char-list kinsoku-jis-bol) | |
179 do (modify-category-entry char ?s)) | |
180 (loop for char in (string-to-char-list kinsoku-jis-eol) | |
181 do (modify-category-entry char ?e)) | |
182 ;; kinsoku-gb | |
183 (loop for char in kinsoku-gb-bol | |
184 do (modify-category-entry char ?s)) | |
185 (loop for char in kinsoku-gb-eol | |
186 do (modify-category-entry char ?e)) | |
187 ;; kinsoku-big5 | |
188 (loop for char in kinsoku-big5-bol | |
189 do (modify-category-entry char ?s)) | |
190 (loop for char in kinsoku-big5-eol | |
191 do (modify-category-entry char ?e)) | |
192 | |
193 (defun kinsoku-bol-p () | |
194 "Check if point would break forbidden beginning-of-line rules | |
195 Uses category \'s\' to check. | |
196 point$B$G2~9T$9$k$H9TF,6XB'$K?($l$k$+$I$&$+$r$+$($9!#(B | |
197 $B9TF,6XB'J8;z$O(B\'s\'$B$N(Bcategory$B$G;XDj$9$k!#(B" | |
198 (let ((ch (following-char))) | |
199 (if (or | |
200 (and kinsoku-ascii (char-in-category-p ch ?a)) | |
201 (and kinsoku-jis (char-in-category-p ch ?j)) | |
202 (and kinsoku-gb (char-in-category-p ch ?c)) | |
203 (and kinsoku-big5 (char-in-category-p ch ?t))) | |
204 (char-in-category-p ch ?s) | |
205 nil))) | |
206 | |
207 (defun kinsoku-eol-p () | |
208 "Check if point would break forbidden end-of-line rules | |
209 Uses category \'e\' to check. | |
210 point$B$G2~9T$9$k$H9TKv6XB'$K?($l$k$+$I$&$+$r$+$($9!#(B | |
211 $B9TKv6XB'J8;z$O(B\'s\'$B$N(Bcategory$B$G;XDj$9$k!#(B" | |
212 (let ((ch (preceding-char))) | |
213 (if (or | |
214 (and kinsoku-ascii (char-in-category-p ch ?a)) | |
215 (and kinsoku-jis (char-in-category-p ch ?j)) | |
216 (and kinsoku-gb (char-in-category-p ch ?c)) | |
217 (and kinsoku-big5 (char-in-category-p ch ?t))) | |
218 (char-in-category-p ch ?e) | |
219 nil))) | |
220 | |
221 (defvar kinsoku-extend-limit nil | |
222 "Defines how many characters kinsoku will search forward before giving up. | |
223 A value of nil equates to infinity. | |
224 $B6XB'=hM}$G9T$r?-$P$7$FNI$$H>3QJ8;z?t$r;XDj$9$k!#(B | |
225 $BHsIi@0?t0J30$N>l9g$OL58BBg$r0UL#$9$k!#(B") | |
226 | |
227 (defun kinsoku-process () | |
228 "Move to a point that will not break forbidden line break rules. | |
229 $B6XB'$K?($l$J$$E@$X0\F0$9$k!#(B | |
230 point$B$,9TF,6XB'$K?($l$k>l9g$O9T$r?-$P$7$F!"6XB'$K?($l$J$$E@$rC5$9!#(B | |
231 point$B$,9TKv6XB'$K?($l$k>l9g$O9T$r=L$a$F!"6XB'$K?($l$J$$E@$rC5$9!#(B | |
232 $B$?$@$7!"9T?-$P$7H>3QJ8;z?t$,(Bkinsoku-extend-limit$B$r1[$($k$H!"(B | |
233 $B9T$r=L$a$F6XB'$K?($l$J$$E@$rC5$9!#(B" | |
234 (let ((bol-kin nil) (eol-kin nil)) | |
235 (if (and (not (bolp)) | |
236 (not (eolp)) | |
237 (or (setq bol-kin (kinsoku-bol-p)) | |
238 (setq eol-kin (kinsoku-eol-p)))) | |
239 (cond(bol-kin (kinsoku-process-extend)) | |
240 (eol-kin (kinsoku-process-shrink)))))) | |
241 | |
242 (defun kinsoku-process-extend () | |
243 "Move point forward to a permissable for line-breaking. | |
244 $B9T$r?-$P$7$F6XB'$K?($l$J$$E@$X0\F0$9$k!#(B" | |
245 (let ((max-column (+ fill-column | |
246 (if (and (numberp kinsoku-extend-limit) | |
247 (>= kinsoku-extend-limit 0)) | |
248 kinsoku-extend-limit | |
249 10000))) ;;; 10000 is deliberatly unreasonably large | |
250 ch1 ch2) | |
251 (while (and (<= (+ (current-column) | |
252 (char-width (setq ch1 (following-char)))) | |
253 max-column) | |
254 (not (bolp)) | |
255 (not (eolp)) | |
256 (or (kinsoku-eol-p) | |
257 (kinsoku-bol-p) | |
258 ;;; don't break in the middle of an English word | |
259 (and (char-in-category-p ch1 ?a) | |
260 (char-in-category-p (setq ch2 (preceding-char)) ?a) | |
261 (= ?w (char-syntax ch2)) | |
262 (= ?w (char-syntax ch1))))) | |
263 (forward-char)) | |
264 (if (or (kinsoku-eol-p) (kinsoku-bol-p)) | |
265 (kinsoku-process-shrink)))) | |
266 | |
267 (defun kinsoku-process-shrink () | |
268 "Move point backward to a point permissable for line-breaking. | |
269 $B9T$r=L$a$F6XB'$K?($l$J$$E@$X0\F0$9$k!#(B" | |
270 (let (ch1 ch2) | |
271 (while (and (not (bolp)) | |
272 (not (eolp)) | |
273 (or (kinsoku-bol-p) | |
274 (kinsoku-eol-p) | |
275 ;;; don't break in the middle of an English word | |
276 (and | |
277 (char-in-category-p (setq ch1 (following-char)) ?a) | |
278 (char-in-category-p (setq ch2 (preceding-char)) ?a) | |
279 (= ?w (char-syntax ch2)) | |
280 (= ?w (char-syntax ch1))))) | |
281 (backward-char)))) |