Created
March 22, 2017 05:00
-
-
Save hoyang/c30863b9a6504b964e8a0fe31c8748f7 to your computer and use it in GitHub Desktop.
Emacs dictionary, translate english to chinese or chinese to english
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
;; sudo apt-get install sqlite3 | |
;; download dict.db from: | |
;; https://www.dropbox.com/sh/u3r3q66x03vqxxy/AAACXdrMy2yxVrwwn1gahQXqa?dl=0 | |
;; put dict.db to ~/.emacs.d/data/dict.db | |
(defun my-simple-dictionary () | |
(interactive) | |
(defvar sqlite-program | |
(or (executable-find "sqlite3") | |
(executable-find "sqlite") | |
"sqlite")) | |
(defvar dictionary-db | |
"~/.emacs.d/data/dict.db") | |
(setq shell-file-name "/bin/bash") | |
(setq shell-command-switch "-c") | |
(setq sql "\"select mean from dict where word like \\\"%s%%\\\" limit 1\"") | |
(setq query (buffer-substring-no-properties | |
(region-beginning) (region-end))) | |
(deactivate-mark) | |
(setq query-sql (format sql query)) | |
(setq query-result | |
(replace-regexp-in-string "\n$" "" | |
(shell-command-to-string | |
(concat sqlite-program " " dictionary-db " " query-sql)))) | |
(message query-result)) | |
;; mark word and press C-x t to translate | |
(global-set-key (kbd "C-x t") 'my-simple-dictionary) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment