Skip to content

Instantly share code, notes, and snippets.

@syohex
Created July 25, 2012 13:51
Show Gist options
  • Save syohex/3176296 to your computer and use it in GitHub Desktop.
Save syohex/3176296 to your computer and use it in GitHub Desktop.
Using dictionary with ace-jump-mode
(require 'sdic)
(require 'cl)
(require 'ace-jump-mode)
(defvar dictionary-with-ace:orig-point nil)
(defvar dictionary-with-ace:action
(lambda (word)
(sdic-describe-word word)))
;; For using browser
(defvar dictionary-with-ace:browser-action
(lambda (word)
(browse-url (format "http://eow.alc.co.jp/%s/UTF-8/?ref=sa" word))))
(defun dictionary-with-ace:after-moving ()
(let ((word (substring-no-properties (thing-at-point 'word))))
(goto-char dictionary-with-ace:orig-point)
(funcall dictionary-with-ace:action word)
(setq dictionary-with-ace:not-match-one nil)
(dictionary-with-ace:remove-hooks)))
(defun dictionary-with-ace:remove-hooks ()
(remove-hook 'ace-jump-mode-end-hook 'dictionary-with-ace:after-moving)
(remove-hook 'ace-jump-mode-hook 'dictionary-with-ace:check))
(defvar dictionary-with-ace:not-match-one nil)
(defun dictionary-with-ace:check ()
(setq dictionary-with-ace:not-match-one t))
(defun dictionary-with-ace ()
(interactive)
(let ((c (read-char "Input Char >> ")))
(setq dictionary-with-ace:orig-point (point))
(setq ace-jump-query-char c)
(setq ace-jump-current-mode 'ace-jump-word-mode)
(add-hook 'ace-jump-mode-hook 'dictionary-with-ace:check)
(add-hook 'ace-jump-mode-end-hook 'dictionary-with-ace:after-moving)
(let ((noerror (ignore-errors
(ace-jump-do (concat "\\b" (regexp-quote (make-string 1 c))))
t)))
(if (not noerror)
(dictionary-with-ace:remove-hooks)
(if (not dictionary-with-ace:not-match-one)
(dictionary-with-ace:after-moving))))))
(global-set-key (kbd "C-c C-w") 'dictionary-with-ace)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment