补充说明一下:
1. StarDict不仅有Linux、FreeBSD、Windows、MaeMo版本,在手机上也有不少使用stardict词典文件的词典工具: iphone上有gurudict,wedict和istardict(最后这个需要越狱), android上有colordict和wordmate,在任天堂DS上也都有。详见维基百科: StarDict
2. 刚找到一个可以下载stardict中文词典的地方: http://sourceforge.net/projects/stardictdata/
这当然是最简单的方式,你不用在Emacs上安装配置什么东西。在Linux下可以使用StarDict 或者GoldenDict,Windows下你可以用金山词霸、有道辞典、灵格斯等等。
其它也没有什么好说的,屏幕取词最简单了。当然前提是在GUI下工作,如果你想在console/terminal下查辞典,或者想在Emacs里面显示、拷贝查询结果,可以看看下面的方法。
让Emacs变成字典
对门的刘勇同学昨晚感慨了一下:“为什么好多好用的工具都是Linux下的呢?”呵呵,今天,我又发现了一个好玩的东东。那就是可以把Emacs搞成词典来用。这当然是合理的,那么多人都说Emacs功能强大,倘若连个单词都不能查,那还叫甚么强大了。
Linux下,有一个工具,叫做dictd/dict。dictd是服务器,负责管理词库,它接受客户端的请求,在词库中找到所查询的词条返给客户端。dict是客户端,是面向用户的接口,用户使用dict只需在命令行下输入'dict xxx',然后dict程序就请求dictd查询“xxx”这个单词。
dictd可以在internet服务器上,这时,你可以通过网络查询单词。dictd也可以装在你的局域网服务器上;还可以装在你的本地机器上,这是你的机器即是服务器,又是客户端。这种方式很灵活,选择那种方式全看你的。
Emacs能具备字典功能,全靠dictd/dict了。Emacs需要一个叫做dictionary.el的扩展,就具备驱动dict程序的能力了,并且它将dictd反给dict的词条显示在它自己的buffer内。Linux下很多工具就是靠着这种灵活的手法组装在一起,展示其强大功能的!
下载 dictd-1.10.0.tar.gz,解包,然后编译:
./configure --prefix=/usr/local/tool/dictd make make install
上面的--prefix路径根据你的情况,自行设置即可。如果你采用默认设置,那就装在/usr/local下了。
下一步就是装你喜欢的词典,去 dict.org 下载,web1913是大名鼎鼎的webster,还有比较全的gcide,查计算机词汇的foldoc,查地理的gazetteer,princeton开放的著名的wordnet(wn),以及查化学元素的element。很多很多。
词典包下载后解压,将解出来的*.dict.dz和*.index文件放到dictd包的安装目录下的lib/dict子目录中(我的是/usr/local/tool/dictd/lib/dict),如果没有dict子目录,就自行建一个。这里一定要确认*.dict.dz和*.index文件是否具有可读权限,不然后面可能会吃苦头(我已经吃过了)。
再接下来,就是配置dictd和dict了。首先配置dictd,就是在dictd的安装目录下建一个etc子目录(我的是/usr/local/tool/dictd/etc),然后再建立一个dictd.conf文件,内容如下:
database web1913 { data "/usr/local/lib/dict/web1913.dict.dz" index "/usr/local/lib/dict/web1913.index" } database wn { data "/usr/local/lib/dict/wn.dict.dz" index "/usr/local/lib/dict/wn.index" }
上面的dictd.conf文件中出现的web1913和wn分别代指我下的web1913.dict.dz和wn.dict.dz,应该可以自己对其进行命名的(我没试过)。
然后就是配置dict了,在dictd.conf所在的那个目录中再建一个dict.conf文件,内容如下:
server 你的主机名
对于dict.conf的配置,官方所给的文档并没有明确说明,我在网上看到一些人是将本机的IP当作server,或者是直接将localhost当作server,我这里测试,它们都不行,只有设为自己的主机名才可以用。
下面,可以测试一下dictd是否可用,跑到dictd安装目录下,进入sbin目录:
$ dictd -c ../etc/dictd.conf -t hello :I: 4587 starting dictd 1.10.0/rf on Linux 2.6.18-1.2798.fc6 Tue Nov 7 21:40:45 2006 database wn { data /usr/local/tool/dictd/lib/dict/wn.dict.dz index /usr/local/tool/dictd/lib/dict/wn.index } database web1913 { data /usr/local/tool/dictd/lib/dict/web1913.dict.dz index /usr/local/tool/dictd/lib/dict/web1913.index } :I: wn 154563 3163244 8954034 27955005 :I: web1913 185399 3521270 11728366 31946961 From WordNet (r) 2.0 [wn]: hello n : an expression of greeting; "every morning they exchanged polite hellos" [syn: {hullo}, {hi}, {howdy}, {how-do-you-do}] From Webster's Revised Unabridged Dictionary (1913) [web1913]: Hello \Hel*lo"\, interj. & n. See {Halloo}. 115 comparisons
如果测试通过,就应该能输出单词‘hello’的词条。确认后,就可以‘dictd -c ../etc/dictd.conf’,启动dictd服务。doctd启动后,你可以测试客户端dict是否可用:
]$ dict hello 2 definitions found From WordNet (r) 2.0 [wn]: hello n : an expression of greeting; "every morning they exchanged polite hellos" [syn: {hullo}, {hi}, {howdy}, {how-do-you-do}] From Webster's Revised Unabridged Dictionary (1913) [web1913]: …… See {Halloo}
这样,dictd/dict就装好了。
下载 dictionary.el 文件,解压之后make,然后将byte-compile后的elc文件复制到你自己的lisp目录下,按照README和init-dictionary.el的方法配置自己的.emacs文件,我的是:
(autoload 'dictionary-search "dictionary" "Ask for a word and search it in all dictionaries" t) (autoload 'dictionary-match-words "dictionary" "Ask for a word and search all matching words in the dictionaries" t) (autoload 'dictionary-lookup-definition "dictionary" "Unconditionally lookup the word at point." t) (autoload 'dictionary "dictionary" "Create a new dictionary buffer" t) ;;autosearch had been canceled (autoload 'dictionary-mouse-popup-matching-words "dictionary" "Display entries matching the word at the cursor"t ) (autoload 'dictionary-popup-matching-words "dictionary" "Display entries matching the word at the point" t) (autoload 'dictionary-tooltip-mode "dictionary" "Display tooltips for the current word" t) (autoload 'global-dictionary-tooltip-mode "dictionary" "Enable/disable dictionary-tooltip-mode for all buffers" t) (global-set-key [mouse-3] 'dictionary-mouse-popup-matching-words) (global-set-key [(control c)(d)] 'dictionary-lookup-definition) (global-set-key [(control c)(s)] 'dictionary-search) (global-set-key [(control c)(m)] 'dictionary-match-words) ;; choose a dictionary server (setq dictionary-server "lyanry.sdut.org")
然后重新启动一下Emacs,就可以用了。查单词,只要将光标移到单词上,‘C-c d’即可,Emacs会开辟一个buffer显示单词释义。鼠标右键也可以。另外,由于咱用的是Emacs 23,不支持dictionary的tooltip,而Emacs 21、22都支持。