-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgoogle-wikipedia.el
More file actions
110 lines (89 loc) · 3.13 KB
/
google-wikipedia.el
File metadata and controls
110 lines (89 loc) · 3.13 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
;;; google.el --- Google access functions... Plus wikipedia
;; Copyright (C) 2009 Filipe Cabecinhas
(defvar gsearch-url
"http://www.google.com/search?q=%s"
"URL that searches Google.")
(defvar gsearch-prompt
"String to search: ")
(defvar glucky-search-url
"http://www.google.com/search?btnI=I%27m+Feeling+Lucky&q=%s"
"URL that performs an ``I'm feeling lucky'' search in Google.")
(defvar glucky-prompt
"String to do a \"lucky\" search: ")
(defvar gcodesearch-url
"http://www.google.com/codesearch?hl=en&lr=&q=%s"
"URL that performs a Google Code search.")
(defvar gcodesearch-prompt
"String to search in Google Code: ")
(defvar gtranslate-url
"http://translate.google.com/translate_t?prev=hp&hl=en&js=n&text=%s&sl=%s&tl=%s"
"URL that performs a Google Translate.")
(defvar gtranslate-prompt
"String to translate: ")
(defvar gmaps-url
"http://maps.google.com/maps?q=%s"
"URL that performs a Google Maps search.")
(defvar gmaps-prompt
"Location to search: ")
(defvar wikipedia-url
"http://%s.wikipedia.com/wiki/Special:Search?search=%s&go=Go"
"URL that searches wikipedia and goes directly to the result page.")
(defvar wikipedia-prompt
"Term to search wikipedia: ")
(defun google ()
(interactive)
(process-file "open" nil nil nil
(format gsearch-url
(g-url-encode
(get-region-or-ask-string
gsearch-prompt)))))
(defun glucky ()
(interactive)
(process-file "open" nil nil nil
(format glucky-search-url
(g-url-encode
(get-region-or-ask-string
glucky-prompt)))))
(defun gcode ()
(interactive)
(process-file "open" nil nil nil
(format gcodesearch-url
(g-url-encode
(get-region-or-ask-string
gcodesearch-prompt)))))
(defun gtranslate ()
(interactive)
(process-file "open" nil nil nil
(format gtranslate-url
(g-url-encode
(get-region-or-ask-string
gtranslate-prompt))
"auto"
"en")))
(defun gmaps ()
(interactive)
(process-file "open" nil nil nil
(format gmaps-url
(g-url-encode
(get-region-or-ask-string
gmaps-prompt)))))
(defun wikipedia ()
(interactive)
(process-file "open" nil nil nil
(format wikipedia-url
"en"
(g-url-encode
(get-region-or-ask-string
wikipedia-prompt)))))
(defsubst g-url-encode (str)
"URL encode string."
(mapconcat '(lambda (c)
(cond ((= c 32) "+")
((or (and (>= c ?a) (<= c ?z))
(and (>= c ?A) (<= c ?Z))
(and (>= c ?0) (<= c ?9)))
(char-to-string c))
(t (upcase (format "%%%02x" c)))))
str
""))
(provide 'google-wikipedia)