Commit 3b369e52 authored by Richard M. Stallman's avatar Richard M. Stallman
Browse files

Initial revision

parent b53e01dc
;;; webjump.el --- programmable Web hotlist
;; Copyright (C) 1996 Free Software Foundation
;; Author: Neil W. Van Dyke <>
;; Created: Fri 09 Aug 1996
;; Keywords: comm www
;; X-URL:
;; This file is part of GNU Emacs.
;; GNU Emacs 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.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;; WebJump provides a sort of ``programmable hotlist'' of Web sites that can
;; quickly be invoked in your Web browser. Each Web site in the hotlist has a
;; name, and you select the desired site name via a completing string prompt in
;; the minibuffer. The URL for each Web site is defined as a static string or
;; a built-in or custom function, allowing interactive prompting for
;; site-specific queries and options.
;; Note that WebJump was originally intended to complement your conventional
;; browser-based hotlist, not replace it. (Though there's no reason you
;; couldn't use WebJump for your entire hotlist if you were so inclined.)
;; The `webjump-sites' variable, which defines the hotlist, defaults to some
;; example sites. You'll probably want to override it with your own favorite
;; sites. The documentation for the variable describes the syntax.
;; You may wish to add something like the following to your `.emacs' file:
;; (load "webjump")
;; (global-set-key "\C-cj" 'webjump)
;; (setq webjump-sites
;; (append '(
;; ("My Home Page" . "")
;; ("Pop's Site" . "")
;; )
;; webjump-sample-sites))
;; The above loads this package, binds `C-c j' to invoke WebJump, and adds
;; your personal favorite sites to the hotlist.
;; The `webjump-sample-sites' constant mostly contains sites that are expected
;; to be generally useful to Emacs users or that have some sort of query which
;; can be coded in WebJump. There are two main goals of this sample site list:
;; (1) demonstrate WebJump capabilities and usage; (2) provide definitions for
;; many popular sites so that people don't have to reinvent the wheel. A few
;; assorted other sites have been thrown in on a whim. No commercial sites are
;; included unless they provide a free, generally-useful service. Inclusion of
;; a site does not represent an endorsement. Please contact the maintainer
;; with change requests.
;; The `browse-url' package is used to submit URLs to the browser, so any
;; browser-specific configuration should be done there.
;; WebJump inherits a small amount code from my `altavista.el' package, and is
;; intended to obsolete that package.
;;; Code:
;;-------------------------------------------------------- Package Dependencies
(require 'browse-url)
;;------------------------------------------------------------------- Constants
(defconst-TEST webjump-sample-sites
'(("AltaVista" .
("Archie" .
[simple-query ""
"" ""])
("Bastard Operator from Hell" . "")
("Brown University" .
[simple-query "" "" ""])
("Computer Professionals for Social Responsibility" . "")
("Digital Espresso" .
[simple-query ""
("Dilbert" . "")
("Electronic Frontier Foundation" . "")
("Emacs Lisp Archive" .
("Free Software Foundation" . "")
("GNU FTP Archive". [mirrors
;; ASIA:
;; USA:
("Insidious Big Brother Database" . "")
("Interactive Weather Information Network" . webjump-to-iwin)
("Java API" . webjump-to-javaapi)
("Lycos" .
[simple-query "" "" ""])
("Mailcrypt" . "")
("Pretty Good Privacy" . "")
("Playboy" . (if (webjump-adult-p) "" ""))
("Usenet FAQs" .
[simple-query ""
("Risks Digest" . webjump-to-risks)
("RTFM Usenet FAQs by Group" .
("RTFM Usenet FAQs by Hierachy" .
("Webster" .
[simple-query ""
"" ""])
("X Consortium Archive". "")
("Yahoo" .
[simple-query "" "" ""])
("Yahoo Emacs" .
("Yahoo Reference" "")
"Sample hotlist for WebJump.")
(defconst webjump-state-to-postal-alist
'(("Alabama" . "al") ("Alaska" . "ak") ("Arizona" . "az") ("Arkansas" . "ar")
("California" . "ca") ("Colorado" . "co") ("Connecticut" . "ct")
("Delaware" . "de") ("Florida" . "fl") ("Georgia" . "ga") ("Hawaii" . "hi")
("Idaho" . "id") ("Illinois" . "il") ("Indiana" . "in") ("Iowa" . "ia")
("Kansas" . "ks") ("Kentucky" . "ky") ("Louisiana" . "la") ("Maine" . "me")
("Maryland" . "md") ("Massachusetts" . "ma") ("Michigan" . "mi")
("Minnesota" . "mn") ("Mississippi" . "ms") ("Missouri" . "mo")
("Montana" . "mt") ("Nebraska" . "ne") ("Nevada" . "nv")
("New Hampshire" . "nh") ("New Jersey" . "nj") ("New Mexico" . "nm")
("New York" . "ny") ("North Carolina" . "nc") ("North Dakota" . "nd")
("Ohio" . "oh") ("Oklahoma" . "ok") ("Oregon" . "or")
("Pennsylvania" . "pa") ("Rhode Island" . "ri") ("South Carolina" . "sc")
("South Dakota" . "sd") ("Tennessee" . "tn") ("Texas" . "tx")
("Utah" . "ut") ("Vermont" . "vt") ("Virginia" . "va")
("Washington" . "wa") ("West Virginia" . "wv") ("Wisconsin" . "wi")
("Wyoming" . "wy")))
;;------------------------------------------------------------ Option Variables
(defvar webjump-sites
"*Hotlist for WebJump.
The hotlist is represented as an association list, with the CAR of each cell
being the name of the Web site, and the CDR being the definition for the URL of
that site. The URL definition can be a string (the URL), a vector (specifying
a special \"builtin\" which returns a URL), a symbol (name of a function which
returns a URL), or a list (which when `eval'ed yields a URL).
If the URL definition is a vector, then a \"builtin\" is used. A builtin has a
Lisp-like syntax, with the name as the first element of the vector, and any
arguments as the following elements. The three current builtins are `name',
which returns the name of the site as the URL, `simple-query', which
returns a URL that is a function of a query entered by the user, and `mirrors',
which allows the user to select from among multiple mirror sites for the same
The first argument to the `simple-query' builtin is a static URL to use if the
user enters a blank query. The second and third arguments are the prefix and
suffix, respectively, to add to the encoded query the user enters. This
builtin covers Web sites that have single-string searches with the query
embedded in the URL.
The arguments to the `mirrors' builtin are URLs of mirror sites.
If the symbol of a function is given, then the function will be called with the
Web site name (the one you specified in the CAR of the alist cell) as a
parameter. This might come in handy for various kludges.
For convenience, if the `http://', `ftp://', or `file://' prefix is missing
from a URL, WebJump will make a guess at what you wanted and prepend it before
submitting the URL.")
;;------------------------------------------------------- Sample Site Functions
(defun webjump-to-iwin (name)
(let ((prefix "")
(state (webjump-read-choice name "state"
(append '(("Puerto Rico" . "pr"))
(if state
(concat prefix "iwin/" state "/"
(webjump-read-choice name "option"
'(("Hourly Report" . "hourly")
("State Forecast" . "state")
("Local Forecast" . "local")
("Zone Forecast" . "zone")
("Short-Term Forecast" . "shortterm")
("Weather Summary" . "summary")
("Public Information" . "public")
("Climatic Data" . "climate")
("Aviation Products" . "aviation")
("Hydro Products" . "hydro")
("Special Weather" . "special")
("Watches and Warnings" . "warnings"))
(defun webjump-to-javaapi (name)
(let* ((prefix "")
(packages '(("java.applet") ("java.awt") ("java.awt.image")
("java.awt.peer") ("") ("java.lang") ("")
("java.util") ("")))
(completion-ignore-case t)
(package (completing-read (concat name " package: ") packages nil t)))
(if (webjump-null-or-blank-string-p package)
(concat prefix "packages.html")
(concat prefix "Package-" package ".html"))))
(defun webjump-to-risks (name)
(let (issue volume)
(if (and (setq volume (webjump-read-number (concat name " volume")))
(setq issue (webjump-read-number (concat name " issue"))))
(format "" volume issue)
;;-------------------------------------------------------------- Core Functions
(defun webjump ()
"Jumps to a Web site from a programmable hotlist.
See the documentation for the `webjump-sites' variable for how to customize the
Feedback on WebJump can be sent to the author, Neil W. Van Dyke <>,
or submitted via `\\[webjump-submit-bug-report]'. The latest version can be
gotten from `'."
(let* ((completion-ignore-case t)
(item (assoc (completing-read "WebJump to site: " webjump-sites nil t)
(name (car item))
(expr (cdr item)))
(funcall browse-url-browser-function
(cond ((not expr) "")
((stringp expr) expr)
((vectorp expr) (webjump-builtin expr name))
((listp expr) (eval expr))
((symbolp expr)
(if (fboundp expr)
(funcall expr name)
(error "WebJump URL function \"%s\" undefined." expr)))
(t (error "WebJump URL expression for \"%s\" invalid."
(defun webjump-adult-p ()
(and (boundp 'age) (integerp age) (>= age 21)))
(defun webjump-builtin (expr name)
(if (< (length expr) 1)
(error "WebJump URL builtin for \"%s\" empty." name))
(let ((builtin (aref expr 0)))
((eq builtin 'mirrors)
(if (= (length expr) 1)
"WebJump URL builtin \"mirrors\" for \"%s\" needs at least 1 arg."))
(webjump-choose-mirror name (cdr (append expr nil))))
((eq builtin 'name)
((eq builtin 'simple-query)
(webjump-builtin-check-args expr name 3)
(webjump-do-simple-query name (aref expr 1) (aref expr 2) (aref expr 3)))
(t (error "WebJump URL builtin \"%s\" for \"%s\" invalid."
builtin name)))))
(defun webjump-builtin-check-args (expr name count)
(or (= (length expr) (1+ count))
(error "WebJump URL builtin \"%s\" for \"%s\" needs %d args."
(aref expr 0) name count)))
(defun webjump-choose-mirror (name urls)
(webjump-read-url-choice (concat name " mirror")
(webjump-mirror-default urls)))
(defun webjump-do-simple-query (name noquery-url query-prefix query-suffix)
(let ((query (webjump-read-string (concat name " query"))))
(if query
(concat query-prefix (webjump-url-encode query) query-suffix)
(defun webjump-mirror-default (urls)
;; Note: This should be modified to apply some simple kludges/heuristics to
;; pick a site which is likely "close". As a tie-breaker among candidates
;; judged equally desirable, randomness should be used.
(car urls))
(defun webjump-read-choice (name what choices &optional default)
(let* ((completion-ignore-case t)
(choice (completing-read (concat name " " what ": ") choices nil t)))
(if (webjump-null-or-blank-string-p choice)
(cdr (assoc choice choices)))))
(defun webjump-read-number (prompt)
;; Note: I should make this more robust someday.
(let ((input (webjump-read-string prompt)))
(if input (string-to-number input))))
(defun webjump-read-string (prompt)
(let ((input (read-string (concat prompt ": "))))
(if (webjump-null-or-blank-string-p input) nil input)))
(defun webjump-read-url-choice (what urls &optional default)
;; Note: Convert this to use `webjump-read-choice' someday.
(let* ((completions (mapcar (function (lambda (n) (cons n n)))
(input (completing-read (concat what
;;(if default " (RET for default)" "")
": ")
(if (webjump-null-or-blank-string-p input)
(car (assoc input completions)))))
(defun webjump-null-or-blank-string-p (str)
(or (null str) (string-match "^[ \t]*$" str)))
(defun webjump-url-encode (str)
(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)))))
(defun webjump-url-fix (url)
(if (webjump-null-or-blank-string-p url)
((string-match "^[a-zA-Z]+:" url) url)
((string-match "^/" url) (concat "file://" url))
((string-match "^\\([^\\./]+\\)" url)
(concat (if (string= (downcase (match-string 1 url)) "ftp")
(t url)))))
(defun webjump-url-fix-trailing-slash (url)
(if (string-match "^[a-zA-Z]+://[^/]+$" url)
(concat url "/")
(provide 'webjump)
;; webjump.el ends here
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment