comparison lisp/international/kinsoku.el @ 17052:d0d7b244b1d0

Initial revision
author Karl Heuer <kwzh@gnu.org>
date Thu, 20 Feb 1997 07:02:49 +0000
parents
children 70194012fb3a
comparison
equal deleted inserted replaced
17051:fd0b17a79b07 17052:d0d7b244b1d0
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
21 ;; along with GNU Emacs; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23
24 ;;; Commentary:
25
26 ;; `Kinsoku' processing is to prohibit specific characters to be
27 ;; placed at beginning of line or at end of line. Characters not to
28 ;; be placed at beginning and end of line have character category `>'
29 ;; and `<' respectively. This restriction is dissolved by making a
30 ;; line longer or shorter.
31 ;;
32 ;; `Kinsoku' is a Japanese word which originally means ordering to
33 ;; stay in one place, and is used for the text processing described
34 ;; above in the context of text formatting.
35
36 ;;; Code:
37
38 (defvar kinsoku-limit 4
39 "How many more columns we can make lines longer by `kinsoku' processing.
40 The value 0 means there's no limitation.")
41
42 ;; Setting character category `>' for characters which should not be
43 ;; placed at beginning of line.
44 (let* ((kinsoku-bol
45 (concat
46 ;; ASCII
47 "!)-_~}]:;',.?"
48 ;; Japanese JISX0208
49 "$B!"!#!$!%!&!'!(!)!*!+!,!-!.!/!0!1!2!3!4!5!6!7!8!9!:!;!<!=!>(B\
50 $B!?!@!A!B!C!D!E!G!I!K!M!O!Q!S!U!W!Y![!k!l!m!n(B\
51 $B$!$#$%$'$)$C$c$e$g$n%!%#%%%'%)%C%c%e%g%n%u%v(B"
52 ;; Chinese GB2312
53 "$A!"!##.#,!$!%!&!'!(!)!*!+!,!-!/!1#)!3!5!7!9!;!=(B\
54 $A!?#;#:#?#!!@!A!B!C!c!d!e!f#/#\#"#_#~#|(e(B"
55 ;; Chinese BIG5
56 "$(0!"!#!$!%!&!'!(!)!*!+!,!-!.!/!0!1!2(B\
57 $(0!3!4!5!6!7!8!9!:!;!<!=!?!A!C!E!G!I!K(B\
58 $(0!M!O!Q(B $(0!S!U!W!Y![!]!_!a!c!e!g!i!k!q(B\
59 $(0"#"$"%"&"'"(")"*"+","2"3"4"j"k"l"x%7(B"))
60 (len (length kinsoku-bol))
61 (idx 0)
62 ch)
63 (while (< idx len)
64 (setq ch (sref kinsoku-bol idx)
65 idx (+ idx (char-bytes ch)))
66 (modify-category-entry ch ?>)))
67
68 ;; Setting character category `<' for characters which should not be
69 ;; placed at end of line.
70 (let* ((kinsoku-eol
71 (concat
72 ;; ASCII
73 "({[`"
74 ;; Japanese JISX0208
75 "$B!F!H!J!L!N!P!R!T!V!X!Z!k!l!m!n!w!x(B\
76 $A!.!0#"#(!2!4!6!8!:!<!>!c!d!e#@!f!l(B"
77 ;; Chinese GB2312
78 "$A(E(F(G(H(I(J(K(L(M(N(O(P(Q(R(S(T(U(V(W(X(Y(h(B\
79 $(0!>!@!B!D!F!H!J!L!N!P!R!T!V!X!Z!\!^!`!b(B"
80 ;; Chinese BIG5
81 "$(0!d!f!h!j!k!q!p"i"j"k"n"x$u$v$w$x$y$z${(B\
82 $(0$|$}$~%!%"%#%$%%%&%'%(%)%*%+%:(B"))
83 (len (length kinsoku-eol))
84 (idx 0)
85 ch)
86 (while (< idx len)
87 (setq ch (sref kinsoku-eol idx)
88 idx (+ idx (char-bytes ch)))
89 (modify-category-entry ch ?<)))
90
91 ;; Try to resolve `kinsoku' restriction by making the current line longer.
92 (defun kinsoku-longer ()
93 (let ((pos-and-column (save-excursion
94 (forward-char 1)
95 (while (aref (char-category-set (following-char)) ?>)
96 (forward-char 1))
97 (cons (point) (current-column)))))
98 (if (or (<= kinsoku-limit 0)
99 (< (cdr pos-and-column) (+ (current-fill-column) kinsoku-limit)))
100 (goto-char (car pos-and-column)))))
101
102 ;; Try to resolve `kinsoku' restriction by making the current line shorter.
103 ;; The line can't be broken before the buffer position LINEBEG."
104 (defun kinsoku-shorter (linebeg)
105 (let ((pos (save-excursion
106 (forward-char -1)
107 (while (and (< linebeg (point))
108 (or (aref (char-category-set (preceding-char)) ?<)
109 (aref (char-category-set (following-char)) ?>)))
110 (forward-char -1))
111 (point))))
112 (if (< linebeg pos)
113 (goto-char pos))))
114
115 ;;;###autoload
116 (defun kinsoku (linebeg)
117 "Go to a line breaking position near point by doing `kinsoku' processing.
118 LINEBEG is a buffer position we can't break a line before.
119
120 `Kinsoku' processing is to prohibit specific characters to be placed
121 at beginning of line or at end of line. Characters not to be placed
122 at beginning and end of line have character category `>' and `<'
123 respectively. This restriction is dissolved by making a line longer or
124 shorter.
125
126 `Kinsoku' is a Japanese word which originally means ordering to stay
127 in one place, and is used for the text processing described above in
128 the context of text formatting."
129 (if (or (and
130 ;; The character after point can't be placed at beginning
131 ;; of line.
132 (aref (char-category-set (following-char)) ?>)
133 ;; We at first try to dissolve this situation by making a
134 ;; line longer. If it fails, then try making a line
135 ;; shorter.
136 (not (kinsoku-longer)))
137 ;; The character before point can't be placed at end of line.
138 (aref (char-category-set (preceding-char)) ?<))
139 (kinsoku-shorter linebeg)))
140
141 ;; kinsoku.el ends here