help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Additional dict server for dictionary.el


From: Xah
Subject: Re: Additional dict server for dictionary.el
Date: Mon, 3 Nov 2008 14:43:28 -0800 (PST)
User-agent: G2/1.0

i took some time to solve problem about “dictionary.el”.

Now, with the following customized command, one can now effectively
select a set of dictionaries as the default dicts to lookup, with
their results in one pane. The cursor stays in the original pane. And
if the word under cursor is plural, e.g. chairs, or a phrase (e.g.
“Union Jack”), you can select parts of the word or phrase, and the
lookup will use that text selection.

Here's the code:

(defun lookup-word-def ()
  "Look up current word's definition in WordNet, Webster 1913, Moby
Thesaurus.
If there is a text selection (a phrase), lookup that phrase.
This command needs “dictionary.el” installed."
 (interactive)
 (let (myword myurl meat navigText pos)
   (setq myword
         (if (and transient-mark-mode mark-active)
             (buffer-substring-no-properties (region-beginning)
(region-end))
           (thing-at-point 'symbol)))
   (require 'dictionary)
   ;; (dictionary-do-search "fancy" "web1913" 'dictionary-display-
search-result)
   (dictionary-new-search (cons myword "wn"))
   (setq meat (buffer-substring (point-min) (point-max)))

   (dictionary-new-search (cons myword "web1913"))
   (setq meat (concat meat (buffer-substring (point-min) (point-
max))))

   (dictionary-new-search (cons myword "moby-thes"))
   (setq meat (concat meat (buffer-substring (point-min) (point-
max))))

   (switch-to-buffer "*my dict results*")
   (erase-buffer)
   (dictionary-mode)
   (insert meat)
   (goto-char 1) (next-line 2)
   (setq pos (point))

   (setq navigText (buffer-substring 1 pos))

   (goto-char 1)
   ;; remove navigation text
   (while
       (search-forward
        "[Back] [Search Definition]         [Matching words]
[Quit]
       [Select Dictionary]         [Select Match Strategy]
" nil t
        )
     (replace-match
"-----------------------------------------------------------------" t
t))

   ;; remove message about how many def found. e.g. “1 definition
found”.
   (goto-char 1)
   (while
       (search-forward-regexp "[0-9]+ definitions* found\n\n" nil t)
     (replace-match "" t t))

   (goto-char (point-max))
   (insert navigText)
   (goto-char 1)
   (other-window 1)
   ))


The major content of this thread is now cleaned up and summarized as a
tutorial and a essay at:

• Dictionary and Reference Lookup with Emacs
http://xahlee.org/emacs/emacs_lookup_ref.html

• Problems of Open Source Dictionaries
http://xahlee.org/Periodic_dosage_dir/bangu/dict_open_source_probs.html

  Xah
∑ http://xahlee.org/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]