38414
|
1 ;;; kinsoku.el --- `Kinsoku' processing funcs -*- coding: iso-2022-7bit; -*-
|
17052
|
2
|
|
3 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
|
18377
|
4 ;; Licensed to the Free Software Foundation.
|
17052
|
5
|
18377
|
6 ;; Keywords: mule, kinsoku
|
17052
|
7
|
|
8 ;; This file is part of GNU Emacs.
|
|
9
|
|
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
11 ;; it under the terms of the GNU General Public License as published by
|
|
12 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
13 ;; any later version.
|
|
14
|
|
15 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18 ;; GNU General Public License for more details.
|
|
19
|
|
20 ;; You should have received a copy of the GNU General Public License
|
17071
|
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
23 ;; Boston, MA 02111-1307, USA.
|
17052
|
24
|
|
25 ;;; Commentary:
|
|
26
|
|
27 ;; `Kinsoku' processing is to prohibit specific characters to be
|
|
28 ;; placed at beginning of line or at end of line. Characters not to
|
|
29 ;; be placed at beginning and end of line have character category `>'
|
|
30 ;; and `<' respectively. This restriction is dissolved by making a
|
|
31 ;; line longer or shorter.
|
|
32 ;;
|
|
33 ;; `Kinsoku' is a Japanese word which originally means ordering to
|
|
34 ;; stay in one place, and is used for the text processing described
|
|
35 ;; above in the context of text formatting.
|
|
36
|
|
37 ;;; Code:
|
|
38
|
|
39 (defvar kinsoku-limit 4
|
|
40 "How many more columns we can make lines longer by `kinsoku' processing.
|
|
41 The value 0 means there's no limitation.")
|
|
42
|
|
43 ;; Setting character category `>' for characters which should not be
|
|
44 ;; placed at beginning of line.
|
|
45 (let* ((kinsoku-bol
|
|
46 (concat
|
|
47 ;; ASCII
|
|
48 "!)-_~}]:;',.?"
|
17759
|
49 ;; Latin JISX0201
|
23196
|
50 ;; Instead of putting Latin JISX0201 string directly, we
|
17759
|
51 ;; generate the string as below to avoid character
|
|
52 ;; unification problem.
|
|
53 (let* ((str1 "!)-_~}]:;',.?")
|
|
54 (len (length str1))
|
|
55 (idx 0)
|
|
56 (str2 "")
|
|
57 ch)
|
|
58 (while (< idx len)
|
|
59 (setq ch (make-char 'latin-jisx0201 (aref str1 idx))
|
|
60 str2 (concat str2 (char-to-string ch))
|
|
61 idx (1+ idx)))
|
|
62 str2)
|
|
63 ;; Katakana JISX0201
|
|
64 "(I!#'()*+,-./0^_(B"
|
17052
|
65 ;; Japanese JISX0208
|
|
66 "$B!"!#!$!%!&!'!(!)!*!+!,!-!.!/!0!1!2!3!4!5!6!7!8!9!:!;!<!=!>(B\
|
|
67 $B!?!@!A!B!C!D!E!G!I!K!M!O!Q!S!U!W!Y![!k!l!m!n(B\
|
|
68 $B$!$#$%$'$)$C$c$e$g$n%!%#%%%'%)%C%c%e%g%n%u%v(B"
|
|
69 ;; Chinese GB2312
|
|
70 "$A!"!##.#,!$!%!&!'!(!)!*!+!,!-!/!1#)!3!5!7!9!;!=(B\
|
|
71 $A!?#;#:#?#!!@!A!B!C!c!d!e!f#/#\#"#_#~#|(e(B"
|
|
72 ;; Chinese BIG5
|
|
73 "$(0!"!#!$!%!&!'!(!)!*!+!,!-!.!/!0!1!2(B\
|
|
74 $(0!3!4!5!6!7!8!9!:!;!<!=!?!A!C!E!G!I!K(B\
|
23431
|
75 $(0!M!O!Q!S!U!W!Y![!]!_!a!c!e!g!i!k!q(B\
|
17052
|
76 $(0"#"$"%"&"'"(")"*"+","2"3"4"j"k"l"x%7(B"))
|
|
77 (len (length kinsoku-bol))
|
|
78 (idx 0)
|
|
79 ch)
|
|
80 (while (< idx len)
|
20843
|
81 (setq ch (aref kinsoku-bol idx)
|
|
82 idx (1+ idx))
|
17052
|
83 (modify-category-entry ch ?>)))
|
|
84
|
|
85 ;; Setting character category `<' for characters which should not be
|
|
86 ;; placed at end of line.
|
|
87 (let* ((kinsoku-eol
|
|
88 (concat
|
|
89 ;; ASCII
|
|
90 "({[`"
|
17759
|
91 ;; Latin JISX0201
|
|
92 ;; See the comment above.
|
|
93 (let* ((str1 "({[`")
|
|
94 (len (length str1))
|
|
95 (idx 0)
|
|
96 (str2 "")
|
|
97 ch)
|
|
98 (while (< idx len)
|
|
99 (setq ch (make-char 'latin-jisx0201 (aref str1 idx))
|
|
100 str2 (concat str2 (char-to-string ch))
|
|
101 idx (1+ idx)))
|
|
102 str2)
|
|
103 ;; JISX0201 Katakana
|
|
104 "(I"(B"
|
17052
|
105 ;; Japanese JISX0208
|
|
106 "$B!F!H!J!L!N!P!R!T!V!X!Z!k!l!m!n!w!x(B\
|
|
107 $A!.!0#"#(!2!4!6!8!:!<!>!c!d!e#@!f!l(B"
|
|
108 ;; Chinese GB2312
|
|
109 "$A(E(F(G(H(I(J(K(L(M(N(O(P(Q(R(S(T(U(V(W(X(Y(h(B\
|
|
110 $(0!>!@!B!D!F!H!J!L!N!P!R!T!V!X!Z!\!^!`!b(B"
|
|
111 ;; Chinese BIG5
|
|
112 "$(0!d!f!h!j!k!q!p"i"j"k"n"x$u$v$w$x$y$z${(B\
|
|
113 $(0$|$}$~%!%"%#%$%%%&%'%(%)%*%+%:(B"))
|
|
114 (len (length kinsoku-eol))
|
|
115 (idx 0)
|
|
116 ch)
|
|
117 (while (< idx len)
|
20843
|
118 (setq ch (aref kinsoku-eol idx)
|
|
119 idx (1+ idx))
|
17052
|
120 (modify-category-entry ch ?<)))
|
|
121
|
|
122 ;; Try to resolve `kinsoku' restriction by making the current line longer.
|
|
123 (defun kinsoku-longer ()
|
|
124 (let ((pos-and-column (save-excursion
|
|
125 (forward-char 1)
|
|
126 (while (aref (char-category-set (following-char)) ?>)
|
|
127 (forward-char 1))
|
|
128 (cons (point) (current-column)))))
|
|
129 (if (or (<= kinsoku-limit 0)
|
|
130 (< (cdr pos-and-column) (+ (current-fill-column) kinsoku-limit)))
|
|
131 (goto-char (car pos-and-column)))))
|
|
132
|
|
133 ;; Try to resolve `kinsoku' restriction by making the current line shorter.
|
17759
|
134 ;; The line can't be broken before the buffer position LINEBEG.
|
17052
|
135 (defun kinsoku-shorter (linebeg)
|
|
136 (let ((pos (save-excursion
|
|
137 (forward-char -1)
|
|
138 (while (and (< linebeg (point))
|
|
139 (or (aref (char-category-set (preceding-char)) ?<)
|
|
140 (aref (char-category-set (following-char)) ?>)))
|
|
141 (forward-char -1))
|
|
142 (point))))
|
|
143 (if (< linebeg pos)
|
|
144 (goto-char pos))))
|
|
145
|
|
146 ;;;###autoload
|
|
147 (defun kinsoku (linebeg)
|
|
148 "Go to a line breaking position near point by doing `kinsoku' processing.
|
|
149 LINEBEG is a buffer position we can't break a line before.
|
|
150
|
|
151 `Kinsoku' processing is to prohibit specific characters to be placed
|
|
152 at beginning of line or at end of line. Characters not to be placed
|
|
153 at beginning and end of line have character category `>' and `<'
|
|
154 respectively. This restriction is dissolved by making a line longer or
|
|
155 shorter.
|
|
156
|
|
157 `Kinsoku' is a Japanese word which originally means ordering to stay
|
|
158 in one place, and is used for the text processing described above in
|
|
159 the context of text formatting."
|
23492
|
160 (if enable-kinsoku
|
|
161 (if (or (and
|
|
162 ;; The character after point can't be placed at beginning
|
|
163 ;; of line.
|
|
164 (aref (char-category-set (following-char)) ?>)
|
|
165 ;; We at first try to dissolve this situation by making a
|
|
166 ;; line longer. If it fails, then try making a line
|
|
167 ;; shorter.
|
|
168 (not (kinsoku-longer)))
|
|
169 ;; The character before point can't be placed at end of line.
|
|
170 (aref (char-category-set (preceding-char)) ?<))
|
|
171 (kinsoku-shorter linebeg))))
|
17052
|
172
|
38414
|
173 ;;; kinsoku.el ends here
|