Skip to content

Instantly share code, notes, and snippets.

@xuchunyang
Created January 26, 2015 14:10
Show Gist options
  • Save xuchunyang/67d9f39c4ae7ce0be833 to your computer and use it in GitHub Desktop.
Save xuchunyang/67d9f39c4ae7ce0be833 to your computer and use it in GitHub Desktop.
osx-dictionary-realtime.el
(add-hook 'text-mode-hook
(lambda ()
;; (remove-hook 'after-change-functions #'first-line-if-changed nil t)
(add-hook 'post-command-hook 'first-line-if-changed2 nil 'local)))
(defun first-line-if-changed (beg end len)
(save-excursion
(goto-char (point-min))
(end-of-line)
(buffer-substring-no-properties (point-min) (point))))
(defun first-line-if-changed2 ()
(interactive)
(ignore-errors
(let ((word (thing-at-point 'word t)))
(with-current-buffer "*t*"
(erase-buffer)
(goto-char (point-min))
(when (and word
(> (length word) 2)
(not (string= (thing-at-point 'word t) word)))
(insert (osx-dictionary--search word)))))))
(require 'osx-dictionary)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment