Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Superbil
Created March 8, 2013 03:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Superbil/5113974 to your computer and use it in GitHub Desktop.
Save Superbil/5113974 to your computer and use it in GitHub Desktop.
lookup dictionary in emacs on mac
;; from http://larkery.tumblr.com/post/465585528/emacs-dictionary-app
(defun mac-open-dictionary (the-word)
"Open Dictionary.app for the-word"
(interactive "Dictionary Lookup: ")
(shell-command
(concat "open \"dict:///" (replace-regexp-in-string "\"" "\\\\\"" the-word) "\"")))
;; see https://gist.github.com/1228110
;; dict.py is from http://sakito.jp/mac/dictionary.html
(defun dictionary ()
"lookup from Dictionary.app"
(interactive "Dictionary Lookup: ")
(let ((word (if (and transient-mark-mode mark-active)
(buffer-substring-no-properties (region-beginning) (region-end))
(read-string "Dictionary: ")))
(cur-buffer (current-buffer))
(tmpbuf "* dict-process *"))
(set-buffer (get-buffer-create tmpbuf))
(erase-buffer)
(insert word "\n")
(let ((coding-system-for-read 'utf-8-mac)
(coding-system-for-write 'utf-8-mac))
(call-process "~/.emacs.d/site-lisp/dict.py" nil tmpbuf nil word) ;; specify full pass of dict.py
(let ((str (buffer-substring (point-min) (- (point-max) 2))))
(set-buffer cur-buffer)
(popup-tip str :scroll-bar t)))))
(when *is-a-mac*
(global-set-key (kbd "C-c d")
'(lambda ()
(mac-open-dictionary (current-word))))
(global-set-key (kbd "C-c D") 'dictionary))
(provide 'init-dictionay)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment