webjump.el 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. ;;; webjump.el --- programmable Web hotlist
  2. ;; Copyright (C) 1996-1997, 2001-2012 Free Software Foundation, Inc.
  3. ;; Author: Neil W. Van Dyke <nwv@acm.org>
  4. ;; Created: 09-Aug-1996
  5. ;; Keywords: comm www
  6. ;; This file is part of GNU Emacs.
  7. ;; GNU Emacs is free software: you can redistribute it and/or modify
  8. ;; it under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation, either version 3 of the License, or
  10. ;; (at your option) any later version.
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;; GNU General Public License for more details.
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  17. ;;; Commentary:
  18. ;; WebJump provides a sort of ``programmable hotlist'' of Web sites that can
  19. ;; quickly be invoked in your Web browser. Each Web site in the hotlist has a
  20. ;; name, and you select the desired site name via a completing string prompt in
  21. ;; the minibuffer. The URL for each Web site is defined as a static string or
  22. ;; a built-in or custom function, allowing interactive prompting for
  23. ;; site-specific queries and options.
  24. ;; Note that WebJump was originally intended to complement your conventional
  25. ;; browser-based hotlist, not replace it. (Though there's no reason you
  26. ;; couldn't use WebJump for your entire hotlist if you were so inclined.)
  27. ;; The `webjump-sites' variable, which defines the hotlist, defaults to some
  28. ;; example sites. You'll probably want to override it with your own favorite
  29. ;; sites. The documentation for the variable describes the syntax.
  30. ;; You may wish to add something like the following to your `.emacs' file:
  31. ;;
  32. ;; (require 'webjump)
  33. ;; (global-set-key "\C-cj" 'webjump)
  34. ;; (setq webjump-sites
  35. ;; (append '(
  36. ;; ("My Home Page" . "www.someisp.net/users/joebobjr/")
  37. ;; ("Pop's Site" . "www.joebob-and-son.com/")
  38. ;; )
  39. ;; webjump-sample-sites))
  40. ;;
  41. ;; The above loads this package, binds `C-c j' to invoke WebJump, and adds your
  42. ;; personal favorite sites to the hotlist.
  43. ;; The `webjump-sample-sites' variable mostly contains some site entries that
  44. ;; are expected to be generally relevant to many users, but excluding
  45. ;; those that the GNU project would not want to recommend.
  46. ;; The `browse-url' package is used to submit URLs to the browser, so any
  47. ;; browser-specific configuration should be done there.
  48. ;;; Code:
  49. ;;-------------------------------------------------------- Package Dependencies
  50. (require 'browse-url)
  51. ;;------------------------------------------------------------------- Constants
  52. (defvar webjump-sample-sites
  53. '(
  54. ;; FSF, not including Emacs-specific.
  55. ("GNU Project FTP Archive" .
  56. ;; GNU FTP Mirror List from http://www.gnu.org/order/ftp.html
  57. [mirrors "ftp://ftp.gnu.org/pub/gnu/"
  58. ;; United States
  59. "ftp://mirrors.kernel.org/gnu"
  60. "ftp://gatekeeper.dec.com/pub/GNU/"
  61. "ftp://ftp.keystealth.org/pub/gnu/"
  62. "ftp://mirrors.usc.edu/pub/gnu/"
  63. "ftp://cudlug.cudenver.edu/pub/mirrors/ftp.gnu.org/"
  64. "ftp://ftp.cise.ufl.edu/pub/mirrors/GNU/"
  65. "ftp://uiarchive.cso.uiuc.edu/pub/ftp/ftp.gnu.org/gnu/"
  66. "ftp://gnu.cs.lewisu.edu/gnu/"
  67. "ftp://ftp.in-span.net/pub/mirrors/ftp.gnu.org/"
  68. "ftp://gnu.ms.uky.edu/pub/mirrors/gnu/"
  69. "ftp://ftp.algx.net/pub/gnu/"
  70. "ftp://aeneas.mit.edu/pub/gnu/"
  71. "ftp://ftp.egr.msu.edu/pub/gnu/"
  72. "ftp://ftp.wayne.edu/pub/gnu/"
  73. "ftp://wuarchive.wustl.edu/mirrors/gnu/"
  74. "ftp://gnu.teleglobe.net/ftp.gnu.org/"
  75. "ftp://ftp.cs.columbia.edu/archives/gnu/prep/"
  76. "ftp://ftp.ece.cornell.edu/pub/mirrors/gnu/"
  77. "ftp://ftp.ibiblio.org/pub/mirrors/gnu/"
  78. "ftp://ftp.cis.ohio-state.edu/mirror/gnu/"
  79. "ftp://ftp.club.cc.cmu.edu/gnu/"
  80. "ftp://ftp.sunsite.utk.edu/pub/gnu/ftp/"
  81. "ftp://thales.memphis.edu/pub/gnu/"
  82. "ftp://gnu.wwc.edu"
  83. "ftp://ftp.twtelecom.net/pub/GNU/"
  84. ;; Africa
  85. "ftp://ftp.sun.ac.za/mirrorsites/ftp.gnu.org"
  86. ;; The Americas
  87. "ftp://ftp.unicamp.br/pub/gnu/"
  88. "ftp://master.softaplic.com.br/pub/gnu/"
  89. "ftp://ftp.matrix.com.br/pub/gnu/"
  90. "ftp://ftp.pucpr.br/gnu"
  91. "ftp://ftp.linorg.usp.br/gnu"
  92. "ftp://ftp.cs.ubc.ca/mirror2/gnu/"
  93. "ftp://cs.ubishops.ca/pub/ftp.gnu.org/"
  94. "ftp://ftp.inf.utfsm.cl/pub/gnu/"
  95. "ftp://sunsite.ulatina.ac.cr/Mirrors/GNU/"
  96. "ftp://www.gnu.unam.mx/pub/gnu/software/"
  97. "ftp://gnu.cem.itesm.mx/pub/mirrors/gnu.org/"
  98. "ftp://ftp.azc.uam.mx/mirrors/gnu/"
  99. ;; Australia
  100. "ftp://mirror.aarnet.edu.au/pub/gnu/"
  101. "ftp://gnu.mirror.pacific.net.au/gnu/"
  102. ;; Asia
  103. "ftp://ftp.cs.cuhk.edu.hk/pub/gnu/gnu/"
  104. "ftp://sunsite.ust.hk/pub/gnu/"
  105. "ftp://ftp.gnupilgrims.org/pub/gnu"
  106. "ftp://www.imtech.res.in/mirror/gnuftp/"
  107. "ftp://kambing.vlsm.org/gnu"
  108. "ftp://ftp.cs.huji.ac.il/mirror/GNU/"
  109. "ftp://tron.um.u-tokyo.ac.jp/pub/GNU/"
  110. "ftp://core.ring.gr.jp/pub/GNU/"
  111. "ftp://ftp.ring.gr.jp/pub/GNU/"
  112. "ftp://mirrors.hbi.co.jp/gnu/"
  113. "ftp://ftp.cs.titech.ac.jp/pub/gnu/"
  114. "ftp://ftpmirror.hanyang.ac.kr/GNU/"
  115. "ftp://ftp.linux.sarang.net/mirror/gnu/gnu/"
  116. "ftp://ftp.xgate.co.kr/pub/mirror/gnu/"
  117. "ftp://ftp://gnu.xinicks.com/"
  118. "ftp://ftp.isu.net.sa/pub/gnu/"
  119. "ftp://ftp.nctu.edu.tw/UNIX/gnu/"
  120. "ftp://coda.nctu.edu.tw/UNIX/gnu/"
  121. "ftp://ftp1.sinica.edu.tw/pub3/GNU/gnu/"
  122. "ftp://gnu.cdpa.nsysu.edu.tw/gnu"
  123. "ftp://ftp.nectec.or.th/pub/mirrors/gnu/"
  124. ;; Europe
  125. "ftp://ftp.gnu.vbs.at/"
  126. "ftp://ftp.univie.ac.at/packages/gnu/"
  127. "ftp://gd.tuwien.ac.at/gnu/gnusrc/"
  128. "ftp://ftp.belnet.be/mirror/ftp.gnu.org/"
  129. "ftp://gnu.blic.net/pub/gnu/"
  130. "ftp://ftp.fi.muni.cz/pub/gnu/"
  131. "ftp://ftp.dkuug.dk/pub/gnu/"
  132. "ftp://sunsite.dk/mirrors/gnu"
  133. "ftp://ftp.funet.fi/pub/gnu/prep/"
  134. "ftp://ftp.irisa.fr/pub/gnu/"
  135. "ftp://ftp.cs.univ-paris8.fr/mirrors/ftp.gnu.org/"
  136. "ftp://ftp.cs.tu-berlin.de/pub/gnu/"
  137. "ftp://ftp.leo.org/pub/comp/os/unix/gnu/"
  138. "ftp://ftp.informatik.rwth-aachen.de/pub/gnu/"
  139. "ftp://ftp.de.uu.net/pub/gnu/"
  140. "ftp://ftp.freenet.de/pub/ftp.gnu.org/gnu/"
  141. "ftp://ftp.cs.uni-bonn.de/pub/gnu/"
  142. "ftp://ftp-stud.fht-esslingen.de/pub/Mirrors/ftp.gnu.org/"
  143. "ftp://ftp.stw-bonn.de/pub/mirror/ftp.gnu.org/"
  144. "ftp://ftp.math.uni-bremen.de/pub/gnu"
  145. "ftp://ftp.forthnet.gr/pub/gnu/"
  146. "ftp://ftp.ntua.gr/pub/gnu/"
  147. "ftp://ftp.duth.gr/pub/gnu/"
  148. "ftp://ftp.physics.auth.gr/pub/gnu/"
  149. "ftp://ftp.esat.net/pub/gnu/"
  150. "ftp://ftp.heanet.ie/mirrors/ftp.gnu.org"
  151. "ftp://ftp.lugroma2.org/pub/gnu/"
  152. "ftp://ftp.gnu.inetcosmos.org/pub/gnu/"
  153. "ftp://ftp.digitaltrust.it/pub/gnu"
  154. "ftp://ftp://rm.mirror.garr.it/mirrors/gnuftp"
  155. "ftp://ftp.nluug.nl/pub/gnu/"
  156. "ftp://ftp.mirror.nl/pub/mirror/gnu/"
  157. "ftp://ftp.nl.uu.net/pub/gnu/"
  158. "ftp://mirror.widexs.nl/pub/gnu/"
  159. "ftp://ftp.easynet.nl/mirror/GNU/"
  160. "ftp://ftp.win.tue.nl/pub/gnu"
  161. "ftp://gnu.mirror.vuurwerk.net/pub/GNU/"
  162. "ftp://gnu.kookel.org/pub/ftp.gnu.org/"
  163. "ftp://ftp.uninett.no/pub/gnu/"
  164. "ftp://ftp.task.gda.pl/pub/gnu/"
  165. "ftp://sunsite.icm.edu.pl/pub/gnu/"
  166. "ftp://ftp.man.poznan.pl/pub/gnu"
  167. "ftp://ftp.ist.utl.pt/pub/GNU/gnu/"
  168. "ftp://ftp.telepac.pt/pub/gnu/"
  169. "ftp://ftp.timisoara.roedu.net/mirrors/ftp.gnu.org/pub/gnu"
  170. "ftp://ftp.chg.ru/pub/gnu/"
  171. "ftp://gnuftp.axitel.ru/"
  172. "ftp://ftp.arnes.si/software/gnu/"
  173. "ftp://ftp.etsimo.uniovi.es/pub/gnu/"
  174. "ftp://ftp.rediris.es/pub/gnu/"
  175. "ftp://ftp.chl.chalmers.se/pub/gnu/"
  176. "ftp://ftp.isy.liu.se/pub/gnu/"
  177. "ftp://ftp.luth.se/pub/unix/gnu/"
  178. "ftp://ftp.stacken.kth.se/pub/gnu/"
  179. "ftp://ftp.sunet.se/pub/gnu/"
  180. "ftp://sunsite.cnlab-switch.ch/mirror/gnu/"
  181. "ftp://ftp.ulak.net.tr/gnu/"
  182. "ftp://ftp.gnu.org.ua"
  183. "ftp://ftp.mcc.ac.uk/pub/gnu/"
  184. "ftp://ftp.mirror.ac.uk/sites/ftp.gnu.org/gnu/"
  185. "ftp://ftp.warwick.ac.uk/pub/gnu/"
  186. "ftp://ftp.hands.com/ftp.gnu.org/"
  187. "ftp://gnu.teleglobe.net/ftp.gnu.org/"])
  188. ("GNU Project Home Page" . "www.gnu.org")
  189. ;; Emacs.
  190. ("Emacs Home Page" .
  191. "www.gnu.org/software/emacs/emacs.html")
  192. ("Savannah Emacs page" .
  193. "savannah.gnu.org/projects/emacs")
  194. ("Emacs Lisp List" .
  195. "www.damtp.cam.ac.uk/user/eglen/emacs/ell.html")
  196. ("Emacs Wiki" .
  197. [simple-query "www.emacswiki.org"
  198. "www.emacswiki.org/cgi-bin/wiki/" ""])
  199. ;; Internet search engines.
  200. ("Google" .
  201. [simple-query "www.google.com"
  202. "www.google.com/search?q=" ""])
  203. ("Google Groups" .
  204. [simple-query "groups.google.com"
  205. "groups.google.com/groups?q=" ""])
  206. ("Yahoo" .
  207. [simple-query "www.yahoo.com" "search.yahoo.com/search?p=" ""])
  208. ("Yahoo: Reference" . "www.yahoo.com/Reference/")
  209. ("Wikipedia" .
  210. [simple-query "wikipedia.org" "wikipedia.org/wiki/" ""])
  211. ;; Misc. general interest.
  212. ("Interactive Weather Information Network" . webjump-to-iwin)
  213. ("Usenet FAQs" .
  214. "www.faqs.org/faqs/")
  215. ("RTFM Usenet FAQs by Group" .
  216. "ftp://rtfm.mit.edu/pub/usenet-by-group/")
  217. ("RTFM Usenet FAQs by Hierarchy" .
  218. "ftp://rtfm.mit.edu/pub/usenet-by-hierarchy/")
  219. ("X Consortium Archive" . "ftp.x.org")
  220. ;; Computer social issues, privacy, professionalism.
  221. ("Association for Computing Machinery" . "www.acm.org")
  222. ("Computer Professionals for Social Responsibility" . "www.cpsr.org")
  223. ("Electronic Frontier Foundation" . "www.eff.org")
  224. ("IEEE Computer Society" . "www.computer.org")
  225. ("Risks Digest" . webjump-to-risks)
  226. ;; More.
  227. ("Supplemental Web site list for webjump" .
  228. "www.neilvandyke.org/webjump/")
  229. )
  230. "Sample hotlist for WebJump. See the documentation for the `webjump'
  231. function and the `webjump-sites' variable.")
  232. (defvar webjump-state-to-postal-alist
  233. '(("Alabama" . "al") ("Alaska" . "ak") ("Arizona" . "az") ("Arkansas" . "ar")
  234. ("California" . "ca") ("Colorado" . "co") ("Connecticut" . "ct")
  235. ("Delaware" . "de") ("Florida" . "fl") ("Georgia" . "ga") ("Hawaii" . "hi")
  236. ("Idaho" . "id") ("Illinois" . "il") ("Indiana" . "in") ("Iowa" . "ia")
  237. ("Kansas" . "ks") ("Kentucky" . "ky") ("Louisiana" . "la") ("Maine" . "me")
  238. ("Maryland" . "md") ("Massachusetts" . "ma") ("Michigan" . "mi")
  239. ("Minnesota" . "mn") ("Mississippi" . "ms") ("Missouri" . "mo")
  240. ("Montana" . "mt") ("Nebraska" . "ne") ("Nevada" . "nv")
  241. ("New Hampshire" . "nh") ("New Jersey" . "nj") ("New Mexico" . "nm")
  242. ("New York" . "ny") ("North Carolina" . "nc") ("North Dakota" . "nd")
  243. ("Ohio" . "oh") ("Oklahoma" . "ok") ("Oregon" . "or")
  244. ("Pennsylvania" . "pa") ("Rhode Island" . "ri") ("South Carolina" . "sc")
  245. ("South Dakota" . "sd") ("Tennessee" . "tn") ("Texas" . "tx")
  246. ("Utah" . "ut") ("Vermont" . "vt") ("Virginia" . "va")
  247. ("Washington" . "wa") ("West Virginia" . "wv") ("Wisconsin" . "wi")
  248. ("Wyoming" . "wy")))
  249. ;;------------------------------------------------------------ Option Variables
  250. (defvar webjump-sites
  251. webjump-sample-sites
  252. "*Hotlist for WebJump.
  253. The hotlist is represented as an association list, with the CAR of each cell
  254. being the name of the Web site, and the CDR being the definition for the URL of
  255. that site. The URL definition can be a string (the URL), a vector (specifying
  256. a special \"builtin\" which returns a URL), a symbol (name of a function which
  257. returns a URL), or a list (which when `eval'ed yields a URL).
  258. If the URL definition is a vector, then a \"builtin\" is used. A builtin has a
  259. Lisp-like syntax, with the name as the first element of the vector, and any
  260. arguments as the following elements. The three current builtins are `name',
  261. which returns the name of the site as the URL, `simple-query', which
  262. returns a URL that is a function of a query entered by the user, and `mirrors',
  263. which allows the user to select from among multiple mirror sites for the same
  264. content.
  265. The first argument to the `simple-query' builtin is a static URL to use if the
  266. user enters a blank query. The second and third arguments are the prefix and
  267. suffix, respectively, to add to the encoded query the user enters. This
  268. builtin covers Web sites that have single-string searches with the query
  269. embedded in the URL.
  270. The arguments to the `mirrors' builtin are URLs of mirror sites.
  271. If the symbol of a function is given, then the function will be called with the
  272. Web site name (the one you specified in the CAR of the alist cell) as a
  273. parameter. This might come in handy for various kludges.
  274. For convenience, if the `http://', `ftp://', or `file://' prefix is missing
  275. from a URL, WebJump will make a guess at what you wanted and prepend it before
  276. submitting the URL.")
  277. ;;------------------------------------------------------- Sample Site Functions
  278. (defun webjump-to-iwin (name)
  279. (let ((prefix "http://iwin.nws.noaa.gov/")
  280. (state (webjump-read-choice name "state"
  281. (append '(("Puerto Rico" . "pr"))
  282. webjump-state-to-postal-alist))))
  283. (if state
  284. (concat prefix "iwin/" state "/"
  285. (webjump-read-choice name "option"
  286. '(("Hourly Report" . "hourly")
  287. ("State Forecast" . "state")
  288. ("Local Forecast" . "local")
  289. ("Zone Forecast" . "zone")
  290. ("Short-Term Forecast" . "shortterm")
  291. ("Weather Summary" . "summary")
  292. ("Public Information" . "public")
  293. ("Climatic Data" . "climate")
  294. ("Aviation Products" . "aviation")
  295. ("Hydro Products" . "hydro")
  296. ("Special Weather" . "special")
  297. ("Watches and Warnings" . "warnings"))
  298. "zone")
  299. ".html")
  300. prefix)))
  301. (defun webjump-to-risks (name)
  302. (let (issue volume)
  303. (if (and (setq volume (webjump-read-number (concat name " volume")))
  304. (setq issue (webjump-read-number (concat name " issue"))))
  305. (format "catless.ncl.ac.uk/Risks/%d.%02d.html" volume issue)
  306. "catless.ncl.ac.uk/Risks/")))
  307. ;;-------------------------------------------------------------- Core Functions
  308. ;;;###autoload
  309. (defun webjump ()
  310. "Jumps to a Web site from a programmable hotlist.
  311. See the documentation for the `webjump-sites' variable for how to customize the
  312. hotlist.
  313. Please submit bug reports and other feedback to the author, Neil W. Van Dyke
  314. <nwv@acm.org>."
  315. (interactive)
  316. (let* ((completion-ignore-case t)
  317. (item (assoc-string
  318. (completing-read "WebJump to site: " webjump-sites nil t)
  319. webjump-sites t))
  320. (name (car item))
  321. (expr (cdr item)))
  322. (browse-url (webjump-url-fix
  323. (cond ((not expr) "")
  324. ((stringp expr) expr)
  325. ((vectorp expr) (webjump-builtin expr name))
  326. ((listp expr) (eval expr))
  327. ((symbolp expr)
  328. (if (fboundp expr)
  329. (funcall expr name)
  330. (error "WebJump URL function \"%s\" undefined"
  331. expr)))
  332. (t (error "WebJump URL expression for \"%s\" invalid"
  333. name)))))))
  334. (defun webjump-builtin (expr name)
  335. (if (< (length expr) 1)
  336. (error "WebJump URL builtin for \"%s\" empty" name))
  337. (let ((builtin (aref expr 0)))
  338. (cond
  339. ((eq builtin 'mirrors)
  340. (if (= (length expr) 1)
  341. (error
  342. "WebJump URL builtin \"mirrors\" for \"%s\" needs at least 1 arg"
  343. name))
  344. (webjump-choose-mirror name (cdr (append expr nil))))
  345. ((eq builtin 'name)
  346. name)
  347. ((eq builtin 'simple-query)
  348. (webjump-builtin-check-args expr name 3)
  349. (webjump-do-simple-query name (aref expr 1) (aref expr 2) (aref expr 3)))
  350. (t (error "WebJump URL builtin \"%s\" for \"%s\" invalid"
  351. builtin name)))))
  352. (defun webjump-builtin-check-args (expr name count)
  353. (or (= (length expr) (1+ count))
  354. (error "WebJump URL builtin \"%s\" for \"%s\" needs %d args"
  355. (aref expr 0) name count)))
  356. (defun webjump-choose-mirror (name urls)
  357. (webjump-read-url-choice (concat name " mirror")
  358. urls
  359. (webjump-mirror-default urls)))
  360. (defun webjump-do-simple-query (name noquery-url query-prefix query-suffix)
  361. (let ((query (webjump-read-string (concat name " query"))))
  362. (if query
  363. (concat query-prefix (webjump-url-encode query) query-suffix)
  364. noquery-url)))
  365. (defun webjump-mirror-default (urls)
  366. ;; Note: This should be modified to apply some simple kludges/heuristics to
  367. ;; pick a site which is likely "close". As a tie-breaker among candidates
  368. ;; judged equally desirable, randomness might be used.
  369. (car urls))
  370. (defun webjump-read-choice (name what choices &optional default)
  371. (let* ((completion-ignore-case t)
  372. (choice (completing-read (concat name " " what ": ") choices nil t)))
  373. (if (webjump-null-or-blank-string-p choice)
  374. default
  375. (cdr (assoc choice choices)))))
  376. (defun webjump-read-number (prompt)
  377. ;; Note: I should make this more robust someday.
  378. (let ((input (webjump-read-string prompt)))
  379. (if input (string-to-number input))))
  380. (defun webjump-read-string (prompt)
  381. (let ((input (read-string (concat prompt ": "))))
  382. (if (webjump-null-or-blank-string-p input) nil input)))
  383. (defun webjump-read-url-choice (what urls &optional default)
  384. ;; Note: Convert this to use `webjump-read-choice' someday.
  385. (let* ((completions (mapcar (function (lambda (n) (cons n n)))
  386. urls))
  387. (input (completing-read (concat what
  388. ;;(if default " (RET for default)" "")
  389. ": ")
  390. completions
  391. nil
  392. t)))
  393. (if (webjump-null-or-blank-string-p input)
  394. default
  395. (car (assoc input completions)))))
  396. (defun webjump-null-or-blank-string-p (str)
  397. (or (null str) (string-match "^[ \t]*$" str)))
  398. (defun webjump-url-encode (str)
  399. (mapconcat (lambda (c)
  400. (let ((s (char-to-string c)))
  401. (cond ((string= s " ") "+")
  402. ((string-match "[a-zA-Z_.-/]" s) s)
  403. (t (upcase (format "%%%02x" c))))))
  404. (encode-coding-string str 'utf-8)
  405. ""))
  406. (defun webjump-url-fix (url)
  407. (if (webjump-null-or-blank-string-p url)
  408. ""
  409. (webjump-url-fix-trailing-slash
  410. (cond
  411. ((string-match "^[a-zA-Z]+:" url) url)
  412. ((string-match "^/" url) (concat "file://" url))
  413. ((string-match "^\\([^\\./]+\\)" url)
  414. (concat (if (string= (downcase (match-string 1 url)) "ftp")
  415. "ftp"
  416. "http")
  417. "://"
  418. url))
  419. (t url)))))
  420. (defun webjump-url-fix-trailing-slash (url)
  421. (if (string-match "^[a-zA-Z]+://[^/]+$" url)
  422. (concat url "/")
  423. url))
  424. ;;-----------------------------------------------------------------------------
  425. (provide 'webjump)
  426. ;;; webjump.el ends here