Skip to content

Instantly share code, notes, and snippets.

@yoshinari-nomura
Created February 5, 2019 12:52
Show Gist options
  • Save yoshinari-nomura/2bb05f6d342e5088d69deb480fc87f2e to your computer and use it in GitHub Desktop.
Save yoshinari-nomura/2bb05f6d342e5088d69deb480fc87f2e to your computer and use it in GitHub Desktop.
(require 'popup)
(require 'stem)
(defun dic-find-first (word-list lookup-func)
(let ((result))
(catch 'ret
(while (car word-list)
(if (setq result (funcall lookup-func (car word-list)))
(throw 'ret result))
(setq word-list (cdr word-list))))))
(defun dic-lookup-word (word)
(let ((description
(shell-command-to-string (format "dic '%s'" word))))
(and word
(not (string= word ""))
(not (string= description ""))
description)))
(defun dic-lookup-with-stem (word)
(let ((word-list (cons word (stem-english word))))
(dic-find-first word-list 'dic-lookup-word)))
(defun dic-at-point ()
(interactive)
(let* ((word (word-at-point))
(desc (dic-lookup-with-stem word)))
(when (and desc (null popup-instances))
(popup-tip desc :margin t))))
(defvar dic-timer nil)
(defvar dic-delay 1.0)
(defvar dic-tip-point nil)
(defun dic-timer ()
(when (and (not (eq dic-tip-point (point)))
(not (minibufferp)))
(setq dic-tip-point (point))
(dic-at-point)))
(defun dic-start-popup ()
(interactive)
(setq dic-timer (run-with-idle-timer dic-delay dic-delay 'dic-timer)))
(defun dic-stop-popup ()
(interactive)
(cancel-timer dic-timer)
(setq dic-timer nil))
(provide 'dic-at-point)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment