-
-
Save yugaego/c32dcb5057652a0317fad298ff0d3cdb to your computer and use it in GitHub Desktop.
lookup dictionary in emacs on mac
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
;; 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) |
You're welcome, though note this is just a fork 😉
For reference, here's the version I'm currently using.
The approach with the current-word
call has been working fine for me so far, so I don't see a reason to change that.
Still, feel free to submit a PR if you think that version could be improved meaningfully.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing this, but this is a bit shorter and does the same thing:
Just select a region in a buffer, and then
M-x dict RET
and it'll look up a word.