-
Notifications
You must be signed in to change notification settings - Fork 619
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Chen Bin
committed
Apr 14, 2023
1 parent
4947379
commit fce9fd9
Showing
11 changed files
with
300 additions
and
482 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
projects | ||
request/ | ||
.cache | ||
.depend | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
;; -*- coding: utf-8; lexical-binding: t; -*- | ||
|
||
(defvar my-dict-buffer-name "*MYDICT*" | ||
"The buffer buffer of my dictionary lookup.") | ||
|
||
;; English => Chinese | ||
(defvar my-dict-simple | ||
'("~/.stardict/dic/stardict-langdao-ec-gb-2.4.2" "langdao-ec-gb")) | ||
;; WordNet English => English | ||
(defvar my-dict-complete | ||
'("~/.stardict/dic/stardict-dictd_www.dict.org_wn-2.4.2" "dictd_www.dict.org_wn")) | ||
|
||
(defvar my-dict-simple-cache nil "Internal variable.") | ||
(defvar my-dict-complete-cache nil "Internal variable.") | ||
|
||
(defun my-dict-prompt-input () | ||
"Prompt input for translate." | ||
(let* ((word (if mark-active | ||
(buffer-substring-no-properties (region-beginning) | ||
(region-end)) | ||
(thing-at-point 'word)))) | ||
(read-string (format "Word (%s): " (or word "")) | ||
nil nil | ||
word))) | ||
|
||
(defun my-dict-quit-window () | ||
"Quit window." | ||
(interactive) | ||
(quit-window t)) | ||
|
||
(defmacro my-dict-search-detail (dict cache) | ||
"Return word's definition with DICT, CACHE." | ||
`(let* ((word (my-dict-prompt-input))) | ||
|
||
(when word | ||
(unless (featurep 'stardict) (require 'stardict)) | ||
(unless ,cache | ||
(setq ,cache | ||
(stardict-open (nth 0 ,dict) (nth 1 ,dict) t))) | ||
(stardict-lookup ,cache word)))) | ||
|
||
(defun my-dict-complete-definition () | ||
"Show dictionary lookup in buffer." | ||
(interactive) | ||
(let* ((def (my-dict-search-detail my-dict-complete my-dict-complete-cache)) | ||
buf | ||
win) | ||
(when def | ||
(setq buf (get-buffer-create my-dict-buffer-name)) | ||
(with-current-buffer buf | ||
(setq buffer-read-only nil) | ||
(erase-buffer) | ||
(insert def) | ||
(goto-char (point-min)) | ||
|
||
;; quit easily | ||
(local-set-key (kbd "q") 'my-dict-quit-window) | ||
(when (and (boundp 'evil-mode) evil-mode) | ||
(evil-local-set-key 'normal "q" 'my-dict-quit-window))) | ||
(unless (eq (current-buffer) buf) | ||
(if (null (setq win (get-buffer-window buf))) | ||
(switch-to-buffer-other-window buf) | ||
(select-window win)))))) | ||
|
||
(defun my-dict-simple-definition () | ||
"Show dictionary lookup in popup." | ||
(interactive) | ||
(let* ((def (my-dict-search-detail my-dict-simple my-dict-simple-cache))) | ||
(when def | ||
(unless (featurep 'popup) (require 'popup)) | ||
(popup-tip def)))) | ||
|
||
(provide 'init-dictionary) | ||
;;; init-dictionary.el ends here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.