-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpaw-focus.el
613 lines (561 loc) · 29.4 KB
/
paw-focus.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
;;; paw-focus.el -*- lexical-binding: t; -*-
(require 'paw-vars)
(require 'paw-kagome)
(require 'paw-ecdict)
(require 'paw-jlpt)
(require 'paw-jieba)
(require 'paw-hsk)
(require 'paw-note)
(require 'paw-org)
(require 'paw-svg)
(require 'focus)
(defun paw-focus-find-current-thing()
(interactive)
(cond ((get-char-property (point) 'paw-entry)
(paw-view-note))
(t (let* ((thing (or paw-note-word
(if mark-active
(buffer-substring-no-properties (region-beginning) (region-end))
(if focus-mode
(buffer-substring-no-properties (car (focus-bounds)) (cdr (focus-bounds)))
(paw-get-sentence-or-line))) ))
(lang_word (paw-remove-spaces-based-on-ascii-rate-return-cons thing))
(lang (car lang_word))
(new-thing (cdr lang_word)))
(paw-view-note (paw-new-entry new-thing :lang lang))))))
(defun paw-focus-find-current-thing-with-mouse(event)
(interactive "e")
(let ((window (posn-window (event-end event)))
(pos (posn-point (event-end event))))
(if (not (windowp window))
(error "No URL chosen"))
(with-current-buffer (window-buffer window)
(goto-char pos)
(paw-focus-find-current-thing))))
(defun paw-focus-find-current-thing-segment-with-mouse(event)
(interactive "e")
(let ((window (posn-window (event-end event)))
(pos (posn-point (event-end event))))
(if (not (windowp window))
(error "No URL chosen"))
(with-current-buffer (window-buffer window)
(goto-char pos)
(paw-focus-find-current-thing-segment))))
(defun paw-focus-find-current-thing-segment(&optional thing)
(interactive)
(let* ((thing (or thing
(paw-note-word)
(if mark-active
(buffer-substring-no-properties (region-beginning) (region-end))
(if focus-mode
(let ((focus-thing (buffer-substring-no-properties (car (focus-bounds)) (cdr (focus-bounds)))))
;; remove org links
(when (string-match "\\[\\[.*?\\]\\[.*?\\]\\]" focus-thing)
(setq focus-thing (replace-match "" nil nil focus-thing)))
focus-thing)
(paw-get-sentence-or-line)))))
(lang_word (paw-remove-spaces-based-on-ascii-rate-return-cons thing))
(lang (car lang_word))
(new-thing (cdr lang_word))
(paw-view-note-show-type 'buffer))
;; ;; delete the overlay, focus mode does not not need click overlay
;; (if paw-click-overlay
;; (delete-overlay paw-click-overlay) )
;; deactivate mark indicating it is processing
(when mark-active
(paw-click-show (region-beginning) (region-end) 'paw-focus-face)
(deactivate-mark))
;; (format "Analysing %s..." new-thing)
(cond ((string= lang "en")
(paw-view-note (paw-new-entry new-thing :lang "en")
:no-pushp t ;; for better performance
:kagome (lambda(word _buffer) ;; FIXME buffer is not used
(paw-ecdict-db-command word 'paw-focus-view-note-process-sentinel-english "SENTENCE"))))
((string= lang "ja")
(paw-view-note (paw-new-entry new-thing :lang "ja")
:no-pushp t ;; for better performance
:kagome (lambda(word _buffer) ;; FIXME buffer is not used
(paw-kagome-command word 'paw-focus-view-note-process-sentinel-japanese))))
;; fallbck to normal `paw-view-note'
(t (paw-view-note (paw-new-entry new-thing :lang lang))))))
(defcustom paw-focus-buffer-max-size 40000
"The maximum size of the buffer to be processed by
`paw-focus-find-words'. If the buffer size is larger than
this value, the buffer will be saved to a temporary file and
processed by `paw-focus-find-words' with the file name as
the argument."
:type 'integer
:group 'paw)
(defcustom paw-focus-buffer-file-name "paw-focus-buffer-file"
"The file name to save the buffer to be processed by
`paw-focus-find-words'."
:type 'string
:group 'paw)
(define-obsolete-variable-alias 'paw-focus-find-unknown-words
'paw-focus-find-words "paw 1.1.0")
(defun paw-focus-find-words(&rest args)
(interactive)
(let* ((wordlist (plist-get args :wordlist))
(buffer (current-buffer))
(thing (or (plist-get args :thing)
paw-note-word
(if mark-active
(buffer-substring-no-properties (region-beginning) (region-end))
(if focus-mode
(let ((focus-thing (buffer-substring-no-properties (car (focus-bounds)) (cdr (focus-bounds)))))
;; remove org links
(when (string-match "\\[\\[.*?\\]\\[.*?\\]\\]" focus-thing)
(setq focus-thing (replace-match "" nil nil focus-thing)))
focus-thing)
(if (and (buffer-file-name) (not (string= (file-name-extension (buffer-file-name)) "epub")))
;; if a file, send a filename to python to processed
;; directly, so that we can handle very big file
buffer-file-name
(if (> (buffer-size) paw-focus-buffer-max-size)
(with-temp-file (expand-file-name paw-focus-buffer-file-name temporary-file-directory)
(insert (with-current-buffer buffer (buffer-string)))
(expand-file-name paw-focus-buffer-file-name temporary-file-directory))
(buffer-string))
)))))
(lang_word (paw-remove-spaces-based-on-ascii-rate-return-cons thing))
(lang (car lang_word))
(new-thing (cdr lang_word)))
;; delete the click overlay
(if paw-click-overlay
(delete-overlay paw-click-overlay) )
;; deactivate mark indicating it is processing
(if mark-active
(deactivate-mark))
;; (format "Analysing %s..." new-thing)
(cond (wordlist
(pcase lang
("en" (paw-ecdict-csv-command new-thing 'paw-focus-find-wordlist-words-sentinel-english "MATCH"))
("ja" (paw-jlpt-csv-command new-thing 'paw-focus-find-wordlist-words-sentinel-japanese "MATCH"))
(_ (message "Unsupported language %s" lang))))
((string= lang "en")
(paw-ecdict-db-command new-thing 'paw-focus-find-unknown-words-sentinel-english "SENTENCE"))
((string= lang "ja")
(paw-jlpt-db-command new-thing 'paw-focus-find-unknown-words-sentinel-japanese "SENTENCE"))
(t (message "Unsupported language %s" lang)))))
(defun paw-focus-find-next-thing-segment()
(interactive)
(call-interactively 'paw-focus-next-thing)
(call-interactively 'paw-focus-find-current-thing-segment))
(defun paw-focus-next-thing (&optional n)
"Move the point to the middle of the Nth next thing without `recenter.'"
(interactive "p")
(let ((current-bounds (focus-bounds))
(thing (focus-get-thing)))
(forward-thing thing n)
(when (equal current-bounds (focus-bounds))
(forward-thing thing (cl-signum n)))
(let ((bounds (focus-bounds)))
(when bounds
(goto-char (/ (+ (car bounds) (cdr bounds)) 2))))))
(defun paw-focus-prev-thing (&optional n)
"Move the point to the middle of the Nth previous thing."
(interactive "p")
(paw-focus-next-thing (- n)))
(defun paw-focus-find-prev-thing-segment()
(interactive)
(call-interactively 'paw-focus-prev-thing)
(call-interactively 'paw-focus-find-current-thing-segment))
(defun paw-focus-find-current-thing-segment-japanese()
(interactive)
(if (get-char-property (point) 'paw-entry)
(paw-view-note)
(paw-kagome-command
(if mark-active
(paw-remove-spaces-based-on-ascii-rate (buffer-substring-no-properties (region-beginning) (region-end)) )
(if focus-mode
(paw-remove-spaces-based-on-ascii-rate (buffer-substring-no-properties (car (focus-bounds)) (cdr (focus-bounds))) )
(paw-remove-spaces-based-on-ascii-rate (thing-at-point 'sentence t) )))
'paw-focus-view-note-process-sentinel-japanese) ))
(defun paw-focus-find-next-thing-segment-japanese()
(interactive)
(call-interactively 'focus-next-thing)
(paw-kagome-command
(if mark-active
(paw-remove-spaces-based-on-ascii-rate (buffer-substring-no-properties (region-beginning) (region-end)) )
(if focus-mode
(paw-remove-spaces-based-on-ascii-rate (buffer-substring-no-properties (car (focus-bounds)) (cdr (focus-bounds))) )
(paw-remove-spaces-based-on-ascii-rate (thing-at-point 'sentence t) )))
'paw-focus-view-note-process-sentinel-japanese))
(defun paw-focus-find-prev-thing-segment-japanese()
(interactive)
(call-interactively 'focus-prev-thing)
(paw-kagome-command
(if mark-active
(paw-remove-spaces-based-on-ascii-rate (buffer-substring-no-properties (region-beginning) (region-end)) )
(if focus-mode
(paw-remove-spaces-based-on-ascii-rate (buffer-substring-no-properties (car (focus-bounds)) (cdr (focus-bounds))) )
(paw-remove-spaces-based-on-ascii-rate (thing-at-point 'sentence t) )))
'paw-focus-view-note-process-sentinel-japanese))
(defun paw-focus-view-note-process-sentinel-japanese (proc _event)
"Handles the Kagome process termination event."
(when (eq (process-status proc) 'exit)
(let* ((json-object-type 'plist)
(json-array-type 'list)
(buffer-content (with-current-buffer (process-buffer proc)
(buffer-string)))
(json-responses (json-read-from-string buffer-content))
(segmented-text (mapconcat
(lambda (resp) (plist-get resp :surface))
json-responses
" "))
candidates)
(with-current-buffer (get-buffer paw-view-note-buffer-name)
(let ((buffer-read-only nil))
(search-forward "** Meaning" nil t)
(org-mark-subtree)
(forward-line)
(delete-region (region-beginning) (region-end))
(dolist (resp json-responses candidates)
(let* ((start (plist-get resp :start))
(end (plist-get resp :end))
(surface (plist-get resp :surface))
(cls (plist-get resp :class)) ;; 'class' is a built-in function
(pos (plist-get resp :pos))
(base-form (plist-get resp :base_form))
(reading (plist-get resp :reading))
(pronunciation (plist-get resp :pronunciation))
(features (plist-get resp :features))
(entry (paw-candidate-by-word surface))) ; features just a combination of other fields
(when (string= cls "KNOWN")
(insert (format "*** [[paw:%s][%s]] %s " surface surface pos))
(insert (paw-play-button
(lambda ()
(interactive)
(funcall paw-default-say-word-function surface
:lang "ja"))) " ")
(insert (paw-play-source-button
(lambda ()
(interactive)
(funcall paw-default-say-word-function surface
:lang "ja"
:source t))) " ")
(if entry
(progn
(insert (paw-edit-button
(lambda ()
(interactive)
(funcall 'paw-find-note (car (paw-candidate-by-word surface) )))) " ")
(insert (paw-delete-button
(lambda ()
(interactive)
(funcall 'paw-delete-word (car (paw-candidate-by-word surface) )))) " ")
)
(insert (paw-add-button
(lambda ()
(interactive)
(if paw-add-button-online-p
(funcall-interactively 'paw-add-online-word surface segmented-text)
(funcall-interactively 'paw-add-offline-word surface segmented-text)))) " ")
)
(insert (paw-goldendict-button (lambda ()
(interactive)
(funcall paw-external-dictionary-function surface))) "\n")
;; (insert "#+BEGIN_SRC\n")
(insert (format "base_form: %s, reading: %s, pronunciation: %s\n"
base-form reading pronunciation) )
;; (insert "#+BEGIN_SRC sh\n"
;; (shell-command-to-string (format "myougiden --human %s" surface))
;; "#+END_SRC\n\n"
;; )
;; (insert "#+END_SRC\n\n")
)
(if entry (push (car entry) candidates))))
(paw-show-all-annotations candidates)
(deactivate-mark)
(goto-char (point-min))
(unless (search-forward "** Dictionaries" nil t)
(search-forward "** Translation" nil t))
(beginning-of-line))
)
;; TODO back to original window, but unsafe
;; (other-window 1)
)))
(defun paw-focus-find-current-thing-segment-english()
(interactive)
(if (get-char-property (point) 'paw-entry)
(paw-view-note)
(paw-ecdict-db-command
(if mark-active
(paw-remove-spaces-based-on-ascii-rate (buffer-substring-no-properties (region-beginning) (region-end)) )
(if focus-mode
(paw-remove-spaces-based-on-ascii-rate (buffer-substring-no-properties (car (focus-bounds)) (cdr (focus-bounds))) )
(paw-remove-spaces-based-on-ascii-rate (thing-at-point 'sentence t) )))
'paw-focus-view-note-process-sentinel-english) ))
(defun paw-focus-view-note-process-sentinel-english (proc _event)
"Handles the english process termination event."
(when (eq (process-status proc) 'exit)
(let* ((json-object-type 'plist)
(json-array-type 'list)
(original-string (with-current-buffer (process-buffer proc)
original-string))
(buffer-content (with-current-buffer (process-buffer proc)
(buffer-string)))
(json-responses (json-parse-string buffer-content :object-type 'plist :array-type 'list :null-object nil))
(segmented-text (mapconcat
(lambda (resp) (plist-get resp :word))
json-responses
" "))
candidates)
(with-current-buffer (get-buffer paw-view-note-buffer-name)
(let ((buffer-read-only nil))
(goto-char (point-min))
(org-entry-put nil "METADATA"
(format "Total %s; tags:%s; oxford:%s; collins:%s; bnc:%s frq:%s"
(length json-responses)
paw-ecdict-tags
(number-to-string paw-ecdict-oxford)
(number-to-string paw-ecdict-collins-max-level)
(number-to-string paw-ecdict-bnc)
(number-to-string paw-ecdict-frq)))
(search-forward "** Meaning" nil t)
(org-mark-subtree)
(forward-line)
(delete-region (region-beginning) (region-end))
(dolist (resp json-responses candidates)
(let* ((id (plist-get resp :id))
(word (plist-get resp :word))
(sw (plist-get resp :sw))
(phonetic (plist-get resp :phonetic))
(definition (plist-get resp :definition))
(translation (plist-get resp :translation))
(pos (plist-get resp :pos))
(collins (plist-get resp :collins))
(oxford (plist-get resp :oxford))
(tag (plist-get resp :tag))
(bnc (plist-get resp :bnc))
(frq (plist-get resp :frq))
(exchange (plist-get resp :exchange))
(detail (plist-get resp :detail))
(audio (plist-get resp :audio))
(entry (paw-candidate-by-word word))) ; features just a combination of other fields
(when (not (string= word "nil"))
(insert (format "*** [[paw:%s][%s]] " word word))
(insert (paw-play-button
(lambda ()
(interactive)
(funcall paw-default-say-word-function word
:lang "en"))) " ")
(insert (paw-play-source-button
(lambda ()
(interactive)
(funcall paw-default-say-word-function word
:lang "en"
:source t))) " ")
(if entry
(progn
(insert (paw-edit-button (lambda ()
(interactive)
(funcall 'paw-find-note (car (paw-candidate-by-word word) )))) " ")
(insert (paw-delete-button (lambda ()
(interactive)
(funcall 'paw-delete-word (car (paw-candidate-by-word word) )))) " "))
(insert (paw-add-button (lambda ()
(interactive)
(if paw-add-button-online-p
(funcall-interactively 'paw-add-online-word word original-string)
(funcall-interactively 'paw-add-offline-word word original-string) ))) " "))
(insert (paw-goldendict-button (lambda ()
(interactive)
(funcall paw-external-dictionary-function word))) "\n")
(let ((bg-color paw-view-note-background-color))
(paw-insert-and-make-overlay
(paw-ecdict-format-string phonetic translation definition collins oxford tag bnc frq exchange "\n")
'face `(:background ,bg-color :extend t))
(insert "\n"))
(insert "\n")
(if entry (push (car entry) candidates) ))))
;; (paw-show-all-annotations candidates)
(deactivate-mark)
(goto-char (point-min))
(unless (search-forward "** Dictionaries" nil t)
(search-forward "** Translation" nil t))
(beginning-of-line)))
;; TODO back to original window, but unsafe
;; (other-window 1)
)))
(defun paw-focus-find-unknown-words-sentinel-english (proc _event)
"Handles the english process termination event."
(when (eq (process-status proc) 'exit)
(let* ((json-object-type 'plist)
(json-array-type 'list)
(original-string (with-current-buffer (process-buffer proc)
original-string))
(buffer-content (with-current-buffer (process-buffer proc)
(buffer-string)))
(json-responses (json-parse-string buffer-content :object-type 'plist :array-type 'list :null-object nil))
candidates
order)
(setq order 1)
(dolist (resp json-responses candidates)
(setq order (+ order 1))
(let* ((id (plist-get resp :id))
(word (plist-get resp :word))
(sw (plist-get resp :sw))
(phonetic (plist-get resp :phonetic))
(definition (plist-get resp :definition))
(translation (plist-get resp :translation))
(pos (plist-get resp :pos))
(collins (plist-get resp :collins))
(oxford (plist-get resp :oxford))
(tag (plist-get resp :tag))
(bnc (plist-get resp :bnc))
(frq (plist-get resp :frq))
(exchange (plist-get resp :exchange))
(detail (plist-get resp :detail))
(audio (plist-get resp :audio))) ; features just a combination of other fields
;; skip the similar word in db
;; FIXME: this could be done in python as well
(unless (paw-check-word-exist-p word)
(push (paw-new-entry word :lang "en"
:exp (paw-ecdict-format-string phonetic translation definition collins oxford tag bnc frq exchange "\n")
;; FIXME: use created-at to store the order,
;; because new words are not in db, can not
;; compare the time with the words in db
:created-at (format-time-string "%Y-%m-%d %H:%M:%S" (time-add (current-time) (seconds-to-time order)))
:add-to-known-words t ;; so that it could be added into default known file
) candidates) )))
(with-current-buffer (current-buffer)
(paw-show-all-annotations candidates))
)))
(defun paw-focus-find-wordlist-words-sentinel-english (proc _event)
"Handles the english process termination event."
(when (eq (process-status proc) 'exit)
(let* ((json-object-type 'plist)
(json-array-type 'list)
(original-string (with-current-buffer (process-buffer proc)
original-string))
(buffer-content (with-current-buffer (process-buffer proc)
(buffer-string)))
(json-responses (json-parse-string buffer-content :object-type 'plist :array-type 'list :null-object nil))
candidates
order)
(setq order 1)
(dolist (resp json-responses candidates)
(setq order (+ order 1))
(let* ((word (plist-get resp :word))
(definition (plist-get resp :definition)))
;; skip the similar word in db
;; FIXME: this could be done in python as well
(unless (paw-check-word-exist-p word)
(if word
(push (paw-new-entry word :lang "en"
:exp (replace-regexp-in-string "\\\\n" "\n" definition)
:created-at (format-time-string "%Y-%m-%d %H:%M:%S" (time-add (current-time) (seconds-to-time order)))
:add-to-known-words t ;; so that it could be added into default known file
) candidates) ) )))
(with-current-buffer (current-buffer)
(paw-show-all-annotations candidates)))))
(defun paw-focus-find-unknown-words-sentinel-japanese (proc _event)
"Handles the japanese process termination event."
(when (eq (process-status proc) 'exit)
(let* ((json-object-type 'plist)
(json-array-type 'list)
(original-string (with-current-buffer (process-buffer proc)
original-string))
(buffer-content (with-current-buffer (process-buffer proc)
(buffer-string)))
(json-responses (json-parse-string buffer-content :object-type 'plist :array-type 'list))
candidates
order)
;; find by kanji
(setq order 1)
(dolist (resp json-responses candidates)
(setq order (+ order 1))
(when-let* ((word (plist-get resp :kanji))
(kana (plist-get resp :kana))
(origin (plist-get resp :origin))
(level (plist-get resp :level))
(wordp (not (string= word "")))
(waller_definition (plist-get resp :waller_definition))
;; (entry (paw-candidate-by-word word)) ;; check in db, if KNOWN words, would not push
) ; features just a combination of other fields
;; skip the similar word in db
;; FIXME: this could be done in python as well
(unless (paw-check-word-exist-p word)
(if (string= (alist-get 'word (car candidates)) word)
(progn
;; (message "Found multiple meanings %s" word)
(setf (alist-get 'exp (car candidates))
(format "%s\n%s[%s](%s)\n%s" (alist-get 'exp (car candidates)) kana level origin waller_definition)) )
(push (paw-new-entry word :lang "ja"
:exp (format "%s[%s](%s)\n%s" kana level origin waller_definition)
;; FIXME: use created-at to store the order,
;; because new words are not in db, can not
;; compare the time with the words in db
:created-at (format-time-string "%Y-%m-%d %H:%M:%S" (time-add (current-time) (seconds-to-time order)))
:add-to-known-words t ;; so that it could be added into default known file
) candidates)
)
))
)
;; find by kana
(dolist (resp json-responses candidates)
(setq order (+ order 1))
(when-let* ((word (plist-get resp :kana))
(kanji (plist-get resp :kanji))
(origin (plist-get resp :origin))
(level (plist-get resp :level))
(wordp (not (string= word "")))
(waller_definition (plist-get resp :waller_definition))
;; (entry (paw-candidate-by-word word)) ;; check in db, if KNOWN words, would not push
) ; features just a combination of other fields
;; skip the similar word in db
;; FIXME: this could be done in python as well
(unless (paw-check-word-exist-p word)
(if (string= (alist-get 'word (car candidates)) word)
(progn
;; (message "Found multiple meanings %s" word)
(setf (alist-get 'exp (car candidates))
(format "%s\n%s[%s](%s)\n%s" (alist-get 'exp (car candidates)) kanji level origin waller_definition)) )
(push (paw-new-entry word :lang "ja"
:exp (format "%s[%s](%s)\n%s" kanji level origin waller_definition)
;; FIXME: use created-at to store the order,
;; because new words are not in db, can not
;; compare the time with the words in db
:created-at (format-time-string "%Y-%m-%d %H:%M:%S" (time-add (current-time) (seconds-to-time order)))
:add-to-known-words t ;; so that it could be added into default known file
) candidates)))))
;; (pp candidates)
(with-current-buffer (current-buffer)
(paw-show-all-annotations candidates)))))
(defun paw-focus-find-wordlist-words-sentinel-japanese (proc _event)
"Handles the english process termination event."
(when (eq (process-status proc) 'exit)
(let* ((json-object-type 'plist)
(json-array-type 'list)
(original-string (with-current-buffer (process-buffer proc)
original-string))
(buffer-content (with-current-buffer (process-buffer proc)
(buffer-string)))
(json-responses (json-parse-string buffer-content :object-type 'plist :array-type 'list :null-object nil))
candidates
order)
(setq order 1)
(dolist (resp json-responses candidates)
(setq order (+ order 1))
(let* ((word (plist-get resp :kanji))
(waller_definition (plist-get resp :waller_definition)))
;; skip the similar word in db
;; FIXME: this could be done in python as well
(unless (paw-check-word-exist-p word)
(if (string= (alist-get 'word (car candidates)) word)
(progn
;; (message "Found multiple meanings %s" word)
(setf (alist-get 'exp (car candidates))
(format "%s" (alist-get 'exp (car candidates)) waller_definition)) )
(push (paw-new-entry word :lang "ja"
:exp (format "%s" waller_definition)
;; FIXME: use created-at to store the order,
;; because new words are not in db, can not
;; compare the time with the words in db
:created-at (format-time-string "%Y-%m-%d %H:%M:%S" (time-add (current-time) (seconds-to-time order)))
:add-to-known-words t ;; so that it could be added into default known file
) candidates)))))
(with-current-buffer (current-buffer)
(paw-show-all-annotations candidates)))))
(provide 'paw-focus)