~ubuntu-branches/debian/squeeze/dictem/squeeze

« back to all changes in this revision

Viewing changes to dictem.el

  • Committer: Bazaar Package Importer
  • Author(s): Yauheni Kaliuta
  • Date: 2009-08-16 14:16:41 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090816141641-zzo9zxtpgq8piss0
Tags: 1.0.2-1
* New upstream release, see NEWS. Closes: #541281
* Install symlink in the flavour directory. Closes: #541287
* Update packaging:
  - Homepage is a regular field;
  - depends on current emacs23 first;
  - copyright points to GPL-2.
  - Standards-Version: 3.8.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
; dictionary.el written by Torsten Hilbrich <Torsten.Hilbrich@gmx.net>
5
5
; but now probably doesn't contain original code.
6
6
; Most of the code has been written
7
 
; from scratch by Aleksey Cheusov <vle@gmx.net>, 2004-2005.
 
7
; from scratch by Aleksey Cheusov <vle@gmx.net>, 2004-2008.
8
8
;
9
9
; DictEm is free software; you can redistribute it and/or modify it
10
10
; under the terms of the GNU General Public License as published by
21
21
; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22
22
; 02111-1307, USA
23
23
 
 
24
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
24
25
;
25
 
; Note! Documentation is in README file.
 
26
; NOTE! Documentation is in README file.
26
27
;
27
28
; Latest information about dictem project and sources
28
29
; are available at
29
30
;
30
31
; http://freshmeat.net/projects/dictem
 
32
; http://sourceforge.net/projects/dictem
31
33
; http://mova.org/~cheusov/pub/dictem
32
34
;
33
35
 
48
50
  :group 'dictem
49
51
  :group 'faces)
50
52
 
51
 
(defcustom dictem-server "dict.org"
 
53
(defcustom dictem-server nil
52
54
  "The DICT server"
53
55
  :group 'dictem
54
 
  :type 'string)
 
56
  :type '(restricted-sexp :match-alternatives (stringp 'nil)))
55
57
 
56
58
(defcustom dictem-port 2628
57
59
  "The port of the DICT server"
190
192
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
191
193
;;;;;           Variables          ;;;;;
192
194
 
193
 
(defconst dictem-version "0.8"
 
195
(defconst dictem-version "1.0.2"
194
196
  "DictEm version information.")
195
197
 
196
198
(defvar dictem-strategy-alist
197
 
  '(("word"    nil)
198
 
    ("exact"     nil)
199
 
    ("prefix"    nil)
200
 
    ("substring" nil)
201
 
    ("suffix"  nil)
202
 
    ("re"      nil)
203
 
    ("regexp"  nil)
204
 
    ("soundex" nil)
205
 
    ("lev"     nil)
206
 
    )
207
 
 
 
199
  nil
208
200
  "ALIST of search strategies")
209
201
 
210
202
(defvar dictem-database-alist
211
 
  '(("elements" nil )
212
 
    ("web1913" nil )
213
 
    ("wn" nil )
214
 
    ("gazetteer" nil )
215
 
    ("jargon" nil )
216
 
    ("foldoc" nil )
217
 
    ("easton" nil )
218
 
    ("hitchcock" nil )
219
 
    ("devils" nil )
220
 
    ("world02" nil )
221
 
    ("vera" nil )
222
 
    )
223
 
 
 
203
  nil
224
204
  "ALIST of databases")
225
205
 
226
206
(defvar dictem-strategy-history
494
474
;;;             call-process functions
495
475
 
496
476
(defun dictem-local-dict-basic-option (host port option-mime)
497
 
  (append
498
 
   (list "-P" "-" 
499
 
         "-h" (if host host (dictem-get-server))
500
 
         "-p" (dictem-get-port port)
501
 
         "--client" (dictem-client-text)
502
 
         )
503
 
   (if option-mime '("-M"))
504
 
   dictem-client-prog-args-list
505
 
   ))
 
477
  (let ((server-host (if host host (dictem-get-server))))
 
478
    (append
 
479
     (list "-P" "-" 
 
480
           "--client" (dictem-client-text))
 
481
     (if server-host
 
482
         (list "-h" server-host "-p" (dictem-get-port port)))
 
483
     (if option-mime '("-M"))
 
484
     dictem-client-prog-args-list
 
485
     )))
506
486
 
507
487
(defun dictem-call-process-SHOW-SERVER (buffer host port)
508
488
  (apply 'call-process
786
766
(defun dictem-get-port (&optional port)
787
767
  (let ((p (if port port dictem-port)))
788
768
    (cond
 
769
     ((and (stringp p) (string= "" p)) 2628)
 
770
     ((null p) 2628)
789
771
     ((stringp p) p)
790
772
     ((numberp p) (number-to-string p))
791
773
     (t (error "The value of dictem-port variable should be \
794
776
 
795
777
(defun dictem-get-server ()
796
778
  (cond
 
779
   ((and (stringp dictem-server) (string= "" dictem-server)) nil)
797
780
   ((stringp dictem-server) dictem-server)
 
781
   ((null dictem-server) nil)
798
782
   (t (error "The value of dictem-server variable should be \
799
 
either a string or a number"))
 
783
either a string or a nil"))
800
784
   ))
801
785
 
802
786
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
817
801
and sets dictem-database-alist variable."
818
802
  (interactive)
819
803
  (setq dictem-database-alist
820
 
        (dictem-delete-alist-predicate
821
 
         (dictem-get-databases
822
 
          server
823
 
          (dictem-get-port port))
824
 
         'dictem-db-should-be-excluded)))
 
804
        (dictem-get-databases server (dictem-get-port port)))
 
805
  (if (dictem-error-p dictem-database-alist)
 
806
      dictem-database-alist
 
807
    (setq dictem-database-alist
 
808
          (dictem-delete-alist-predicate
 
809
           dictem-database-alist
 
810
           'dictem-db-should-be-excluded))))
825
811
 
826
812
(defun dictem-initialize ()
827
813
  "Initializes dictem, i.e. obtains
833
819
    (if (dictem-error-p dbs)
834
820
        dbs strats)))
835
821
 
 
822
(defun dictem-reinitialize-err ()
 
823
  "Initializes dictem if it is not initialized yet
 
824
and run (error ...) if an initialization fails"
 
825
  (interactive)
 
826
  (if (or (dictem-error-p dictem-database-alist)
 
827
          (null dictem-database-alist))
 
828
      (if (dictem-error-p (dictem-initialize))
 
829
          (error (dictem-error-message dictem-database-alist)))))
 
830
 
836
831
;;; Functions related to Minibuffer ;;;;
837
832
 
838
833
(defun dictem-select-strategy (&optional default-strat)
839
834
  "Switches to minibuffer and asks the user
840
835
to enter a search strategy."
841
836
  (interactive)
842
 
  (if (dictem-error-p dictem-strategy-alist)
843
 
      (error (concat "server error: "
844
 
                     (dictem-error-message dictem-strategy-alist))))
 
837
  (dictem-reinitialize-err)
845
838
  (dictem-select
846
839
   "strategy"
847
840
   (dictem-prepand-special-strats
853
846
  "Switches to minibuffer and asks user
854
847
to enter a database name."
855
848
  (interactive)
856
 
  (if (dictem-error-p dictem-database-alist)
857
 
      (error (concat "server error: "
858
 
                     (dictem-error-message dictem-database-alist))))
 
849
  (dictem-reinitialize-err)
859
850
  (let* ((dbs (dictem-remove-value-from-alist dictem-database-alist))
860
851
         (dbs2 (if user-dbs
861
852
                   (if dictem-use-user-databases-only
1358
1349
  "*dictem buffer*")
1359
1350
 
1360
1351
(defconst dictem-url-regexp
1361
 
  "^\\(dict\\)://\\([^/:]+\\)\\(:\\([0-9]+\\)\\)?/\\(.*\\)$")
 
1352
  "^\\(dict\\)://\\([^/:]*\\)\\(:\\([0-9]+\\)\\)?/\\(.*\\)$")
1362
1353
 
1363
1354
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1364
1355
 
1383
1374
  (let ((fun (assoc cmd alist)))
1384
1375
    (if fun
1385
1376
        (symbol-function (cadr fun))
1386
 
      (error "Unknown command" cmd)
 
1377
      (error "Unknown command \"%s\"" cmd)
1387
1378
      )
1388
1379
    ))
1389
1380
 
1536
1527
          (progn
1537
1528
            (setq buffer-read-only nil)
1538
1529
            (delete-region (point-min) (point-max))
1539
 
            (insert-string (car (car dictem-content-history)))
 
1530
            (insert (car (car dictem-content-history)))
1540
1531
            (goto-char (cadr (car dictem-content-history)))
1541
1532
            (setq dictem-content-history (cdr dictem-content-history))
1542
1533
            )
1836
1827
    (end-of-line)
1837
1828
    (let (eol (point))
1838
1829
      (goto-char (point-min))
1839
 
      (if (search-forward-regexp "definitions? found" eol t)
 
1830
      (if (search-forward-regexp "[0-9] definitions? found" eol t)
1840
1831
          (progn
1841
1832
            (goto-char (point-min))
1842
 
            (kill-line 2)
1843
 
            )
1844
 
        ))))
 
1833
            (let ((kill-whole-line t))
 
1834
              (kill-line 1))
 
1835
            )))))
1845
1836
 
1846
1837
;;;;;       On-Click Functions     ;;;;;
1847
1838
(defun dictem-define-on-press ()