Category: | Text Processing |
Author/Contact Info | |
Description: | Convenient access to dict.org from emacs, your shell, and if you like, other programs. |
Use strict; use warnings; use Net::Dict; use vars qw( $DICT $DICT_HOST %DICT_PARAMS ); $DICT_HOST = 'dict.org'; main( @ARGV ); exit; sub main { initialize( @_ ); for my $word ( @_ ) { my $definitions = $DICT->define( $word ); for my $definition ( @$definitions ) { print dictionary_name( $definition->[0] ) . "\n$definition->[1]\n"; } } 1; } sub initialize { $DICT = Net::Dict->new( $DICT_HOST, %DICT_PARAMS ); $| = 1; 1; } { my %dicts; sub dictionary_name { my $dict = shift; $dicts{$dict} ||= $DICT->dbTitle( $dict ); } } __END__ =pod =head1 NAME dict - a simple client for http://dict.org =head1 SYNOPSIS dict insufflation (define-word "insufflation") C-x d =head1 EMACS BINDING Emacs is a great place to bind all sorts things together and this is no exception. Add this to your .emacs file to create the function DEFINE-WORD. If you don't give it a word then it will attempt to define whatever word is currently under your point. (defun define-word (input-word) "Define a word using http://dict.org." (interactive "MWord to define: ") (let ((buf (generate-new-buffer "*dict*")) (word (if (> (length input-word) 0) input-word (current-word)))) (shell-command (concat "~/bin/dict " word) buf) buf)) The following command binds C-x d to the function. (global-set-key "\C-xd" 'define-word) =end |
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: dict.org cli lookup
by belg4mit (Prior) on Dec 12, 2004 at 23:25 UTC | |
by diotalevi (Canon) on Dec 12, 2004 at 23:27 UTC | |
by belg4mit (Prior) on Dec 13, 2004 at 04:30 UTC | |
Re: dict.org cli lookup
by tmoertel (Chaplain) on Dec 13, 2004 at 02:58 UTC |
Back to
Code Catacombs