How to use dictem in emacs?

3

I have dictem from Lubuntu repositories installed, but I do not know how to run it. I would like to know the basic usage, how to add/remove dictionaries, how to look up web resources like Wiki, Wiktionary, forvo for pronunciation, etc.

I am using GoldenDict at the moment, but it would be nice to have similar features from within emacs so that the results of a lookup may be easily used in other documents.

usp2011

Posted 2011-10-31T08:37:40.957

Reputation: 53

Answers

1

I use dict in emacs all the time with dictem plugin. Infact dictem README has very good information. Anyway this is my setup. Install dependencies listed below before using this code. BTW this setup only contacts the localhost server but not the web resources.

;; ubuntu packages needed
;; dict - client installed by default
;; dictd - server
;; dict-wn - Wordnet dictinory
;; any other dicts you want

(when (executable-find "dictd")            ; check dictd is available
   (require 'dictem))


(setq dictem-server "localhost")
(setq dictem-user-databases-alist
      `(("_en-en"  . ("foldoc" "gcide" "wn"))))

(setq dictem-use-user-databases-only t)

(setq dictem-port   "2628")
(dictem-initialize)

(setq dictem-default-strategy "word")
(setq dictem-use-user-databases-only t)

;; For creating hyperlinks on database names
;; and found matches.
(add-hook 'dictem-postprocess-match-hook
          'dictem-postprocess-match)

;; For highlighting the separator between the definitions found.
;; This also creates hyperlink on database names.
(add-hook 'dictem-postprocess-definition-hook
          'dictem-postprocess-definition-separator)

;; For creating hyperlinks in dictem buffer
;; that contains definitions.
(add-hook 'dictem-postprocess-definition-hook
          'dictem-postprocess-definition-hyperlinks)

;; For creating hyperlinks in dictem buffer
;; that contains information about a database.
(add-hook 'dictem-postprocess-show-info-hook
          'dictem-postprocess-definition-hyperlinks)

(define-key dictem-mode-map [tab] 'dictem-next-link)
(define-key dictem-mode-map [(backtab)] 'dictem-previous-link)

(setq dictem-user-databases-alist
      '(("_en-en"  . ("foldoc" "gcide" "wn"))))

;;; http://paste.lisp.org/display/89086
(defun dictem-run-define-at-point-with-query ()
  "Query the default dict server with the word read in within this function."
  (interactive)
  (let* ((default-word (thing-at-point 'symbol))
         (default-prompt (concat "Lookup Word "
                                 (if default-word
                                     (concat "(" default-word ")") nil)
                                 ": "))
         (dictem-query
          (funcall #'(lambda (str)
                       "Remove Whitespace from beginning and end of a string."
                       (replace-regexp-in-string "^[ \n\t]*\\(.*?\\)[ \n\t]*$"
                                                 "\\1"
                                                 str))
                   (read-string default-prompt nil nil default-word))))
    (if (= (length dictem-query) 0) nil
      (dictem-run 'dictem-base-search "*" dictem-query "."))))

(defun dictem-run-define-at-point ()
  "dictem look up for thing at point"
  (interactive)
  (let* ((default-word (thing-at-point 'symbol))
         (dictem-query
          (funcall #'(lambda (str)
                       "Remove Whitespace from beginning and end of a string."
                       (replace-regexp-in-string "^[ \n\t]*\\(.*?\\)[ \n\t]*$"
                                                 "\\1"
                                                 str))
                   default-word)))
    (if (= (length dictem-query) 0) nil
      (dictem-run 'dictem-base-search "*" dictem-query "."))))

(global-set-key "\C-cd" 'dictem-run-define-at-point)
(global-set-key "\C-cD" 'dictem-run-define-at-point-with-query)

(global-set-key "\C-zs" 'dictem-run-search)
(global-set-key "\C-zm" 'dictem-run-match)
;; (global-set-key "\C-cd" 'dictem-run-define)

kindahero

Posted 2011-10-31T08:37:40.957

Reputation: 1 088

One more question: I have a BGL file. I converted it to .index (using the program dictconv), and copied the .index file to /usr/share/dictd, and added the filename (without the extension to the list dictem-user-database-alist) but it does not seem to work. Could you please suggest what I have to do to be able to use a BGL file? Thank you. – None – 2011-10-31T23:34:57.150