comparison lisp/egg/egg-kinsoku.el @ 70:131b0175ea99 r20-0b30

Import from CVS: tag r20-0b30
author cvs
date Mon, 13 Aug 2007 09:02:59 +0200
parents
children
comparison
equal deleted inserted replaced
69:804d1389bcd6 70:131b0175ea99
1 ;; Kinsoku shori for Egg
2 ;; Copyright (C) 1992 Free Software Foundation, Inc.
3 ;; This file is part of Mule (MULtilingual Enhancement of GNU Emacs).
4 ;; This file contains Japanese characters.
5
6 ;; Mule is free software distributed in the form of patches to GNU Emacs.
7 ;; You can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 1, or (at your option)
10 ;; any later version.
11
12 ;; Mule is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
16
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs; see the file COPYING. If not, write to
19 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 ;; Coded by S.Tomura, Electrotechnical Lab. (tomura@etl.go.jp)
22
23 ;;; 93.5.4 modified for Mule Ver.0.9.8 by K.Handa <handa@etl.go.jp>
24 ;;; and K.Mugitani <a50350@sakura.kudpc.kyoto-u.ac.jp>
25 ;;; Kinsoku for GB and BIG5 added.
26
27 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
28 ;;; Change Log before Ver.0.9.7
29 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
30 ;;; Modified for Mule 0.9.4 by K.Handa 92-May-2
31 ;;; Since syntax of multi-byte char is defined now,
32 ;;; check of English word is modified.
33 ;;; Modified for Mule 0.9.0 by K.Handa 92-Mar-3
34 ;;; Nemacs 3.2 created by S. Tomura 89-Nov-15
35 ;;; Ver. 3.2 3.2 $BBP1~$KJQ99(B
36 ;;; Nemacs 3.0 created by S. Tomura 89-Mar-17
37 ;;; Ver. 2.1a modified by S. Tomura 88-Nov-17
38 ;;; word$B$NESCf$GJ,3d$7$J$$$h$&$K=$@5$7$?!#(B
39 ;;; Ver. 2.1 modified by S. Tomura 88-Jun-24
40 ;;; kinsoku-shori moves the point <= fill-column + kinsoku-nobashi
41 ;;; Nemacs V.2.1
42 ;;; Ver. 1.1 modified by S. Tomura 88-Feb-29
43 ;;; Bug fix: regexp-quote is used.
44 ;;; Ver. 1.0 Created by S. Tomura
45 ;;; $B6XB'=hM}5!G=$rDs6!$9$k!#(B
46 ;;;
47
48 (defvar japanese-kinsoku-version "3.21")
49 ;;; Last modified date: Wed Nov 15 11:59:00 1989
50
51 ;;; The followings must be merged into kanji.el
52 ;;; patched by S.Tomura 87-Dec-7
53 ;;; JIS code$B$NFC<lJ8;z$N0lMwI=$G$9!#!J8MB<!K(B
54 ;;;; "$B!!!"!#!$!%!&!'!'!(!)!*!+!,!-!.!/(B"
55 ;;;; "$B!0!1!2!3!4!5!6!7!8!9!:!;!<!=!>!?(B"
56 ;;;; "$B!@!A!B!C!D!E!F!G!H!I!J!K!L!M!N!O(B"
57 ;;;; "$B!P!Q!R!S!T!U!V!W!X!Y!Z![!\!]!^!_(B"
58 ;;;; "$B!`!a!b!c!d!e!f!g!h!i!j!k!l!m!n!o(B"
59 ;;;; "$B!p!q!r!s!t!u!v!w!x!y!z!{!|!}!~(B"
60 ;;;; "$B"!"""#"$"%"&"'"(")"*"+","-".(B "
61 ;;;; "$B&!&"&#&$&%&&&'&(&)&*&+&,&-&.&/(B"
62 ;;;; "$B&0&1&2&3&4&5&6&7&8(B"
63 ;;;; "$B&A&B&C&D&E&F&G&H&I&J&K&L&M&N&O(B"
64 ;;;; "$B&P&Q&R&S&T&U&V&W&X(B"
65 ;;;; "$B'!'"'#'$'%'&'''(')'*'+','-'.'/(B"
66 ;;;; "$B'0'1'2'3'4'5'6'7'8'9':';'<'='>'?(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2$3$4$5$6$7$8$9$:$;$<$=$>$?(B
146 ;;;$(0$@$A$B$C$D$E$F$G$H$I$J$K$L$M$N$O(B
147 ;;;$(0$P$Q$R$S$T$U$V$W$X$Y$Z$[$\$]$^$_(B
148 ;;;$(0$`$a$b$c$d$e$f$g$h$i$j$k$l$m$n$o(B
149 ;;;$(0$p$q$r$s$t$u$v$w$x$y$z${$|$}$~(B
150 ;;; $(0%!%"%#%$%%%&%'%(%)%*%+%,%-%.%/(B
151 ;;;$(0%0%1%2%3%4%5%6%7%8%9%:%;%<%=%>%?(B
152
153 ;;;###autoload
154 (defvar kinsoku-ascii t "Do kinsoku-shori for ASCII.")
155 ;;;###autoload
156 (defvar kinsoku-jis t "Do kinsoku-shori for JISX0208.")
157 ;;;###autoload
158 (defvar kinsoku-gb t "Do kinsoku-shori for GB2312.")
159 ;;;###autoload
160 (defvar kinsoku-big5 t "Do kinsoku-shori for Big5..")
161
162 (defvar kinsoku-ascii-bol "!)-_~}]:;',.?" "BOL kinsoku for ASCII.")
163 (defvar kinsoku-ascii-eol "({[" "EOL kinsoku for ASCII.")
164 (defvar kinsoku-jis-bol
165 (concat "$B!"!#!$!%!&!'!(!)!*!+!,!-!.!/!0!1!2!3!4!5!6!7!8!9!:!;!<!=!>(B"
166 "$B!?!@!A!B!C!D!E!G!I!K!M!O!Q!S!U!W!Y![!k!l!m!n(B"
167 "$B$!$#$%$'$)$C$c$e$g$n%!%#%%%'%)%C%c%e%g%n%u%v(B")
168 "BOL kinsoku for JISX0208.")
169 (defvar kinsoku-jis-eol
170 "$B!F!H!J!L!N!P!R!T!V!X!Z!k!l!m!n!w!x(B"
171 "EOL kinsoku for JISX0208.")
172 (defvar kinsoku-gb-bol
173 (concat "$A!"!##.#,!$!%!&!'!(!)!*!+!,!-!/!1#)!3!5!7!9!;!=(B"
174 "$A!?#;#:#?#!!@!A!B!C!c!d!e!f#/#\#"#_#~#|(e(B")
175 "BOL kinsoku for GB2312.")
176 (defvar kinsoku-gb-eol
177 (concat "$A!.!0#"#(!2!4!6!8!:!<!>!c!d!e#@!f!l(B"
178 "$A(E(F(G(H(I(J(K(L(M(N(O(P(Q(R(S(T(U(V(W(X(Y(h(B")
179 "EOL kinsoku for GB2312.")
180 (defvar kinsoku-big5-bol
181 (concat "$(0!"!#!$!%!&!'!(!)!*!+!,!-!.!/!0!1!2(B"
182 "$(0!3!4!5!6!7!8!9!:!;!<!=!?!A!C!E!G!I!K(B"
183 "$(0!M!O!Q(B $(0!S!U!W!Y![!]!_!a!c!e!g!i!k!q(B"
184 "$(0"#"$"%"&"'"(")"*"+","2"3"4"j"k"l"x%7(B")
185 "BOL kinsoku for BIG5.")
186 (defvar kinsoku-big5-eol
187 (concat "$(0!>!@!B!D!F!H!J!L!N!P!R!T!V!X!Z!\!^!`!b(B"
188 "$(0!d!f!h!j!k!q!p"i"j"k"n"x$u$v$w$x$y$z${(B"
189 "$(0$|$}$~%!%"%#%$%%%&%'%(%)%*%+%:(B")
190 "EOL kinsoku for BIG5.")
191
192 (defvar kinsoku-bol-chars
193 (concat
194 (if kinsoku-ascii kinsoku-ascii-bol "")
195 (if kinsoku-jis kinsoku-jis-bol "")
196 (if kinsoku-gb kinsoku-gb-bol "")
197 (if kinsoku-big5 kinsoku-big5-bol ""))
198 "$B9TF,6XB'$r9T$J$&J8;z$r$9$Y$F4^$`J8;zNs$r;XDj$9$k!#(B
199 A string consisting of such characters that can't be beginning of line.")
200
201 (defvar kinsoku-eol-chars
202 (concat
203 (if kinsoku-ascii kinsoku-ascii-eol "")
204 (if kinsoku-jis kinsoku-jis-eol "")
205 (if kinsoku-gb kinsoku-gb-eol "")
206 (if kinsoku-big5 kinsoku-big5-eol ""))
207 "$B9TKv6XB'$r9T$J$&J8;z$r$9$Y$F4^$`J8;zNs$r;XDj$9$k!#(B
208 A string consisting of such characters that can't be end of line.")
209
210 ;;;
211 ;;; Buffers for kinsoku-shori
212 ;;;
213 (defconst $kinsoku-buff1$ " " "$B6XB'=hM}$N$?$a$N(B ASCII $BJ8;zMQ:n6HNN0h(B")
214 (defconst $kinsoku-buff2$ " " "$B6XB'=hM}$N$?$a$N(B 1BYTE $BJ8;zMQ:n6HNN0h(B")
215 (defconst $kinsoku-buff3$ " " "$B6XB'=hM}$N$?$a$N(B 2BYTE $BJ8;zMQ:n6HNN0h(B")
216
217 (defun kinsoku-buff (ch)
218 "Set CHAR to appropriate kinsoku-buffer and return the buffer."
219 (let ((bytes (char-bytes ch)))
220 (cond ((= bytes 1)
221 (aset $kinsoku-buff1$ 0 ch)
222 (regexp-quote $kinsoku-buff1$))
223 ((= bytes 2)
224 (aset $kinsoku-buff2$ 0 (char-component ch 0))
225 (aset $kinsoku-buff2$ 1 (char-component ch 1))
226 $kinsoku-buff2$)
227 (t
228 (aset $kinsoku-buff3$ 0 (char-component ch 0))
229 (aset $kinsoku-buff3$ 1 (char-component ch 1))
230 (aset $kinsoku-buff3$ 2 (char-component ch 2))
231 $kinsoku-buff3$))))
232
233
234 (defun kinsoku-bol-p ()
235 "point$B$G2~9T$9$k$H9TF,6XB'$K?($l$k$+$I$&$+$r$+$($9!#(B
236 $B9TF,6XB'J8;z$O(Bkinsoku-bol-chars$B$G;XDj$9$k!#(B"
237 (string-match "" "") ;;;$B$3$l$O(Bregex comp$B$N%j%;%C%H$G$9!#(B
238 (string-match (kinsoku-buff (following-char))
239 kinsoku-bol-chars))
240
241 (defun kinsoku-eol-p ()
242 "point$B$G2~9T$9$k$H9TKv6XB'$K?($l$k$+$I$&$+$r$+$($9!#(B
243 $B9TKv6XB'J8;z$O(Bkinsoku-eol-chars$B$G;XDj$9$k!#(B"
244 (string-match "" "") ;;;$B$3$l$O(Bregex comp$B$N%j%;%C%H$G$9!#(B
245 (let ((ch (preceding-char)))
246 (string-match (kinsoku-buff ch)
247 kinsoku-eol-chars)))
248
249 (defvar kinsoku-nobashi-limit nil
250 "$B6XB'=hM}$G9T$r?-$P$7$FNI$$H>3QJ8;z?t$r;XDj$9$k!#(B
251 $BHsIi@0?t0J30$N>l9g$OL58BBg$r0UL#$9$k!#(B")
252
253 ;;;###autoload
254 (defun kinsoku-shori ()
255 "$B6XB'$K?($l$J$$E@$X0\F0$9$k!#(B
256 point$B$,9TF,6XB'$K?($l$k>l9g$O9T$r?-$P$7$F!"6XB'$K?($l$J$$E@$rC5$9!#(B
257 point$B$,9TKv6XB'$K?($l$k>l9g$O9T$r=L$a$F!"6XB'$K?($l$J$$E@$rC5$9!#(B
258 $B$?$@$7!"9T?-$P$7H>3QJ8;z?t$,(Bkinsoku-nobashi-limit$B$r1[$($k$H!"(B
259 $B9T$r=L$a$F6XB'$K?($l$J$$E@$rC5$9!#(B"
260
261 (let ((bol-kin nil) (eol-kin nil))
262 (if (and (not (bolp))
263 (not (eolp))
264 (or (setq bol-kin (kinsoku-bol-p))
265 (setq eol-kin (kinsoku-eol-p))))
266 (cond(bol-kin (kinsoku-shori-nobashi))
267 (eol-kin (kinsoku-shori-chizime))))))
268
269 ;;;###autoload
270 (defun kinsoku-shori-nobashi ()
271 "$B9T$r?-$P$7$F6XB'$K?($l$J$$E@$X0\F0$9$k!#(B"
272 (let ((max-column (+ fill-column
273 (if (and (numberp kinsoku-nobashi-limit)
274 (>= kinsoku-nobashi-limit 0))
275 kinsoku-nobashi-limit
276 10000))) ;;; 10000$B$OL58BBg$N$D$b$j$G$9!#(B
277 ch1 ch2) ; 92.5.2 by K.Handa
278 (while (and (<= (+ (current-column)
279 (char-width (setq ch1 (following-char))))
280 max-column)
281 (not (bolp))
282 (not (eolp))
283 (or (kinsoku-eol-p)
284 (kinsoku-bol-p)
285 ;;; English word $B$NESCf$G$OJ,3d$7$J$$!#(B
286 (and (< ch1 127) ; 92.5.2 by K.Handa
287 (< (setq ch2 (preceding-char)) 127)
288 (= ?w (char-syntax ch2))
289 (= ?w (char-syntax ch1)))))
290 (forward-char))
291 (if (or (kinsoku-eol-p) (kinsoku-bol-p))
292 (kinsoku-shori-chizime))))
293
294 ;;;###autoload
295 (defun kinsoku-shori-chizime ()
296 "$B9T$r=L$a$F6XB'$K?($l$J$$E@$X0\F0$9$k!#(B"
297 (let (ch1 ch2) ; 92.5.2 by K.Handa
298 (while (and (not (bolp))
299 (not (eolp))
300 (or (kinsoku-bol-p)
301 (kinsoku-eol-p)
302 ;;; English word $B$NESCf$G$OJ,3d$7$J$$!#(B
303 (and ; 92.5.2 by K.Handa
304 (< (setq ch1 (following-char)) 127)
305 (< (setq ch2 (preceding-char)) 127)
306 (= ?w (char-syntax ch2))
307 (= ?w (char-syntax ch1)))))
308 (backward-char))))
309
310