1 ;;; kinsoku.el --- `Kinsoku' processing funcs -*- coding: iso-2022-7bit; -*-
3 ;; Copyright (C) 1997, 2001-2012 Free Software Foundation, Inc.
4 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
5 ;; 2005, 2006, 2007, 2008, 2009, 2010, 2011
6 ;; National Institute of Advanced Industrial Science and Technology (AIST)
7 ;; Registration Number H14PRO021
9 ;; Keywords: mule, kinsoku
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
28 ;; `Kinsoku' processing is to prohibit specific characters to be
29 ;; placed at beginning of line or at end of line. Characters not to
30 ;; be placed at beginning and end of line have character category `>'
31 ;; and `<' respectively. This restriction is dissolved by making a
32 ;; line longer or shorter.
34 ;; `Kinsoku' is a Japanese word which originally means ordering to
35 ;; stay in one place, and is used for the text processing described
36 ;; above in the context of text formatting.
40 (defvar kinsoku-limit
4
41 "How many more columns we can make lines longer by `kinsoku' processing.
42 The value 0 means there's no limitation.")
44 ;; Setting character category `>' for characters which should not be
45 ;; placed at beginning of line.
51 ;; Instead of putting Latin JISX0201 string directly, we
52 ;; generate the string as below to avoid character
53 ;; unification problem.
54 (let* ((str1 "!)-_~}]:;',.?")
60 (setq ch
(make-char 'latin-jisx0201
(aref str1 idx
))
61 str2
(concat str2
(char-to-string ch
))
65 "\e(I!#'()*+,-./0^_\e(B"
67 "\e$B!"!#!$
!%
!&!'!(!)!*!+!,!-
!.
!/!0!1!2!3!4!5!6!7!8!9!:!;!<!=!>\e(B\
68 \e$B
!?
!@!A
!B
!C
!D
!E
!G
!I
!K
!M
!O
!Q
!S
!U
!W
!Y
![!k
!l
!m
!n
\e(B\
69 \e$B$
!$
#$%$
'$
)$C$c$e$g$n%
!%
#%%%
'%
)%C%c%e%g%n%u%v
\e(B"
71 "\e$A
!"!##.#,!$!%!&!'!(!)!*!+!,!-!/!1#)!3!5!7!9!;!=\e(B\
72 \e$A!?#;#:#?#!!@!A!B!C!c!d!e!f#/#\#"#_
#~
#|
(e\e(B"
74 "\e$
(0!"!#!$!%!&!'!(!)!*!+!,!-!.!/!0!1!2\e(B\
75 \e$(0!3!4!5!6!7!8!9!:!;!<!=!?!A!C!E!G!I!K\e(B\
76 \e$(0!M!O!Q!S!U!W!Y![!]!_!a!c!e!g!i!k!q\e(B\
77 \e$(0"#"$"%
"&"'"(")"*"+","2"3"4"j"k
"l"x%
7\e(B"))
78 (len (length kinsoku-bol))
82 (setq ch (aref kinsoku-bol idx)
84 (modify-category-entry ch ?>)))
86 ;; Setting character category `<' for characters which should not be
87 ;; placed at end of line.
93 ;; See the comment above.
100 (setq ch (make-char 'latin-jisx0201 (aref str1 idx))
101 str2 (concat str2 (char-to-string ch))
107 "\e$B!F!H!J!L!N!P!R!T!V!X!Z!k!l!m!n!w!x\e(B\
108 \e$A!.!0#"#(!2!4!6!8!:!<!>!c
!d
!e
#@!f
!l
\e(B"
110 "\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\
111 \
\e$
(0!>!@!B
!D
!F
!H
!J
!L
!N
!P
!R
!T
!V
!X
!Z
!\
!^
!`!b
\e(B"
113 "\e$
(0!d
!f
!h
!j
!k
!q
!p
"i"j
"k"n
"x$u$v$w$x$y$z${\e(B\
114 \e$(0$|$}$~%!%"%
#%$%%%
&%
'%
(%
)%
*%
+%
:\e(B"))
115 (len (length kinsoku-eol))
119 (setq ch (aref kinsoku-eol idx)
121 (modify-category-entry ch ?<)))
123 ;; Try to resolve `kinsoku' restriction by making the current line longer.
124 (defun kinsoku-longer ()
125 (let ((pos-and-column
128 (while (and (not (eolp))
129 (or (aref (char-category-set (following-char)) ?>)
130 ;; protect non-kinsoku words
131 (not (or (eq (preceding-char) ? )
132 (aref (char-category-set (preceding-char))
135 (cons (point) (current-column)))))
136 (if (or (<= kinsoku-limit 0)
137 (< (cdr pos-and-column) (+ (current-fill-column) kinsoku-limit)))
138 (goto-char (car pos-and-column)))))
140 ;; Try to resolve `kinsoku' restriction by making the current line shorter.
141 ;; The line can't be broken before the buffer position LINEBEG.
142 (defun kinsoku-shorter (linebeg)
143 (let ((pos (save-excursion
147 (or (aref (char-category-set (preceding-char)) ?<)
148 (aref (char-category-set (following-char)) ?>)
149 ;; protect non-kinsoku words
150 (not (or (eq (preceding-char) ? )
151 (aref (char-category-set (preceding-char))
159 (defun kinsoku (linebeg)
160 "Go to a line breaking position near point by doing
`kinsoku
' processing.
161 LINEBEG is a buffer position we can
't break a line before.
163 `Kinsoku
' processing is to prohibit specific characters to be placed
164 at beginning of line or at end of line. Characters not to be placed
165 at beginning and end of line have character category
`>' and
`<'
166 respectively. This restriction is dissolved by making a line longer or
169 `Kinsoku
' is a Japanese word which originally means ordering to stay
170 in one place
, and is used for the text processing described above in
171 the context of text formatting.
"
174 ;; The character after point can't be placed at beginning
176 (aref (char-category-set (following-char)) ?>)
177 ;; We at first try to dissolve this situation by making a
178 ;; line longer. If it fails, then try making a line
180 (not (kinsoku-longer)))
181 ;; The character before point can't be placed at end of line.
182 (aref (char-category-set (preceding-char)) ?<))
183 (kinsoku-shorter linebeg))))
185 ;;; kinsoku.el ends here