Mercurial > emacs
annotate lisp/international/kinsoku.el @ 69573:96795267cd9b
*** empty log message ***
author | Kim F. Storm <storm@cua.dk> |
---|---|
date | Sun, 19 Mar 2006 19:59:17 +0000 |
parents | 99f4a941eb41 |
children | 43cc94d955c2 7beb78bc1f8e |
rev | line source |
---|---|
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
23492
diff
changeset
|
1 ;;; kinsoku.el --- `Kinsoku' processing funcs -*- coding: iso-2022-7bit; -*- |
17052 | 2 |
62274 | 3 ;; Copyright (C) 1997, 2003 Free Software Foundation, Inc. |
4 ;; Copyright (C) 1995, 1997, 1998 | |
5 ;; National Institute of Advanced Industrial Science and Technology (AIST) | |
6 ;; Registration Number H14PRO021 | |
17052 | 7 |
18377
8b4a66c66dd6
Change copyright notice.
Richard M. Stallman <rms@gnu.org>
parents:
17759
diff
changeset
|
8 ;; Keywords: mule, kinsoku |
17052 | 9 |
10 ;; This file is part of GNU Emacs. | |
11 | |
12 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
13 ;; it under the terms of the GNU General Public License as published by | |
14 ;; the Free Software Foundation; either version 2, or (at your option) | |
15 ;; any later version. | |
16 | |
17 ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
17071 | 23 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
64085 | 24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
25 ;; Boston, MA 02110-1301, USA. | |
17052 | 26 |
27 ;;; Commentary: | |
28 | |
29 ;; `Kinsoku' processing is to prohibit specific characters to be | |
30 ;; placed at beginning of line or at end of line. Characters not to | |
31 ;; be placed at beginning and end of line have character category `>' | |
32 ;; and `<' respectively. This restriction is dissolved by making a | |
33 ;; line longer or shorter. | |
34 ;; | |
35 ;; `Kinsoku' is a Japanese word which originally means ordering to | |
36 ;; stay in one place, and is used for the text processing described | |
37 ;; above in the context of text formatting. | |
38 | |
39 ;;; Code: | |
40 | |
41 (defvar kinsoku-limit 4 | |
42 "How many more columns we can make lines longer by `kinsoku' processing. | |
43 The value 0 means there's no limitation.") | |
44 | |
45 ;; Setting character category `>' for characters which should not be | |
46 ;; placed at beginning of line. | |
47 (let* ((kinsoku-bol | |
48 (concat | |
49 ;; ASCII | |
50 "!)-_~}]:;',.?" | |
17759
ef12c80a8a1e
Set category of kinsoku-bol and kinsoku-eol for
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
51 ;; Latin JISX0201 |
23196 | 52 ;; Instead of putting Latin JISX0201 string directly, we |
17759
ef12c80a8a1e
Set category of kinsoku-bol and kinsoku-eol for
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
53 ;; generate the string as below to avoid character |
ef12c80a8a1e
Set category of kinsoku-bol and kinsoku-eol for
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
54 ;; unification problem. |
ef12c80a8a1e
Set category of kinsoku-bol and kinsoku-eol for
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
55 (let* ((str1 "!)-_~}]:;',.?") |
ef12c80a8a1e
Set category of kinsoku-bol and kinsoku-eol for
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
56 (len (length str1)) |
ef12c80a8a1e
Set category of kinsoku-bol and kinsoku-eol for
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
57 (idx 0) |
ef12c80a8a1e
Set category of kinsoku-bol and kinsoku-eol for
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
58 (str2 "") |
ef12c80a8a1e
Set category of kinsoku-bol and kinsoku-eol for
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
59 ch) |
ef12c80a8a1e
Set category of kinsoku-bol and kinsoku-eol for
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
60 (while (< idx len) |
ef12c80a8a1e
Set category of kinsoku-bol and kinsoku-eol for
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
61 (setq ch (make-char 'latin-jisx0201 (aref str1 idx)) |
ef12c80a8a1e
Set category of kinsoku-bol and kinsoku-eol for
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
62 str2 (concat str2 (char-to-string ch)) |
ef12c80a8a1e
Set category of kinsoku-bol and kinsoku-eol for
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
63 idx (1+ idx))) |
ef12c80a8a1e
Set category of kinsoku-bol and kinsoku-eol for
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
64 str2) |
ef12c80a8a1e
Set category of kinsoku-bol and kinsoku-eol for
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
65 ;; Katakana JISX0201 |
ef12c80a8a1e
Set category of kinsoku-bol and kinsoku-eol for
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
66 "(I!#'()*+,-./0^_(B" |
17052 | 67 ;; Japanese JISX0208 |
68 "$B!"!#!$!%!&!'!(!)!*!+!,!-!.!/!0!1!2!3!4!5!6!7!8!9!:!;!<!=!>(B\ | |
69 $B!?!@!A!B!C!D!E!G!I!K!M!O!Q!S!U!W!Y![!k!l!m!n(B\ | |
70 $B$!$#$%$'$)$C$c$e$g$n%!%#%%%'%)%C%c%e%g%n%u%v(B" | |
71 ;; Chinese GB2312 | |
72 "$A!"!##.#,!$!%!&!'!(!)!*!+!,!-!/!1#)!3!5!7!9!;!=(B\ | |
73 $A!?#;#:#?#!!@!A!B!C!c!d!e!f#/#\#"#_#~#|(e(B" | |
74 ;; Chinese BIG5 | |
75 "$(0!"!#!$!%!&!'!(!)!*!+!,!-!.!/!0!1!2(B\ | |
76 $(0!3!4!5!6!7!8!9!:!;!<!=!?!A!C!E!G!I!K(B\ | |
23431 | 77 $(0!M!O!Q!S!U!W!Y![!]!_!a!c!e!g!i!k!q(B\ |
17052 | 78 $(0"#"$"%"&"'"(")"*"+","2"3"4"j"k"l"x%7(B")) |
79 (len (length kinsoku-bol)) | |
80 (idx 0) | |
81 ch) | |
82 (while (< idx len) | |
20843 | 83 (setq ch (aref kinsoku-bol idx) |
84 idx (1+ idx)) | |
17052 | 85 (modify-category-entry ch ?>))) |
86 | |
87 ;; Setting character category `<' for characters which should not be | |
88 ;; placed at end of line. | |
89 (let* ((kinsoku-eol | |
90 (concat | |
91 ;; ASCII | |
92 "({[`" | |
17759
ef12c80a8a1e
Set category of kinsoku-bol and kinsoku-eol for
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
93 ;; Latin JISX0201 |
ef12c80a8a1e
Set category of kinsoku-bol and kinsoku-eol for
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
94 ;; See the comment above. |
ef12c80a8a1e
Set category of kinsoku-bol and kinsoku-eol for
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
95 (let* ((str1 "({[`") |
ef12c80a8a1e
Set category of kinsoku-bol and kinsoku-eol for
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
96 (len (length str1)) |
ef12c80a8a1e
Set category of kinsoku-bol and kinsoku-eol for
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
97 (idx 0) |
ef12c80a8a1e
Set category of kinsoku-bol and kinsoku-eol for
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
98 (str2 "") |
ef12c80a8a1e
Set category of kinsoku-bol and kinsoku-eol for
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
99 ch) |
ef12c80a8a1e
Set category of kinsoku-bol and kinsoku-eol for
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
100 (while (< idx len) |
ef12c80a8a1e
Set category of kinsoku-bol and kinsoku-eol for
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
101 (setq ch (make-char 'latin-jisx0201 (aref str1 idx)) |
ef12c80a8a1e
Set category of kinsoku-bol and kinsoku-eol for
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
102 str2 (concat str2 (char-to-string ch)) |
ef12c80a8a1e
Set category of kinsoku-bol and kinsoku-eol for
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
103 idx (1+ idx))) |
ef12c80a8a1e
Set category of kinsoku-bol and kinsoku-eol for
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
104 str2) |
ef12c80a8a1e
Set category of kinsoku-bol and kinsoku-eol for
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
105 ;; JISX0201 Katakana |
ef12c80a8a1e
Set category of kinsoku-bol and kinsoku-eol for
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
106 "(I"(B" |
17052 | 107 ;; Japanese JISX0208 |
108 "$B!F!H!J!L!N!P!R!T!V!X!Z!k!l!m!n!w!x(B\ | |
109 $A!.!0#"#(!2!4!6!8!:!<!>!c!d!e#@!f!l(B" | |
110 ;; Chinese GB2312 | |
111 "$A(E(F(G(H(I(J(K(L(M(N(O(P(Q(R(S(T(U(V(W(X(Y(h(B\ | |
67333
99f4a941eb41
(kinsoku-longer): Check eolp, not eobp.
Kenichi Handa <handa@m17n.org>
parents:
64085
diff
changeset
|
112 \$(0!>!@!B!D!F!H!J!L!N!P!R!T!V!X!Z!\!^!`!b(B" |
17052 | 113 ;; Chinese BIG5 |
114 "$(0!d!f!h!j!k!q!p"i"j"k"n"x$u$v$w$x$y$z${(B\ | |
115 $(0$|$}$~%!%"%#%$%%%&%'%(%)%*%+%:(B")) | |
116 (len (length kinsoku-eol)) | |
117 (idx 0) | |
118 ch) | |
119 (while (< idx len) | |
20843 | 120 (setq ch (aref kinsoku-eol idx) |
121 idx (1+ idx)) | |
17052 | 122 (modify-category-entry ch ?<))) |
123 | |
124 ;; Try to resolve `kinsoku' restriction by making the current line longer. | |
125 (defun kinsoku-longer () | |
52362
28bd29f9f91c
(kinsoku-longer, kinsoku-shorter): Do not choose a
Kenichi Handa <handa@m17n.org>
parents:
49598
diff
changeset
|
126 (let ((pos-and-column |
28bd29f9f91c
(kinsoku-longer, kinsoku-shorter): Do not choose a
Kenichi Handa <handa@m17n.org>
parents:
49598
diff
changeset
|
127 (save-excursion |
28bd29f9f91c
(kinsoku-longer, kinsoku-shorter): Do not choose a
Kenichi Handa <handa@m17n.org>
parents:
49598
diff
changeset
|
128 (forward-char 1) |
67333
99f4a941eb41
(kinsoku-longer): Check eolp, not eobp.
Kenichi Handa <handa@m17n.org>
parents:
64085
diff
changeset
|
129 (while (and (not (eolp)) |
52362
28bd29f9f91c
(kinsoku-longer, kinsoku-shorter): Do not choose a
Kenichi Handa <handa@m17n.org>
parents:
49598
diff
changeset
|
130 (or (aref (char-category-set (following-char)) ?>) |
28bd29f9f91c
(kinsoku-longer, kinsoku-shorter): Do not choose a
Kenichi Handa <handa@m17n.org>
parents:
49598
diff
changeset
|
131 ;; protect non-kinsoku words |
28bd29f9f91c
(kinsoku-longer, kinsoku-shorter): Do not choose a
Kenichi Handa <handa@m17n.org>
parents:
49598
diff
changeset
|
132 (not (or (eq (preceding-char) ? ) |
28bd29f9f91c
(kinsoku-longer, kinsoku-shorter): Do not choose a
Kenichi Handa <handa@m17n.org>
parents:
49598
diff
changeset
|
133 (aref (char-category-set (preceding-char)) |
28bd29f9f91c
(kinsoku-longer, kinsoku-shorter): Do not choose a
Kenichi Handa <handa@m17n.org>
parents:
49598
diff
changeset
|
134 ?|))))) |
28bd29f9f91c
(kinsoku-longer, kinsoku-shorter): Do not choose a
Kenichi Handa <handa@m17n.org>
parents:
49598
diff
changeset
|
135 (forward-char 1)) |
28bd29f9f91c
(kinsoku-longer, kinsoku-shorter): Do not choose a
Kenichi Handa <handa@m17n.org>
parents:
49598
diff
changeset
|
136 (cons (point) (current-column))))) |
17052 | 137 (if (or (<= kinsoku-limit 0) |
138 (< (cdr pos-and-column) (+ (current-fill-column) kinsoku-limit))) | |
139 (goto-char (car pos-and-column))))) | |
140 | |
141 ;; Try to resolve `kinsoku' restriction by making the current line shorter. | |
17759
ef12c80a8a1e
Set category of kinsoku-bol and kinsoku-eol for
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
142 ;; The line can't be broken before the buffer position LINEBEG. |
17052 | 143 (defun kinsoku-shorter (linebeg) |
144 (let ((pos (save-excursion | |
145 (forward-char -1) | |
52362
28bd29f9f91c
(kinsoku-longer, kinsoku-shorter): Do not choose a
Kenichi Handa <handa@m17n.org>
parents:
49598
diff
changeset
|
146 (while (and |
28bd29f9f91c
(kinsoku-longer, kinsoku-shorter): Do not choose a
Kenichi Handa <handa@m17n.org>
parents:
49598
diff
changeset
|
147 (< linebeg (point)) |
28bd29f9f91c
(kinsoku-longer, kinsoku-shorter): Do not choose a
Kenichi Handa <handa@m17n.org>
parents:
49598
diff
changeset
|
148 (or (aref (char-category-set (preceding-char)) ?<) |
28bd29f9f91c
(kinsoku-longer, kinsoku-shorter): Do not choose a
Kenichi Handa <handa@m17n.org>
parents:
49598
diff
changeset
|
149 (aref (char-category-set (following-char)) ?>) |
28bd29f9f91c
(kinsoku-longer, kinsoku-shorter): Do not choose a
Kenichi Handa <handa@m17n.org>
parents:
49598
diff
changeset
|
150 ;; protect non-kinsoku words |
28bd29f9f91c
(kinsoku-longer, kinsoku-shorter): Do not choose a
Kenichi Handa <handa@m17n.org>
parents:
49598
diff
changeset
|
151 (not (or (eq (preceding-char) ? ) |
28bd29f9f91c
(kinsoku-longer, kinsoku-shorter): Do not choose a
Kenichi Handa <handa@m17n.org>
parents:
49598
diff
changeset
|
152 (aref (char-category-set (preceding-char)) |
28bd29f9f91c
(kinsoku-longer, kinsoku-shorter): Do not choose a
Kenichi Handa <handa@m17n.org>
parents:
49598
diff
changeset
|
153 ?|))))) |
17052 | 154 (forward-char -1)) |
155 (point)))) | |
156 (if (< linebeg pos) | |
157 (goto-char pos)))) | |
158 | |
159 ;;;###autoload | |
160 (defun kinsoku (linebeg) | |
161 "Go to a line breaking position near point by doing `kinsoku' processing. | |
162 LINEBEG is a buffer position we can't break a line before. | |
163 | |
164 `Kinsoku' processing is to prohibit specific characters to be placed | |
165 at beginning of line or at end of line. Characters not to be placed | |
166 at beginning and end of line have character category `>' and `<' | |
167 respectively. This restriction is dissolved by making a line longer or | |
168 shorter. | |
169 | |
170 `Kinsoku' is a Japanese word which originally means ordering to stay | |
171 in one place, and is used for the text processing described above in | |
172 the context of text formatting." | |
23492
dc49b662b956
(kinsoku): Check the variable enable-kinsoku.
Kenichi Handa <handa@m17n.org>
parents:
23431
diff
changeset
|
173 (if enable-kinsoku |
dc49b662b956
(kinsoku): Check the variable enable-kinsoku.
Kenichi Handa <handa@m17n.org>
parents:
23431
diff
changeset
|
174 (if (or (and |
dc49b662b956
(kinsoku): Check the variable enable-kinsoku.
Kenichi Handa <handa@m17n.org>
parents:
23431
diff
changeset
|
175 ;; The character after point can't be placed at beginning |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38414
diff
changeset
|
176 ;; of line. |
23492
dc49b662b956
(kinsoku): Check the variable enable-kinsoku.
Kenichi Handa <handa@m17n.org>
parents:
23431
diff
changeset
|
177 (aref (char-category-set (following-char)) ?>) |
dc49b662b956
(kinsoku): Check the variable enable-kinsoku.
Kenichi Handa <handa@m17n.org>
parents:
23431
diff
changeset
|
178 ;; We at first try to dissolve this situation by making a |
dc49b662b956
(kinsoku): Check the variable enable-kinsoku.
Kenichi Handa <handa@m17n.org>
parents:
23431
diff
changeset
|
179 ;; line longer. If it fails, then try making a line |
dc49b662b956
(kinsoku): Check the variable enable-kinsoku.
Kenichi Handa <handa@m17n.org>
parents:
23431
diff
changeset
|
180 ;; shorter. |
dc49b662b956
(kinsoku): Check the variable enable-kinsoku.
Kenichi Handa <handa@m17n.org>
parents:
23431
diff
changeset
|
181 (not (kinsoku-longer))) |
dc49b662b956
(kinsoku): Check the variable enable-kinsoku.
Kenichi Handa <handa@m17n.org>
parents:
23431
diff
changeset
|
182 ;; The character before point can't be placed at end of line. |
dc49b662b956
(kinsoku): Check the variable enable-kinsoku.
Kenichi Handa <handa@m17n.org>
parents:
23431
diff
changeset
|
183 (aref (char-category-set (preceding-char)) ?<)) |
dc49b662b956
(kinsoku): Check the variable enable-kinsoku.
Kenichi Handa <handa@m17n.org>
parents:
23431
diff
changeset
|
184 (kinsoku-shorter linebeg)))) |
17052 | 185 |
52401 | 186 ;;; arch-tag: e6b036bc-9e5b-4e9f-a22c-4ed04e37777e |
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
23492
diff
changeset
|
187 ;;; kinsoku.el ends here |