(defcustom dictionary-overlay-refresh-buffer-after-mark-word nil
"Refresh buffer or not after mark word as known or unknown.
Since rerendering buffer overlay while looking up words in
background takes relatively long time, One can refresh buffer manually with
`dictionary-overlay-refresh-buffer'.
TODO: Or rather, switching different overlay between known and unknown
status?"
:group 'dictionary-overlay
:type 'boolean)
;; make refresh buffer command interactively
(defun dictionary-overlay-refresh-buffer ()
"Refresh current buffer."
(interactive)
(when dictionary-overlay-active-p
(remove-overlays)
(websocket-bridge-call-buffer "render")))
(defun dictionary-overlay-mark-word-known ()
"Mark current word known."
(interactive)
(websocket-bridge-call-word "mark_word_known")
(when dictionary-overlay-refresh-buffer-after-mark-word
(dictionary-overlay-refresh-buffer)))
(defun dictionary-overlay-mark-word-unknown ()
"Mark current word unknown."
(interactive)
(websocket-bridge-call-word "mark_word_unknown")
(when dictionary-overlay-refresh-buffer-after-mark-word
(dictionary-overlay-refresh-buffer)))
(defun dictionary-add-overlay (begin end source target)
"Add a overlay with range BEGIN to END for the translation SOURCE to TARGET."
(let ((ov (make-overlay begin end)))
(overlay-put ov 'display source)
(overlay-put ov 'face 'font-lock-keyword-face))
(let ((ov (make-overlay end (+ end 1))))
(overlay-put ov 'display (format "(%s)" target))
(overlay-put ov 'face 'font-lock-comment-face)))
(defvar dictionary-add-overlay-function #'dictionary-add-overlay "Add overlay function.")