免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1233 | 回复: 0
打印 上一主题 下一主题

让Emacs变成字典 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-11-07 22:37 |只看该作者 |倒序浏览
1Emacs 需要词典功能吗?对门的刘勇同学昨晚感慨了一下:“为什么好多好用的工具都是Linux下的呢?”呵呵,今天,我又发现了一个好玩的东东。那就是可以把Emacs搞成词典来用。这当然是合理的,那么多人都说Emacs功能强大,倘若连个单词都不能查,那还叫甚么强大了。
2原理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下很多工具就是靠着这种灵活的手法组装在一起,展示其强大功能的!
3安装dictd/dict下载
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就装好了。
4让Emacs驱动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都支持。
----李延瑞(lyanry@gmail.com)写于 2006年11月7日
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/18537/showart_197033.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP