-
Notifications
You must be signed in to change notification settings - Fork 4
/
paw-jlpt.el
122 lines (106 loc) · 5.22 KB
/
paw-jlpt.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
;;; paw-jlpt.el -*- lexical-binding: t; -*-
(require 'paw-vars)
(defvar paw-jlpt-program (concat (file-name-directory load-file-name) "paw-jlpt.py")
"Path to jlpt program.")
(defcustom paw-jlpt-db (concat (file-name-directory load-file-name) "japanese.db")
"Path to jplt database. Made by
git clone https://github.com/chenyanming/yomichan-jlpt-vocab
cd yomichan-jlpt-vocab
python make_dictionary_db.py"
:type 'string
:group 'paw-jlpt)
(defcustom paw-jlpt-wordlist-files nil
"Path to wordlist files. Words inside the wordlist files will
be searched by jlpt. Set
`paw-annotation-show-wordlists-words-p' to t, and use your own
wordlist files."
:type 'string
:group 'paw-jlpt)
(defcustom paw-jlpt-wordlist-tags ""
"Tags for wordlist files, currently it is empty.")
(defcustom paw-jlpt-default-known-words-file nil
"Default file for known words, when you delete unknown words, it will be save the here.")
(defcustom paw-jlpt-known-words-files nil
"Path to the known words, known words will be skipped by jlpt.
If csv, the first column is the word, and comma or tab seperated.
For other file types, one word one line."
:type 'string
:group 'paw-jlpt)
(defcustom paw-jlpt-tags "n5 n4 n3 n2 n1"
"Tags for querying japanese words, set it part of: 'n5 n4 n3 n2 n1'.")
(defvar paw-jlpt-running-process nil)
(defun paw-jlpt-kill-process ()
(interactive)
(when (process-live-p paw-jlpt-running-process )
(kill-process paw-jlpt-running-process)
(setq paw-jlpt-running-process nil)))
(defvar paw-jlpt-csv-running-process nil)
(defun paw-jlpt-csv-kill-process ()
(interactive)
(when (process-live-p paw-jlpt-csv-running-process )
(kill-process paw-jlpt-csv-running-process)
(setq paw-jlpt-csv-running-process nil)))
(defun paw-jlpt-process-filter (proc string)
"Accumulates the strings received from the ECDICT process."
(when (buffer-live-p (process-buffer proc))
(with-current-buffer (process-buffer proc)
(insert string)) ))
(defun paw-jlpt-db-command (string sentinel &optional search-type)
"Segments a STRING of Japanese text using paw-jlpt.py and logs the result asynchronously."
(paw-jlpt-kill-process)
(let* ((original-output-buffer (get-buffer "*paw-jlpt-output*"))
(output-buffer (if (buffer-live-p original-output-buffer)
(progn (kill-buffer original-output-buffer)
(get-buffer-create "*paw-jlpt-output*") )
(get-buffer-create "*paw-jlpt-output*") ))
(paw-jlpt-process (make-process
:name "JLPT"
:buffer output-buffer
:noquery t
:command `(,paw-python-program
,paw-jlpt-program
,paw-jlpt-db
,search-type
,string
,paw-jlpt-tags
""
,(if paw-jlpt-known-words-files
(mapconcat #'identity paw-jlpt-known-words-files ",")
""))
:filter 'paw-jlpt-process-filter
:sentinel sentinel)))
(setq paw-jlpt-running-process paw-jlpt-process)
(with-current-buffer output-buffer
(setq-local original-string string))
(process-send-eof paw-jlpt-process)))
(defun paw-jlpt-csv-command (string sentinel &optional search-type)
"Segments a STRING of Japanese text using paw-jlpt.py and logs the result asynchronously."
(paw-jlpt-csv-kill-process)
(let* ((original-output-buffer (get-buffer "*paw-jlpt-csv-output*"))
(output-buffer (if (buffer-live-p original-output-buffer)
(progn (kill-buffer original-output-buffer)
(get-buffer-create "*paw-jlpt-csv-output*") )
(get-buffer-create "*paw-jlpt-csv-output*") ))
(paw-jlpt-process (make-process
:name "JLPT-CSV"
:buffer output-buffer
:noquery t
:command `(,paw-python-program
,paw-jlpt-program
,paw-jlpt-db
,search-type
,string
,paw-jlpt-wordlist-tags
,(if (= (length paw-jlpt-wordlist-files) 1)
(car paw-jlpt-wordlist-files)
(mapconcat #'identity paw-jlpt-wordlist-files ","))
,(if paw-jlpt-known-words-files
(mapconcat #'identity paw-jlpt-known-words-files ",")
""))
:filter 'paw-jlpt-process-filter
:sentinel sentinel)))
(setq paw-jlpt-csv-running-process paw-jlpt-process)
(with-current-buffer output-buffer
(setq-local original-string string))
(process-send-eof paw-jlpt-process)))
(provide 'paw-jlpt)