502
+ − 1 ;; kinsoku.el -- Kinsoku (line wrap) processing for XEmacs/Mule -*- coding: iso-2022-7bit; -*-
333
+ − 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"
+ − 32 ;;; "$B!p!q!r!s!t!u!v!w!x!y!z!{!|!}!~(B"
+ − 33 ;;; "$B"!"""#"$"%"&"'"(")"*"+","-".(B "
+ − 34 ;;; "$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"=">"?(B
+ − 107 ;;;$(0"@"A"B"C"D"E"F"G"H"I"J"K"L"M"N"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
771
+ − 173 (loop for char in (string-to-list kinsoku-ascii-bol)
333
+ − 174 do (modify-category-entry char ?s))
908
+ − 175 (loop for char in (string-to-list kinsoku-ascii-eol)
333
+ − 176 do (modify-category-entry char ?e))
+ − 177 ;; kinsoku-jis
771
+ − 178 (loop for char in (string-to-list kinsoku-jis-bol)
333
+ − 179 do (modify-category-entry char ?s))
771
+ − 180 (loop for char in (string-to-list kinsoku-jis-eol)
333
+ − 181 do (modify-category-entry char ?e))
+ − 182 ;; kinsoku-gb
908
+ − 183 (loop for char in (string-to-list kinsoku-gb-bol)
333
+ − 184 do (modify-category-entry char ?s))
908
+ − 185 (loop for char in (string-to-list kinsoku-gb-eol)
333
+ − 186 do (modify-category-entry char ?e))
+ − 187 ;; kinsoku-big5
908
+ − 188 (loop for char in (string-to-list kinsoku-big5-bol)
333
+ − 189 do (modify-category-entry char ?s))
908
+ − 190 (loop for char in (string-to-list kinsoku-big5-eol)
333
+ − 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"
908
+ − 198 (let ((before (char-before))
+ − 199 (after (char-after)))
+ − 200 (if (and after
333
+ − 201 (or
908
+ − 202 (and kinsoku-ascii (char-in-category-p after ?a))
+ − 203 (and kinsoku-jis (or (char-in-category-p after ?j)
+ − 204 (and before
+ − 205 (char-in-category-p before ?j))))
+ − 206 (and kinsoku-gb (or (char-in-category-p after ?c)
+ − 207 (and before
+ − 208 (char-in-category-p before ?c))))
+ − 209 (and kinsoku-big5 (or (char-in-category-p after ?t)
+ − 210 (and before
+ − 211 (char-in-category-p before ?t))))))
+ − 212 (char-in-category-p after ?s)
333
+ − 213 nil)))
+ − 214
+ − 215 (defun kinsoku-eol-p ()
+ − 216 "Check if point would break forbidden end-of-line rules
+ − 217 Uses category \'e\' to check.
+ − 218 point$B$G2~9T$9$k$H9TKv6XB'$K?($l$k$+$I$&$+$r$+$($9!#(B
+ − 219 $B9TKv6XB'J8;z$O(B\'s\'$B$N(Bcategory$B$G;XDj$9$k!#(B"
908
+ − 220 (let ((before (char-before))
+ − 221 (after (char-after)))
+ − 222 (if (and before
333
+ − 223 (or
908
+ − 224 (and kinsoku-ascii (char-in-category-p before ?a))
+ − 225 (and kinsoku-jis (or (char-in-category-p before ?j)
+ − 226 (and after
+ − 227 (char-in-category-p after ?j))))
+ − 228 (and kinsoku-gb (or (char-in-category-p before ?c)
+ − 229 (and after
+ − 230 (char-in-category-p after ?c))))
+ − 231 (and kinsoku-big5 (or (char-in-category-p before ?t)
+ − 232 (and after
+ − 233 (char-in-category-p after ?t))))))
+ − 234 (char-in-category-p before ?e)
333
+ − 235 nil)))
+ − 236
+ − 237 (defvar kinsoku-extend-limit nil
+ − 238 "Defines how many characters kinsoku will search forward before giving up.
+ − 239 A value of nil equates to infinity.
+ − 240 $B6XB'=hM}$G9T$r?-$P$7$FNI$$H>3QJ8;z?t$r;XDj$9$k!#(B
+ − 241 $BHsIi@0?t0J30$N>l9g$OL58BBg$r0UL#$9$k!#(B")
+ − 242
+ − 243 (defun kinsoku-process ()
+ − 244 "Move to a point that will not break forbidden line break rules.
+ − 245 $B6XB'$K?($l$J$$E@$X0\F0$9$k!#(B
+ − 246 point$B$,9TF,6XB'$K?($l$k>l9g$O9T$r?-$P$7$F!"6XB'$K?($l$J$$E@$rC5$9!#(B
+ − 247 point$B$,9TKv6XB'$K?($l$k>l9g$O9T$r=L$a$F!"6XB'$K?($l$J$$E@$rC5$9!#(B
+ − 248 $B$?$@$7!"9T?-$P$7H>3QJ8;z?t$,(Bkinsoku-extend-limit$B$r1[$($k$H!"(B
+ − 249 $B9T$r=L$a$F6XB'$K?($l$J$$E@$rC5$9!#(B"
+ − 250 (let ((bol-kin nil) (eol-kin nil))
+ − 251 (if (and (not (bolp))
+ − 252 (not (eolp))
+ − 253 (or (setq bol-kin (kinsoku-bol-p))
+ − 254 (setq eol-kin (kinsoku-eol-p))))
+ − 255 (cond(bol-kin (kinsoku-process-extend))
+ − 256 (eol-kin (kinsoku-process-shrink))))))
+ − 257
+ − 258 (defun kinsoku-process-extend ()
+ − 259 "Move point forward to a permissable for line-breaking.
+ − 260 $B9T$r?-$P$7$F6XB'$K?($l$J$$E@$X0\F0$9$k!#(B"
+ − 261 (let ((max-column (+ fill-column
+ − 262 (if (and (numberp kinsoku-extend-limit)
+ − 263 (>= kinsoku-extend-limit 0))
+ − 264 kinsoku-extend-limit
+ − 265 10000))) ;;; 10000 is deliberatly unreasonably large
+ − 266 ch1 ch2)
+ − 267 (while (and (setq ch1 (char-after))
+ − 268 (<= (+ (current-column)
+ − 269 (char-width ch1 ))
+ − 270 max-column)
+ − 271 (not (bolp))
+ − 272 (not (eolp))
+ − 273 (or (kinsoku-eol-p)
+ − 274 (kinsoku-bol-p)
+ − 275 ;;; don't break in the middle of an English word
+ − 276 (and (char-in-category-p ch1 ?a)
+ − 277 (setq ch2 (char-before))
+ − 278 (char-in-category-p ch2 ?a)
+ − 279 (= ?w (char-syntax ch2))
+ − 280 (= ?w (char-syntax ch1)))))
+ − 281 (forward-char))
+ − 282 (if (or (kinsoku-eol-p) (kinsoku-bol-p))
+ − 283 (kinsoku-process-shrink))))
+ − 284
+ − 285 (defun kinsoku-process-shrink ()
+ − 286 "Move point backward to a point permissable for line-breaking.
+ − 287 $B9T$r=L$a$F6XB'$K?($l$J$$E@$X0\F0$9$k!#(B"
+ − 288 (let (ch1 ch2)
+ − 289 (while (and (not (bolp))
+ − 290 (not (eolp))
+ − 291 (or (kinsoku-bol-p)
+ − 292 (kinsoku-eol-p)
+ − 293 ;;; don't break in the middle of an English word
+ − 294 (and
+ − 295 (char-in-category-p (setq ch1 (following-char)) ?a)
+ − 296 (char-in-category-p (setq ch2 (preceding-char)) ?a)
+ − 297 (= ?w (char-syntax ch2))
+ − 298 (= ?w (char-syntax ch1)))))
+ − 299 (backward-char))))