3
(use-modules (ice-9 optargs) ;let-optional
5
(srfi srfi-2) ;and-let*
7
(srfi srfi-13) ;string-lib
12
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13
;;; Handle search URLs
15
;; Makes a searcher routine. If the routine is called without any
16
;; arguments, return the home page location. Otherwise, construct a
17
;; URL searching for the arguments specified.
19
;; (define f (make-searcher "http://www.google.com/"
20
;; "http://www.google.com/search?q="
21
;; "&btnG=Google%20Search"))
23
;; => "http://www.google.com/"
24
;; (f '("google" "me"))
25
;; => "http://www.google.com/search?q=google%20me&btnG=Google%20Search"
26
(define (make-searcher home-page prefix . maybe-postfix)
27
(let-optional maybe-postfix ((postfix ""))
31
(string-append prefix (string-join words "%20") postfix)))))
33
;; TODO: ,gg -> gg: format update to the standard ELinks one. --pasky
35
(define goto-url-searchers
36
`((",gg" . ,(make-searcher "http://www.google.com/"
37
"http://www.google.com/search?q=" "&btnG=Google%20Search"))
38
(",fm" . ,(make-searcher "http://www.freshmeat.net/"
39
"http://www.freshmeat.net/search/?q="))
40
(",dict" . ,(make-searcher "http://www.dictionary.com/"
41
"http://www.dictionary.com/cgi-bin/dict.pl?db=%2A&term="))
42
(",wtf" . ,(make-searcher "http://www.ucc.ie/cgi-bin/acronym?wtf"
43
"http://www.ucc.ie/cgi-bin/acronym?"))))
45
(add-hook! goto-url-hooks
47
(let* ((words (string-tokenize url))
50
(cond ((assoc key goto-url-searchers) =>
51
(lambda (x) ((cdr x) rest)))
56
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
57
;;; Handle simple URLs
59
(define goto-url-simples
60
`((",forecast" . "http://www.bom.gov.au/cgi-bin/wrap_fwo.pl?IDV10450.txt")
61
(",local" . "XXXXXXXXXXXXXXXXXXX")
64
(add-hook! goto-url-hooks
66
(cond ((assoc url goto-url-simples) => cdr)
71
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
72
;;; Expand ~/ and ~user/ URLs
74
(define (home-directory . maybe-user)
75
(let-optional maybe-user ((user (cuserid)))
76
(and-let* ((user (catch 'misc-error
77
(lambda () (getpwnam user))
81
(define (expand-tilde-file-name file-name)
82
(and (string-prefix? "~" file-name)
83
(let* ((slash/end (or (string-index file-name #\/)
84
(string-length file-name)))
85
(user (substring file-name 1 slash/end)))
86
(string-append (if user
88
(home-directory user))
89
(substring file-name slash/end)))))
91
(add-hook! goto-url-hooks
93
(and (string-prefix? "~" url)
94
(expand-tilde-file-name url))))
97
;;; pre-format-html-hooks
98
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
99
;;; Mangle linuxgames.com pages
101
(add-hook! pre-format-html-hooks
103
(and (string-contains url "linuxgames.com")
104
(and-let* ((start (string-contains html "<CENTER>"))
105
(end (string-contains html "</center>" (+ start 1))))
106
(string-append (substring/shared html 0 start)
107
(substring/shared html (+ end 10)))))))
110
;;; pre-format-html-hooks
111
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
112
;;; Mangle dictionary.com result pages
114
(add-hook! pre-format-html-hooks
116
(and (string-contains url "dictionary.reference.com/search?")
117
(and-let* ((m (string-match
119
"<table border=\"0\" cellpadding=\"2\" width=\"100%\">"
120
".*<td width=\"120\" align=\"center\">")
122
(string-append "<html><head><title>Dictionary.com lookup</title>"
124
(regexp-substitute/global #f
125
"<br>\n<p><b>" (match:substring m 0)
126
'pre "<br>\n<hr>\n<p><b>" 'post))))))
130
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
131
;;; Some addresses require a special proxy
133
(add-hook! get-proxy-hooks
135
(and (or (string-contains url "XXXXXXXXXXXXXX")
136
(string-contains url "XXXXXXXXXXXXXX"))
137
"XXXXXXXXXXXXXXXXXXXXXXXXXXX")))
141
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
142
;;; Some addresses work better without a proxy
144
(add-hook! get-proxy-hooks
146
(and (or (string-contains url "XXXXXXXXXXXXXXXXXXX")
147
(string-contains url "XXXXXXXXXX"))
152
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
153
;;; Delete temporary files when quitting
155
(define temporary-files '())
157
(add-hook! quit-hooks
159
(for-each delete-file temporary-files)))
162
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;