1 ;;; kinsoku.el --- `Kinsoku' processing funcs -*- coding: iso-2022-7bit; -*-
3 ;; Copyright (C) 1997, 2001, 2002, 2003, 2004, 2005, 2006, 2007
4 ;; Free Software Foundation, Inc.
5 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
7 ;; National Institute of Advanced Industrial Science and Technology (AIST)
8 ;; Registration Number H14PRO021
10 ;; Keywords: mule, kinsoku
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 2, or (at your option)
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27 ;; Boston, MA 02110-1301, USA.
31 ;; `Kinsoku' processing is to prohibit specific characters to be
32 ;; placed at beginning of line or at end of line. Characters not to
33 ;; be placed at beginning and end of line have character category `>'
34 ;; and `<' respectively. This restriction is dissolved by making a
35 ;; line longer or shorter.
37 ;; `Kinsoku' is a Japanese word which originally means ordering to
38 ;; stay in one place, and is used for the text processing described
39 ;; above in the context of text formatting.
43 (defvar kinsoku-limit
4
44 "How many more columns we can make lines longer by `kinsoku' processing.
45 The value 0 means there's no limitation.")
47 ;; Setting character category `>' for characters which should not be
48 ;; placed at beginning of line.
54 ;; Instead of putting Latin JISX0201 string directly, we
55 ;; generate the string as below to avoid character
56 ;; unification problem.
57 (let* ((str1 "!)-_~}]:;',.?")
63 (setq ch
(make-char 'latin-jisx0201
(aref str1 idx
))
64 str2
(concat str2
(char-to-string ch
))
68 "\e(I!#'()*+,-./0^_\e(B"
70 "\e$B!"!#!$
!%
!&!'!(!)!*!+!,!-
!.
!/!0!1!2!3!4!5!6!7!8!9!:!;!<!=!>\e(B\
71 \e$B
!?
!@!A
!B
!C
!D
!E
!G
!I
!K
!M
!O
!Q
!S
!U
!W
!Y
![!k
!l
!m
!n
\e(B\
72 \e$B$
!$
#$%$
'$
)$C$c$e$g$n%
!%
#%%%
'%
)%C%c%e%g%n%u%v
\e(B"
74 "\e$A
!"!##.#,!$!%!&!'!(!)!*!+!,!-!/!1#)!3!5!7!9!;!=\e(B\
75 \e$A!?#;#:#?#!!@!A!B!C!c!d!e!f#/#\#"#_
#~
#|
(e\e(B"
77 "\e$
(0!"!#!$!%!&!'!(!)!*!+!,!-!.!/!0!1!2\e(B\
78 \e$(0!3!4!5!6!7!8!9!:!;!<!=!?!A!C!E!G!I!K\e(B\
79 \e$(0!M!O!Q!S!U!W!Y![!]!_!a!c!e!g!i!k!q\e(B\
80 \e$(0"#"$"%
"&"'"(")"*"+","2"3"4"j"k
"l"x%
7\e(B"))
81 (len (length kinsoku-bol))
85 (setq ch (aref kinsoku-bol idx)
87 (modify-category-entry ch ?>)))
89 ;; Setting character category `<' for characters which should not be
90 ;; placed at end of line.
96 ;; See the comment above.
103 (setq ch (make-char 'latin-jisx0201 (aref str1 idx))
104 str2 (concat str2 (char-to-string ch))
110 "\e$B!F!H!J!L!N!P!R!T!V!X!Z!k!l!m!n!w!x\e(B\
111 \e$A!.!0#"#(!2!4!6!8!:!<!>!c
!d
!e
#@!f
!l
\e(B"
113 "\e$A
(E(F(G(H(I(J(K(L(M(N(O(P(Q(R(S(T(U(V(W(X(Y(h\e(B\
114 \
\e$
(0!>!@!B
!D
!F
!H
!J
!L
!N
!P
!R
!T
!V
!X
!Z
!\
!^
!`!b
\e(B"
116 "\e$
(0!d
!f
!h
!j
!k
!q
!p
"i"j
"k"n
"x$u$v$w$x$y$z${\e(B\
117 \e$(0$|$}$~%!%"%
#%$%%%
&%
'%
(%
)%
*%
+%
:\e(B"))
118 (len (length kinsoku-eol))
122 (setq ch (aref kinsoku-eol idx)
124 (modify-category-entry ch ?<)))
126 ;; Try to resolve `kinsoku' restriction by making the current line longer.
127 (defun kinsoku-longer ()
128 (let ((pos-and-column
131 (while (and (not (eolp))
132 (or (aref (char-category-set (following-char)) ?>)
133 ;; protect non-kinsoku words
134 (not (or (eq (preceding-char) ? )
135 (aref (char-category-set (preceding-char))
138 (cons (point) (current-column)))))
139 (if (or (<= kinsoku-limit 0)
140 (< (cdr pos-and-column) (+ (current-fill-column) kinsoku-limit)))
141 (goto-char (car pos-and-column)))))
143 ;; Try to resolve `kinsoku' restriction by making the current line shorter.
144 ;; The line can't be broken before the buffer position LINEBEG.
145 (defun kinsoku-shorter (linebeg)
146 (let ((pos (save-excursion
150 (or (aref (char-category-set (preceding-char)) ?<)
151 (aref (char-category-set (following-char)) ?>)
152 ;; protect non-kinsoku words
153 (not (or (eq (preceding-char) ? )
154 (aref (char-category-set (preceding-char))
162 (defun kinsoku (linebeg)
163 "Go to a line breaking position near point by doing
`kinsoku
' processing.
164 LINEBEG is a buffer position we can
't break a line before.
166 `Kinsoku
' processing is to prohibit specific characters to be placed
167 at beginning of line or at end of line. Characters not to be placed
168 at beginning and end of line have character category
`>' and
`<'
169 respectively. This restriction is dissolved by making a line longer or
172 `Kinsoku
' is a Japanese word which originally means ordering to stay
173 in one place
, and is used for the text processing described above in
174 the context of text formatting.
"
177 ;; The character after point can't be placed at beginning
179 (aref (char-category-set (following-char)) ?>)
180 ;; We at first try to dissolve this situation by making a
181 ;; line longer. If it fails, then try making a line
183 (not (kinsoku-longer)))
184 ;; The character before point can't be placed at end of line.
185 (aref (char-category-set (preceding-char)) ?<))
186 (kinsoku-shorter linebeg))))
188 ;;; arch-tag: e6b036bc-9e5b-4e9f-a22c-4ed04e37777e
189 ;;; kinsoku.el ends here