annotate lisp/international/kinsoku.el @ 108351:b9c7f875c4e8

* info.el (Info-fontify-node): Put Info-breadcrumbs to the `display' property instead of `invisible' and `after-string' (bug#5998).
author Juri Linkov <juri@jurta.org>
date Fri, 23 Apr 2010 19:46:03 +0300
parents 1d1d5d9bd884
children 376148b31b5e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2
106815
1d1d5d9bd884 Add 2010 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
3 ;; Copyright (C) 1997, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
74544
43cc94d955c2 Update copyright years.
Glenn Morris <rgm@gnu.org>
parents: 67333
diff changeset
4 ;; Free Software Foundation, Inc.
74605
6ee41fdd69ff Update AIST copyright years.
Kenichi Handa <handa@m17n.org>
parents: 74544
diff changeset
5 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
106815
1d1d5d9bd884 Add 2010 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
6 ;; 2005, 2006, 2007, 2008, 2009, 2010
62274
c36561fe0657 Fix copyrights.
Kenichi Handa <handa@m17n.org>
parents: 52401
diff changeset
7 ;; National Institute of Advanced Industrial Science and Technology (AIST)
c36561fe0657 Fix copyrights.
Kenichi Handa <handa@m17n.org>
parents: 52401
diff changeset
8 ;; Registration Number H14PRO021
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
9
18377
8b4a66c66dd6 Change copyright notice.
Richard M. Stallman <rms@gnu.org>
parents: 17759
diff changeset
10 ;; Keywords: mule, kinsoku
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
11
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
12 ;; This file is part of GNU Emacs.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
13
94664
889bc336b89b Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
14 ;; GNU Emacs is free software: you can redistribute it and/or modify
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
15 ;; it under the terms of the GNU General Public License as published by
94664
889bc336b89b Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
16 ;; the Free Software Foundation, either version 3 of the License, or
889bc336b89b Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
17 ;; (at your option) any later version.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
18
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
19 ;; GNU Emacs is distributed in the hope that it will be useful,
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
22 ;; GNU General Public License for more details.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
23
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
24 ;; You should have received a copy of the GNU General Public License
94664
889bc336b89b Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
25 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
26
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
27 ;;; Commentary:
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
28
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
29 ;; `Kinsoku' processing is to prohibit specific characters to be
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
30 ;; placed at beginning of line or at end of line. Characters not to
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
31 ;; be placed at beginning and end of line have character category `>'
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
32 ;; and `<' respectively. This restriction is dissolved by making a
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
33 ;; line longer or shorter.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
34 ;;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
35 ;; `Kinsoku' is a Japanese word which originally means ordering to
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
36 ;; stay in one place, and is used for the text processing described
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
37 ;; above in the context of text formatting.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
38
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
39 ;;; Code:
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
40
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
41 (defvar kinsoku-limit 4
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
42 "How many more columns we can make lines longer by `kinsoku' processing.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
43 The value 0 means there's no limitation.")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
44
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
45 ;; Setting character category `>' for characters which should not be
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
46 ;; placed at beginning of line.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
47 (let* ((kinsoku-bol
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
48 (concat
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
49 ;; ASCII
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
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
30beacf88b75 Doc fixes.
Karl Heuer <kwzh@gnu.org>
parents: 20843
diff changeset
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
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
67 ;; Japanese JISX0208
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
68 "$B!"!#!$!%!&!'!(!)!*!+!,!-!.!/!0!1!2!3!4!5!6!7!8!9!:!;!<!=!>(B\
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
69 $B!?!@!A!B!C!D!E!G!I!K!M!O!Q!S!U!W!Y![!k!l!m!n(B\
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
70 $B$!$#$%$'$)$C$c$e$g$n%!%#%%%'%)%C%c%e%g%n%u%v(B"
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
71 ;; Chinese GB2312
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
72 "$A!"!##.#,!$!%!&!'!(!)!*!+!,!-!/!1#)!3!5!7!9!;!=(B\
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
73 $A!?#;#:#?#!!@!A!B!C!c!d!e!f#/#\#"#_#~#|(e(B"
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
74 ;; Chinese BIG5
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
75 "$(0!"!#!$!%!&!'!(!)!*!+!,!-!.!/!0!1!2(B\
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
76 $(0!3!4!5!6!7!8!9!:!;!<!=!?!A!C!E!G!I!K(B\
23431
9aad69351f7b Add coding tag.
Kenichi Handa <handa@m17n.org>
parents: 23196
diff changeset
77 $(0!M!O!Q!S!U!W!Y![!]!_!a!c!e!g!i!k!q(B\
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
78 $(0"#"$"%"&"'"(")"*"+","2"3"4"j"k"l"x%7(B"))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
79 (len (length kinsoku-bol))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
80 (idx 0)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
81 ch)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
82 (while (< idx len)
20843
b60871b4710f Use aref instead of sref.
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
83 (setq ch (aref kinsoku-bol idx)
b60871b4710f Use aref instead of sref.
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
84 idx (1+ idx))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
85 (modify-category-entry ch ?>)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
86
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
87 ;; Setting character category `<' for characters which should not be
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
88 ;; placed at end of line.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
89 (let* ((kinsoku-eol
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
90 (concat
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
91 ;; ASCII
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
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
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
107 ;; Japanese JISX0208
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
108 "$B!F!H!J!L!N!P!R!T!V!X!Z!k!l!m!n!w!x(B\
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
109 $A!.!0#"#(!2!4!6!8!:!<!>!c!d!e#@!f!l(B"
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
110 ;; Chinese GB2312
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
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
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
113 ;; Chinese BIG5
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
114 "$(0!d!f!h!j!k!q!p"i"j"k"n"x$u$v$w$x$y$z${(B\
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
115 $(0$|$}$~%!%"%#%$%%%&%'%(%)%*%+%:(B"))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
116 (len (length kinsoku-eol))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
117 (idx 0)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
118 ch)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
119 (while (< idx len)
20843
b60871b4710f Use aref instead of sref.
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
120 (setq ch (aref kinsoku-eol idx)
b60871b4710f Use aref instead of sref.
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
121 idx (1+ idx))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
122 (modify-category-entry ch ?<)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
123
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
124 ;; Try to resolve `kinsoku' restriction by making the current line longer.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
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
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
137 (if (or (<= kinsoku-limit 0)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
138 (< (cdr pos-and-column) (+ (current-fill-column) kinsoku-limit)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
139 (goto-char (car pos-and-column)))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
140
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
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
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
143 (defun kinsoku-shorter (linebeg)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
144 (let ((pos (save-excursion
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
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
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
154 (forward-char -1))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
155 (point))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
156 (if (< linebeg pos)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
157 (goto-char pos))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
158
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
159 ;;;###autoload
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
160 (defun kinsoku (linebeg)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
161 "Go to a line breaking position near point by doing `kinsoku' processing.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
162 LINEBEG is a buffer position we can't break a line before.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
163
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
164 `Kinsoku' processing is to prohibit specific characters to be placed
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
165 at beginning of line or at end of line. Characters not to be placed
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
166 at beginning and end of line have character category `>' and `<'
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
167 respectively. This restriction is dissolved by making a line longer or
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
168 shorter.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
169
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
170 `Kinsoku' is a Japanese word which originally means ordering to stay
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
171 in one place, and is used for the text processing described above in
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
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
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
185
93975
1e3a407766b9 Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 79709
diff changeset
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