This repository was archived by the owner on Sep 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutl-dictem.el
82 lines (70 loc) · 2.79 KB
/
utl-dictem.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
;;; dictem.el --- Additional functionality for dictem
;; Author: Alex Kost <[email protected]>
;; Created: 10 Mar 2013
;;; Code:
(require 'dictem)
(require 'utl-misc)
(defun utl-dictem ()
"Same as `dictem' but do not use other window for a dictem buffer."
(let ((buffer (generate-new-buffer dictem-buffer-name))
(window-configuration (current-window-configuration))
(selected-window (frame-selected-window)))
(switch-to-buffer buffer) ; not `switch-to-buffer-other-window'
(dictem-mode)
(make-local-variable 'dictem-window-configuration)
(make-local-variable 'dictem-selected-window)
(make-local-variable 'dictem-content-history)
(setq dictem-window-configuration window-configuration)
(setq dictem-selected-window selected-window)))
(defun utl-dictem-define-on-press ()
"Same as `dictem-define-on-press' but with \"*\" for dicts."
(interactive)
(let* ((properties (text-properties-at (point)))
(data (plist-get properties 'link-data))
(fun (plist-get properties 'link-function))
(dictem-server (plist-get properties 'dictem-server))
(dictem-port (plist-get properties 'dictem-port))
(word (assq 'word data))
(dbname (assq 'dbname data)))
(if (or word dbname)
(dictem-run fun "*"
;; "*" instead of:
;; (if dbname (cdr dbname) dictem-last-database)
(if word (cdr word) nil)
nil))))
(defun utl-dictem-read-query (&optional default-query)
"Similar to `dictem-read-query', but uses `utl-read-string'."
(utl-read-string "Query word" nil 'dictem-query-history default-query))
(defvar utl-dictem-dicts '(nil "mueller7")
"List of dictionaries to search by `utl-dictem-run-word'.
dictem ignores the first dictionary, so the first element of the
list should be nil.")
;;;###autoload
(defun utl-dictem-run-word (&optional word)
"Ask about word and show definitions in new buffer."
(interactive)
(let ((dictem-server nil))
(dictem-run 'dictem-base-define
utl-dictem-dicts
(or word (utl-dictem-read-query (thing-at-point 'word)))
"exact")))
;;;###autoload
(defun utl-dictem-run-dict-search ()
"Search in \"dict.org\". Ask about search strategy and query."
(interactive)
(let ((dictem-server "dict.org")
(query (utl-dictem-read-query (thing-at-point 'word)))
(strat (dictem-select-strategy (dictem-get-default-strategy))))
(dictem-run 'dictem-base-search "*" query strat)))
;;;###autoload
(defun utl-dictem-run-show-all-info ()
"Show information about all local databases"
(interactive)
(let ((dictem-server "localhost"))
(dictem-run
(lambda (a b c)
(dictem-base-show-strategies nil nil nil)
(dictem-base-show-databases nil nil nil)
(dictem-base-show-server nil nil nil)))))
(provide 'utl-dictem)
;;; utl-dictem.el ends here