emacs で英単語の意味を調べる

不満

Macの辞書アプリを使ったりしてたのですが(これはすごく便利です)が 他のOS上でも使いたいので探してみました。(正確にはいま使ってるUbuntuの環境をもっと快適にしたいので)

いままではedict とかlookup 使ってましたがもう少し詳細な情報が欲しかったり設定が楽なのないかなと思いました。

これまで

■いままで使ってた設定の1つ

参考) カーソル位置の単語をOSXの辞書で調べて、Emacs上にポップアップ表示する - Qiita

やったこと

■その1 emacs-helm/helm-dictionary

参考) https://github.com/emacs-helm/helm-dictionary

これも割と手間でしたが。。 辞書のダウンロードには以下のスクリプトを作って取得したい言語を引数で渡してあげればできます。 ただ、DLにlynx を使っているのでこれをインストールする必要がありましたが。ruby とかで簡単にできそうだが。

辞書のダウンロードスクリプト

# "User:Matthias Buchmeier/download - Wiktionary" - https://en.wiktionary.org/wiki/User:Matthias_Buchmeier/download
#!/bin/bash
#printout usage info:
if [ $# -lt 2 ] 
then
echo "usage: gettextdictionary.sh SOURCE-ISO  TARGET-ISO >dictionaryfile.ding";
echo "where SOURCE-ISO  and  TARGET-ISO are the iso-languagecodes of the source- target-language resp., e.g \"es\" \"en\" for the Spanish-English dictionary"
exit;
fi
 
iso=$1
iso2=$2
WIKIPATH=User:Matthias_Buchmeier/$iso-$iso2
 
for letter in a b c d e f g h i j k l m n o p q r s t u v w x y z 0
do
lynx -width=1000 -nolist -underscore -dump -assume_charset=utf-8 -display_charset=utf-8 "http://en.wiktionary.org/w/index.php?title=$WIKIPATH-$letter&printable=yes" |\
awk '/::/ {gsub(/[\ ]+/, " "); gsub(/^[\ ]/, ""); print;}' 
done

lynx のインストールと上記のスクリプトをつかって辞書のダウンロード

% sudo apt-get install lynx

% gettextdictionary.sh en ja > dictionaryfile_en-ja.ding

ただ、、、 => 辞書の登録単語数がすくないのでやめた

その2 ■ Online Dictionary In Emacs 24.4 — Medium

参考) Online Dictionary In Emacs 24.4 — Medium

これよんでよさそうだったので(オンラインでしか使えなさそうですが)インストールしてみました。 このためにわざわざEmacs24.4 にしました。

% ./configure --with-x-toolkit=no --with-xpm=no --with-gif=no | tee configure.log

この辞書使うとき、libxml2 をつけてemacs コンパイルしろと怒られたので再インストールするはめに。。

% sudo apt-get install libxml2-dev

init.el に記述するところはもとのサイトの式の以下を修正。 デフォルトは中国語のbing使うようになってたのでアルクのサイトを使うようにした。でも4月以降サービス変わるようなので英英辞典に変えるかも。

;; (eww (concat "http://cn.bing.com/dict/search?q=" current-word))
 (eww (concat "http://dictionary.reference.com/browse/" current-word))

結局こうしました。(alc を利用)

;; ==================== DICT ==================================
(defun alc-dict ()
 "Search current word in alc dictionary."
 (interactive)
 (save-restriction
 (let (start end)
 (skip-chars-backward "A-Za-z0–9") (setq start (point))
 (skip-chars-forward "A-Za-z0–9") (setq end (point))
 (setq current-word (buffer-substring start end))
;; (eww (concat "http://cn.bing.com/dict/search?q=" current-word))
;; (eww (concat "http://dictionary.reference.com/browse/" current-word))
 (eww (concat "http://eow.alc.co.jp/search?q=" current-word))
;http://dictionary.reference.com/browse/overlay
;;http://eow.alc.co.jp/search?q=legalize
 (if (not (string= (buffer-name) "*eww*"))
 (switch-to-buffer-other-window "*eww*"))
 (hl-line-mode "*eww*")
 ;wait for 2 second, because the buffer will refresh soon and it go back to top line.
 (sit-for 2)
 (search-forward current-word nil t 2)
 ;mark the word for 1 second 
 (end-of-line)
 (set-mark (line-beginning-position))
 (sit-for 1)
 (deactivate-mark)
 ))
)

(global-set-key (kbd "C-c q") 'alc-dict)

Ctrl-c q のキーバイドしてるので単語の上で実行するとサイトに飛んで結果を出してくれます

■おまけ スペルチェック

参考) MacのEmacsでスペルチェック(ispell)できない aspell - 黒川仁の文具堂ブログ三昧

あと、ispell が動かなくなってたのでaspell を使うように修正。 このサイトと同様にlanguage の設定で怒られたので修正。

上記のサイトの以下の部分もおなじくはまりました。(ありがとうございました。)

~/.aspell.conf に言語を指定すればよいようだ。

lang en_US

ちなみにいまは英辞郎の辞書データを買おうかなと考えています。

Written on March 6, 2015