-
Notifications
You must be signed in to change notification settings - Fork 4
/
paw.el
622 lines (575 loc) · 28 KB
/
paw.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
614
615
616
617
618
619
620
621
622
;;; paw.el -*- lexical-binding: t; -*-
;; Copyright (C) 2021 Damon Chan
;; Author: Damon Chan <[email protected]>
;; URL: https://github.com/chenyanming/paw
;; Keywords: tools
;; Created: 31 May 2021
;; Version: 1.1.1
;; Package-Requires: ((emacs "25.1") (request "0.3.3") (emacsql "3.0.0") (s "1.12.0") (dash "2.17.0") (go-translate "3.0.5") (gptel "0.8.6") (focus "1.0.1") (svg-lib "0.3") (anki-editor "0.3.3") (esxml "0.3.7"))
;; This file is NOT part of GNU Emacs.
;; This program 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 3 of the License, or
;; (at your option) any later version.
;; This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; Emacs Annotation Tool
;;; Code:
(require 'paw-vars)
(require 'paw-db)
(require 'paw-util)
(require 'paw-note)
(require 'paw-annotation)
(require 'paw-org)
(require 'paw-gptel)
(require 'paw-faces)
(require 'paw-search)
(require 'paw-request)
(require 'thingatpt)
(require 'pcase)
(require 'ido)
(require 'ivy nil t)
(require 'consult nil t)
(require 'evil-core nil t)
(require 's)
(require 'dash)
(declare-function ivy-read "ivy")
(declare-function evil-define-key* "ext:evil-core.el" t t)
(define-derived-mode paw-search-mode fundamental-mode "paw-search"
"Major mode for display word lists.
\\{paw-search-mode-map}"
(setq truncate-lines t
buffer-read-only t
header-line-format '(:eval (funcall paw-header-function)))
(buffer-disable-undo)
(require 'hl-line)
(set (make-local-variable 'hl-line-face) 'paw-search-highlight-face)
(hl-line-mode)
(add-function :before-until (local 'eldoc-documentation-function) #'paw-get-eldoc-word)
(add-hook 'minibuffer-setup-hook 'paw-search-minibuffer-setup))
(defvar paw-header-function #'paw-header)
(defvar paw-search-entries-length 0)
(defun paw-header ()
"Header function for *paw* buffer."
(format "%s%s"
(format "Annotations: %s Total: %s Page: %s/%s "
(propertize paw-db-file 'face 'font-lock-keyword-face)
(propertize (number-to-string paw-search-entries-length) 'face 'font-lock-type-face)
(propertize (number-to-string paw-search-current-page) 'face 'font-lock-type-face)
(propertize (number-to-string paw-search-pages) 'face 'font-lock-type-face))
(format "%s"
(if (equal paw-search-filter "")
""
(concat
(if paw-group-filteringp
"Group: "
"Keyword: ")
(propertize paw-search-filter 'face 'font-lock-builtin-face) )))))
(defvar paw-search-mode-map
(let ((map (make-sparse-keymap)))
;; (define-key map [mouse-1] #'paw-mouse-1)
(define-key map "/" #'paw-search-live-filter)
(define-key map "R" #'paw-search-update-buffer-and-resume)
(define-key map "r" #'paw-search-clear-filter)
(define-key map "s" #'paw-view-note-query)
(define-key map "S" #'paw-search-input)
(define-key map "v" #'paw-view-note)
(define-key map "V" #'paw-view-notes)
(define-key map "<RET>" #'paw-find-origin)
(define-key map "a" #'paw-add-word)
(define-key map "c" #'paw-change-content)
(define-key map "C" #'paw-change-note_type)
(define-key map "dd" #'paw-delete-word)
(define-key map "dn" #'paw-anki-editor-delete-note)
(define-key map "dN" #'paw-anki-editor-delete-notes)
(define-key map "dp" #'paw-delete-words-by-origin_path)
(define-key map "D" #'paw-delete-word)
(define-key map "u" #'paw-anki-editor-push-note)
(define-key map "U" #'paw-anki-editor-push-notes)
(define-key map "n" #'paw-search-next-page)
(define-key map "N" #'paw-next-word)
(define-key map "y" #'paw-copy-annotation)
(define-key map "p" #'paw-search-previous-page)
(define-key map "P" #'paw-previous-word)
(define-key map "i" #'paw-find-note)
(define-key map "I" #'paw-find-notes)
(define-key map "'" #'paw-list-groups)
(define-key map "q" #'paw-quit)
(define-key map "m" #'paw-mark-and-forward)
(define-key map "e" #'paw-anki-gui-edit-note)
(define-key map "o" #'paw-anki-gui-browse)
(define-key map (kbd "<DEL>") #'paw-unmark-and-backward)
map)
"Keymap for `paw-search-mode'.")
(if (bound-and-true-p evil-mode)
(evil-define-key* '(normal emacs) paw-search-mode-map
;; (kbd "<mouse-1>") 'paw-mouse-1
(kbd "/") 'paw-search-live-filter
(kbd "g R") 'paw-search-update-buffer-and-resume
(kbd "g r") 'paw-search-clear-filter
(kbd "s") 'paw-view-note-query
(kbd "S") 'paw-search-input
(kbd "v") 'paw-view-note
(kbd "V") 'paw-view-notes
(kbd "<RET>") 'paw-find-origin
(kbd "a") 'paw-add-word
(kbd "e") 'paw-anki-gui-edit-note
(kbd "c c") 'paw-change-content
(kbd "c n") 'paw-change-note_type
(kbd "c p") 'paw-change-origin_path
(kbd "D") 'paw-delete-word
(kbd "d n") 'paw-anki-editor-delete-note
(kbd "d N") 'paw-anki-editor-delete-notes
(kbd "d d") 'paw-delete-word
(kbd "d p") 'paw-delete-words-by-origin_path
(kbd "u") 'paw-anki-editor-push-note
(kbd "U") 'paw-anki-editor-push-notes
(kbd "y y") 'paw-org-link-copy
(kbd "y a") 'paw-copy-annotation
(kbd "y w") 'paw-copy-word
(kbd "p") 'paw-search-previous-page
(kbd "r") 'paw-view-note-play
(kbd "R") 'paw-view-note-replay
(kbd "n") 'paw-search-next-page
(kbd "i") 'paw-find-note
(kbd "I") 'paw-find-notes
(kbd "'") 'paw-list-groups
(kbd "q") 'paw-quit
(kbd "m") 'paw-mark-and-forward
(kbd "o") 'paw-anki-gui-browse
(kbd "<DEL>") 'paw-unmark-and-backward) )
;;;###autoload
(defun paw (&optional silent path)
(interactive "P")
(paw-db)
(let ((beg (point))
(pos (window-start)))
(with-current-buffer (paw-buffer)
(paw-search-update-buffer)
(paw-search-mode))
(if (eq major-mode 'paw-search-mode)
(progn
(set-window-start (selected-window) pos)
(goto-char beg))
(unless silent
(switch-to-buffer (paw-buffer))
(goto-char (point-min))))
(when path
(paw-search-update-buffer-with-keyword
(if paw-annotation-mode (paw-get-origin-path) "")))))
(defun paw-goto-dashboard (&optional entry)
(interactive)
(let* ((entry (or entry (get-char-property (point) 'paw-entry)))
(word (or paw-note-word (alist-get 'word entry) )))
(if (window-live-p (get-buffer-window "*paw*"))
(select-window (get-buffer-window "*paw*"))
(if (buffer-live-p (get-buffer "*paw*"))
(switch-to-buffer "*paw*")
(paw-search-refresh)))
(goto-char (point-min))
(while (and
(not (string= word (alist-get 'word (get-text-property (point) 'paw-entry))) )
(not (eq (point) (point-max))))
(forward-line 1))))
(defun paw-change-content ()
"Change the content filed of entry at point."
(interactive)
(let* ((entry (get-char-property (point) 'paw-entry))
(word (alist-get 'word entry))
(real-word (paw-get-real-word word) )
(content (alist-get 'content entry)))
(let ((content (read-string "Change content: " (or content real-word))))
;; update content
(paw-update-content word content)))
;; update buffer
(if (buffer-live-p (get-buffer "*paw*"))
(paw t)))
(defun paw-change-origin_point ()
"Change the origin_point filed of entry at point."
(interactive)
(let* ((origin-point (paw-get-location)))
(if (featurep 'ivy-read)
(ivy-read (format "New Location %s for: " origin-point) (paw-candidates-format nil)
:sort nil
:action (lambda (x)
(let* ((entry (get-text-property 0 'paw-entry x))
(word (alist-get 'word entry))
(old-word (paw-get-real-word entry))
(new-word (paw-get-word))
(is-same (if (equal old-word new-word)
t
(yes-or-no-p "The word at point/region is different than the annotation, still change? "))))
(when is-same
(paw-update-origin_point word origin-point)
;; delete the old overlay
(-map (lambda (b)
(with-current-buffer b
(if (eq paw-annotation-mode t)
(let ((o (cl-find-if
(lambda (o)
(equal (alist-get 'word (overlay-get o 'paw-entry)) word))
(overlays-in (point-min) (point-max)))))
(if o (delete-overlay o))))))
(buffer-list))
;; update back the origin_point to entry
(setf (alist-get 'origin_point entry) origin-point)
;; add overlay
(paw-add-annotation-overlay entry)
;; quit mark
(if (featurep 'evil)
(evil-force-normal-state))
;; update buffer
(if (buffer-live-p (get-buffer "*paw*"))
(paw t)) ))))
(let* ((entry (consult--read (paw-candidates-format nil)
:prompt (format "New Location %s for: " origin-point)
:sort nil
:lookup (lambda(_ candidates cand)
(get-text-property 0 'paw-entry (assoc cand candidates)))
))
(word (alist-get 'word entry))
(old-word (paw-get-real-word entry))
(new-word (paw-get-word))
(is-same (if (equal old-word new-word)
t
(yes-or-no-p "The word at point/region is different than the annotation, still change? "))))
(when is-same
(paw-update-origin_point word origin-point)
;; delete the old overlay
(-map (lambda (b)
(with-current-buffer b
(if (eq paw-annotation-mode t)
(let ((o (cl-find-if
(lambda (o)
(equal (alist-get 'word (overlay-get o 'paw-entry)) word))
(overlays-in (point-min) (point-max)))))
(if o (delete-overlay o))))))
(buffer-list))
;; update back the origin_point to entry
(setf (alist-get 'origin_point entry) origin-point)
;; add overlay
(paw-add-annotation-overlay entry)
;; quit mark
(if (featurep 'evil)
(evil-force-normal-state))
;; update buffer
(if (buffer-live-p (get-buffer "*paw*"))
(paw t)) )))))
(defun paw-change-note_type ()
"Change the note_type filed of entry at point."
(interactive)
(let* ((origin-point (paw-get-location))
(type (if (featurep 'ivy-read)
(ivy-read (format "New Annotation Type: ") paw-note-type-alist
:sort nil)
(consult--read paw-note-type-alist
:prompt "New Annotation Type: "
:sort nil)))
(new-note-type (assoc (intern type) paw-note-type-alist) ))
(let* ((entry (get-char-property (point) 'paw-entry))
(word (alist-get 'word entry))
(old-word (paw-get-real-word entry))
(new-word (paw-get-word)))
(paw-update-note_type word new-note-type)
;; delete the old overlay
(-map (lambda (b)
(with-current-buffer b
(if (eq paw-annotation-mode t)
(let ((o (cl-find-if
(lambda (o)
(equal (alist-get 'word (overlay-get o 'paw-entry)) word))
(overlays-in (point-min) (point-max)))))
(if o (delete-overlay o))))))
(buffer-list))
;; update back the note_type to entry
(setf (alist-get 'note_type entry) new-note-type)
;; add overlay
(paw-add-annotation-overlay entry)
;; quit mark
(if (featurep 'evil)
(evil-force-normal-state))
;; update buffer
(if (buffer-live-p (get-buffer "*paw*"))
(paw t)))))
(defun paw-change-origin_path ()
"Change the origin_path filed of entry at point."
(interactive)
(let* ((origin-path (paw-get-origin-path))
(new-origin-path (let ((file (if (yes-or-no-p "Select(y) or input(n) a path? ")
(read-file-name "Select the new path: ")
(read-string "Input the new path: ")) ))
(if (file-exists-p file)
(abbreviate-file-name file)
(user-error "No this file, please input another path")))))
(paw-db-update-all-origin_path origin-path new-origin-path)
(if (buffer-live-p (get-buffer "*paw*"))
(paw t))))
(defcustom paw-add-to-known-words-without-asking t
"If non-nil, add the word to known words without asking."
:group 'paw
:type 'boolean)
;;; TODO
;;;###autoload
(defun paw-delete-word (&optional entry)
"Delete marked word(s)."
(interactive)
(let* ((marked-entries (paw-find-marked-candidates))
(entries
(or marked-entries
(if entry (list entry)
(if (get-text-property (point) 'paw-entry)
(list (get-text-property (point) 'paw-entry))
;; any word at point
(list (paw-new-entry (word-at-point t) :add-to-known-words t)))))))
(when (if (eq (length entries) 1)
(progn
(if (alist-get 'add-to-known-words (car entries))
(if paw-add-to-known-words-without-asking
t
(format "Add '%s' to known words? " (alist-get 'word (car entries))))
(yes-or-no-p (format "Delete: %s " (alist-get 'word (car entries))) )))
(yes-or-no-p (format "Delete %s entries" (length entries)) ) )
(when entries
(cl-loop for entry in entries do
(let* ((word (alist-get 'word entry))
(content (alist-get 'content entry))
(content-json (condition-case nil
(let ((output (json-read-from-string content)))
(if (and (not (eq output nil))
(not (arrayp output))
(not (numberp output)))
output
nil))
(error nil)))
(content-filename (alist-get 'filename content-json))
(content-path (alist-get 'path content-json))
(note-type (alist-get 'note_type entry))
(serverp (alist-get 'serverp entry))
(origin_id (alist-get 'origin_id entry))
(lang (alist-get 'lang entry))
(add-to-known-words (alist-get 'add-to-known-words entry))
(file (expand-file-name (concat word ".org") temporary-file-directory)))
(if add-to-known-words ;; if add-to-known-words is t, we put the word to known file instead of deleting it in db
(pcase lang
("en" (if (and paw-ecdict-default-known-words-file (file-exists-p paw-ecdict-default-known-words-file))
(progn
(with-temp-buffer
(insert-file-contents paw-ecdict-default-known-words-file)
(goto-char (point-max))
(insert word "\n")
(write-region (point-min) (point-max) paw-ecdict-default-known-words-file)
(message "Added %s to known words." word))
;; delete overlay search on the buffers enable `paw-annotation-mode'
(paw-delete-word-overlay word))
(message "Known words file not exists.")))
("ja" (if (and paw-jlpt-default-known-words-file (file-exists-p paw-jlpt-default-known-words-file))
(progn
(with-temp-buffer
(insert-file-contents paw-jlpt-default-known-words-file)
(goto-char (point-max))
(insert word "\n")
(write-region (point-min) (point-max) paw-jlpt-default-known-words-file)
(message "Added %s to known words." word))
;; delete overlay search on the buffers enable `paw-annotation-mode'
(paw-delete-word-overlay word))
(message "Known words file not exists.")))
("zh" (if (and paw-hsk-default-known-words-file (file-exists-p paw-hsk-default-known-words-file))
(progn
(with-temp-buffer
(insert-file-contents paw-hsk-default-known-words-file)
(goto-char (point-max))
(insert word "\n")
(write-region (point-min) (point-max) paw-hsk-default-known-words-file)
(message "Added %s to known words." word))
;; delete overlay search on the buffers enable `paw-annotation-mode'
(paw-delete-word-overlay word))
(message "Known words file not exists.")))
(_ (message "Unsupport language %s during adding known words." lang)))
(if (not (paw-online-p serverp))
;; not in the server delete directly
(progn
;; delete word in db
(paw-db-delete word)
;; delete image/attachment
(if content-path
(pcase (car note-type)
('image (let ((png (expand-file-name content-path paw-note-dir)))
(if (file-exists-p png)
(delete-file png)
(message "Image %s not exists." png))))
('attachment (let ((attachment (expand-file-name content-path paw-note-dir)))
(if (file-exists-p attachment)
(delete-file attachment)
(message "Attachment %s not exists." attachment))))
(_ nil)))
;; delete overlay search on the buffers enable `paw-annotation-mode'
(paw-delete-word-overlay word)
(paw-search-refresh))
(cl-loop for server in paw-online-word-servers do
(pcase server
('eudic
;; it is in the server, must delete server's first
(paw-request-eudic-delete-word word origin_id
(lambda()
;; delete word in db
(paw-db-delete word)
;; delete overlay search on the buffers enable `paw-annotation-mode'
(paw-delete-word-overlay word)
(paw-search-refresh))))
('anki
;; it is in the server, must delete server's first
(paw-request-anki-delete-word word
(lambda()
;; delete word in db
(paw-db-delete word)
;; delete overlay search on the buffers enable `paw-annotation-mode'
(paw-delete-word-overlay word)
(paw-search-refresh)))))
)
))))))))
(defun paw-delete-word-overlay(word)
"Delete overlay search on the buffers enable `paw-annotation-mode'"
(-map (lambda (b)
(with-current-buffer b
(if (eq major-mode 'eaf-mode)
(eaf-call-async "execute_function_with_args" eaf--buffer-id "paw_delete_word" `,word)
(if (eq paw-annotation-mode t)
(let ((overlays-to-delete
(cl-remove-if-not
(lambda (o) (equal (alist-get 'word (overlay-get o 'paw-entry)) word))
(overlays-in (point-min) (point-max)))))
(dolist (o overlays-to-delete) ; delete all matching overlays
(delete-overlay o))
(setq-local paw-db-update-p t))))))
(buffer-list)))
(defvar paw-copied-entries nil)
(defun paw-copy-word ()
"Copy marked word(s)."
(interactive)
(let* ((marked-entries (paw-find-marked-candidates))
(entries (or marked-entries (list (get-text-property (point) 'paw-entry)))))
(paw-clear-marks)
(message "Copied %s entries" (length entries))
(setq paw-copied-entries entries)))
(defun paw-paste-word ()
"Paste marked word(s)."
(interactive)
(dolist (entry paw-copied-entries)
(paw-db-insert
`(((word . ,(alist-get 'word entry)) (exp . ,(alist-get 'exp entry))))
:content (alist-get 'content entry)
:serverp (alist-get 'serverp entry)
:note (alist-get 'note entry)
:note_type (alist-get 'note_type entry)
:origin_type (alist-get 'origin_type entry)
:origin_path (alist-get 'origin_path entry)
:origin_id (alist-get 'origin_id entry)
:origin_point (alist-get 'origin_point entry)
:created_at (alist-get 'created_at entry)))
(message "Pasted %s entries" (length paw-copied-entries))
(paw-search-refresh)
(setq paw-copied-entries nil))
(defun paw-delete-words-by-origin_path ()
"TODO: Delete all words by origin_path in database and entries.
It is fast but has drawbacks:
1. Image and attachments could not be deleted.
2. Overlay should be disabled manually."
(interactive)
(let ((origin-path (paw-get-origin-path)))
(when (yes-or-no-p (format "Delete all notes under %s? " origin-path))
(paw-db-delete-words-by-origin_path origin-path)
(if (buffer-live-p (get-buffer "*paw*"))
(paw t)))))
(defun paw-update-word (prefix)
"Update the word meaning with sdcv or gptel."
(interactive "P")
(let* ((entry (get-text-property (point) 'paw-entry))
(id (alist-get 'word entry))
(word (paw-get-real-word id))
(type (alist-get 'note_type entry))
(file (expand-file-name (concat (if (string-match ":id:\\(.*\\)" id)
(match-string 1 id)
id) ".org") temporary-file-directory)))
(when (yes-or-no-p (format "Are your sure to add exp for: %s? " word))
;; update content with gptel
(if prefix
(paw-gptel-update-exp id word (car type)
(lambda ()
(when (file-exists-p file)
(let ((buffer (find-buffer-visiting file)))
(if buffer
(kill-buffer buffer)))
(delete-file file))
(paw-search-refresh)))
;; update content with sdcv
(paw-update-exp
id
(sdcv-translate-result word sdcv-dictionary-simple-list))
(message "Update word done.")
(paw-search-refresh)))))
(defun paw-previous-word ()
"Jump to previous headline."
(interactive)
(paw-previous)
(paw-view-note))
(defun paw-next-word ()
"Jump to next headline."
(interactive)
(paw-next)
(paw-view-note))
(defun paw-list-groups ()
(interactive)
(if (featurep 'ivy-read)
(ivy-read "Select the annotation group: " (paw-get-all-origin-path)
:action (lambda(x)
(setq paw-group-filteringp t)
(setq paw-search-current-page 1)
(paw-search-update-buffer-with-keyword (car x))))
(setq paw-group-filteringp t)
(setq paw-search-current-page 1)
(paw-search-update-buffer-with-keyword
(consult--read (append (paw-get-all-origin-path) (paw-get-all-study-list))
:prompt "Select the annotation group: "
;; :lookup (lambda(_ candidates cand)
;; (car (assoc cand candidates)))
))))
(defun paw-get-eldoc-word ()
(let* ((entry (get-char-property (point) 'paw-entry))
(word (alist-get 'word entry))
(note-type (alist-get 'note_type entry))
(exp (alist-get 'exp entry))
(note (alist-get 'note entry)))
(pcase (car note-type)
('word
(if entry
(format "%s | %s | %s"
(propertize word 'face 'bold)
(or (s-collapse-whitespace exp) "")
(or (s-collapse-whitespace (replace-regexp-in-string word (propertize word 'face '(bold underline)) note)) "") )))
(_ (format "%s | %s"
(propertize (paw-get-real-word word) 'face 'bold)
(or (s-collapse-whitespace note)))))))
(defun paw-search-input ()
(interactive)
(let* ((sdcv-say-word-p t)
(word (paw-get-real-word (get-text-property (point) 'paw-entry)))
(default (if word (format " (default %s)" word) ""))
(final-word (read-string (format "Stardict%s: " default) nil nil word)))
(sdcv-search-detail final-word)))
(defun paw-quit ()
"Quit paw."
(interactive)
(when (get-buffer "*paw*")
(quit-window)
(kill-buffer "*paw*"))
(setq paw-search-pages 0)
(setq paw-search-current-page 1)
;; close the db, so that it will release the db, and start to sync (if use syncthing)
(paw-close-db)
)
(provide 'paw)