以下の様な単語を調べるコマンドがあるとして
$ dic_search.rb -r <word1> <word2> "<phrase>"
.emacsに以下の様な設定を加えると楽に単語を調べられる。
(defun my-dic-search () (interactive)
(let ((word (current-word)))
(shell-command (concat "dic_search.rb -r " word))))
(defun my-dic-search-region (beg end) (interactive "r")
(shell-command-on-region beg end "cat | xargs dic_search.rb -r"))
(global-set-key "\C-c\C-e" 'my-dic-search-region)
(global-set-key [f4] 'my-dic-search)
例えば(単語を調べるコマンドの例)
class Caller
def initialize
useja if self.respond_to? :useja
raise "create_url method is not found." unless self.respond_to? :create_url
end
def get_mean word
@content = create_url word
system("firefox --new-tab #{@content}")
self
end
alias run get_mean
end
class EtoJ < Caller
def create_url x
url=%W{http://eow.alc.co.jp/ /UTF-8/}
url.join(x).gsub(' ','%20')
end
end
require 'optparse'
dic = nil
ARGV.options do |opt|
opt.on('-r', '--entoja', 'EIGRO on THE WEB'){ dic = EtoJ }
opt.parse!
end
ARGV.inject(dic.send(:new)){ |d, e| p(e); d.run(e); sleep(0.1); d}