| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
(defvar kinsoku-limit 4 |
|---|
| 44 |
"How many more columns we can make lines longer by `kinsoku' processing. |
|---|
| 45 |
The value 0 means there's no limitation.") |
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
(let* ((kinsoku-bol |
|---|
| 50 |
(concat |
|---|
| 51 |
|
|---|
| 52 |
"!)-_~}]:;',.?" |
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
(let* ((str1 "!)-_~}]:;',.?") |
|---|
| 58 |
(len (length str1)) |
|---|
| 59 |
(idx 0) |
|---|
| 60 |
(str2 "") |
|---|
| 61 |
ch) |
|---|
| 62 |
(while (< idx len) |
|---|
| 63 |
(setq ch (make-char 'latin-jisx0201 (aref str1 idx)) |
|---|
| 64 |
str2 (concat str2 (char-to-string ch)) |
|---|
| 65 |
idx (1+ idx))) |
|---|
| 66 |
str2) |
|---|
| 67 |
|
|---|
| 68 |
"(I!#'()*+,-./0^_(B" |
|---|
| 69 |
|
|---|
| 70 |
"$B!"!#!$!%!&!'!(!)!*!+!,!-!.!/!0!1!2!3!4!5!6!7!8!9!:! |
|---|
| 71 |
$B!?!@!A!B!C!D!E!G!I!K!M!O!Q!S!U!W!Y![!k!l!m!n(B\ |
|---|
| 72 |
$B$!$#$%$'$)$C$c$e$g$n%!%#%%%'%)%C%c%e%g%n%u%v(B" |
|---|
| 73 |
;; Chinese GB2312 |
|---|
| 74 |
"$A!"!##.#,!$!%!&!'!(!)!*!+!,!-!/!1#)!3!5!7!9!;!=(B\ |
|---|
| 75 |
$A!?#;#:#?#!!@!A!B!C!c!d!e!f#/#\#"#_#~#|(e(B" |
|---|
| 76 |
;; Chinese BIG5 |
|---|
| 77 |
"$(0!"!#!$!%!&!'!(!)!*!+!,!-!.!/!0!1!2(B\ |
|---|
| 78 |
$(0!3!4!5!6!7!8!9!:!;!<!=!?!A!C!E!G!I!K(B\ |
|---|
| 79 |
$(0!M!O!Q!S!U!W!Y![!]!_!a!c!e!g!i!k!q(B\ |
|---|
| 80 |
$(0"#"$"%"&"'"(")"*"+","2"3"4"j"k"l"x%7(B")) |
|---|
| 81 |
(len (length kinsoku-bol)) |
|---|
| 82 |
(idx 0) |
|---|
| 83 |
ch) |
|---|
| 84 |
(while (< idx len) |
|---|
| 85 |
(setq ch (aref kinsoku-bol idx) |
|---|
| 86 |
idx (1+ idx)) |
|---|
| 87 |
(modify-category-entry ch ?>))) |
|---|
| 88 |
|
|---|
| 89 |
;; Setting character category `<' for characters which should not be |
|---|
| 90 |
;; placed at end of line. |
|---|
| 91 |
(let* ((kinsoku-eol |
|---|
| 92 |
(concat |
|---|
| 93 |
;; ASCII |
|---|
| 94 |
"({[`" |
|---|
| 95 |
;; Latin JISX0201 |
|---|
| 96 |
;; See the comment above. |
|---|
| 97 |
(let* ((str1 "({[`") |
|---|
| 98 |
(len (length str1)) |
|---|
| 99 |
(idx 0) |
|---|
| 100 |
(str2 "") |
|---|
| 101 |
ch) |
|---|
| 102 |
(while (< idx len) |
|---|
| 103 |
(setq ch (make-char 'latin-jisx0201 (aref str1 idx)) |
|---|
| 104 |
str2 (concat str2 (char-to-string ch)) |
|---|
| 105 |
idx (1+ idx))) |
|---|
| 106 |
str2) |
|---|
| 107 |
;; JISX0201 Katakana |
|---|
| 108 |
"(I"(B" |
|---|
| 109 |
|
|---|
| 110 |
"$B!F!H!J!L!N!P!R!T!V!X!Z!k!l!m!n!w!x(B\ |
|---|
| 111 |
#(!2!4!6!8!:!<!>!c!d!e#@!f!l(B" |
|---|
| 112 |
|
|---|
| 113 |
$A(E(F(G(H(I(J(K(L(M(N(O(P(Q(R(S(T(U(V(W(X(Y(h(B\ |
|---|
| 114 |
\$(0!>!@!B!D!F!H!J!L!N!P!R!T!V!X!Z!\!^!`!b(B" |
|---|
| 115 |
;; Chinese BIG5 |
|---|
| 116 |
"$(0!d!f!h!j!k!q!p"i"j"k"n"x$u$v$w$x$y$z${(B\ |
|---|
| 117 |
$(0$|$}$~%!%"%#%$%%%&%'%(%)%*%+%:(B")) |
|---|
| 118 |
(len (length kinsoku-eol)) |
|---|
| 119 |
(idx 0) |
|---|
| 120 |
ch) |
|---|
| 121 |
(while (< idx len) |
|---|
| 122 |
(setq ch (aref kinsoku-eol idx) |
|---|
| 123 |
idx (1+ idx)) |
|---|
| 124 |
(modify-category-entry ch ?<))) |
|---|
| 125 |
|
|---|
| 126 |
;; Try to resolve `kinsoku' restriction by making the current line longer. |
|---|
| 127 |
(defun kinsoku-longer () |
|---|
| 128 |
(let ((pos-and-column |
|---|
| 129 |
(save-excursion |
|---|
| 130 |
(forward-char 1) |
|---|
| 131 |
(while (and (not (eolp)) |
|---|
| 132 |
(or (aref (char-category-set (following-char)) ?>) |
|---|
| 133 |
;; protect non-kinsoku words |
|---|
| 134 |
(not (or (eq (preceding-char) ? ) |
|---|
| 135 |
(aref (char-category-set (preceding-char)) |
|---|
| 136 |
?|))))) |
|---|
| 137 |
(forward-char 1)) |
|---|
| 138 |
(cons (point) (current-column))))) |
|---|
| 139 |
(if (or (<= kinsoku-limit 0) |
|---|
| 140 |
(< (cdr pos-and-column) (+ (current-fill-column) kinsoku-limit))) |
|---|
| 141 |
(goto-char (car pos-and-column))))) |
|---|
| 142 |
|
|---|
| 143 |
;; Try to resolve `kinsoku' restriction by making the current line shorter. |
|---|
| 144 |
;; The line can't be broken before the buffer position LINEBEG. |
|---|
| 145 |
(defun kinsoku-shorter (linebeg) |
|---|
| 146 |
(let ((pos (save-excursion |
|---|
| 147 |
(forward-char -1) |
|---|
| 148 |
(while (and |
|---|
| 149 |
(< linebeg (point)) |
|---|
| 150 |
(or (aref (char-category-set (preceding-char)) ?<) |
|---|
| 151 |
(aref (char-category-set (following-char)) ?>) |
|---|
| 152 |
;; protect non-kinsoku words |
|---|
| 153 |
(not (or (eq (preceding-char) ? ) |
|---|
| 154 |
(aref (char-category-set (preceding-char)) |
|---|
| 155 |
?|))))) |
|---|
| 156 |
(forward-char -1)) |
|---|
| 157 |
(point)))) |
|---|
| 158 |
(if (< linebeg pos) |
|---|
| 159 |
(goto-char pos)))) |
|---|
| 160 |
|
|---|
| 161 |
;;;###autoload |
|---|
| 162 |
(defun kinsoku (linebeg) |
|---|
| 163 |
"Go to a line breaking position near point by doing `kinsoku' processing. |
|---|
| 164 |
LINEBEG is a buffer position we can't break a line before. |
|---|
| 165 |
|
|---|
| 166 |
`Kinsoku' processing is to prohibit specific characters to be placed |
|---|
| 167 |
at beginning of line or at end of line. Characters not to be placed |
|---|
| 168 |
at beginning and end of line have character category `>' and `<' |
|---|
| 169 |
respectively. This restriction is dissolved by making a line longer or |
|---|
| 170 |
shorter. |
|---|
| 171 |
|
|---|
| 172 |
`Kinsoku' is a Japanese word which originally means ordering to stay |
|---|
| 173 |
in one place, and is used for the text processing described above in |
|---|
| 174 |
the context of text formatting." |
|---|
| 175 |
(if enable-kinsoku |
|---|
| 176 |
(if (or (and |
|---|
| 177 |
;; The character after point can't be placed at beginning |
|---|
| 178 |
;; of line. |
|---|
| 179 |
(aref (char-category-set (following-char)) ?>) |
|---|
| 180 |
;; We at first try to dissolve this situation by making a |
|---|
| 181 |
;; line longer. If it fails, then try making a line |
|---|
| 182 |
;; shorter. |
|---|
| 183 |
(not (kinsoku-longer))) |
|---|
| 184 |
;; The character before point can't be placed at end of line. |
|---|
| 185 |
(aref (char-category-set (preceding-char)) ?<)) |
|---|
| 186 |
(kinsoku-shorter linebeg)))) |
|---|
| 187 |
|
|---|
| 188 |
;;; arch-tag: e6b036bc-9e5b-4e9f-a22c-4ed04e37777e |
|---|
| 189 |
;;; kinsoku.el ends here |
|---|
| 190 |
|
|---|