Skip to content

Instantly share code, notes, and snippets.

@tequilasunset
Created December 31, 2010 01:43
Show Gist options
  • Save tequilasunset/760604 to your computer and use it in GitHub Desktop.
Save tequilasunset/760604 to your computer and use it in GitHub Desktop.
(require 'cl)
(defun region-string ()
"Return a string of marked region or nil."
(and mark-active
transient-mark-mode
(buffer-substring-no-properties (region-beginning) (region-end))))
(defun word/region-string ()
"Return a string of word at point or region."
(or (region-string)
(substring-no-properties (or (word-at-point) ""))))
(defun look-up-in-dictionary (&optional word)
"Look up WORD in Dictionary.app.
WORD is a word at point, marked region or specified word."
(interactive)
(or word (setq word (word/region-string)))
(browse-url (concat "dict:///" (url-hexify-string word)))
(message "Look up `%s' in Dictionary..." word))
(defun open-emacs-app ()
"open -a Emacs"
(call-process-shell-command "open" nil nil nil "-a" "Emacs"))
(defmacro with-emacs-app (&rest body)
"Execute BODY then focus on Emacs.app."
(declare (indent 0))
`(unwind-protect
(progn ,@body)
(open-emacs-app)))
(defun look-up-in-dictionary-background ()
"Look up a word in Dictionary.app then focus on Emacs.app."
(interactive)
(with-emacs-app
(flet ((message (&rest ignore)))
(look-up-in-dictionary))))
(global-set-key (kbd "C-c d") 'look-up-in-dictionary-background)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment