Mercurial > emacs
annotate lisp/net/webjump.el @ 63955:b8a680debd99
*** empty log message ***
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 03 Jul 2005 16:51:26 +0000 |
parents | df55e63482c4 |
children | 18a818a2ee7c f042e7c0fe20 |
rev | line source |
---|---|
28210 | 1 ;;; webjump.el --- programmable Web hotlist |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
41948
diff
changeset
|
2 |
62437
df55e63482c4
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
62122
diff
changeset
|
3 ;; Copyright (C) 1996, 1997, 2005 Free Software Foundation, Inc. |
28210 | 4 |
5 ;; Author: Neil W. Van Dyke <nwv@acm.org> | |
6 ;; Created: 09-Aug-1996 | |
7 ;; Keywords: comm www | |
8 | |
9 ;; This file is part of GNU Emacs. | |
10 | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
13 ;; the Free Software Foundation; either version 2, or (at your option) | |
14 ;; any later version. | |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 ;; Boston, MA 02111-1307, USA. | |
25 | |
26 ;;; Commentary: | |
27 | |
28 ;; WebJump provides a sort of ``programmable hotlist'' of Web sites that can | |
29 ;; quickly be invoked in your Web browser. Each Web site in the hotlist has a | |
30 ;; name, and you select the desired site name via a completing string prompt in | |
31 ;; the minibuffer. The URL for each Web site is defined as a static string or | |
32 ;; a built-in or custom function, allowing interactive prompting for | |
33 ;; site-specific queries and options. | |
34 | |
35 ;; Note that WebJump was originally intended to complement your conventional | |
36 ;; browser-based hotlist, not replace it. (Though there's no reason you | |
37 ;; couldn't use WebJump for your entire hotlist if you were so inclined.) | |
38 | |
39 ;; The `webjump-sites' variable, which defines the hotlist, defaults to some | |
40 ;; example sites. You'll probably want to override it with your own favorite | |
41 ;; sites. The documentation for the variable describes the syntax. | |
42 | |
43 ;; You may wish to add something like the following to your `.emacs' file: | |
44 ;; | |
45 ;; (require 'webjump) | |
46 ;; (global-set-key "\C-cj" 'webjump) | |
47 ;; (setq webjump-sites | |
48 ;; (append '( | |
49 ;; ("My Home Page" . "www.someisp.net/users/joebobjr/") | |
50 ;; ("Pop's Site" . "www.joebob-and-son.com/") | |
51 ;; ) | |
52 ;; webjump-sample-sites)) | |
53 ;; | |
54 ;; The above loads this package, binds `C-c j' to invoke WebJump, and adds your | |
55 ;; personal favorite sites to the hotlist. | |
56 | |
57 ;; The `webjump-sample-sites' variable mostly contains some site entries that | |
58 ;; are expected to be generally relevant to many users, but excluding | |
59 ;; those that the GNU project would not want to recommend. | |
60 | |
61 ;; The `browse-url' package is used to submit URLs to the browser, so any | |
62 ;; browser-specific configuration should be done there. | |
63 | |
64 ;;; Code: | |
65 | |
66 ;;-------------------------------------------------------- Package Dependencies | |
67 | |
68 (require 'browse-url) | |
69 | |
70 ;;------------------------------------------------------------------- Constants | |
71 | |
72 (defvar webjump-sample-sites | |
73 '( | |
74 | |
75 ;; FSF, not including Emacs-specific. | |
76 ("GNU Project FTP Archive" . | |
77 [mirrors "ftp://ftp.gnu.org/pub/gnu/" | |
78 ;; ASIA: | |
79 "ftp://ftp.cs.titech.ac.jp" | |
80 "ftp://tron.um.u-tokyo.ac.jp/pub/GNU/prep" | |
81 "ftp://cair-archive.kaist.ac.kr/pub/gnu" | |
82 "ftp://ftp.nectec.or.th/pub/mirrors/gnu" | |
83 ;; AUSTRALIA: | |
84 "ftp://archie.au/gnu" | |
85 "ftp://archie.oz/gnu" | |
86 "ftp://archie.oz.au/gnu" | |
87 ;; AFRICA: | |
88 "ftp://ftp.sun.ac.za/pub/gnu" | |
89 ;; MIDDLE-EAST: | |
90 "ftp://ftp.technion.ac.il/pub/unsupported/gnu" | |
91 ;; EUROPE: | |
92 "ftp://irisa.irisa.fr/pub/gnu" | |
93 "ftp://ftp.univ-lyon1.fr/pub/gnu" | |
94 "ftp://ftp.mcc.ac.uk" | |
95 "ftp://unix.hensa.ac.uk/mirrors/uunet/systems/gnu" | |
96 "ftp://src.doc.ic.ac.uk/gnu" | |
97 "ftp://ftp.ieunet.ie/pub/gnu" | |
98 "ftp://ftp.eunet.ch" | |
99 "ftp://nic.switch.ch/mirror/gnu" | |
100 "ftp://ftp.informatik.rwth-aachen.de/pub/gnu" | |
101 "ftp://ftp.informatik.tu-muenchen.de" | |
102 "ftp://ftp.win.tue.nl/pub/gnu" | |
103 "ftp://ftp.nl.net" | |
104 "ftp://ftp.etsimo.uniovi.es/pub/gnu" | |
105 "ftp://ftp.funet.fi/pub/gnu" | |
106 "ftp://ftp.denet.dk" | |
107 "ftp://ftp.stacken.kth.se" | |
108 "ftp://isy.liu.se" | |
109 "ftp://ftp.luth.se/pub/unix/gnu" | |
110 "ftp://ftp.sunet.se/pub/gnu" | |
111 "ftp://archive.eu.net" | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
41948
diff
changeset
|
112 ;; SOUTH AMERICA: |
28210 | 113 "ftp://ftp.inf.utfsm.cl/pub/gnu" |
114 "ftp://ftp.unicamp.br/pub/gnu" | |
115 ;; WESTERN CANADA: | |
116 "ftp://ftp.cs.ubc.ca/mirror2/gnu" | |
117 ;; USA: | |
118 "ftp://wuarchive.wustl.edu/systems/gnu" | |
119 "ftp://labrea.stanford.edu" | |
120 "ftp://ftp.digex.net/pub/gnu" | |
121 "ftp://ftp.kpc.com/pub/mirror/gnu" | |
122 "ftp://f.ms.uky.edu/pub3/gnu" | |
123 "ftp://jaguar.utah.edu/gnustuff" | |
124 "ftp://ftp.hawaii.edu/mirrors/gnu" | |
125 "ftp://uiarchive.cso.uiuc.edu/pub/gnu" | |
126 "ftp://ftp.cs.columbia.edu/archives/gnu/prep" | |
127 "ftp://gatekeeper.dec.com/pub/GNU" | |
128 "ftp://ftp.uu.net/systems/gnu"]) | |
129 ("GNU Project Home Page" . "www.gnu.org") | |
130 | |
131 ;; Emacs. | |
132 ("Emacs Lisp Archive" . | |
133 "ftp://ftp.emacs.org/pub/") | |
134 | |
135 ;; Internet search engines. | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
41948
diff
changeset
|
136 ("AltaVista" . |
28210 | 137 [simple-query |
138 "www.altavista.digital.com" | |
139 "www.altavista.digital.com/cgi-bin/query?pg=aq&what=web&fmt=.&q=" | |
140 "&r=&d0=&d1="]) | |
141 ("Archie" . | |
142 [simple-query "hoohoo.ncsa.uiuc.edu/cgi-bin/AA.pl" | |
143 "hoohoo.ncsa.uiuc.edu/cgi-bin/AA.pl?query=" ""]) | |
144 ("Lycos" . | |
145 [simple-query "www.lycos.com" | |
146 "www.lycos.com/cgi-bin/pursuit?cat=lycos&query=" ""]) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
41948
diff
changeset
|
147 ("Yahoo" . |
28210 | 148 [simple-query "www.yahoo.com" "search.yahoo.com/bin/search?p=" ""]) |
149 | |
150 ;; Misc. general interest. | |
151 ("Interactive Weather Information Network" . webjump-to-iwin) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
41948
diff
changeset
|
152 ("Usenet FAQs" . |
28210 | 153 [simple-query "www.cis.ohio-state.edu/hypertext/faq/usenet/FAQ-List.html" |
154 "www.cis.ohio-state.edu/htbin/search-usenet-faqs/form?find=" | |
155 ""]) | |
156 ("RTFM Usenet FAQs by Group" . | |
157 "ftp://rtfm.mit.edu/pub/usenet-by-group/") | |
158 ("RTFM Usenet FAQs by Hierachy" . | |
159 "ftp://rtfm.mit.edu/pub/usenet-by-hierarchy/") | |
160 ("X Consortium Archive" . "ftp.x.org") | |
161 ("Yahoo: Reference" . "www.yahoo.com/Reference/") | |
162 | |
163 ;; Computer social issues, privacy, professionalism. | |
164 ("Association for Computing Machinery" . "www.acm.org") | |
165 ("Computer Professionals for Social Responsibility" . "www.cpsr.org/dox/") | |
166 ("Electronic Frontier Foundation" . "www.eff.org") | |
167 ("IEEE Computer Society" . "www.computer.org") | |
168 ("Risks Digest" . webjump-to-risks) | |
169 | |
170 ;; Fun. | |
171 ("Bastard Operator from Hell" . "www.replay.com/bofh/") | |
172 | |
173 ) | |
174 "Sample hotlist for WebJump. See the documentation for the `webjump' | |
175 function and the `webjump-sites' variable.") | |
176 | |
177 (defvar webjump-state-to-postal-alist | |
178 '(("Alabama" . "al") ("Alaska" . "ak") ("Arizona" . "az") ("Arkansas" . "ar") | |
179 ("California" . "ca") ("Colorado" . "co") ("Connecticut" . "ct") | |
180 ("Delaware" . "de") ("Florida" . "fl") ("Georgia" . "ga") ("Hawaii" . "hi") | |
181 ("Idaho" . "id") ("Illinois" . "il") ("Indiana" . "in") ("Iowa" . "ia") | |
182 ("Kansas" . "ks") ("Kentucky" . "ky") ("Louisiana" . "la") ("Maine" . "me") | |
183 ("Maryland" . "md") ("Massachusetts" . "ma") ("Michigan" . "mi") | |
184 ("Minnesota" . "mn") ("Mississippi" . "ms") ("Missouri" . "mo") | |
185 ("Montana" . "mt") ("Nebraska" . "ne") ("Nevada" . "nv") | |
186 ("New Hampshire" . "nh") ("New Jersey" . "nj") ("New Mexico" . "nm") | |
187 ("New York" . "ny") ("North Carolina" . "nc") ("North Dakota" . "nd") | |
188 ("Ohio" . "oh") ("Oklahoma" . "ok") ("Oregon" . "or") | |
189 ("Pennsylvania" . "pa") ("Rhode Island" . "ri") ("South Carolina" . "sc") | |
190 ("South Dakota" . "sd") ("Tennessee" . "tn") ("Texas" . "tx") | |
191 ("Utah" . "ut") ("Vermont" . "vt") ("Virginia" . "va") | |
192 ("Washington" . "wa") ("West Virginia" . "wv") ("Wisconsin" . "wi") | |
193 ("Wyoming" . "wy"))) | |
194 | |
195 ;;------------------------------------------------------------ Option Variables | |
196 | |
197 (defvar webjump-sites | |
198 webjump-sample-sites | |
199 "*Hotlist for WebJump. | |
200 | |
201 The hotlist is represented as an association list, with the CAR of each cell | |
202 being the name of the Web site, and the CDR being the definition for the URL of | |
203 that site. The URL definition can be a string (the URL), a vector (specifying | |
204 a special \"builtin\" which returns a URL), a symbol (name of a function which | |
205 returns a URL), or a list (which when `eval'ed yields a URL). | |
206 | |
207 If the URL definition is a vector, then a \"builtin\" is used. A builtin has a | |
208 Lisp-like syntax, with the name as the first element of the vector, and any | |
209 arguments as the following elements. The three current builtins are `name', | |
210 which returns the name of the site as the URL, `simple-query', which | |
211 returns a URL that is a function of a query entered by the user, and `mirrors', | |
212 which allows the user to select from among multiple mirror sites for the same | |
213 content. | |
214 | |
215 The first argument to the `simple-query' builtin is a static URL to use if the | |
216 user enters a blank query. The second and third arguments are the prefix and | |
217 suffix, respectively, to add to the encoded query the user enters. This | |
218 builtin covers Web sites that have single-string searches with the query | |
219 embedded in the URL. | |
220 | |
221 The arguments to the `mirrors' builtin are URLs of mirror sites. | |
222 | |
223 If the symbol of a function is given, then the function will be called with the | |
224 Web site name (the one you specified in the CAR of the alist cell) as a | |
225 parameter. This might come in handy for various kludges. | |
226 | |
227 For convenience, if the `http://', `ftp://', or `file://' prefix is missing | |
228 from a URL, WebJump will make a guess at what you wanted and prepend it before | |
229 submitting the URL.") | |
230 | |
231 ;;------------------------------------------------------- Sample Site Functions | |
232 | |
233 (defun webjump-to-iwin (name) | |
234 (let ((prefix "http://iwin.nws.noaa.gov/") | |
235 (state (webjump-read-choice name "state" | |
236 (append '(("Puerto Rico" . "pr")) | |
237 webjump-state-to-postal-alist)))) | |
238 (if state | |
239 (concat prefix "iwin/" state "/" | |
240 (webjump-read-choice name "option" | |
241 '(("Hourly Report" . "hourly") | |
242 ("State Forecast" . "state") | |
243 ("Local Forecast" . "local") | |
244 ("Zone Forecast" . "zone") | |
245 ("Short-Term Forecast" . "shortterm") | |
246 ("Weather Summary" . "summary") | |
247 ("Public Information" . "public") | |
248 ("Climatic Data" . "climate") | |
249 ("Aviation Products" . "aviation") | |
250 ("Hydro Products" . "hydro") | |
251 ("Special Weather" . "special") | |
252 ("Watches and Warnings" . "warnings")) | |
253 "zone") | |
254 ".html") | |
255 prefix))) | |
256 | |
257 (defun webjump-to-risks (name) | |
258 (let (issue volume) | |
259 (if (and (setq volume (webjump-read-number (concat name " volume"))) | |
260 (setq issue (webjump-read-number (concat name " issue")))) | |
261 (format "catless.ncl.ac.uk/Risks/%d.%02d.html" volume issue) | |
262 "catless.ncl.ac.uk/Risks/"))) | |
263 | |
264 ;;-------------------------------------------------------------- Core Functions | |
265 | |
266 ;;;###autoload | |
267 (defun webjump () | |
268 "Jumps to a Web site from a programmable hotlist. | |
269 | |
270 See the documentation for the `webjump-sites' variable for how to customize the | |
271 hotlist. | |
272 | |
273 Please submit bug reports and other feedback to the author, Neil W. Van Dyke | |
274 <nwv@acm.org>." | |
275 (interactive) | |
276 (let* ((completion-ignore-case t) | |
62122
96701ef6c56d
(webjump): Replace `assoc-ignore-case' by `assoc-string'.
Juanma Barranquero <lekktu@gmail.com>
parents:
53857
diff
changeset
|
277 (item (assoc-string |
28210 | 278 (completing-read "WebJump to site: " webjump-sites nil t) |
62122
96701ef6c56d
(webjump): Replace `assoc-ignore-case' by `assoc-string'.
Juanma Barranquero <lekktu@gmail.com>
parents:
53857
diff
changeset
|
279 webjump-sites t)) |
28210 | 280 (name (car item)) |
281 (expr (cdr item))) | |
282 (browse-url (webjump-url-fix | |
283 (cond ((not expr) "") | |
284 ((stringp expr) expr) | |
285 ((vectorp expr) (webjump-builtin expr name)) | |
286 ((listp expr) (eval expr)) | |
287 ((symbolp expr) | |
288 (if (fboundp expr) | |
289 (funcall expr name) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
41948
diff
changeset
|
290 (error "WebJump URL function \"%s\" undefined" |
28210 | 291 expr))) |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
28210
diff
changeset
|
292 (t (error "WebJump URL expression for \"%s\" invalid" |
28210 | 293 name))))))) |
294 | |
295 (defun webjump-builtin (expr name) | |
296 (if (< (length expr) 1) | |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
28210
diff
changeset
|
297 (error "WebJump URL builtin for \"%s\" empty" name)) |
28210 | 298 (let ((builtin (aref expr 0))) |
299 (cond | |
300 ((eq builtin 'mirrors) | |
301 (if (= (length expr) 1) | |
302 (error | |
53857
4fdf85312c1c
(webjump-builtin): Add missing format string
Andreas Schwab <schwab@suse.de>
parents:
52401
diff
changeset
|
303 "WebJump URL builtin \"mirrors\" for \"%s\" needs at least 1 arg" |
4fdf85312c1c
(webjump-builtin): Add missing format string
Andreas Schwab <schwab@suse.de>
parents:
52401
diff
changeset
|
304 name)) |
28210 | 305 (webjump-choose-mirror name (cdr (append expr nil)))) |
306 ((eq builtin 'name) | |
307 name) | |
308 ((eq builtin 'simple-query) | |
309 (webjump-builtin-check-args expr name 3) | |
310 (webjump-do-simple-query name (aref expr 1) (aref expr 2) (aref expr 3))) | |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
28210
diff
changeset
|
311 (t (error "WebJump URL builtin \"%s\" for \"%s\" invalid" |
28210 | 312 builtin name))))) |
313 | |
314 (defun webjump-builtin-check-args (expr name count) | |
315 (or (= (length expr) (1+ count)) | |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
28210
diff
changeset
|
316 (error "WebJump URL builtin \"%s\" for \"%s\" needs %d args" |
28210 | 317 (aref expr 0) name count))) |
318 | |
319 (defun webjump-choose-mirror (name urls) | |
320 (webjump-read-url-choice (concat name " mirror") | |
321 urls | |
322 (webjump-mirror-default urls))) | |
323 | |
324 (defun webjump-do-simple-query (name noquery-url query-prefix query-suffix) | |
325 (let ((query (webjump-read-string (concat name " query")))) | |
326 (if query | |
327 (concat query-prefix (webjump-url-encode query) query-suffix) | |
328 noquery-url))) | |
329 | |
330 (defun webjump-mirror-default (urls) | |
331 ;; Note: This should be modified to apply some simple kludges/heuristics to | |
332 ;; pick a site which is likely "close". As a tie-breaker among candidates | |
333 ;; judged equally desirable, randomness might be used. | |
334 (car urls)) | |
335 | |
336 (defun webjump-read-choice (name what choices &optional default) | |
337 (let* ((completion-ignore-case t) | |
338 (choice (completing-read (concat name " " what ": ") choices nil t))) | |
339 (if (webjump-null-or-blank-string-p choice) | |
340 default | |
341 (cdr (assoc choice choices))))) | |
342 | |
343 (defun webjump-read-number (prompt) | |
344 ;; Note: I should make this more robust someday. | |
345 (let ((input (webjump-read-string prompt))) | |
346 (if input (string-to-number input)))) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
41948
diff
changeset
|
347 |
28210 | 348 (defun webjump-read-string (prompt) |
349 (let ((input (read-string (concat prompt ": ")))) | |
350 (if (webjump-null-or-blank-string-p input) nil input))) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
41948
diff
changeset
|
351 |
28210 | 352 (defun webjump-read-url-choice (what urls &optional default) |
353 ;; Note: Convert this to use `webjump-read-choice' someday. | |
354 (let* ((completions (mapcar (function (lambda (n) (cons n n))) | |
355 urls)) | |
356 (input (completing-read (concat what | |
357 ;;(if default " (RET for default)" "") | |
358 ": ") | |
359 completions | |
360 nil | |
361 t))) | |
362 (if (webjump-null-or-blank-string-p input) | |
363 default | |
364 (car (assoc input completions))))) | |
365 | |
366 (defun webjump-null-or-blank-string-p (str) | |
367 (or (null str) (string-match "^[ \t]*$" str))) | |
368 | |
369 (defun webjump-url-encode (str) | |
370 (mapconcat '(lambda (c) | |
371 (cond ((= c 32) "+") | |
372 ((or (and (>= c ?a) (<= c ?z)) | |
373 (and (>= c ?A) (<= c ?Z)) | |
374 (and (>= c ?0) (<= c ?9))) | |
375 (char-to-string c)) | |
376 (t (upcase (format "%%%02x" c))))) | |
377 str | |
378 "")) | |
379 | |
380 (defun webjump-url-fix (url) | |
381 (if (webjump-null-or-blank-string-p url) | |
382 "" | |
383 (webjump-url-fix-trailing-slash | |
384 (cond | |
385 ((string-match "^[a-zA-Z]+:" url) url) | |
386 ((string-match "^/" url) (concat "file://" url)) | |
387 ((string-match "^\\([^\\./]+\\)" url) | |
388 (concat (if (string= (downcase (match-string 1 url)) "ftp") | |
389 "ftp" | |
390 "http") | |
391 "://" | |
392 url)) | |
393 (t url))))) | |
394 | |
395 (defun webjump-url-fix-trailing-slash (url) | |
396 (if (string-match "^[a-zA-Z]+://[^/]+$" url) | |
397 (concat url "/") | |
398 url)) | |
399 | |
400 ;;----------------------------------------------------------------------------- | |
401 | |
402 (provide 'webjump) | |
403 | |
52401 | 404 ;;; arch-tag: f1d20156-0a6f-488b-bd91-f69ee8b6d5cc |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
28210
diff
changeset
|
405 ;;; webjump.el ends here |