From: Aleksey C. <vl...@gm...> - 2004-07-08 13:25:49
|
I've created new DICT client for GNU Emacs. Initial version is available here http://freshmeat.net/projects/dictem A part of README file containing examples of configuration follows. CONFIGURING ============= Customization group ------------------- Take note, that DictEm defines customization group "dictem". So, it may be easier for you to customize DictEm by running M-x customize-group <RET> dictem <RET> Manual Configuration -------------------- The easiest configuration of dictem may look like this ; Add to load-path variable a new directory with files of dictem ;(add-to-list 'load-path "/usr/local/share/emacs/emacs-site") ; Loading dictem functions (require 'dictem) ; Setting the server host and port (setq dictem-server "localhost") (setq dictem-port "2628") ; Code necessary to obtain database and strategy list ; from DICT server (dictem-initialize) ; Assigning hot keys for accessing DICT server ; SEARCH = MATCH + DEFINE ; Ask for word, database and search strategy ; and show definitions found (global-set-key "\C-cs" 'dictem-run-search) ; MATCH ; Ask for word, database and search strategy ; and show matches found (global-set-key "\C-cm" 'dictem-run-match) ; DEFINE ; Ask for word and database name ; and show definitions found (global-set-key "\C-cd" 'dictem-run-define) ; SHOW SERVER ; Show information about DICT server (global-set-key "\C-c\M-r" 'dictem-run-show-server) ; SHOW INFO ; Show information about the database (global-set-key "\C-c\M-i" 'dictem-run-show-info) ; SHOW DB ; Show a list of databases provided by DICT server (global-set-key "\C-c\M-b" 'dictem-run-show-databases) ------- There are a few functions that can make dictem look a bit nicer and be more functional. They should be added to special hooks like the following. ; For creating hyperlinks on database names ; and found matches. ; Click on them with mouse-2 (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) ------- If you want to combine some databases in you own "virtual" dictionary, create them like this (setq dictem-user-databases-alist '(("_en-ru" . ("mueller7" "korolew_en-ru")) ("_en-en" . ("foldoc" "gcide" "wn")) ("_ru-ru" . ("beslov" "ushakov" "ozhegov" "brok_and_efr")) ("_unidoc" . ("susv3" "man" "info" "howto" "rfc")) )) As a result four new special database collections will be created and new names will appear when dictem-run function will ask you about database name. ------- If your DICT server provides too many databases and most of which are of no interest for you, you can disable them and use only those specified in dictem-user-databases-alist variable. (setq dictem-use-user-databases-only t) ------- You are not limited to the default DICT server only. The following code will allow you to access any server you want. You'll be asked for host and port. (global-set-key "\C-c\M-d" '(lambda () (interactive) (save-dictem (let* ((dictem-server (read-string "server> " dictem-server nil "dict.org" nil)) (dictem-port (read-string "port> " (dictem-get-port) nil "2628" nil))) (dictem-initialize) (dictem-run-define))))) (global-set-key "\C-c\M-m" '(lambda () (interactive) (save-dictem (let* ((dictem-server (read-string "server> " dictem-server nil "dict.org" nil)) (dictem-port (read-string "port> " (dictem-get-port) nil "2628" nil))) (dictem-initialize) (dictem-run-match))))) ------- Some databases may have specially formatted definitions, for example, HTML, MIME, DICF or ROFF formats. It is easy to postprocess them. ; All functions from dictem-postprocess-each-definition-hook ; will be run for each definition which in turn will be narrowed. ; Current database name is kept in dictem-current-dbname variable. ; The following code demonstrates how to highlight SUSV3 and ROFF ; definitions. (add-hook 'dictem-postprocess-definition-hook 'dictem-postprocess-each-definition) ; Function for highlighting definition from the database "susv3". (defun dictem-highlight-susv3-definition () (interactive) (cond ((string= "susv3" dictem-current-dbname) (goto-char (point-min)) (while (search-forward-regexp "^ *[QWERTYUIOPASDFGHJKLZXCVBNM ]+$" nil t) (put-text-property (match-beginning 0) (match-end 0) 'face 'white-foreground) )))) ; Function to show roff-formatted text from the database "man". (require 'woman) (defun dictem-highlight-man-definition () (interactive) (cond ((string= "man" dictem-current-dbname) (goto-char (point-min)) (while (search-forward-regexp "^ " nil t) (replace-match "")) (goto-char (point-min)) (forward-line 2) (woman-decode-region (point) (point-max)) ))) (add-hook 'dictem-postprocess-each-definition-hook 'dictem-highlight-susv3-definition) (add-hook 'dictem-postprocess-each-definition-hook 'dictem-highlight-man-definition) ------- ; By using dictem-run function more advanced ELISP programmers ; may create their own search scenaria. Look at this code. (dictem-run 'dictem-base-search "gcide" "apple" "lev") (dictem-run '(lambda (a b c) (dictem-define-base '("man" "susv3") (dictem-read-query (thing-at-point 'word)) nil )) nil nil) (let ((query (dictem-read-query (thing-at-point 'word)))) (dictem-run `((lambda (a b c) (dictem-match-base '("gcide" "wn") ,query "exact")) (lambda (a b c) (dictem-search-base '("mueller7" "korolew_en-ru") ,query "word"))))) -- Best regards, Aleksey Cheusov. |