-
Notifications
You must be signed in to change notification settings - Fork 2
/
skk-inline.el
197 lines (180 loc) · 6.73 KB
/
skk-inline.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
;;; skk-inline.el --- Inline candidate display support for SKK -*- coding: iso-2022-jp -*-
;; Copyright (C) 2005 Masatake YAMATO <jet@gyve.org>
;; Copyright (C) 2007 IRIE Tetsuya <irie@t.email.ne.jp>
;; Maintainer: SKK Development Team <skk@ring.gr.jp>
;; Keywords: japanese, mule, input method
;; This file is part of Daredevil SKK.
;; Daredevil SKK is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2, or
;; (at your option) any later version.
;; Daredevil SKK is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with Daredevil SKK, see the file COPYING. If not, write to
;; the Free Software Foundation Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;; Commentary:
;;; Code:
(eval-when-compile
(require 'cl)
(require 'skk-vars)
(require 'skk-macs))
;; Functions.
(defun skk-add-background-color (string color)
"STRING $B$N$&$AGX7J?'$,;XDj$5$l$F$$$J$$J8;z$K8B$C$F(B COLOR $B$NGX7J?'$r(B
$BE,MQ$9$k!#(B"
(when (eval-when-compile (featurep 'emacs))
(when (and string
color
(color-defined-p color))
(let ((start 0)
(end 1)
(len (length string))
orig-face)
(while (< start len)
(setq orig-face (get-text-property start 'face string))
(while (and (< end len)
(eq orig-face (get-text-property end 'face string)))
(incf end))
(cond ((not orig-face)
(put-text-property start end 'face
`(:background ,color)
string))
;;
((and (facep orig-face)
(not (face-background orig-face)))
(put-text-property start end 'face
`(:inherit ,orig-face :background ,color)
string))
;;
((and (listp orig-face)
(not (plist-get (get-text-property start 'face string)
:background))
(not (and (plist-get (get-text-property start 'face start)
:inherit)
(face-background
(plist-get (get-text-property start 'face start)
:inherit)))))
(put-text-property start end 'face
(cons `(:background ,color)
orig-face)
string)))
(setq start (max (1+ start) end)
end (1+ start)))))
string))
;;;###autoload
(defun skk-inline-show (str face &optional vertical-str text-max-height)
(skk-delete-overlay skk-inline-overlays)
(if (and (eq 'vertical skk-show-inline)
;; window $B$,8uJd72$rI=<($G$-$k9b$5$,$"$k$+%A%'%C%/(B
(stringp vertical-str)
(integerp text-max-height)
(< (1+ text-max-height) (skk-window-body-height)))
(skk-inline-show-vertically vertical-str face)
(skk-inline-show-horizontally str face)))
(defun skk-inline-show-horizontally (string face)
(unless (skk-in-minibuffer-p)
(let ((ol (make-overlay (point) (point)))
(base-ol (make-overlay (point) (1+ (point)))))
(overlay-put base-ol 'face 'default)
(push base-ol skk-inline-overlays)
(push ol skk-inline-overlays)
(when face
(setq string (propertize string 'face face)))
(when skk-inline-show-background-color
(setq string (skk-add-background-color
string skk-inline-show-background-color)))
(overlay-put ol 'after-string string))))
(defun skk-inline-show-vertically (string face)
(unless (skk-in-minibuffer-p)
(let* ((margin 2)
;; XXX beg-col $B$,(B -1 $B$K$J$C$F(B `make-string' $B$G%(%i!<$K$J$k(B
;; $B>l9g$"$j(B ?
(beg-col (max 0 (- (skk-screen-column) margin)))
(candidates (split-string string "\n"))
(max-width (skk-max-string-width candidates))
(i 0)
bottom col ol invisible)
(dolist (str candidates)
(setq str (concat (when (/= 0 i) (make-string margin ? ))
str
(make-string (+ (- max-width (string-width str))
margin)
? )))
(when face
(setq str (propertize str 'face face)))
(when skk-inline-show-background-color
(setq str (skk-add-background-color str
skk-inline-show-background-color)))
(save-excursion
(scroll-left (max 0
(- (+ beg-col margin max-width margin 1)
(window-width) (window-hscroll))))
(unless (zerop (window-hscroll))
(setq beg-col
(save-excursion (goto-char skk-henkan-start-point)
(- (current-column) margin))))
(case i
(0
(setq col (skk-screen-column)))
(t
(setq bottom (> i (vertical-motion i)))
(cond
(bottom
;; $B%P%C%U%!:G=*9T$G$OIaDL$K(B overlay $B$rDI2C$7$F$$$/J}K!$@(B
;; $B$H(B overlay $B$NI=<($5$l$k=gHV$,68$&$3$H$,$"$C$F$&$^$/$J(B
;; $B$$!#$7$?$,$C$FA02s$N(B overlay $B$N(B after-string $B$KDI2C$9(B
;; $B$k!#(B
(setq ol (cond ((< (overlay-end
(car skk-inline-overlays))
(point))
(make-overlay (point) (point)))
(t (pop skk-inline-overlays))))
(setq str (concat (overlay-get ol 'after-string)
"\n" (make-string beg-col ? ) str)))
(t
(setq col (skk-move-to-screen-column beg-col))
(cond ((> beg-col col)
;; $B7e9g$o$;$N6uGr$rDI2C(B
(setq str (concat (make-string (- beg-col col) ? )
str)))
;; overlay $B$N:8C<$,%^%k%AI}J8;z$H=E$J$C$?$H$-$NHyD4@0(B
((< beg-col col)
(backward-char)
(setq col (skk-screen-column))
(setq str (concat (make-string (- beg-col col) ? )
str))))))))
;; $B$3$N;~E@$G(B overlay $B$N3+;O0LCV$K(B point $B$,$"$k(B
(unless bottom
(let ((ol-beg (point))
(ol-end-col (+ col (string-width str)))
base-ol)
(setq col (skk-move-to-screen-column ol-end-col))
;; overlay $B$N1&C<$,%^%k%AI}J8;z$H=E$J$C$?$H$-$NHyD4@0(B
(when (< ol-end-col col)
(setq str (concat str
(make-string (- col ol-end-col) ? ))))
(setq ol (make-overlay ol-beg (point)))
;; $B85%F%-%9%H$N(B face $B$r7Q>5$7$J$$$h$&$K(B1$B$D8e$m$K(B overlay
;; $B$r:n$C$F!"$=$N(B face $B$r(B 'default $B$K;XDj$7$F$*$/(B
(setq base-ol (make-overlay (point) (1+ (point))))
(overlay-put base-ol 'face 'default)
(push base-ol skk-inline-overlays)
;; $B8uJd$,2D;k$+$I$&$+%A%'%C%/(B
(unless (pos-visible-in-window-p (point))
(setq invisible t)))))
(overlay-put ol 'invisible t)
(overlay-put ol 'after-string str)
(push ol skk-inline-overlays)
(incf i))
(when (or invisible
(and bottom
(> (1+ (* 7 skk-henkan-show-candidates-rows))
(- (skk-window-body-height)
(count-screen-lines (window-start) (point))))))
(recenter (- (1+ (* 7 skk-henkan-show-candidates-rows))))))))
(provide 'skk-inline)
;;; skk-inline.el ends here