1 ;;; kinsoku.el --- `Kinsoku' processing funcs -*- coding: iso-2022-7bit; -*-
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
8 ;; Keywords: mule, kinsoku
10 ;; This file is part of GNU Emacs.
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)
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.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
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.
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.
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.")
45 ;; Setting character category `>' for characters which should not be
46 ;; placed at beginning of line.
52 ;; Instead of putting Latin JISX0201 string directly, we
53 ;; generate the string as below to avoid character
54 ;; unification problem.
55 (let* ((str1 "!)-_~}]:;',.?")
61 (setq ch
(make-char 'latin-jisx0201
(aref str1 idx
))
62 str2
(concat str2
(char-to-string ch
))
66 "\e(I!#'()*+,-./0^_\e(B"
68 "\e$B!"!#!$
!%
!&!'!(!)!*!+!,!-
!.
!/!0!1!2!3!4!5!6!7!8!9!:!;!<!=!>\e(B\
69 \e$B
!?
!@!A
!B
!C
!D
!E
!G
!I
!K
!M
!O
!Q
!S
!U
!W
!Y
![!k
!l
!m
!n
\e(B\
70 \e$B$
!$
#$%$
'$
)$C$c$e$g$n%
!%
#%%%
'%
)%C%c%e%g%n%u%v
\e(B"
72 "\e$A
!"!##.#,!$!%!&!'!(!)!*!+!,!-!/!1#)!3!5!7!9!;!=\e(B\
73 \e$A!?#;#:#?#!!@!A!B!C!c!d!e!f#/#\#"#_
#~
#|
(e\e(B"
75 "\e$
(0!"!#!$!%!&!'!(!)!*!+!,!-!.!/!0!1!2\e(B\
76 \e$(0!3!4!5!6!7!8!9!:!;!<!=!?!A!C!E!G!I!K\e(B\
77 \e$(0!M!O!Q!S!U!W!Y![!]!_!a!c!e!g!i!k!q\e(B\
78 \e$(0"#"$"%
"&"'"(")"*"+","2"3"4"j"k
"l"x%
7\e(B"))
79 (len (length kinsoku-bol))
83 (setq ch (aref kinsoku-bol idx)
85 (modify-category-entry ch ?>)))
87 ;; Setting character category `<' for characters which should not be
88 ;; placed at end of line.
94 ;; See the comment above.
101 (setq ch (make-char 'latin-jisx0201 (aref str1 idx))
102 str2 (concat str2 (char-to-string ch))
108 "\e$B!F!H!J!L!N!P!R!T!V!X!Z!k!l!m!n!w!x\e(B\
109 \e$A!.!0#"#(!2!4!6!8!:!<!>!c
!d
!e
#@!f
!l
\e(B"
111 "\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\
112 \e$
(0!>!@!B
!D
!F
!H
!J
!L
!N
!P
!R
!T
!V
!X
!Z
!\
!^
!`!b
\e(B"
114 "\e$
(0!d
!f
!h
!j
!k
!q
!p
"i"j
"k"n
"x$u$v$w$x$y$z${\e(B\
115 \e$(0$|$}$~%!%"%
#%$%%%
&%
'%
(%
)%
*%
+%
:\e(B"))
116 (len (length kinsoku-eol))
120 (setq ch (aref kinsoku-eol idx)
122 (modify-category-entry ch ?<)))
124 ;; Try to resolve `kinsoku' restriction by making the current line longer.
125 (defun kinsoku-longer ()
126 (let ((pos-and-column
129 (while (and (not (eobp))
130 (or (aref (char-category-set (following-char)) ?>)
131 ;; protect non-kinsoku words
132 (not (or (eq (preceding-char) ? )
133 (aref (char-category-set (preceding-char))
136 (cons (point) (current-column)))))
137 (if (or (<= kinsoku-limit 0)
138 (< (cdr pos-and-column) (+ (current-fill-column) kinsoku-limit)))
139 (goto-char (car pos-and-column)))))
141 ;; Try to resolve `kinsoku' restriction by making the current line shorter.
142 ;; The line can't be broken before the buffer position LINEBEG.
143 (defun kinsoku-shorter (linebeg)
144 (let ((pos (save-excursion
148 (or (aref (char-category-set (preceding-char)) ?<)
149 (aref (char-category-set (following-char)) ?>)
150 ;; protect non-kinsoku words
151 (not (or (eq (preceding-char) ? )
152 (aref (char-category-set (preceding-char))
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.
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
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.
"
175 ;; The character after point can't be placed at beginning
177 (aref (char-category-set (following-char)) ?>)
178 ;; We at first try to dissolve this situation by making a
179 ;; line longer. If it fails, then try making a line
181 (not (kinsoku-longer)))
182 ;; The character before point can't be placed at end of line.
183 (aref (char-category-set (preceding-char)) ?<))
184 (kinsoku-shorter linebeg))))
186 ;;; arch-tag: e6b036bc-9e5b-4e9f-a22c-4ed04e37777e
187 ;;; kinsoku.el ends here