Skip to content

Instantly share code, notes, and snippets.

@peccu peccu/dict.m

forked from hitode909/
Created Jan 6, 2012
What would you like to do?
// copy from
// gcc -o dict -Wall -fobjc-gc -O2 -std=c99 dict.m -framework carbon -framework cocoa
#import <Cocoa/Cocoa.h>
#import <CoreServices/CoreServices.h>
int main(int argc, char *argv[])
NSString *word;
NSString *result;
if (argc > 1) {
word = [[NSString alloc] initWithUTF8String:argv[1]];
result = (NSString *)DCSCopyTextDefinition(NULL, (CFStringRef)word, CFRangeMake(0, [word length]));
// NSLog(@"word: %@", word);
// NSLog(@"result: %@", result);
if (result) {
printf("%s", [result UTF8String]);
return 0;
return 1;
import sys
from DictionaryServices import *
def main():
word = sys.argv[1].decode('utf-8')
result = DCSCopyTextDefinition(None, word, (0, len(word)))
if result:
print result.encode('utf-8')
print "nil"
if __name__ == '__main__':
;; 非同期に辞書を引く
;; (+ ""
;; ""
;; ""
;; "")
(require 'cl)
(require 'deferred)
(require 'popup)
(defvar dict-bin "~/bin/"
"dict 実行ファイルのパス")
(defun my-dictionary ()
(lexical-let ((current-word (thing-at-point 'word)))
(when current-word
(deferred:process dict-bin current-word)
(deferred:nextc it
(lambda (res) (popup-tip (concat current-word "\n" res))))))))
;; mac-key-modeを参考にしたのでリージョンとかいらん処理かも
(defun my-dictionary-at-mouse-cursor (event)
(interactive "e")
(let ((editable (not buffer-read-only))
(pt (save-excursion (mouse-set-point last-nonmenu-event)))
beg end
;; getting word boundaries
(if (and mark-active
(<= (region-beginning) pt) (<= pt (region-end)) )
(setq beg (region-beginning)
end (region-end))
(goto-char pt)
(setq end (progn (forward-word) (point)))
(setq beg (progn (backward-word) (point)))
(lexical-let ((current-word (buffer-substring-no-properties beg end))
(pt pt))
(deferred:process dict-bin current-word)
(deferred:nextc it
(lambda (res)
(popup-tip (concat current-word "\n" res) :point pt :truncate t)))))))
(provide 'dictionary)
(require 'dictionary)
;; (このgistのdict.m)をコンパイルしたものに置き換え
(setq dict-bin "~/bin/dict")
;; popupの背景色を白にする
(set-face-background 'popup-tip-face "white")
;; 右クリックした位置の単語の辞書を引く
(global-set-key (kbd "<mouse-3>") 'my-dictionary-at-mouse-cursor)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.