summaryrefslogtreecommitdiffstats
path: root/emacs.d/nxhtml/util/tyda.el
blob: d4f3ea639f18daf2d3d167ca8e358e181945ee51 (plain)
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
83
84
85
86
87
88
89
90
91
92
93
94
;;; tyda.el --- Lookup words in swe/eng dictionary at tyda.se
;;
;; Author: Lennart Borgman (lennart O borgman A gmail O com)
;; Created: 2008-08-26T02:51:27+0200 Tue
;; Version: 0.2
;; Last-Updated:
;; URL:
;; Keywords:
;; Compatibility:
;;
;; Features that might be required by this library:
;;
;;   None
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Commentary:
;;
;; Lookup swedish or english words in the dictionary at
;;
;;   http://www.tyda.se/
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Change log:
;;
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;; General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; see the file COPYING.  If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
;; Floor, Boston, MA 02110-1301, USA.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Code:

(eval-when-compile (require 'appmenu))

(defun tyda-lookup-word (word)
  "Look up word WORD at URL `http://tyda.se/'.
This site translates between English and Swedish.  The site will
be opened in your webbrowser with WORD looked up."
  (interactive (list (or (thing-at-point 'word)
                         (read-string "Lookup word: "))))
  ;; http://tyda.se/search?form=1&w=weird&w_lang=&x=0&y=0
  (browse-url
   ;;(concat "http://www.tyda.se/?rid=651940&w=" word)
   (format "http://tyda.se/search?form=1&w=%s&w_lang=&x=0&y=0" word)
   ))

(defvar tyda-appmenu-map
  (let ((map (make-sparse-keymap)))
    (define-key map [tyda-lookup]
      (list 'menu-item "Lookup word at point in Tyda"
            'tyda-lookup-word))
    map))

(defvar tyda-mode-map
  (let ((map (make-sparse-keymap)))
    (define-key map [(alt mouse-1)] 'tyda-lookup-word)
    (define-key map [(control ?c) ?=] 'tyda-lookup-word)
    map))

;;;###autoload
(define-minor-mode tyda-mode
  "Minor mode for key bindings for `tyda-lookup-word'.
It binds Alt-Mouse-1 just as the Tyda add-on does in Firefox.
Here are all key bindings

\\{tyda-mode-map}
"
  :global t
  (if tyda-mode
      (progn
        (require 'appmenu nil t)
        (when (featurep 'appmenu)
          (appmenu-add 'tyda nil tyda-mode "Lookup word" tyda-appmenu-map)))))


(provide 'tyda)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; tyda.el ends here