1 ;;; goldendict.el --- query word smartly with goldendict.el
3 ;; Authors: stardiviner <numbchild@gmail.com>
4 ;; Package-Requires: ((emacs "24.4") (cl-lib "0.5"))
5 ;; Package-Version: 0.1
6 ;; Keywords: dict goldendict
7 ;; homepage: https://repo.or.cz/goldendict.el.git
9 ;; You should have received a copy of the GNU General Public License
10 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
14 ;; query word smartly with goldendict.el
18 ;; (global-set-key (kbd "C-x d") 'goldendict-dwim)
19 ;; If invoke with [C-u] prefix, then it will raise the main window.
24 (defgroup goldendict nil
25 "Use goldendict in Emacs."
29 (defcustom goldendict-cmd
"goldendict"
30 "Specify Goldendict command."
34 (defun goldendict-ensure ()
35 "Ensure goldendict is running."
36 (unless (string-match "goldendict" (shell-command-to-string "ps -C 'goldendict' | sed -n '2p'"))
37 (start-process-shell-command
43 (defun goldendict-dwim (&optional raise-main-window
)
44 "Query current symbol/word at point or region selected with Goldendict.
45 If you invoke command with `RAISE-MAIN-WINDOW' prefix \\<universal-argument>, it will raise Goldendict main window."
48 (if current-prefix-arg
50 (call-process goldendict-cmd nil nil nil
))
52 (substring-no-properties
54 (buffer-substring-no-properties (mark) (point))
55 ;; way: get word with `thing-at-point'
56 (thing-at-point 'word
))))))
58 ;; pass the selection to shell command goldendict.
59 ;; use Goldendict API: "Scan Popup"
60 (call-process goldendict-cmd nil nil nil word
)))
67 ;;; goldendict.el ends here