17052
|
1 ;;; kinsoku.el --- `Kinsoku' processing functions.
|
|
2
|
|
3 ;; Copyright (C) 1995 Free Software Foundation, Inc.
|
|
4 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
|
|
5
|
|
6 ;; Keywords: kinsoku
|
|
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 "!)-_~}]:;',.?"
|
|
49 ;; Japanese JISX0208
|
|
50 "$B!"!#!$!%!&!'!(!)!*!+!,!-!.!/!0!1!2!3!4!5!6!7!8!9!:!;!<!=!>(B\
|
|
51 $B!?!@!A!B!C!D!E!G!I!K!M!O!Q!S!U!W!Y![!k!l!m!n(B\
|
|
52 $B$!$#$%$'$)$C$c$e$g$n%!%#%%%'%)%C%c%e%g%n%u%v(B"
|
|
53 ;; Chinese GB2312
|
|
54 "$A!"!##.#,!$!%!&!'!(!)!*!+!,!-!/!1#)!3!5!7!9!;!=(B\
|
|
55 $A!?#;#:#?#!!@!A!B!C!c!d!e!f#/#\#"#_#~#|(e(B"
|
|
56 ;; Chinese BIG5
|
|
57 "$(0!"!#!$!%!&!'!(!)!*!+!,!-!.!/!0!1!2(B\
|
|
58 $(0!3!4!5!6!7!8!9!:!;!<!=!?!A!C!E!G!I!K(B\
|
|
59 $(0!M!O!Q(B $(0!S!U!W!Y![!]!_!a!c!e!g!i!k!q(B\
|
|
60 $(0"#"$"%"&"'"(")"*"+","2"3"4"j"k"l"x%7(B"))
|
|
61 (len (length kinsoku-bol))
|
|
62 (idx 0)
|
|
63 ch)
|
|
64 (while (< idx len)
|
|
65 (setq ch (sref kinsoku-bol idx)
|
|
66 idx (+ idx (char-bytes ch)))
|
|
67 (modify-category-entry ch ?>)))
|
|
68
|
|
69 ;; Setting character category `<' for characters which should not be
|
|
70 ;; placed at end of line.
|
|
71 (let* ((kinsoku-eol
|
|
72 (concat
|
|
73 ;; ASCII
|
|
74 "({[`"
|
|
75 ;; Japanese JISX0208
|
|
76 "$B!F!H!J!L!N!P!R!T!V!X!Z!k!l!m!n!w!x(B\
|
|
77 $A!.!0#"#(!2!4!6!8!:!<!>!c!d!e#@!f!l(B"
|
|
78 ;; Chinese GB2312
|
|
79 "$A(E(F(G(H(I(J(K(L(M(N(O(P(Q(R(S(T(U(V(W(X(Y(h(B\
|
|
80 $(0!>!@!B!D!F!H!J!L!N!P!R!T!V!X!Z!\!^!`!b(B"
|
|
81 ;; Chinese BIG5
|
|
82 "$(0!d!f!h!j!k!q!p"i"j"k"n"x$u$v$w$x$y$z${(B\
|
|
83 $(0$|$}$~%!%"%#%$%%%&%'%(%)%*%+%:(B"))
|
|
84 (len (length kinsoku-eol))
|
|
85 (idx 0)
|
|
86 ch)
|
|
87 (while (< idx len)
|
|
88 (setq ch (sref kinsoku-eol idx)
|
|
89 idx (+ idx (char-bytes ch)))
|
|
90 (modify-category-entry ch ?<)))
|
|
91
|
|
92 ;; Try to resolve `kinsoku' restriction by making the current line longer.
|
|
93 (defun kinsoku-longer ()
|
|
94 (let ((pos-and-column (save-excursion
|
|
95 (forward-char 1)
|
|
96 (while (aref (char-category-set (following-char)) ?>)
|
|
97 (forward-char 1))
|
|
98 (cons (point) (current-column)))))
|
|
99 (if (or (<= kinsoku-limit 0)
|
|
100 (< (cdr pos-and-column) (+ (current-fill-column) kinsoku-limit)))
|
|
101 (goto-char (car pos-and-column)))))
|
|
102
|
|
103 ;; Try to resolve `kinsoku' restriction by making the current line shorter.
|
|
104 ;; The line can't be broken before the buffer position LINEBEG."
|
|
105 (defun kinsoku-shorter (linebeg)
|
|
106 (let ((pos (save-excursion
|
|
107 (forward-char -1)
|
|
108 (while (and (< linebeg (point))
|
|
109 (or (aref (char-category-set (preceding-char)) ?<)
|
|
110 (aref (char-category-set (following-char)) ?>)))
|
|
111 (forward-char -1))
|
|
112 (point))))
|
|
113 (if (< linebeg pos)
|
|
114 (goto-char pos))))
|
|
115
|
|
116 ;;;###autoload
|
|
117 (defun kinsoku (linebeg)
|
|
118 "Go to a line breaking position near point by doing `kinsoku' processing.
|
|
119 LINEBEG is a buffer position we can't break a line before.
|
|
120
|
|
121 `Kinsoku' processing is to prohibit specific characters to be placed
|
|
122 at beginning of line or at end of line. Characters not to be placed
|
|
123 at beginning and end of line have character category `>' and `<'
|
|
124 respectively. This restriction is dissolved by making a line longer or
|
|
125 shorter.
|
|
126
|
|
127 `Kinsoku' is a Japanese word which originally means ordering to stay
|
|
128 in one place, and is used for the text processing described above in
|
|
129 the context of text formatting."
|
|
130 (if (or (and
|
|
131 ;; The character after point can't be placed at beginning
|
|
132 ;; of line.
|
|
133 (aref (char-category-set (following-char)) ?>)
|
|
134 ;; We at first try to dissolve this situation by making a
|
|
135 ;; line longer. If it fails, then try making a line
|
|
136 ;; shorter.
|
|
137 (not (kinsoku-longer)))
|
|
138 ;; The character before point can't be placed at end of line.
|
|
139 (aref (char-category-set (preceding-char)) ?<))
|
|
140 (kinsoku-shorter linebeg)))
|
|
141
|
|
142 ;; kinsoku.el ends here
|