sekka 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +22 -0
- data/bin/.gitignore +1 -0
- data/bin/sekka-jisyo +98 -0
- data/bin/sekka-server +83 -0
- data/emacs/http-cookies.el +416 -0
- data/emacs/http-get.el +448 -0
- data/emacs/sekka.el +1069 -0
- data/lib/sekka/alphabet-lib.nnd +59 -0
- data/lib/sekka/approximatesearch.rb +72 -0
- data/lib/sekka/convert-jisyo.nnd +129 -0
- data/lib/sekka/henkan.nnd +464 -0
- data/lib/sekka/jisyo-db.nnd +184 -0
- data/lib/sekka/kvs.rb +135 -0
- data/lib/sekka/roman-lib.nnd +660 -0
- data/lib/sekka/sekkaversion.rb +6 -0
- data/lib/sekka/util.nnd +64 -0
- data/lib/sekka.ru +36 -0
- data/lib/sekkaconfig.rb +62 -0
- data/lib/sekkaserver.rb +127 -0
- data/test/alphabet-lib.nnd +188 -0
- data/test/approximate-bench.nnd +83 -0
- data/test/common.nnd +51 -0
- data/test/henkan-main.nnd +942 -0
- data/test/jisyo.nnd +94 -0
- data/test/roman-lib.nnd +422 -0
- data/test/util.nnd +100 -0
- metadata +223 -0
data/emacs/sekka.el
ADDED
@@ -0,0 +1,1069 @@
|
|
1
|
+
;; -*- coding: iso-2022-jp -*-
|
2
|
+
;;
|
3
|
+
;; "sekka.el" is a client for Sekka server
|
4
|
+
;;
|
5
|
+
;; Copyright (C) 2010 Kiyoka Nishiyama
|
6
|
+
;; This program was derived from sumibi.el and yc.el-4.0.13(auther: knak)
|
7
|
+
;;
|
8
|
+
;;
|
9
|
+
;; This file is part of Sekka
|
10
|
+
;;
|
11
|
+
;; Sekka is free software; you can redistribute it and/or modify
|
12
|
+
;; it under the terms of the GNU General Public License as published by
|
13
|
+
;; the Free Software Foundation; either version 2, or (at your option)
|
14
|
+
;; any later version.
|
15
|
+
;;
|
16
|
+
;; Sekka is distributed in the hope that it will be useful,
|
17
|
+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18
|
+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19
|
+
;; GNU General Public License for more details.
|
20
|
+
;;
|
21
|
+
;; You should have received a copy of the GNU General Public License
|
22
|
+
;; along with Sekka; see the file COPYING.
|
23
|
+
;;
|
24
|
+
|
25
|
+
;;; Code:
|
26
|
+
(require 'cl)
|
27
|
+
(require 'http-get)
|
28
|
+
|
29
|
+
;;;
|
30
|
+
;;;
|
31
|
+
;;; customize variables
|
32
|
+
;;;
|
33
|
+
(defgroup sekka nil
|
34
|
+
"Sekka client."
|
35
|
+
:group 'input-method
|
36
|
+
:group 'Japanese)
|
37
|
+
|
38
|
+
(defcustom sekka-server-url "http://localhost:12929/"
|
39
|
+
"Sekka$B%5!<%P!<$N(BURL$B$r;XDj$9$k!#(B"
|
40
|
+
:type 'string
|
41
|
+
:group 'sekka)
|
42
|
+
|
43
|
+
(defcustom sekka-server-timeout 10
|
44
|
+
"Sekka$B%5!<%P!<$HDL?.$9$k;~$N%?%$%`%"%&%H$r;XDj$9$k!#(B($BIC?t(B)"
|
45
|
+
:type 'integer
|
46
|
+
:group 'sekka)
|
47
|
+
|
48
|
+
(defcustom sekka-stop-chars "(){}<> "
|
49
|
+
"*$B4A;zJQ49J8;zNs$r<h$j9~$`;~$KJQ49HO0O$K4^$a$J$$J8;z$r@_Dj$9$k(B"
|
50
|
+
:type 'string
|
51
|
+
:group 'sekka)
|
52
|
+
|
53
|
+
(defcustom sekka-curl "curl"
|
54
|
+
"curl$B%3%^%s%I$N@dBP%Q%9$r@_Dj$9$k(B"
|
55
|
+
:type 'string
|
56
|
+
:group 'sekka)
|
57
|
+
|
58
|
+
(defcustom sekka-use-viper nil
|
59
|
+
"*Non-nil $B$G$"$l$P!"(BVIPER $B$KBP1~$9$k(B"
|
60
|
+
:type 'boolean
|
61
|
+
:group 'sekka)
|
62
|
+
|
63
|
+
(defcustom sekka-realtime-guide-running-seconds 30
|
64
|
+
"$B%j%"%k%?%$%`%,%$%II=<($N7QB3;~4V(B($BIC?t(B)$B!&%<%m$G%,%$%II=<(5!G=$,L58z$K$J$k(B"
|
65
|
+
:type 'integer
|
66
|
+
:group 'sekka)
|
67
|
+
|
68
|
+
(defcustom sekka-realtime-guide-limit-lines 5
|
69
|
+
"$B:G8e$KJQ49$7$?9T$+$i(B N $B9TN%$l$?$i%j%"%k%?%$%`%,%$%II=<($,;_$^$k(B"
|
70
|
+
:type 'integer
|
71
|
+
:group 'sekka)
|
72
|
+
|
73
|
+
(defcustom sekka-realtime-guide-interval 0.2
|
74
|
+
"$B%j%"%k%?%$%`%,%$%II=<($r99?7$9$k;~4V4V3V(B"
|
75
|
+
:type 'integer
|
76
|
+
:group 'sekka)
|
77
|
+
|
78
|
+
(defcustom sekka-roman-method "normal"
|
79
|
+
"$B%m!<%^;zF~NOJ}<0$H$7$F!$(Bnormal($BDL>o%m!<%^;z(B)$B$+!"(BAZIK($B3HD%%m!<%^;z(B)$B$N$I$A$i$N2r<a$rM%@h$9$k$+(B"
|
80
|
+
:type '(choice (const :tag "normal" "normal")
|
81
|
+
(const :tag "AZIK" "azik" ))
|
82
|
+
:group 'sekka)
|
83
|
+
|
84
|
+
|
85
|
+
(defface sekka-guide-face
|
86
|
+
'((((class color) (background light)) (:background "#E0E0E0" :foreground "#F03030")))
|
87
|
+
"$B%j%"%k%?%$%`%,%$%I$N%U%'%$%9(B($BAu>~!"?'$J$I$N;XDj(B)"
|
88
|
+
:group 'sekka)
|
89
|
+
|
90
|
+
|
91
|
+
(defvar sekka-sticky-shift nil "*Non-nil $B$G$"$l$P!"(BSticky-Shift$B$rM-8z$K$9$k(B")
|
92
|
+
(defvar sekka-mode nil "$B4A;zJQ49%H%0%kJQ?t(B")
|
93
|
+
(defvar sekka-mode-line-string " Sekka")
|
94
|
+
(defvar sekka-select-mode nil "$B8uJdA*Br%b!<%IJQ?t(B")
|
95
|
+
(or (assq 'sekka-mode minor-mode-alist)
|
96
|
+
(setq minor-mode-alist (cons
|
97
|
+
'(sekka-mode sekka-mode-line-string)
|
98
|
+
minor-mode-alist)))
|
99
|
+
|
100
|
+
|
101
|
+
;; $B%m!<%^;z4A;zJQ49;~!"BP>]$H$9$k%m!<%^;z$r@_Dj$9$k$?$a$NJQ?t(B
|
102
|
+
(defvar sekka-skip-chars "a-zA-Z0-9.,@:`\\-+!\\[\\]?;")
|
103
|
+
(defvar sekka-mode-map (make-sparse-keymap) "$B4A;zJQ49%H%0%k%^%C%W(B")
|
104
|
+
(defvar sekka-select-mode-map (make-sparse-keymap) "$B8uJdA*Br%b!<%I%^%C%W(B")
|
105
|
+
(defvar sekka-rK-trans-key "\C-j"
|
106
|
+
"*$B4A;zJQ49%-!<$r@_Dj$9$k(B")
|
107
|
+
(or (assq 'sekka-mode minor-mode-map-alist)
|
108
|
+
(setq minor-mode-map-alist
|
109
|
+
(append (list (cons 'sekka-mode sekka-mode-map)
|
110
|
+
(cons 'sekka-select-mode sekka-select-mode-map))
|
111
|
+
minor-mode-map-alist)))
|
112
|
+
|
113
|
+
;;;
|
114
|
+
;;; hooks
|
115
|
+
;;;
|
116
|
+
(defvar sekka-mode-hook nil)
|
117
|
+
(defvar sekka-select-mode-hook nil)
|
118
|
+
(defvar sekka-select-mode-end-hook nil)
|
119
|
+
|
120
|
+
(defconst sekka-login-name (user-login-name))
|
121
|
+
|
122
|
+
(defconst sekka-kind-index 3)
|
123
|
+
(defconst sekka-id-index 4)
|
124
|
+
|
125
|
+
;;--- $B%G%P%C%0%a%C%;!<%8=PNO(B
|
126
|
+
(defvar sekka-psudo-server nil) ; $B%/%i%$%"%s%HC1BN$G2>A[E*$K%5!<%P!<$K@\B3$7$F$$$k$h$&$K$7$F%F%9%H$9$k%b!<%I(B
|
127
|
+
|
128
|
+
;;--- $B%G%P%C%0%a%C%;!<%8=PNO(B
|
129
|
+
(defvar sekka-debug nil) ; $B%G%P%C%0%U%i%0(B
|
130
|
+
(defun sekka-debug-print (string)
|
131
|
+
(if sekka-debug
|
132
|
+
(let
|
133
|
+
((buffer (get-buffer-create "*sekka-debug*")))
|
134
|
+
(with-current-buffer buffer
|
135
|
+
(goto-char (point-max))
|
136
|
+
(insert string)))))
|
137
|
+
|
138
|
+
|
139
|
+
;;; sekka basic output
|
140
|
+
(defvar sekka-fence-start nil) ; fence $B;OC<0LCV(B
|
141
|
+
(defvar sekka-fence-end nil) ; fence $B=*C<0LCV(B
|
142
|
+
(defvar sekka-henkan-separeter " ") ; fence mode separeter
|
143
|
+
(defvar sekka-henkan-buffer nil) ; $BI=<(MQ%P%C%U%!(B
|
144
|
+
(defvar sekka-henkan-length nil) ; $BI=<(MQ%P%C%U%!D9(B
|
145
|
+
(defvar sekka-henkan-revpos nil) ; $BJ8@a;OC<0LCV(B
|
146
|
+
(defvar sekka-henkan-revlen nil) ; $BJ8@aD9(B
|
147
|
+
|
148
|
+
;;; sekka basic local
|
149
|
+
(defvar sekka-cand-cur 0) ; $B%+%l%s%H8uJdHV9f(B
|
150
|
+
(defvar sekka-cand-cur-backup 0) ; $B%+%l%s%H8uJdHV9f(B(UNDO$BMQ$KB`Hr$9$kJQ?t(B)
|
151
|
+
(defvar sekka-cand-len nil) ; $B8uJd?t(B
|
152
|
+
(defvar sekka-last-fix "") ; $B:G8e$K3NDj$7$?J8;zNs(B
|
153
|
+
(defvar sekka-henkan-kouho-list nil) ; $BJQ497k2L%j%9%H(B($B%5!<%P$+$i5"$C$F$-$?%G!<%?$=$N$b$N(B)
|
154
|
+
(defvar sekka-markers '()) ; $BJ8@a3+;O!"=*N;0LCV$N(Bpair: $B<!$N$h$&$J7A<0(B ( 1 . 2 )
|
155
|
+
(defvar sekka-timer nil) ; $B%$%s%?!<%P%k%?%$%^!<7?JQ?t(B
|
156
|
+
(defvar sekka-timer-rest 0) ; $B$"$H2?2s8F=P$5$l$?$i!"%$%s%?!<%P%k%?%$%^$N8F=P$r;_$a$k$+(B
|
157
|
+
(defvar sekka-last-lineno 0) ; $B:G8e$KJQ49$r<B9T$7$?9THV9f(B
|
158
|
+
(defvar sekka-guide-overlay nil) ; $B%j%"%k%?%$%`%,%$%I$K;HMQ$9$k%*!<%P!<%l%$(B
|
159
|
+
(defvar sekka-last-request-time 0) ; Sekka$B%5!<%P!<$K%j%/%(%9%H$7$?:G8e$N;~9o(B($BC10L$OIC(B)
|
160
|
+
(defvar sekka-guide-lastquery "") ; Sekka$B%5!<%P!<$K%j%/%(%9%H$7$?:G8e$N%/%(%jJ8;zNs(B
|
161
|
+
(defvar sekka-guide-lastresult '()) ; Sekka$B%5!<%P!<$K%j%/%(%9%H$7$?:G8e$N%/%(%jJ8;zNs(B
|
162
|
+
|
163
|
+
|
164
|
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
165
|
+
;; Skicky-shift
|
166
|
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
167
|
+
(defvar sticky-key ";")
|
168
|
+
(defvar sticky-list
|
169
|
+
'(("a" . "A")("b" . "B")("c" . "C")("d" . "D")("e" . "E")("f" . "F")("g" . "G")
|
170
|
+
("h" . "H")("i" . "I")("j" . "J")("k" . "K")("l" . "L")("m" . "M")("n" . "N")
|
171
|
+
("o" . "O")("p" . "P")("q" . "Q")("r" . "R")("s" . "S")("t" . "T")("u" . "U")
|
172
|
+
("v" . "V")("w" . "W")("x" . "X")("y" . "Y")("z" . "Z")
|
173
|
+
("1" . "!")("2" . "\"")("3" . "#")("4" . "$")("5" . "%")("6" . "&")("7" . "'")
|
174
|
+
("8" . "(")("9" . ")")
|
175
|
+
("`" . "@")("[" . "{")("]" . "}")("-" . "=")("^" . "~")("\\" . "|")("." . ">")
|
176
|
+
("/" . "?")(";" . ";")(":" . "*")("@" . "`")
|
177
|
+
("\C-h" . "")
|
178
|
+
))
|
179
|
+
(defvar sticky-map (make-sparse-keymap))
|
180
|
+
|
181
|
+
|
182
|
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
183
|
+
;; $BI=<(7O4X?t72(B
|
184
|
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
185
|
+
(defvar sekka-use-fence t)
|
186
|
+
(defvar sekka-use-color nil)
|
187
|
+
|
188
|
+
(defvar sekka-init nil)
|
189
|
+
|
190
|
+
;;
|
191
|
+
;; $B=i4|2=(B
|
192
|
+
;;
|
193
|
+
(defun sekka-init ()
|
194
|
+
;; $B:G=i$N(B n $B7o$N%j%9%H$r<hF@$9$k(B
|
195
|
+
(defun sekka-take (arg-list n)
|
196
|
+
(let ((lst '()))
|
197
|
+
(dotimes (i n (reverse lst))
|
198
|
+
(let ((item (nth i arg-list)))
|
199
|
+
(when item
|
200
|
+
(push item lst))))))
|
201
|
+
|
202
|
+
(when (not sekka-init)
|
203
|
+
;; $B%f!<%6!<8lWC$N%m!<%I(B + $B%5!<%P!<$X$NEPO?(B
|
204
|
+
(sekka-register-userdict-internal)
|
205
|
+
|
206
|
+
;; Emacs$B=*N;;~$N=hM}(B
|
207
|
+
(add-hook 'kill-emacs-hook
|
208
|
+
(lambda ()
|
209
|
+
;; $B2?$b$9$k$3$H$OL5$$(B
|
210
|
+
t))
|
211
|
+
;; $B=i4|2=40N;(B
|
212
|
+
(setq sekka-init t)))
|
213
|
+
|
214
|
+
|
215
|
+
(defun sekka-construct-curl-argstr (arg-alist)
|
216
|
+
(apply 'concat
|
217
|
+
(mapcar
|
218
|
+
(lambda (x)
|
219
|
+
(format "--data '%s=%s' " (car x)
|
220
|
+
(if (stringp (cdr x))
|
221
|
+
(http-url-encode (cdr x) 'utf-8)
|
222
|
+
(cdr x))))
|
223
|
+
arg-alist)))
|
224
|
+
|
225
|
+
;; test-code
|
226
|
+
(when nil
|
227
|
+
(sekka-construct-curl-argstr
|
228
|
+
'(
|
229
|
+
("yomi" . "kanji")
|
230
|
+
("limit" . 2)
|
231
|
+
("method" . "normal")
|
232
|
+
)))
|
233
|
+
|
234
|
+
;;
|
235
|
+
;; $B%m!<%^;z$G=q$+$l$?J8>O$r(BSekka$B%5!<%P!<$r;H$C$FJQ49$9$k(B
|
236
|
+
;;
|
237
|
+
;; arg-alist$B$N0z?t$N7A<0(B
|
238
|
+
;; $BNc(B:
|
239
|
+
;; '(
|
240
|
+
;; ("yomi" . "kanji")
|
241
|
+
;; ("limit" . 2)
|
242
|
+
;; ("method" . "normal")
|
243
|
+
;; )
|
244
|
+
(defun sekka-rest-request (func-name arg-alist)
|
245
|
+
(if sekka-psudo-server
|
246
|
+
;; $B%/%i%$%"%s%HC1BN$G2>A[E*$K%5!<%P!<$K@\B3$7$F$$$k$h$&$K$7$F%F%9%H$9$k%b!<%I(B
|
247
|
+
"((\"$BJQ49(B\" nil \"$B$X$s$+$s(B\" j 0) (\"$BJQ2=(B\" nil \"$B$X$s$+(B\" j 1) (\"$B%X%s%+%s(B\" nil \"$B$X$s$+$s(B\" k 2) (\"$B$X$s$+$s(B\" nil \"$B$X$s$+$s(B\" h 3))"
|
248
|
+
;;"((\"$BJQ49(B\" nil \"$B$X$s$+$s(B\" j 0) (\"$BJQ2=(B\" nil \"$B$X$s$+(B\" j 1))"
|
249
|
+
;; $B<B:]$N%5!<%P$K@\B3$9$k(B
|
250
|
+
(let ((command
|
251
|
+
(concat
|
252
|
+
sekka-curl " --silent --show-error "
|
253
|
+
(format " --max-time %d " sekka-server-timeout)
|
254
|
+
" --insecure "
|
255
|
+
" --header 'Content-Type: application/x-www-form-urlencoded' "
|
256
|
+
(format "%s%s " sekka-server-url func-name)
|
257
|
+
(sekka-construct-curl-argstr (cons
|
258
|
+
'("format" . "sexp")
|
259
|
+
arg-alist))
|
260
|
+
(format "--data 'userid=%s' " sekka-login-name))))
|
261
|
+
|
262
|
+
(sekka-debug-print (format "curl-command :%s\n" command))
|
263
|
+
|
264
|
+
(let (
|
265
|
+
(result
|
266
|
+
(shell-command-to-string
|
267
|
+
command)))
|
268
|
+
|
269
|
+
(sekka-debug-print (format "curl-result-sexp :%s\n" result))
|
270
|
+
result))))
|
271
|
+
|
272
|
+
;;
|
273
|
+
;; $B8=:_;~9o$r(BUNIX$B%?%$%`$rJV$9(B($BC10L$OIC(B)
|
274
|
+
;;
|
275
|
+
(defun sekka-current-unixtime ()
|
276
|
+
(let (
|
277
|
+
(_ (current-time)))
|
278
|
+
(+
|
279
|
+
(* (car _)
|
280
|
+
65536)
|
281
|
+
(cadr _))))
|
282
|
+
|
283
|
+
|
284
|
+
;;
|
285
|
+
;; $B%m!<%^;z$G=q$+$l$?J8>O$r(BSekka$B%5!<%P!<$r;H$C$FJQ49$9$k(B
|
286
|
+
;;
|
287
|
+
(defun sekka-henkan-request (yomi limit)
|
288
|
+
(sekka-debug-print (format "henkan-input :[%s]\n" yomi))
|
289
|
+
|
290
|
+
;;(message "Requesting to sekka server...")
|
291
|
+
|
292
|
+
(let (
|
293
|
+
(result (sekka-rest-request "henkan" `((yomi . ,yomi)
|
294
|
+
(limit . ,limit)
|
295
|
+
(method . ,sekka-roman-method)))))
|
296
|
+
(sekka-debug-print (format "henkan-result:%S\n" result))
|
297
|
+
(if (eq (string-to-char result) ?\( )
|
298
|
+
(progn
|
299
|
+
(message nil)
|
300
|
+
(condition-case err
|
301
|
+
(read result)
|
302
|
+
(end-of-file
|
303
|
+
(progn
|
304
|
+
(message "Parse error for parsing result of Sekka Server.")
|
305
|
+
nil))))
|
306
|
+
(progn
|
307
|
+
(message result)
|
308
|
+
nil))))
|
309
|
+
|
310
|
+
;;
|
311
|
+
;; $B3NDj$7$?C18l$r%5!<%P!<$KEAC#$9$k(B
|
312
|
+
;;
|
313
|
+
(defun sekka-kakutei-request (key tango)
|
314
|
+
(sekka-debug-print (format "henkan-kakutei key=[%s] tango=[%s]\n" key tango))
|
315
|
+
|
316
|
+
(message "Requesting to sekka server...")
|
317
|
+
|
318
|
+
(let ((result (sekka-rest-request "kakutei" `(
|
319
|
+
(key . ,key)
|
320
|
+
(tango . ,tango)))))
|
321
|
+
(sekka-debug-print (format "kakutei-result:%S\n" result))
|
322
|
+
(message result)
|
323
|
+
t))
|
324
|
+
|
325
|
+
;;
|
326
|
+
;; $B%f!<%6!<8lWC$r%5!<%P!<$K:FEYEPO?$9$k!#(B
|
327
|
+
;;
|
328
|
+
(defun sekka-register-userdict (&optional arg)
|
329
|
+
"$B%f!<%6!<<-=q$r%5!<%P!<$K:FEY%"%C%W%m!<%I$9$k(B"
|
330
|
+
(interactive "P")
|
331
|
+
(sekka-register-userdict-internal))
|
332
|
+
|
333
|
+
|
334
|
+
;;
|
335
|
+
;; $B%f!<%6!<8lWC$r%5!<%P!<$KEPO?$9$k!#(B
|
336
|
+
;;
|
337
|
+
(defun sekka-register-userdict-internal ()
|
338
|
+
(let ((str (sekka-get-jisyo-str "~/.sekka-jisyo")))
|
339
|
+
(when str
|
340
|
+
(message "Requesting to sekka server...")
|
341
|
+
(sekka-debug-print (format "register [%s]\n" str))
|
342
|
+
(let ((result (sekka-rest-request "register" `((dict . ,str)))))
|
343
|
+
(sekka-debug-print (format "register-result:%S\n" result))
|
344
|
+
(message result)
|
345
|
+
t))))
|
346
|
+
|
347
|
+
|
348
|
+
(defun sekka-get-jisyo-str (file &optional nomsg)
|
349
|
+
"FILE $B$r3+$$$F(B SKK $B<-=q%P%C%U%!$r:n$j!"%P%C%U%!$rJV$9!#(B
|
350
|
+
$B%*%W%7%g%s0z?t$N(B NOMSG $B$r;XDj$9$k$H%U%!%$%kFI$_9~$_$N:]$N%a%C%;!<%8$rI=<($7$J(B
|
351
|
+
$B$$!#(B"
|
352
|
+
(when file
|
353
|
+
(let* ((file (or (car-safe file)
|
354
|
+
file))
|
355
|
+
(file (expand-file-name file)))
|
356
|
+
(if (not (file-exists-p file))
|
357
|
+
(progn
|
358
|
+
(message (format "SKK $B<-=q(B %s $B$,B8:_$7$^$;$s(B..." file))
|
359
|
+
nil)
|
360
|
+
(let ((str "")
|
361
|
+
(buf-name (file-name-nondirectory file)))
|
362
|
+
(save-excursion
|
363
|
+
(find-file-read-only file)
|
364
|
+
(setq str (with-current-buffer (get-buffer buf-name)
|
365
|
+
(buffer-substring-no-properties (point-min) (point-max))))
|
366
|
+
(message (format "SKK $B<-=q(B %s $B$r3+$$$F$$$^$9(B...$B40N;!*(B" (file-name-nondirectory file)))
|
367
|
+
(kill-buffer-if-not-modified (get-buffer buf-name)))
|
368
|
+
str)))))
|
369
|
+
|
370
|
+
;;(sekka-get-jisyo-str "~/.sekka-jisyo")
|
371
|
+
|
372
|
+
|
373
|
+
;; $B%]!<%?%V%kJ8;zNsCV49(B( Emacs$B$H(BXEmacs$B$NN>J}$GF0$/(B )
|
374
|
+
(defun sekka-replace-regexp-in-string (regexp replace str)
|
375
|
+
(cond ((featurep 'xemacs)
|
376
|
+
(replace-in-string str regexp replace))
|
377
|
+
(t
|
378
|
+
(replace-regexp-in-string regexp replace str))))
|
379
|
+
|
380
|
+
|
381
|
+
;; $B%j!<%8%g%s$r%m!<%^;z4A;zJQ49$9$k4X?t(B
|
382
|
+
(defun sekka-henkan-region (b e)
|
383
|
+
"$B;XDj$5$l$?(B region $B$r4A;zJQ49$9$k(B"
|
384
|
+
(sekka-init)
|
385
|
+
(when (/= b e)
|
386
|
+
(let* (
|
387
|
+
(yomi (buffer-substring-no-properties b e))
|
388
|
+
(henkan-list (sekka-henkan-request yomi 0)))
|
389
|
+
|
390
|
+
(if henkan-list
|
391
|
+
(condition-case err
|
392
|
+
(progn
|
393
|
+
(setq
|
394
|
+
;; $BJQ497k2L$NJ];}(B
|
395
|
+
sekka-henkan-kouho-list henkan-list
|
396
|
+
;; $BJ8@aA*Br=i4|2=(B
|
397
|
+
sekka-cand-cur 0
|
398
|
+
;;
|
399
|
+
sekka-cand-len (length henkan-list))
|
400
|
+
|
401
|
+
(sekka-debug-print (format "sekka-henkan-kouho-list:%s \n" sekka-henkan-kouho-list))
|
402
|
+
(sekka-debug-print (format "sekka-cand-cur:%s \n" sekka-cand-cur))
|
403
|
+
(sekka-debug-print (format "sekka-cand-len:%s \n" sekka-cand-len))
|
404
|
+
;;
|
405
|
+
t)
|
406
|
+
(sekka-trap-server-down
|
407
|
+
(beep)
|
408
|
+
(message (error-message-string err))
|
409
|
+
(setq sekka-select-mode nil))
|
410
|
+
(run-hooks 'sekka-select-mode-end-hook))
|
411
|
+
nil))))
|
412
|
+
|
413
|
+
|
414
|
+
;; $B%+!<%=%kA0$NJ8;z<o$rJV5Q$9$k4X?t(B
|
415
|
+
(eval-and-compile
|
416
|
+
(if (>= emacs-major-version 20)
|
417
|
+
(progn
|
418
|
+
(defalias 'sekka-char-charset (symbol-function 'char-charset))
|
419
|
+
(when (and (boundp 'byte-compile-depth)
|
420
|
+
(not (fboundp 'char-category)))
|
421
|
+
(defalias 'char-category nil))) ; for byte compiler
|
422
|
+
(defun sekka-char-charset (ch)
|
423
|
+
(cond ((equal (char-category ch) "a") 'ascii)
|
424
|
+
((equal (char-category ch) "k") 'katakana-jisx0201)
|
425
|
+
((string-match "[SAHK]j" (char-category ch)) 'japanese-jisx0208)
|
426
|
+
(t nil) )) ))
|
427
|
+
|
428
|
+
|
429
|
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
430
|
+
;; undo $B>pJs$N@)8f(B
|
431
|
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
432
|
+
;; undo buffer $BB`HrMQJQ?t(B
|
433
|
+
(defvar sekka-buffer-undo-list nil)
|
434
|
+
(make-variable-buffer-local 'sekka-buffer-undo-list)
|
435
|
+
(defvar sekka-buffer-modified-p nil)
|
436
|
+
(make-variable-buffer-local 'sekka-buffer-modified-p)
|
437
|
+
|
438
|
+
(defvar sekka-blink-cursor nil)
|
439
|
+
(defvar sekka-cursor-type nil)
|
440
|
+
;; undo buffer $B$rB`Hr$7!"(Bundo $B>pJs$NC_@Q$rDd;_$9$k4X?t(B
|
441
|
+
(defun sekka-disable-undo ()
|
442
|
+
(when (not (eq buffer-undo-list t))
|
443
|
+
(setq sekka-buffer-undo-list buffer-undo-list)
|
444
|
+
(setq sekka-buffer-modified-p (buffer-modified-p))
|
445
|
+
(setq buffer-undo-list t)))
|
446
|
+
|
447
|
+
;; $BB`Hr$7$?(B undo buffer $B$rI|5"$7!"(Bundo $B>pJs$NC_@Q$r:F3+$9$k4X?t(B
|
448
|
+
(defun sekka-enable-undo ()
|
449
|
+
(when (not sekka-buffer-modified-p) (set-buffer-modified-p nil))
|
450
|
+
(when sekka-buffer-undo-list
|
451
|
+
(setq buffer-undo-list sekka-buffer-undo-list)))
|
452
|
+
|
453
|
+
|
454
|
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
455
|
+
;; $B8=:_$NJQ49%(%j%"$NI=<($r9T$&(B
|
456
|
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
457
|
+
(defun sekka-get-display-string ()
|
458
|
+
;; $BJQ497k2LJ8;zNs$rJV$9!#(B
|
459
|
+
(let* ((kouho (nth sekka-cand-cur sekka-henkan-kouho-list))
|
460
|
+
(_ (sekka-debug-print (format "sekka-cand-cur=%s\n" sekka-cand-cur)))
|
461
|
+
(_ (sekka-debug-print (format "kouho=%s\n" kouho)))
|
462
|
+
(word (car kouho))
|
463
|
+
(annotation (cadr kouho)))
|
464
|
+
(sekka-debug-print (format "word:[%d] %s(%s)\n" sekka-cand-cur word annotation))
|
465
|
+
word))
|
466
|
+
|
467
|
+
(defun sekka-display-function (b e select-mode)
|
468
|
+
(setq sekka-henkan-separeter (if sekka-use-fence " " ""))
|
469
|
+
(when sekka-henkan-kouho-list
|
470
|
+
;; UNDO$BM^@)3+;O(B
|
471
|
+
(sekka-disable-undo)
|
472
|
+
|
473
|
+
(delete-region b e)
|
474
|
+
|
475
|
+
;; $B%j%9%H=i4|2=(B
|
476
|
+
(setq sekka-markers '())
|
477
|
+
|
478
|
+
(setq sekka-last-fix "")
|
479
|
+
|
480
|
+
;; $BJQ49$7$?(Bpoint$B$NJ];}(B
|
481
|
+
(setq sekka-fence-start (point-marker))
|
482
|
+
(when select-mode (insert "|"))
|
483
|
+
|
484
|
+
(let* (
|
485
|
+
(start (point-marker))
|
486
|
+
(_cur sekka-cand-cur)
|
487
|
+
(_len sekka-cand-len)
|
488
|
+
(insert-word (sekka-get-display-string)))
|
489
|
+
(progn
|
490
|
+
(insert insert-word)
|
491
|
+
(message (format "[%s] candidate (%d/%d)" insert-word (+ _cur 1) _len))
|
492
|
+
(let* ((end (point-marker))
|
493
|
+
(ov (make-overlay start end)))
|
494
|
+
|
495
|
+
;; $B3NDjJ8;zNs$N:n@.(B
|
496
|
+
(setq sekka-last-fix insert-word)
|
497
|
+
|
498
|
+
;; $BA*BrCf$N>l=j$rAu>~$9$k!#(B
|
499
|
+
(overlay-put ov 'face 'default)
|
500
|
+
(when select-mode
|
501
|
+
(overlay-put ov 'face 'highlight))
|
502
|
+
(setq sekka-markers (cons start end))
|
503
|
+
(sekka-debug-print (format "insert:[%s] point:%d-%d\n" insert-word (marker-position start) (marker-position end))))))
|
504
|
+
|
505
|
+
;; fence$B$NHO0O$r@_Dj$9$k(B
|
506
|
+
(when select-mode (insert "|"))
|
507
|
+
(setq sekka-fence-end (point-marker))
|
508
|
+
|
509
|
+
(sekka-debug-print (format "total-point:%d-%d\n"
|
510
|
+
(marker-position sekka-fence-start)
|
511
|
+
(marker-position sekka-fence-end)))
|
512
|
+
;; UNDO$B:F3+(B
|
513
|
+
(sekka-enable-undo)))
|
514
|
+
|
515
|
+
|
516
|
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
517
|
+
;; $BJQ498uJdA*Br%b!<%I(B
|
518
|
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
519
|
+
(let ((i 0))
|
520
|
+
(while (<= i ?\177)
|
521
|
+
(define-key sekka-select-mode-map (char-to-string i)
|
522
|
+
'sekka-kakutei-and-self-insert)
|
523
|
+
(setq i (1+ i))))
|
524
|
+
(define-key sekka-select-mode-map "\C-m" 'sekka-select-kakutei)
|
525
|
+
(define-key sekka-select-mode-map "\C-g" 'sekka-select-cancel)
|
526
|
+
(define-key sekka-select-mode-map "q" 'sekka-select-cancel)
|
527
|
+
(define-key sekka-select-mode-map "\C-a" 'sekka-select-kanji)
|
528
|
+
(define-key sekka-select-mode-map "\C-p" 'sekka-select-prev)
|
529
|
+
(define-key sekka-select-mode-map "\C-n" 'sekka-select-next)
|
530
|
+
(define-key sekka-select-mode-map sekka-rK-trans-key 'sekka-select-next)
|
531
|
+
(define-key sekka-select-mode-map " " 'sekka-select-next)
|
532
|
+
(define-key sekka-select-mode-map "\C-u" 'sekka-select-hiragana)
|
533
|
+
(define-key sekka-select-mode-map "\C-i" 'sekka-select-katakana)
|
534
|
+
(define-key sekka-select-mode-map "\C-k" 'sekka-select-katakana)
|
535
|
+
(define-key sekka-select-mode-map "\C-l" 'sekka-select-hankaku)
|
536
|
+
(define-key sekka-select-mode-map "\C-e" 'sekka-select-zenkaku)
|
537
|
+
|
538
|
+
|
539
|
+
|
540
|
+
;; $BJQ49$r3NDj$7F~NO$5$l$?%-!<$r:FF~NO$9$k4X?t(B
|
541
|
+
(defun sekka-kakutei-and-self-insert (arg)
|
542
|
+
"$B8uJdA*Br$r3NDj$7!"F~NO$5$l$?J8;z$rF~NO$9$k(B"
|
543
|
+
(interactive "P")
|
544
|
+
(sekka-select-kakutei)
|
545
|
+
(setq unread-command-events (list last-command-event)))
|
546
|
+
|
547
|
+
;; $B8uJdA*Br>uBV$G$NI=<(99?7(B
|
548
|
+
(defun sekka-select-update-display ()
|
549
|
+
(sekka-display-function
|
550
|
+
(marker-position sekka-fence-start)
|
551
|
+
(marker-position sekka-fence-end)
|
552
|
+
sekka-select-mode))
|
553
|
+
|
554
|
+
|
555
|
+
;; $B8uJdA*Br$r3NDj$9$k(B
|
556
|
+
(defun sekka-select-kakutei ()
|
557
|
+
"$B8uJdA*Br$r3NDj$9$k(B"
|
558
|
+
(interactive)
|
559
|
+
;; $B8uJdHV9f%j%9%H$r%P%C%/%"%C%W$9$k!#(B
|
560
|
+
(setq sekka-cand-cur-backup sekka-cand-cur)
|
561
|
+
;; $B%5!<%P!<$K3NDj$7$?C18l$rEA$($k(B($B<-=q3X=,(B)
|
562
|
+
(let* ((kouho (nth sekka-cand-cur sekka-henkan-kouho-list))
|
563
|
+
(_ (sekka-debug-print (format "2:sekka-cand-cur=%s\n" sekka-cand-cur)))
|
564
|
+
(_ (sekka-debug-print (format "2:kouho=%s\n" kouho)))
|
565
|
+
(tango (car kouho))
|
566
|
+
(key (caddr kouho))
|
567
|
+
(kind (nth sekka-kind-index kouho)))
|
568
|
+
(when (eq 'j kind)
|
569
|
+
(sekka-kakutei-request key tango)))
|
570
|
+
(setq sekka-select-mode nil)
|
571
|
+
(run-hooks 'sekka-select-mode-end-hook)
|
572
|
+
(sekka-select-update-display))
|
573
|
+
|
574
|
+
|
575
|
+
;; $B8uJdA*Br$r%-%c%s%;%k$9$k(B
|
576
|
+
(defun sekka-select-cancel ()
|
577
|
+
"$B8uJdA*Br$r%-%c%s%;%k$9$k(B"
|
578
|
+
(interactive)
|
579
|
+
;; $B%+%l%s%H8uJdHV9f$r%P%C%/%"%C%W$7$F$$$?8uJdHV9f$GI|85$9$k!#(B
|
580
|
+
(setq sekka-cand-cur sekka-cand-cur-backup)
|
581
|
+
(setq sekka-select-mode nil)
|
582
|
+
(run-hooks 'sekka-select-mode-end-hook)
|
583
|
+
(sekka-select-update-display))
|
584
|
+
|
585
|
+
;; $BA0$N8uJd$K?J$a$k(B
|
586
|
+
(defun sekka-select-prev ()
|
587
|
+
"$BA0$N8uJd$K?J$a$k(B"
|
588
|
+
(interactive)
|
589
|
+
;; $BA0$N8uJd$K@Z$j$+$($k(B
|
590
|
+
(decf sekka-cand-cur)
|
591
|
+
(when (> 0 sekka-cand-cur)
|
592
|
+
(setq sekka-cand-cur (- sekka-cand-len 1)))
|
593
|
+
(sekka-select-update-display))
|
594
|
+
|
595
|
+
;; $B<!$N8uJd$K?J$a$k(B
|
596
|
+
(defun sekka-select-next ()
|
597
|
+
"$B<!$N8uJd$K?J$a$k(B"
|
598
|
+
(interactive)
|
599
|
+
;; $B<!$N8uJd$K@Z$j$+$($k(B
|
600
|
+
(setq sekka-cand-cur
|
601
|
+
(if (< sekka-cand-cur (- sekka-cand-len 1))
|
602
|
+
(+ sekka-cand-cur 1)
|
603
|
+
0))
|
604
|
+
(sekka-select-update-display))
|
605
|
+
|
606
|
+
;; $B;XDj$5$l$?(B type $B$N8uJd$rH4$-=P$9(B
|
607
|
+
(defun sekka-select-by-type-filter ( _type )
|
608
|
+
(let ((lst '()))
|
609
|
+
(mapcar
|
610
|
+
(lambda (x)
|
611
|
+
(let ((sym (nth sekka-kind-index x)))
|
612
|
+
(when (eq sym _type)
|
613
|
+
(push x lst))))
|
614
|
+
sekka-henkan-kouho-list)
|
615
|
+
(sekka-debug-print (format "filterd-lst = %S" (reverse lst)))
|
616
|
+
(car (reverse lst))))
|
617
|
+
|
618
|
+
;; $B;XDj$5$l$?(B type $B$N8uJd$K6/@)E*$K@Z$j$+$($k(B
|
619
|
+
(defun sekka-select-by-type ( _type )
|
620
|
+
(let ((kouho (sekka-select-by-type-filter _type)))
|
621
|
+
(if (null kouho)
|
622
|
+
(cond
|
623
|
+
((eq _type 'j)
|
624
|
+
(message "Sekka: $B4A;z$N8uJd$O$"$j$^$;$s!#(B"))
|
625
|
+
((eq _type 'h)
|
626
|
+
(message "Sekka: $B$R$i$,$J$N8uJd$O$"$j$^$;$s!#(B"))
|
627
|
+
((eq _type 'k)
|
628
|
+
(message "Sekka: $B%+%?%+%J$N8uJd$O$"$j$^$;$s!#(B"))
|
629
|
+
((eq _type 'l)
|
630
|
+
(message "Sekka: $BH>3Q$N8uJd$O$"$j$^$;$s!#(B"))
|
631
|
+
((eq _type 'z)
|
632
|
+
(message "Sekka: $BA43Q$N8uJd$O$"$j$^$;$s!#(B")))
|
633
|
+
(let ((num (nth sekka-id-index kouho)))
|
634
|
+
(setq sekka-cand-cur num)
|
635
|
+
(sekka-select-update-display)))))
|
636
|
+
|
637
|
+
(defun sekka-select-kanji ()
|
638
|
+
"$B4A;z8uJd$K6/@)E*$K@Z$j$+$($k(B"
|
639
|
+
(interactive)
|
640
|
+
(sekka-select-by-type 'j))
|
641
|
+
|
642
|
+
(defun sekka-select-hiragana ()
|
643
|
+
"$B$R$i$,$J8uJd$K6/@)E*$K@Z$j$+$($k(B"
|
644
|
+
(interactive)
|
645
|
+
(sekka-select-by-type 'h))
|
646
|
+
|
647
|
+
(defun sekka-select-katakana ()
|
648
|
+
"$B%+%?%+%J8uJd$K6/@)E*$K@Z$j$+$($k(B"
|
649
|
+
(interactive)
|
650
|
+
(sekka-select-by-type 'k))
|
651
|
+
|
652
|
+
(defun sekka-select-hankaku ()
|
653
|
+
"$BH>3Q8uJd$K6/@)E*$K@Z$j$+$($k(B"
|
654
|
+
(interactive)
|
655
|
+
(sekka-select-by-type 'l))
|
656
|
+
|
657
|
+
(defun sekka-select-zenkaku ()
|
658
|
+
"$BH>3Q8uJd$K6/@)E*$K@Z$j$+$($k(B"
|
659
|
+
(interactive)
|
660
|
+
(sekka-select-by-type 'z))
|
661
|
+
|
662
|
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
663
|
+
;; $B%m!<%^;z4A;zJQ494X?t(B
|
664
|
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
665
|
+
(defun sekka-rK-trans ()
|
666
|
+
"$B%m!<%^;z4A;zJQ49$r$9$k!#(B
|
667
|
+
$B!&%+!<%=%k$+$i9TF,J}8~$K%m!<%^;zNs$,B3$/HO0O$G%m!<%^;z4A;zJQ49$r9T$&!#(B"
|
668
|
+
(interactive)
|
669
|
+
; (print last-command) ; DEBUG
|
670
|
+
|
671
|
+
(cond
|
672
|
+
;; $B%?%$%^!<%$%Y%s%H$r@_Dj$7$J$$>r7o(B
|
673
|
+
((or
|
674
|
+
sekka-timer
|
675
|
+
(> 1 sekka-realtime-guide-running-seconds)
|
676
|
+
))
|
677
|
+
(t
|
678
|
+
;; $B%?%$%^!<%$%Y%s%H4X?t$NEPO?(B
|
679
|
+
(progn
|
680
|
+
(let
|
681
|
+
((ov-point
|
682
|
+
(save-excursion
|
683
|
+
(forward-line 1)
|
684
|
+
(point))))
|
685
|
+
(setq sekka-guide-overlay
|
686
|
+
(make-overlay ov-point ov-point (current-buffer))))
|
687
|
+
(setq sekka-timer
|
688
|
+
(run-at-time 0.1 sekka-realtime-guide-interval
|
689
|
+
'sekka-realtime-guide)))))
|
690
|
+
|
691
|
+
;; $B%,%$%II=<(7QB32s?t$N99?7(B
|
692
|
+
(when (< 0 sekka-realtime-guide-running-seconds)
|
693
|
+
(setq sekka-timer-rest
|
694
|
+
(/ sekka-realtime-guide-running-seconds
|
695
|
+
sekka-realtime-guide-interval)))
|
696
|
+
|
697
|
+
;; $B:G8e$KJQ49$7$?9THV9f$N99?7(B
|
698
|
+
(setq sekka-last-lineno (line-number-at-pos (point)))
|
699
|
+
|
700
|
+
(cond
|
701
|
+
(sekka-select-mode
|
702
|
+
;; $BJQ49Cf$K8F=P$5$l$?$i!"8uJdA*Br%b!<%I$K0\9T$9$k!#(B
|
703
|
+
(funcall (lookup-key sekka-select-mode-map sekka-rK-trans-key)))
|
704
|
+
|
705
|
+
|
706
|
+
(t
|
707
|
+
(cond
|
708
|
+
|
709
|
+
((eq (sekka-char-charset (preceding-char)) 'ascii)
|
710
|
+
;; $B%+!<%=%kD>A0$,(B alphabet $B$@$C$?$i(B
|
711
|
+
(let ((end (point))
|
712
|
+
(gap (sekka-skip-chars-backward)))
|
713
|
+
(when (/= gap 0)
|
714
|
+
;; $B0UL#$N$"$kF~NO$,8+$D$+$C$?$N$GJQ49$9$k(B
|
715
|
+
(let (
|
716
|
+
(b (+ end gap))
|
717
|
+
(e end))
|
718
|
+
(when (sekka-henkan-region b e)
|
719
|
+
(if (eq (char-before b) ?/)
|
720
|
+
(setq b (- b 1)))
|
721
|
+
(delete-region b e)
|
722
|
+
(goto-char b)
|
723
|
+
(insert (sekka-get-display-string))
|
724
|
+
(setq e (point))
|
725
|
+
(sekka-display-function b e nil)
|
726
|
+
(sekka-select-kakutei)
|
727
|
+
)))))
|
728
|
+
|
729
|
+
|
730
|
+
((sekka-kanji (preceding-char))
|
731
|
+
|
732
|
+
;; $B%+!<%=%kD>A0$,(B $BA43Q$G4A;z0J30(B $B$@$C$?$i8uJdA*Br%b!<%I$K0\9T$9$k!#(B
|
733
|
+
;; $B$^$?!":G8e$K3NDj$7$?J8;zNs$HF1$8$+$I$&$+$b3NG'$9$k!#(B
|
734
|
+
(when (and
|
735
|
+
(<= (marker-position sekka-fence-start) (point))
|
736
|
+
(<= (point) (marker-position sekka-fence-end))
|
737
|
+
(string-equal sekka-last-fix (buffer-substring
|
738
|
+
(marker-position sekka-fence-start)
|
739
|
+
(marker-position sekka-fence-end))))
|
740
|
+
;; $BD>A0$KJQ49$7$?(Bfence$B$NHO0O$KF~$C$F$$$?$i!"JQ49%b!<%I$K0\9T$9$k!#(B
|
741
|
+
(setq sekka-select-mode t)
|
742
|
+
(sekka-debug-print "henkan mode ON\n")
|
743
|
+
|
744
|
+
;; $BI=<(>uBV$r8uJdA*Br%b!<%I$K@ZBX$($k!#(B
|
745
|
+
(sekka-display-function
|
746
|
+
(marker-position sekka-fence-start)
|
747
|
+
(marker-position sekka-fence-end)
|
748
|
+
t))))
|
749
|
+
)))
|
750
|
+
|
751
|
+
|
752
|
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
753
|
+
;; $B%-%c%T%?%i%$%:(B/$B%"%s%-%c%T%?%i%$%:JQ49(B
|
754
|
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
755
|
+
(defun sekka-capitalize-trans ()
|
756
|
+
"$B%-%c%T%?%i%$%:JQ49$r9T$&(B
|
757
|
+
$B!&%+!<%=%k$+$i9TF,J}8~$K%m!<%^;zNs$r8+$D$1!"@hF,J8;z$NBgJ8;z>.J8;z$rH?E>$9$k(B"
|
758
|
+
(interactive)
|
759
|
+
|
760
|
+
(cond
|
761
|
+
(sekka-select-mode
|
762
|
+
;; $B8uJdA*Br%b!<%I$G$OH?1~$7$J$$!#(B
|
763
|
+
;; do nothing
|
764
|
+
)
|
765
|
+
((eq (sekka-char-charset (preceding-char)) 'ascii)
|
766
|
+
;; $B%+!<%=%kD>A0$,(B alphabet $B$@$C$?$i(B
|
767
|
+
(sekka-debug-print "capitalize(2)!\n")
|
768
|
+
|
769
|
+
(let ((end (point))
|
770
|
+
(gap (sekka-skip-chars-backward)))
|
771
|
+
(when (/= gap 0)
|
772
|
+
;; $B0UL#$N$"$kF~NO$,8+$D$+$C$?$N$GJQ49$9$k(B
|
773
|
+
(let* (
|
774
|
+
(b (+ end gap))
|
775
|
+
(e end)
|
776
|
+
(roman-str (buffer-substring-no-properties b e)))
|
777
|
+
(sekka-debug-print (format "capitalize %d %d [%s]" b e roman-str))
|
778
|
+
(setq case-fold-search nil)
|
779
|
+
(cond
|
780
|
+
((string-match-p "^[A-Z]" roman-str)
|
781
|
+
(downcase-region b (+ b 1)))
|
782
|
+
((string-match-p "^[a-z]" roman-str)
|
783
|
+
(upcase-region b (+ b 1))))))))
|
784
|
+
))
|
785
|
+
|
786
|
+
|
787
|
+
;; $BA43Q$G4A;z0J30$NH=Dj4X?t(B
|
788
|
+
(defun sekka-nkanji (ch)
|
789
|
+
(and (eq (sekka-char-charset ch) 'japanese-jisx0208)
|
790
|
+
(not (string-match "[$B0!(B-$Bt$(B]" (char-to-string ch)))))
|
791
|
+
|
792
|
+
(defun sekka-kanji (ch)
|
793
|
+
(eq (sekka-char-charset ch) 'japanese-jisx0208))
|
794
|
+
|
795
|
+
|
796
|
+
;; $B%m!<%^;z4A;zJQ49;~!"JQ49BP>]$H$9$k%m!<%^;z$rFI$_Ht$P$94X?t(B
|
797
|
+
(defun sekka-skip-chars-backward ()
|
798
|
+
(let* (
|
799
|
+
(skip-chars
|
800
|
+
(if auto-fill-function
|
801
|
+
;; auto-fill-mode $B$,M-8z$K$J$C$F$$$k>l9g2~9T$,$"$C$F$b(Bskip$B$rB3$1$k(B
|
802
|
+
(concat sekka-skip-chars "\n")
|
803
|
+
;; auto-fill-mode$B$,L58z$N>l9g$O$=$N$^$^(B
|
804
|
+
sekka-skip-chars))
|
805
|
+
|
806
|
+
;; $B%^!<%/$5$l$F$$$k0LCV$r5a$a$k!#(B
|
807
|
+
(pos (or (and (markerp (mark-marker)) (marker-position (mark-marker)))
|
808
|
+
1))
|
809
|
+
|
810
|
+
;; $B>r7o$K%^%C%A$9$k4V!"A0J}J}8~$K%9%-%C%W$9$k!#(B
|
811
|
+
(result (save-excursion
|
812
|
+
(skip-chars-backward skip-chars (and (< pos (point)) pos))))
|
813
|
+
(limit-point 0))
|
814
|
+
|
815
|
+
(if auto-fill-function
|
816
|
+
;; auto-fill-mode$B$,M-8z$N;~(B
|
817
|
+
(progn
|
818
|
+
(save-excursion
|
819
|
+
(backward-paragraph)
|
820
|
+
(when (< 1 (point))
|
821
|
+
(forward-line 1))
|
822
|
+
(goto-char (point-at-bol))
|
823
|
+
(let (
|
824
|
+
(start-point (point)))
|
825
|
+
(setq limit-point
|
826
|
+
(+
|
827
|
+
start-point
|
828
|
+
(skip-chars-forward (concat "\t " sekka-stop-chars) (point-at-eol))))))
|
829
|
+
|
830
|
+
;; (sekka-debug-print (format "(point) = %d result = %d limit-point = %d\n" (point) result limit-point))
|
831
|
+
;; (sekka-debug-print (format "a = %d b = %d \n" (+ (point) result) limit-point))
|
832
|
+
|
833
|
+
;; $B%Q%i%0%i%U0LCV$G%9%H%C%W$9$k(B
|
834
|
+
(if (< (+ (point) result) limit-point)
|
835
|
+
(-
|
836
|
+
limit-point
|
837
|
+
(point))
|
838
|
+
result))
|
839
|
+
|
840
|
+
;; auto-fill-mode$B$,L58z$N;~(B
|
841
|
+
(progn
|
842
|
+
(save-excursion
|
843
|
+
(goto-char (point-at-bol))
|
844
|
+
(let (
|
845
|
+
(start-point (point)))
|
846
|
+
(setq limit-point
|
847
|
+
(+
|
848
|
+
start-point
|
849
|
+
(skip-chars-forward (concat "\t " sekka-stop-chars) (point-at-eol))))))
|
850
|
+
|
851
|
+
;; (sekka-debug-print (format "(point) = %d result = %d limit-point = %d\n" (point) result limit-point))
|
852
|
+
;; (sekka-debug-print (format "a = %d b = %d \n" (+ (point) result) limit-point))
|
853
|
+
|
854
|
+
(if (< (+ (point) result) limit-point)
|
855
|
+
;; $B%$%s%G%s%H0LCV$G%9%H%C%W$9$k!#(B
|
856
|
+
(-
|
857
|
+
limit-point
|
858
|
+
(point))
|
859
|
+
result)))))
|
860
|
+
|
861
|
+
|
862
|
+
;;;
|
863
|
+
;;; with viper
|
864
|
+
;;;
|
865
|
+
;; code from skk-viper.el
|
866
|
+
(defun sekka-viper-normalize-map ()
|
867
|
+
(let ((other-buffer
|
868
|
+
(if (featurep 'xemacs)
|
869
|
+
(local-variable-p 'minor-mode-map-alist nil t)
|
870
|
+
(local-variable-if-set-p 'minor-mode-map-alist))))
|
871
|
+
;; for current buffer and buffers to be created in the future.
|
872
|
+
;; substantially the same job as viper-harness-minor-mode does.
|
873
|
+
(viper-normalize-minor-mode-map-alist)
|
874
|
+
(setq-default minor-mode-map-alist minor-mode-map-alist)
|
875
|
+
(when other-buffer
|
876
|
+
;; for buffers which are already created and have
|
877
|
+
;; the minor-mode-map-alist localized by Viper.
|
878
|
+
(dolist (buf (buffer-list))
|
879
|
+
(with-current-buffer buf
|
880
|
+
(unless (assq 'sekka-mode minor-mode-map-alist)
|
881
|
+
(setq minor-mode-map-alist
|
882
|
+
(append (list (cons 'sekka-mode sekka-mode-map)
|
883
|
+
(cons 'sekka-select-mode
|
884
|
+
sekka-select-mode-map))
|
885
|
+
minor-mode-map-alist)))
|
886
|
+
(viper-normalize-minor-mode-map-alist))))))
|
887
|
+
|
888
|
+
(defun sekka-viper-init-function ()
|
889
|
+
(sekka-viper-normalize-map)
|
890
|
+
(remove-hook 'sekka-mode-hook 'sekka-viper-init-function))
|
891
|
+
|
892
|
+
(defun sekka-sticky-shift-init-function ()
|
893
|
+
;; sticky-shift
|
894
|
+
(define-key global-map sticky-key sticky-map)
|
895
|
+
(mapcar (lambda (pair)
|
896
|
+
(define-key sticky-map (car pair)
|
897
|
+
`(lambda()(interactive)
|
898
|
+
(if ,(< 0 (length (cdr pair)))
|
899
|
+
(setq unread-command-events
|
900
|
+
(cons ,(string-to-char (cdr pair)) unread-command-events))
|
901
|
+
nil))))
|
902
|
+
sticky-list)
|
903
|
+
(define-key sticky-map sticky-key '(lambda ()(interactive)(insert sticky-key))))
|
904
|
+
|
905
|
+
(defun sekka-realtime-guide ()
|
906
|
+
"$B%j%"%k%?%$%`$GJQ49Cf$N%,%$%I$r=P$9(B
|
907
|
+
sekka-mode$B$,(BON$B$N4VCf8F$S=P$5$l$k2DG=@-$,$"$k!#(B"
|
908
|
+
(cond
|
909
|
+
((or (null sekka-mode)
|
910
|
+
(> 1 sekka-timer-rest))
|
911
|
+
(cancel-timer sekka-timer)
|
912
|
+
(setq sekka-timer nil)
|
913
|
+
(delete-overlay sekka-guide-overlay))
|
914
|
+
(sekka-guide-overlay
|
915
|
+
;; $B;D$j2s?t$N%G%/%j%a%s%H(B
|
916
|
+
(setq sekka-timer-rest (- sekka-timer-rest 1))
|
917
|
+
|
918
|
+
;; $B%+!<%=%k$,(Bsekka-realtime-guide-limit-lines $B$r$O$_=P$7$F$$$J$$$+%A%'%C%/(B
|
919
|
+
(sekka-debug-print (format "sekka-last-lineno [%d] : current-line" sekka-last-lineno (line-number-at-pos (point))))
|
920
|
+
(when (< 0 sekka-realtime-guide-limit-lines)
|
921
|
+
(let ((diff-lines (abs (- (line-number-at-pos (point)) sekka-last-lineno))))
|
922
|
+
(when (<= sekka-realtime-guide-limit-lines diff-lines)
|
923
|
+
(setq sekka-timer-rest 0))))
|
924
|
+
|
925
|
+
(let* (
|
926
|
+
(end (point))
|
927
|
+
(gap (sekka-skip-chars-backward)))
|
928
|
+
(if
|
929
|
+
(or
|
930
|
+
(when (fboundp 'minibufferp)
|
931
|
+
(minibufferp))
|
932
|
+
(= gap 0))
|
933
|
+
;; $B>e2<%9%Z!<%9$,L5$$(B $B$^$?$O(B $BJQ49BP>]$,L5$7$J$i%,%$%I$OI=<($7$J$$!#(B
|
934
|
+
(overlay-put sekka-guide-overlay 'before-string "")
|
935
|
+
;; $B0UL#$N$"$kF~NO$,8+$D$+$C$?$N$G%,%$%I$rI=<($9$k!#(B
|
936
|
+
(let* (
|
937
|
+
(b (+ end gap))
|
938
|
+
(e end)
|
939
|
+
(str (buffer-substring-no-properties b e))
|
940
|
+
(lst (if (string-match "^[\s\t]+$" str)
|
941
|
+
'()
|
942
|
+
(if (string= str sekka-guide-lastquery)
|
943
|
+
sekka-guide-lastresult
|
944
|
+
(progn
|
945
|
+
(setq sekka-guide-lastquery str)
|
946
|
+
(setq sekka-guide-lastresult (sekka-henkan-request str 1))
|
947
|
+
sekka-guide-lastresult))))
|
948
|
+
(mess
|
949
|
+
(if (< 0 (length lst))
|
950
|
+
(concat "[" (caar lst) "]")
|
951
|
+
"")))
|
952
|
+
(sekka-debug-print (format "realtime guide [%s]" str))
|
953
|
+
(move-overlay sekka-guide-overlay
|
954
|
+
;; disp-point (min (point-max) (+ disp-point 1))
|
955
|
+
b e
|
956
|
+
(current-buffer))
|
957
|
+
(overlay-put sekka-guide-overlay 'before-string mess))))
|
958
|
+
(overlay-put sekka-guide-overlay 'face 'sekka-guide-face))))
|
959
|
+
|
960
|
+
|
961
|
+
;;;
|
962
|
+
;;; human interface
|
963
|
+
;;;
|
964
|
+
(define-key sekka-mode-map sekka-rK-trans-key 'sekka-rK-trans)
|
965
|
+
(define-key sekka-mode-map "\M-j" 'sekka-capitalize-trans)
|
966
|
+
(or (assq 'sekka-mode minor-mode-map-alist)
|
967
|
+
(setq minor-mode-map-alist
|
968
|
+
(append (list
|
969
|
+
(cons 'sekka-mode sekka-mode-map))
|
970
|
+
minor-mode-map-alist)))
|
971
|
+
|
972
|
+
|
973
|
+
|
974
|
+
;; sekka-mode $B$N>uBVJQ994X?t(B
|
975
|
+
;; $B@5$N0z?t$N>l9g!">o$K(B sekka-mode $B$r3+;O$9$k(B
|
976
|
+
;; {$BIi(B,0}$B$N0z?t$N>l9g!">o$K(B sekka-mode $B$r=*N;$9$k(B
|
977
|
+
;; $B0z?tL5$7$N>l9g!"(Bsekka-mode $B$r%H%0%k$9$k(B
|
978
|
+
|
979
|
+
;; buffer $BKh$K(B sekka-mode $B$rJQ99$9$k(B
|
980
|
+
(defun sekka-mode (&optional arg)
|
981
|
+
"Sekka mode $B$O(B $B%m!<%^;z$+$iD>@\4A;zJQ49$9$k$?$a$N(B minor mode $B$G$9!#(B
|
982
|
+
$B0z?t$K@5?t$r;XDj$7$?>l9g$O!"(BSekka mode $B$rM-8z$K$7$^$9!#(B
|
983
|
+
|
984
|
+
Sekka $B%b!<%I$,M-8z$K$J$C$F$$$k>l9g(B \\<sekka-mode-map>\\[sekka-rK-trans] $B$G(B
|
985
|
+
point $B$+$i9TF,J}8~$KF1<o$NJ8;zNs$,B3$/4V$r4A;zJQ49$7$^$9!#(B
|
986
|
+
|
987
|
+
$BF1<o$NJ8;zNs$H$O0J2<$N$b$N$r;X$7$^$9!#(B
|
988
|
+
$B!&H>3Q%+%?%+%J$H(Bsekka-stop-chars $B$K;XDj$7$?J8;z$r=|$/H>3QJ8;z(B
|
989
|
+
$B!&4A;z$r=|$/A43QJ8;z(B"
|
990
|
+
(interactive "P")
|
991
|
+
(sekka-mode-internal arg nil))
|
992
|
+
|
993
|
+
;; $BA4%P%C%U%!$G(B sekka-mode $B$rJQ99$9$k(B
|
994
|
+
(defun global-sekka-mode (&optional arg)
|
995
|
+
"Sekka mode $B$O(B $B%m!<%^;z$+$iD>@\4A;zJQ49$9$k$?$a$N(B minor mode $B$G$9!#(B
|
996
|
+
$B0z?t$K@5?t$r;XDj$7$?>l9g$O!"(BSekka mode $B$rM-8z$K$7$^$9!#(B
|
997
|
+
|
998
|
+
Sekka $B%b!<%I$,M-8z$K$J$C$F$$$k>l9g(B \\<sekka-mode-map>\\[sekka-rK-trans] $B$G(B
|
999
|
+
point $B$+$i9TF,J}8~$KF1<o$NJ8;zNs$,B3$/4V$r4A;zJQ49$7$^$9!#(B
|
1000
|
+
|
1001
|
+
$BF1<o$NJ8;zNs$H$O0J2<$N$b$N$r;X$7$^$9!#(B
|
1002
|
+
$B!&H>3Q%+%?%+%J$H(Bsekka-stop-chars $B$K;XDj$7$?J8;z$r=|$/H>3QJ8;z(B
|
1003
|
+
$B!&4A;z$r=|$/A43QJ8;z(B"
|
1004
|
+
(interactive "P")
|
1005
|
+
(sekka-mode-internal arg t))
|
1006
|
+
|
1007
|
+
|
1008
|
+
;; sekka-mode $B$rJQ99$9$k6&DL4X?t(B
|
1009
|
+
(defun sekka-mode-internal (arg global)
|
1010
|
+
(or (local-variable-p 'sekka-mode (current-buffer))
|
1011
|
+
(make-local-variable 'sekka-mode))
|
1012
|
+
(if global
|
1013
|
+
(progn
|
1014
|
+
(setq-default sekka-mode (if (null arg) (not sekka-mode)
|
1015
|
+
(> (prefix-numeric-value arg) 0)))
|
1016
|
+
(sekka-kill-sekka-mode))
|
1017
|
+
(setq sekka-mode (if (null arg) (not sekka-mode)
|
1018
|
+
(> (prefix-numeric-value arg) 0))))
|
1019
|
+
(when sekka-use-viper
|
1020
|
+
(add-hook 'sekka-mode-hook 'sekka-viper-init-function))
|
1021
|
+
(when sekka-sticky-shift
|
1022
|
+
(add-hook 'sekka-mode-hook 'sekka-sticky-shift-init-function))
|
1023
|
+
(when sekka-mode (run-hooks 'sekka-mode-hook)))
|
1024
|
+
|
1025
|
+
|
1026
|
+
;; buffer local $B$J(B sekka-mode $B$r:o=|$9$k4X?t(B
|
1027
|
+
(defun sekka-kill-sekka-mode ()
|
1028
|
+
(let ((buf (buffer-list)))
|
1029
|
+
(while buf
|
1030
|
+
(set-buffer (car buf))
|
1031
|
+
(kill-local-variable 'sekka-mode)
|
1032
|
+
(setq buf (cdr buf)))))
|
1033
|
+
|
1034
|
+
|
1035
|
+
;; $BA4%P%C%U%!$G(B sekka-input-mode $B$rJQ99$9$k(B
|
1036
|
+
(defun sekka-input-mode (&optional arg)
|
1037
|
+
"$BF~NO%b!<%IJQ99(B"
|
1038
|
+
(interactive "P")
|
1039
|
+
(if (< 0 arg)
|
1040
|
+
(progn
|
1041
|
+
(setq inactivate-current-input-method-function 'sekka-inactivate)
|
1042
|
+
(setq sekka-mode t))
|
1043
|
+
(setq inactivate-current-input-method-function nil)
|
1044
|
+
(setq sekka-mode nil)))
|
1045
|
+
|
1046
|
+
|
1047
|
+
;; input method $BBP1~(B
|
1048
|
+
(defun sekka-activate (&rest arg)
|
1049
|
+
(sekka-input-mode 1))
|
1050
|
+
(defun sekka-inactivate (&rest arg)
|
1051
|
+
(sekka-input-mode -1))
|
1052
|
+
(register-input-method
|
1053
|
+
"japanese-sekka" "Japanese" 'sekka-activate
|
1054
|
+
"" "Roman -> Kanji&Kana"
|
1055
|
+
nil)
|
1056
|
+
|
1057
|
+
;; input-method $B$H$7$FEPO?$9$k!#(B
|
1058
|
+
(set-language-info "Japanese" 'input-method "japanese-sekka")
|
1059
|
+
(setq default-input-method "japanese-sekka")
|
1060
|
+
|
1061
|
+
(defconst sekka-version
|
1062
|
+
" 0.8.0 " ;;VERSION;;
|
1063
|
+
)
|
1064
|
+
(defun sekka-version (&optional arg)
|
1065
|
+
"$BF~NO%b!<%IJQ99(B"
|
1066
|
+
(interactive "P")
|
1067
|
+
(message sekka-version))
|
1068
|
+
|
1069
|
+
(provide 'sekka)
|