Update library homepage
[goldendict.el.git] / goldendict.el
blob2bfcb2239cb40754cdd9cd21eff522c6b4b1aedf
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/>.
12 ;;; Commentary:
14 ;; query word smartly with goldendict.el
16 ;; Usage:
18 ;; (global-set-key (kbd "C-x d") 'goldendict-dwim)
19 ;; If invoke with [C-u] prefix, then it will raise the main window.
21 ;;; Code:
24 (defgroup goldendict nil
25 "Use goldendict in Emacs."
26 :prefix "goldendict-"
27 :group 'dictionary)
29 (defcustom goldendict-cmd "goldendict"
30 "Specify Goldendict command."
31 :type 'string
32 :group 'goldendict)
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
38 "*goldendict*"
39 " *goldendict*"
40 "goldendict")))
42 ;;;###autoload
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."
46 (interactive "P")
47 (goldendict-ensure)
48 (if current-prefix-arg
49 (save-excursion
50 (call-process goldendict-cmd nil nil nil))
51 (let ((word (downcase
52 (substring-no-properties
53 (if (region-active-p)
54 (buffer-substring-no-properties (mark) (point))
55 ;; way: get word with `thing-at-point'
56 (thing-at-point 'word))))))
57 (save-excursion
58 ;; pass the selection to shell command goldendict.
59 ;; use Goldendict API: "Scan Popup"
60 (call-process goldendict-cmd nil nil nil word)))
61 (deactivate-mark)))
65 (provide 'goldendict)
67 ;;; goldendict.el ends here