File: skk-show-mode.el

package info (click to toggle)
ddskk 16.2-7
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 4,116 kB
  • sloc: lisp: 34,708; ruby: 476; makefile: 187; awk: 178; sql: 142; sh: 115
file content (182 lines) | stat: -rw-r--r-- 6,519 bytes parent folder | download | duplicates (2)
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
;;; skk-show-mode.el --- $B%b!<%I@ZBX;~$K(B tooltip/inline $BI=<($9$k(B -*- coding: iso-2022-jp -*-

;; Copyright (C) 2011 Tsuyoshi Kitamoto  <tsuyoshi.kitamoto@gmail.com>

;; Author: 2011 Tsuyoshi Kitamoto  <tsuyoshi.kitamoto@gmail.com>
;; 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:
;; 
;;  ~/.skk $B$K$F(B
;;      (setq skk-show-mode-show t)
;;  $B$H@_Dj$7$F$/$@$5$$!#(B
;;  Emacs $B5/F0Cf$O(B M-x skk-show-mode $B$G%H%0%k$9$k$3$H$,$G$-$^$9!#(B

;;  $BJQ?t(B skk-show-mode-style $B$K(B 'tooltip $BKt$O(B 'inline $B$r@_Dj$7$F$/$@$5$$!#(B

;;; Code:

(eval-when-compile
  (require 'skk-vars))

(defadvice skk-isearch-set-initial-mode (before skk-show-mode activate)
  (setq skk-show-mode-show nil))

(defadvice skk-isearch-initialize-working-buffer (before skk-show-mode activate)
  (setq skk-show-mode-show nil))

(defadvice skk-cursor-set (after skk-show-mode activate)
  "$B$+$J%b!<%I$d%"%9%-!<%b!<%I$X@Z$jBX$o$C$?$H$-$K(B skk-*-mode-string $B$r(B
tooltip / inline $BI=<($9$k(B."
  (when (and skk-show-mode-invoked
	     skk-show-mode-show
	     (not skk-isearch-switch))
    (let ((func (cdr (assq skk-show-mode-style skk-show-mode-functions))))
      (when func
	(funcall func))))
  (setq skk-show-mode-invoked t))

(defun skk-show-mode-inline ()
  (let ((skk-henkan-start-point (point))
	string)
    (unless (skk-in-minibuffer-p)
      (cond
       (skk-abbrev-mode
	(setq string skk-abbrev-mode-string)
	(set-face-foreground 'skk-show-mode-inline-face skk-cursor-abbrev-color))
       (skk-jisx0208-latin-mode
	(setq string skk-jisx0208-latin-mode-string)
	(set-face-foreground 'skk-show-mode-inline-face skk-cursor-jisx0208-latin-color))
       (skk-katakana
	(setq string skk-katakana-mode-string)
	(set-face-foreground 'skk-show-mode-inline-face skk-cursor-katakana-color))
       (skk-j-mode
	(setq string skk-hiragana-mode-string)
	(set-face-foreground 'skk-show-mode-inline-face skk-cursor-hiragana-color))
       (skk-jisx0201-mode
	(setq string skk-jisx0201-mode-string)
	(set-face-foreground 'skk-show-mode-inline-face skk-cursor-jisx0201-color))
       (t
	(setq string skk-latin-mode-string)
	(set-face-foreground 'skk-show-mode-inline-face skk-cursor-latin-color)))
      ;;
      (skk-show-mode-inline-1 string)))

  (sit-for 0.5)
  (skk-delete-overlay skk-show-mode-inline-overlays))

(defun skk-show-mode-inline-1 (str)
  ;; skk-dcomp-multiple-show() $B$+$iGR<Z(B
  (let* ((margin 1)
	 (beg-col (max 0 (- (skk-screen-column) margin)))
	 (max-width (string-width str))
	 bottom col ol)
    (when (zerop beg-col)
      (setq margin 0))
    (setq str (propertize (concat (make-string margin 32)
				  str
				  (make-string margin 32))
			  'face 'skk-show-mode-inline-face))
    (save-excursion
      (scroll-left (max 0
			(- (+ beg-col margin max-width margin 1)
			   (window-width) (window-hscroll))))
      (setq bottom (zerop (vertical-motion 1)))
      (cond (bottom
	     ;; $B%P%C%U%!:G=*9T$G$O!"IaDL$K(B overlay $B$rDI2C$7$F$$$/J}K!$@$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$k!#(B
	     ;; $B$?$@$7!"(BEOB $B$N>l9g$O(B prefix $B$N(B overlay $B$H>WFM$9$k$?$a(B
	     ;; `skk-prefix-overlay' $B$KDI2C$9$k(B
	     (setq ol (cond ((or (not skk-echo)
				 (string= "" skk-prefix)
				 (< (overlay-end skk-prefix-overlay)
				    (point)))
			     (make-overlay (point) (point)))
			    (t skk-prefix-overlay)))

	     (setq str (concat (overlay-get ol 'after-string)
				     "\n" (make-string beg-col ? ) str)))
	    ;; bottom $B0J30(B
	    (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!"(B
	  ;; $B$=$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-show-mode-inline-overlays)
	  )))

    (overlay-put ol 'invisible t)
    (overlay-put ol 'after-string str)
    (push ol skk-show-mode-inline-overlays)))


(defun skk-show-mode-tooltip ()
  (when window-system
    (let ((indicator
	   (apply 'skk-mode-string-to-indicator
		  (cond
		   (skk-abbrev-mode
		    `(abbrev ,skk-abbrev-mode-string))
		   (skk-jisx0208-latin-mode
		    `(jisx0208-latin ,skk-jisx0208-latin-mode-string))
		   (skk-katakana
		    `(katakana ,skk-katakana-mode-string))
		   (skk-j-mode
		    `(hiragana ,skk-hiragana-mode-string))
		   (skk-jisx0201-mode
		    `(jisx0201 ,skk-jisx0201-mode-string))
		   (t
		    `(latin ,skk-latin-mode-string))))))
      (skk-tooltip-show-at-point indicator))))

;;;###autoload
(defun skk-show-mode ()
  (interactive)
  (message "skk-show-mode-show: %s"
	   (setq skk-show-mode-show (null skk-show-mode-show))))
(provide 'skk-show-mode)

;;; skk-show-mode.el ends here