[RFC] search word with sdcv
- From: Wang Lei <wanglei 198112 gmail com>
- To: General discussion about sawfish wm <sawfish-list gnome org>
- Subject: [RFC] search word with sdcv
- Date: Thu, 27 Aug 2009 21:36:49 +0800
Sdcv is a dictionary. With it, sdcv-search can get and search a word
from x selection or user input or picked from emacs if it is focus
window. The result display for N secs. But there are two problems. 1.
It can release all sdcv's power. 2. Can we pick word from screen? And
how?
Any suggestion is appriciated!
(defun display-message-seconds (message seconds #!optional attributes)
"Display message for N seconds."
(display-message message attributes)
(make-timer (lambda () (display-message))
seconds))
(defvar sdcv-dict-name "~/.stardict/dic/stardict-langdao-ec-gb-2.4.2/")
(defvar emacs-window-name "@EMACS@")
(defvar sdcv-replace-template ",$|^`|^ |^'| $|\\.$|'$|\\?$")
(defvar errmsg "")
(defun sdcv-get-word ()
"Get the word from current-word in emacs or selection or user input."
(let* ((stream (make-string-output-stream))
(process (make-process stream))
(title "Enter String ")
(word "")
(result ""))
(if (string= (window-name (input-focus)) emacs-window-name)
(progn
(call-process process nil "emacsclient" "-e"
"(with-current-buffer (window-buffer (frame-first-window))
(current-word nil t))")
(setq word (get-output-stream-string stream))
(setq word (string-replace "^\"(.+)\"\n" "\\1" word)))
(if (x-get-selection 'PRIMARY)
(setq word (string-replace sdcv-replace-template ""
(x-get-selection 'PRIMARY)))
(setq word ""))
(when (> (length word) 20); 20 maybe longer than most word, ugly :(
(setq word "")))
(setq word (string-replace sdcv-replace-template "" word))
(setq title (concat title "(" word "):" ))
(setq result (prompt-for-string title))
(cond ((not result)
(setq errmsg "Canceled.")
nil)
((string= result "")
(setq result word))
(t
result))))
(defun sdcv-search ()
"Search word with sdcv."
(interactive)
(let* ((word (sdcv-get-word))
(output (make-string-output-stream))
(proc (make-process output))
(msg-attr '((position . (-1 . -1)) (background . "LightGoldenrod1")
(foreground . "black"))))
(call-process proc nil "sdcv" "-n" "--data-dir" sdcv-dict-name word)
(setq output (get-output-stream-string output))
(if (> (when (string-match "Found \(..?\) items" output)
(string->number (expand-last-match "\\1")))
1)
(display-message-seconds errmsg 2 msg-attr)
(display-message-seconds output 5 msg-attr))))
--
Regards
Lei
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]