2
|
1 ;;; w3.el --- Main functions for emacs-w3 on all platforms/versions
|
0
|
2 ;; Author: wmperry
|
70
|
3 ;; Created: 1996/08/19 03:30:47
|
|
4 ;; Version: 1.22
|
0
|
5 ;; Keywords: faces, help, comm, news, mail, processes, mouse, hypermedia
|
|
6
|
|
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2
|
8 ;;; Copyright (c) 1993 - 1996 by William M. Perry (wmperry@cs.indiana.edu)
|
0
|
9 ;;;
|
70
|
10 ;;; This file is not part of GNU Emacs, but the same permissions apply.
|
0
|
11 ;;;
|
|
12 ;;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
13 ;;; it under the terms of the GNU General Public License as published by
|
|
14 ;;; the Free Software Foundation; either version 2, or (at your option)
|
|
15 ;;; any later version.
|
|
16 ;;;
|
|
17 ;;; GNU Emacs is distributed in the hope that it will be useful,
|
|
18 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
20 ;;; GNU General Public License for more details.
|
|
21 ;;;
|
|
22 ;;; You should have received a copy of the GNU General Public License
|
70
|
23 ;;; along with GNU Emacs; see the file COPYING. If not, write to
|
|
24 ;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
0
|
25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
26
|
|
27 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
28 ;;; This is a major mode for browsing documents written in Hypertext Markup ;;;
|
|
29 ;;; Language (HTML). These documents are typicallly part of the World Wide ;;;
|
|
30 ;;; Web (WWW), a project to create a global information net in hypertext ;;;
|
|
31 ;;; format. ;;;
|
|
32 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
33
|
|
34 ;;; first start by making sure the load path is properly set. This code
|
|
35 ;;; is mostly taken from calc-2.02b
|
|
36 ;;;
|
|
37 ;;; this allows you to put the following in your .emacs file, instead of
|
|
38 ;;; having to know what the load-path for the w3 files is.
|
|
39 ;;;
|
|
40 ;;; (autoload 'w3 "w3/w3" "WWW Browser" t)
|
|
41
|
|
42 ;;; If w3 files exist on the load-path, we're all set.
|
|
43 (let ((name (and (fboundp 'w3)
|
|
44 (eq (car-safe (symbol-function 'w3)) 'autoload)
|
|
45 (nth 1 (symbol-function 'w3))))
|
|
46 (p load-path))
|
|
47 (while (and p (not (file-exists-p
|
|
48 (expand-file-name "w3-vars.elc" (car p)))))
|
|
49 (setq p (cdr p)))
|
|
50 (or p
|
|
51 ;;; If w3 is autoloaded using a path name, look there for w3 files.
|
|
52 ;;; This works for both relative ("w3/w3.elc") and absolute paths.
|
|
53 (and name (file-name-directory name)
|
|
54 (let ((p2 load-path)
|
|
55 (name2 (concat (file-name-directory name)
|
|
56 "w3-vars.elc")))
|
|
57 (while (and p2 (not (file-exists-p
|
|
58 (expand-file-name name2 (car p2)))))
|
|
59 (setq p2 (cdr p2)))
|
|
60 (if p2
|
|
61 (setq load-path (nconc load-path
|
|
62 (list
|
|
63 (directory-file-name
|
|
64 (file-name-directory
|
|
65 (expand-file-name
|
|
66 name (car p2)))))))))))
|
|
67 )
|
|
68
|
|
69
|
70
|
70 (load-library "w3-sysdp")
|
0
|
71 (or (featurep 'efs)
|
|
72 (featurep 'efs-auto)
|
|
73 (condition-case ()
|
|
74 (require 'ange-ftp)
|
|
75 (error nil)))
|
|
76
|
|
77 (require 'cl)
|
|
78 (require 'w3-vars)
|
|
79 (eval-and-compile
|
70
|
80 (require 'w3-draw))
|
0
|
81
|
|
82
|
|
83 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
84 ;;; Code for printing out roman numerals
|
|
85 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
86 (defun w3-decimal-to-roman (n)
|
|
87 ;; Convert from decimal to roman numerals
|
|
88 (let ((curmod 1000)
|
|
89 (str "")
|
|
90 (j 7)
|
|
91 i2 k curcnt)
|
|
92 (while (>= curmod 1)
|
|
93 (if (>= n curmod)
|
|
94 (progn
|
|
95 (setq curcnt (/ n curmod)
|
|
96 n (- n (* curcnt curmod)))
|
|
97 (if (= 4 (% curcnt 5))
|
|
98 (setq i2 (+ j (if (> curcnt 5) 1 0))
|
|
99 str (format "%s%c%c" str
|
|
100 (aref w3-roman-characters (1- j))
|
|
101 (aref w3-roman-characters i2)))
|
|
102 (progn
|
|
103 (if (>= curcnt 5)
|
|
104 (setq str (format "%s%c" str (aref w3-roman-characters j))
|
|
105 curcnt (- curcnt 5)))
|
|
106 (setq k 0)
|
|
107 (while (< k curcnt)
|
|
108 (setq str (format "%s%c" str
|
|
109 (aref w3-roman-characters (1- j)))
|
|
110 k (1+ k)))))))
|
|
111 (setq curmod (/ curmod 10)
|
|
112 j (- j 2)))
|
|
113 str))
|
|
114
|
|
115 (defun w3-decimal-to-alpha (n)
|
|
116 ;; Convert from decimal to alphabetical (a, b, c, ..., aa, ab,...)
|
|
117 (cond
|
|
118 ((< n 1) (char-to-string ?Z))
|
|
119 ((<= n 26) (char-to-string (+ ?A (1- n))))
|
|
120 (t (concat (char-to-string (+ ?A (1- (/ n 27))))
|
|
121 (w3-decimal-to-alpha (% n 26))))))
|
|
122
|
|
123
|
|
124 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
70
|
125 ;;; Functions for compatibility with XMosaic
|
|
126 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
127
|
|
128 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
129 ;;; Parse out the Mosaic documents-menu file
|
|
130 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
131 (defun w3-parse-docs-menu ()
|
|
132 ;; Parse the Mosaic documents menu
|
|
133 (let ((tmp-menu (append '((separator)) w3-starting-documents
|
|
134 '((separator))))
|
|
135 real-menu x y name url)
|
|
136 (if (or (not (file-exists-p w3-documents-menu-file))
|
|
137 (not (file-readable-p w3-documents-menu-file)))
|
|
138 nil
|
|
139 (save-excursion
|
|
140 (set-buffer (get-buffer-create " *w3-temp*"))
|
|
141 (erase-buffer)
|
|
142 (insert-file-contents w3-documents-menu-file)
|
|
143 (goto-char (point-min))
|
|
144 (while (not (eobp))
|
|
145 (if (not (looking-at "-+$"))
|
|
146 (setq x (progn (beginning-of-line) (point))
|
|
147 y (progn (end-of-line) (point))
|
|
148 name (prog1
|
|
149 (buffer-substring x y)
|
|
150 (delete-region x (min (1+ y) (point-max))))
|
|
151 x (progn (beginning-of-line) (point))
|
|
152 y (progn (end-of-line) (point))
|
|
153 url (prog1
|
|
154 (buffer-substring x y)
|
|
155 (delete-region x (min (1+ y) (point-max))))
|
|
156 tmp-menu (if (rassoc url tmp-menu) tmp-menu
|
|
157 (cons (cons name url) tmp-menu)))
|
|
158 (setq tmp-menu (cons '(separator) tmp-menu))
|
|
159 (delete-region (point-min) (min (1+ (progn (end-of-line)
|
|
160 (point)))
|
|
161 (point-max)))))
|
|
162 (kill-buffer (current-buffer))))
|
|
163 (if (equal (car (car tmp-menu)) "") (setq tmp-menu (cdr tmp-menu)))
|
|
164 (while tmp-menu
|
|
165 (setq real-menu (cons (if (equal 'separator (car (car tmp-menu)))
|
|
166 "--------"
|
|
167 (vector (car (car tmp-menu))
|
|
168 (list 'w3-fetch
|
|
169 (if (listp (cdr (car tmp-menu)))
|
|
170 (car (cdr (car tmp-menu)))
|
|
171 (cdr (car tmp-menu)))) t))
|
|
172 real-menu)
|
|
173 tmp-menu (cdr tmp-menu)))
|
|
174 (setq w3-navigate-menu (append w3-navigate-menu real-menu
|
|
175 (list "-----")))))
|
|
176
|
|
177
|
|
178 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
0
|
179 ;;; Functions to pass files off to external viewers
|
|
180 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
181 (defun w3-start-viewer (fname cmd &optional view)
|
70
|
182 "Start a subprocess, named FNAME, executing CMD
|
0
|
183 If third arg VIEW is non-nil, show the output in a buffer when
|
|
184 the subprocess exits."
|
|
185 (if view (save-excursion
|
|
186 (set-buffer (get-buffer-create view))
|
|
187 (erase-buffer)))
|
70
|
188 (let ((proc
|
|
189 (start-process fname view (or shell-file-name
|
|
190 (getenv "ESHELL")
|
|
191 (getenv "SHELL")
|
|
192 "/bin/sh") "-c" cmd)))
|
|
193 proc))
|
0
|
194
|
|
195 (defun w3-viewer-filter (proc string)
|
|
196 ;; A process filter for asynchronous external viewers
|
|
197 (let ((buff (get-buffer-create (url-generate-new-buffer-name
|
|
198 (symbol-name
|
|
199 (read (nth 2 (process-command proc))))))))
|
|
200 (save-excursion
|
|
201 (set-buffer buff)
|
|
202 (erase-buffer)
|
|
203 (insert string)
|
|
204 (set-process-buffer proc buff)
|
|
205 (set-process-filter proc nil))))
|
|
206
|
|
207 (defun w3-viewer-sentinel (proc string)
|
|
208 ;; Delete any temp files left from a viewer process.
|
|
209 (let ((fname (process-name proc))
|
|
210 (buffr (process-buffer proc))
|
|
211 (status (process-exit-status proc)))
|
|
212 (if buffr
|
|
213 (w3-notify-when-ready buffr))
|
|
214 (and (/= 0 status)
|
|
215 (funcall url-confirmation-func
|
|
216 (format "Viewer for %s failed... save to disk? " fname))
|
|
217 (copy-file fname (read-file-name "Save as: ") t))
|
|
218 (if (and (file-exists-p fname)
|
|
219 (file-writable-p fname))
|
|
220 (delete-file fname))))
|
|
221
|
|
222 (defun w3-notify-when-ready (buff)
|
|
223 "Notify the user when BUFF is ready.
|
|
224 See the variable `w3-notify' for the different notification behaviors."
|
|
225 (if (stringp buff) (setq buff (get-buffer buff)))
|
|
226 (cond
|
|
227 ((null buff) nil)
|
|
228 ((eq w3-notify 'newframe)
|
|
229 ;; Since we run asynchronously, perhaps while Emacs is waiting for input,
|
|
230 ;; we must not leave a different buffer current.
|
|
231 ;; We can't rely on the editor command loop to reselect
|
|
232 ;; the selected window's buffer.
|
|
233 (save-excursion
|
|
234 (set-buffer buff)
|
|
235 (make-frame)))
|
|
236 ((eq w3-notify 'bully)
|
|
237 (pop-to-buffer buff)
|
|
238 (delete-other-windows))
|
|
239 ((eq w3-notify 'semibully)
|
70
|
240 (switch-to-buffer buff))
|
0
|
241 ((eq w3-notify 'aggressive)
|
|
242 (pop-to-buffer buff))
|
|
243 ((eq w3-notify 'friendly)
|
|
244 (display-buffer buff 'not-this-window))
|
|
245 ((eq w3-notify 'polite)
|
|
246 (beep)
|
|
247 (message "W3 buffer %s is ready." (buffer-name buff)))
|
|
248 ((eq w3-notify 'quiet)
|
|
249 (message "W3 buffer %s is ready." (buffer-name buff)))
|
|
250 (t (message ""))))
|
|
251
|
|
252 (defun w3-pass-to-viewer ()
|
|
253 ;; Pass a w3 buffer to a viewer
|
|
254 (set-buffer url-working-buffer)
|
|
255 (let* ((info url-current-mime-viewer) ; All the MIME viewer info
|
|
256 (view (cdr-safe (assoc "viewer" info))) ; How to view this file
|
|
257 (url (url-view-url t))
|
|
258 (fmt (cdr-safe (assoc "nametemplate" info)))) ; Template for name
|
|
259 (cond
|
|
260 (fmt nil)
|
|
261 ((cdr-safe (assoc "type" info))
|
|
262 (setq fmt (mm-type-to-file (cdr-safe (assoc "type" info))))
|
70
|
263 (if fmt (setq fmt (concat "%s" (car fmt)))
|
|
264 (setq fmt (concat "%s" (url-file-extension url-current-file))))))
|
0
|
265 (if (null view)
|
|
266 (setq view 'indented-text-mode))
|
|
267 (cond
|
|
268 ((symbolp view)
|
|
269 (if (not (memq view '(w3-prepare-buffer w3-print w3-source
|
|
270 w3-default-local-file
|
|
271 mm-multipart-viewer)))
|
|
272 (let ((bufnam (url-generate-new-buffer-name
|
|
273 (file-name-nondirectory
|
70
|
274 (or url-current-file "Unknown")))))
|
0
|
275 (if (string= bufnam "")
|
|
276 (setq bufnam (url-generate-new-buffer-name
|
|
277 (url-view-url t))))
|
|
278 (rename-buffer bufnam)
|
|
279 ;; Make the URL show in list-buffers output
|
|
280 (make-local-variable 'list-buffers-directory)
|
|
281 (setq list-buffers-directory (url-view-url t))
|
|
282 (set-buffer-modified-p nil)
|
|
283 (buffer-enable-undo)
|
|
284 (funcall view)
|
|
285 (w3-notify-when-ready bufnam))
|
|
286 (funcall view)))
|
|
287 ((stringp view)
|
2
|
288 (let ((fname (url-generate-unique-filename fmt))
|
70
|
289 (proc nil)
|
|
290 (file-coding-system url-mule-no-coding-system))
|
0
|
291 (if (url-file-directly-accessible-p (url-view-url t))
|
70
|
292 (make-symbolic-link url-current-file fname t)
|
|
293 (write-region (point-min) (point-max) fname))
|
0
|
294 (if (get-buffer url-working-buffer)
|
|
295 (kill-buffer url-working-buffer))
|
2
|
296 (setq view (mm-viewer-unescape view fname url))
|
0
|
297 (message "Passing to viewer %s " view)
|
|
298 (setq proc (w3-start-viewer fname view))
|
|
299 (set-process-filter proc 'w3-viewer-filter)
|
|
300 (set-process-sentinel proc 'w3-viewer-sentinel)))
|
|
301 ((listp view)
|
|
302 (set-buffer-modified-p nil)
|
|
303 (buffer-enable-undo)
|
|
304 (eval view))
|
|
305 (t
|
|
306 (message "Unknown viewer specified: %s" view)
|
|
307 (w3-notify-when-ready url-working-buffer)))))
|
|
308
|
|
309 (defun w3-save-binary-file ()
|
|
310 "Save a buffer to disk - this is used when `w3-dump-to-disk' is non-nil"
|
2
|
311 ;; Ok, this is truly fucked. In XEmacs, if you use the mouse to select
|
|
312 ;; a URL that gets saved via this function, read-file-name will pop up a
|
|
313 ;; dialog box for file selection. For some reason which buffer we are in
|
|
314 ;; gets royally screwed (even with save-excursions and the whole nine
|
|
315 ;; yards). SO, we just keep the old buffer name around and away we go.
|
|
316 (let ((old-buff (current-buffer))
|
|
317 (file (read-file-name "Filename to save as: "
|
|
318 (or mm-download-directory "~/")
|
|
319 (url-remove-compressed-extensions
|
|
320 (file-name-nondirectory (url-view-url t)))
|
|
321 nil
|
|
322 (url-remove-compressed-extensions
|
|
323 (file-name-nondirectory (url-view-url t)))))
|
|
324 (require-final-newline nil))
|
|
325 (set-buffer old-buff)
|
70
|
326 (let ((mc-flag t)
|
|
327 (file-coding-system url-mule-no-coding-system))
|
|
328 (write-region (point-min) (point-max) file))
|
2
|
329 (kill-buffer (current-buffer))))
|
0
|
330
|
70
|
331 (defun w3-build-url (protocol)
|
|
332 "Build a url for PROTOCOL, return it as a string"
|
|
333 (interactive (list (cdr (assoc (completing-read
|
|
334 "Protocol: "
|
|
335 w3-acceptable-protocols-alist nil t)
|
|
336 w3-acceptable-protocols-alist))))
|
|
337 (let (user host port file)
|
|
338 (cond
|
|
339 ((null protocol) (error "Protocol is unknown to me!"))
|
|
340 ((string= protocol "news")
|
|
341 (setq host (read-string "Enter news server name, or blank for default: ")
|
|
342 port (read-string "Enter port number, or blank for default: ")
|
|
343 file (read-string "Newgroup name or Message-ID: ")))
|
|
344 ((string= protocol "mailto") (setq file (read-string "E-mail address: ")))
|
|
345 ((string= protocol "http")
|
|
346 (setq host (read-string "Enter server name: ")
|
|
347 port (read-string "Enter port number, or blank for default: ")
|
|
348 file (read-string "Remote file: "))
|
|
349 (and (string= "" port) (setq port nil))
|
|
350 (and (string= "" host) (error "Must specify a remote machine!")))
|
|
351 ((string= protocol "file")
|
|
352 (if (funcall url-confirmation-func "Local file?")
|
|
353 (setq file (read-file-name "Local File: " nil nil t))
|
|
354 (setq user (read-string "Login as user (blank=anonymous): ")
|
|
355 host (read-string "Remote machine name: "))
|
|
356 (and (string= user "") (setq user "anonymous"))
|
|
357 (and (string= host "") (error "Must specify a remote machine!"))
|
|
358 (setq file (read-file-name "File: " (format "/%s@%s:" user host)
|
|
359 nil t)
|
|
360 file (substring file (length (format "/%s@%s:" user host))))))
|
|
361 ((or (string= protocol "telnet")
|
|
362 (string= protocol "tn3270"))
|
|
363 (setq user (read-string "Login as user (blank=none): ")
|
|
364 host (read-string "Remote machine name: ")
|
|
365 port (read-string "Port number (blank=23): "))
|
|
366 (and (string= "" port) (setq port nil))
|
|
367 (and (string= "" user) (setq user nil))
|
|
368 (and (string= "" host) (error "Must specify a host machine!")))
|
|
369 ((string= protocol "gopher")
|
|
370 (setq host (read-string "Enter server name: ")
|
|
371 port (read-string "Enter port number, or blank for default: ")
|
|
372 file (read-string "Remote file: "))
|
|
373 (and (string= "" port) (setq port nil))
|
|
374 (and (string= "" host) (error "Must specify a remote machine!"))))
|
|
375 (message "%s:%s%s"
|
|
376 protocol
|
|
377 (if (null host) "" (concat "//" host
|
|
378 (if (null port) "" (concat ":" port))))
|
|
379 (if (= ?/ (string-to-char file)) file (concat "/" file)))))
|
|
380
|
0
|
381 ;;;###autoload
|
|
382 (defun w3-open-local (fname)
|
|
383 "Find a local file, and interpret it as a hypertext document.
|
|
384 It will prompt for an existing file or directory, and retrieve it as a
|
70
|
385 hypertext document. If it is a directory, and url-use-hypertext-dired
|
|
386 is non-nil, then an HTML directory listing is created on the fly.
|
|
387 Otherwise, dired-mode is used to visit the buffer."
|
0
|
388 (interactive "FLocal file: ")
|
|
389 (if (not w3-setup-done) (w3-do-setup))
|
|
390 (w3-fetch (concat "file:" fname)))
|
|
391
|
|
392 ;;;###autoload
|
|
393 (defun w3-find-file (fname)
|
|
394 "Find a local file, and interpret it as a hypertext document.
|
|
395 It will prompt for an existing file or directory, and retrieve it as a
|
70
|
396 hypertext document. If it is a directory, and url-use-hypertext-dired
|
|
397 is non-nil, then an HTML directory listing is created on the fly.
|
|
398 Otherwise, dired-mode is used to visit the buffer."
|
0
|
399 (interactive "FLocal file: ")
|
|
400 (w3-open-local fname))
|
|
401
|
|
402 ;;;###autoload
|
|
403 (defun w3-fetch-other-frame (&optional url)
|
|
404 "Attempt to follow the hypertext reference under point in a new frame.
|
|
405 With prefix-arg P, ignore viewers and dump the link straight
|
|
406 to disk."
|
|
407 (interactive (list (w3-read-url-with-default)))
|
|
408 (cond
|
|
409 ((and (fboundp 'make-frame)
|
|
410 (fboundp 'select-frame)
|
|
411 (not (eq (device-type) 'tty)))
|
|
412 (let ((frm (make-frame)))
|
|
413 (select-frame frm)
|
|
414 (delete-other-windows)
|
|
415 (w3-fetch url)))
|
|
416 (t (w3-fetch url))))
|
|
417
|
|
418 (defun w3-fetch-other-window (&optional url)
|
|
419 "Attempt to follow the hypertext reference under point in a new window.
|
|
420 With prefix-arg P, ignore viewers and dump the link straight
|
|
421 to disk."
|
|
422 (interactive (list (w3-read-url-with-default)))
|
|
423 (split-window)
|
|
424 (w3-fetch url))
|
|
425
|
|
426 (defun w3-url-completion-function (string predicate function)
|
|
427 (if (not w3-setup-done) (w3-do-setup))
|
|
428 (cond
|
70
|
429 ((null function)
|
|
430 (cond
|
|
431 ((get 'url-gethash 'sysdep-defined-this)
|
|
432 ;; Cheat! If we know that these are the sysdep-defined version
|
|
433 ;; of hashtables, they are an obarray.
|
|
434 (try-completion string url-global-history-hash-table predicate))
|
|
435 ((url-hashtablep url-global-history-hash-table)
|
|
436 (let ((list nil))
|
|
437 (url-maphash (function (lambda (key val)
|
|
438 (setq list (cons (cons (symbol-name key) val)
|
|
439 list))))
|
|
440 url-global-history-hash-table)
|
|
441 (try-completion string (nreverse list) predicate)))
|
|
442 (t nil)))
|
0
|
443 ((eq function t)
|
70
|
444 (cond
|
|
445 ((get 'url-gethash 'sysdep-defined-this)
|
|
446 ;; Cheat! If we know that these are the sysdep-defined version
|
|
447 ;; of hashtables, they are an obarray.
|
|
448 (all-completions string url-global-history-hash-table predicate))
|
|
449 ((url-hashtablep url-global-history-hash-table)
|
|
450 (let ((stub (concat "^" (regexp-quote string)))
|
|
451 (retval nil))
|
|
452 (url-maphash
|
|
453 (function
|
|
454 (lambda (url time)
|
|
455 (setq url (symbol-name url))
|
|
456 (if (string-match stub url)
|
|
457 (setq retval (cons url retval)))))
|
|
458 url-global-history-hash-table)
|
|
459 retval))
|
|
460 (t nil)))
|
0
|
461 ((eq function 'lambda)
|
70
|
462 (and (url-hashtablep url-global-history-hash-table)
|
|
463 (url-gethash string url-global-history-hash-table)
|
|
464 t))))
|
0
|
465
|
|
466 (defun w3-read-url-with-default ()
|
|
467 (url-do-setup)
|
|
468 (let* ((completion-ignore-case t)
|
|
469 (default
|
70
|
470 (if (eq major-mode 'w3-mode)
|
|
471 (if (and current-prefix-arg (w3-view-this-url t))
|
|
472 (w3-view-this-url t)
|
|
473 (url-view-url t))
|
|
474 (url-get-url-at-point)))
|
0
|
475 (url nil))
|
70
|
476 (if (not default)
|
|
477 (setq default "http://www."))
|
0
|
478 (setq url
|
|
479 (completing-read "URL: " 'w3-url-completion-function
|
|
480 nil nil default))
|
|
481 (if (string= url "")
|
|
482 (setq url (if (eq major-mode 'w3-mode)
|
|
483 (if (and current-prefix-arg (w3-view-this-url t))
|
|
484 (w3-view-this-url t)
|
|
485 (url-view-url t))
|
|
486 (url-get-url-at-point))))
|
|
487 url))
|
|
488
|
|
489 ;;;###autoload
|
70
|
490 (defun w3-fetch (&optional url)
|
0
|
491 "Retrieve a document over the World Wide Web.
|
70
|
492 The World Wide Web is a global hypertext system started by CERN in
|
|
493 Switzerland in 1991.
|
|
494
|
|
495 The document should be specified by its fully specified
|
|
496 Uniform Resource Locator. The document will be parsed, printed, or
|
|
497 passed to an external viewer as appropriate. Variable
|
|
498 `mm-mime-info' specifies viewers for particular file types."
|
0
|
499 (interactive (list (w3-read-url-with-default)))
|
|
500 (if (not w3-setup-done) (w3-do-setup))
|
|
501 (if (boundp 'w3-working-buffer)
|
|
502 (setq w3-working-buffer url-working-buffer))
|
|
503 (if (and (boundp 'command-line-args-left)
|
|
504 command-line-args-left
|
|
505 (string-match url-nonrelative-link (car command-line-args-left)))
|
|
506 (setq url (car command-line-args-left)
|
|
507 command-line-args-left (cdr command-line-args-left)))
|
|
508 (if (equal url "") (error "No document specified!"))
|
|
509 ;; legal use for relative URLs ?
|
|
510 (if (string-match "^www:[^/].*" url)
|
70
|
511 (setq url (concat (file-name-directory url-current-file)
|
0
|
512 (substring url 4))))
|
|
513 ;; In the common case, this is probably cheaper than searching.
|
|
514 (while (= (string-to-char url) ? )
|
|
515 (setq url (substring url 1)))
|
|
516 (cond
|
|
517 ((= (string-to-char url) ?#)
|
|
518 (w3-relative-link url))
|
|
519 ((or (and (interactive-p) current-prefix-arg) w3-dump-to-disk)
|
|
520 (w3-download-url url))
|
|
521 (t
|
|
522 (let ((x (url-view-url t))
|
|
523 (lastbuf (current-buffer))
|
|
524 (buf (url-buffer-visiting url)))
|
70
|
525 (and x (or (string= "file:nil" x) (string= "" x))
|
|
526 (setq x nil))
|
0
|
527 (if (or (not buf)
|
|
528 (cond
|
|
529 ((not (equal (downcase (or url-request-method "GET")) "get")) t)
|
|
530 ((memq w3-reuse-buffers '(no never reload)) t)
|
|
531 ((memq w3-reuse-buffers '(yes reuse always)) nil)
|
|
532 (t
|
|
533 (if (and w3-reuse-buffers (not (eq w3-reuse-buffers 'ask)))
|
|
534 (progn
|
|
535 (ding)
|
|
536 (message
|
|
537 "Warning: Invalid value for variable w3-reuse-buffers: %s"
|
|
538 (prin1-to-string w3-reuse-buffers))
|
|
539 (sit-for 2)))
|
|
540 (not (funcall url-confirmation-func
|
|
541 (format "Reuse URL in buffer %s? "
|
|
542 (buffer-name buf)))))))
|
70
|
543 (let ((cached (url-retrieve url)))
|
0
|
544 (if w3-track-last-buffer
|
|
545 (setq w3-last-buffer (get-buffer url-working-buffer)))
|
|
546 (if (get-buffer url-working-buffer)
|
|
547 (cond
|
70
|
548 ((and url-be-asynchronous (string-match "^http:" url)
|
|
549 (not cached))
|
0
|
550 (save-excursion
|
|
551 (set-buffer url-working-buffer)
|
|
552 (if x
|
70
|
553 (w3-add-urls-to-history x (url-view-url t)))
|
0
|
554 (setq w3-current-last-buffer lastbuf)))
|
|
555 (t
|
70
|
556 (w3-add-urls-to-history x url)
|
26
|
557 (w3-sentinel lastbuf)))))
|
0
|
558 (if w3-track-last-buffer
|
|
559 (setq w3-last-buffer buf))
|
2
|
560 (let ((w3-notify (if (memq w3-notify '(newframe bully
|
|
561 semibully aggressive))
|
0
|
562 w3-notify
|
|
563 'aggressive)))
|
|
564 (w3-notify-when-ready buf))
|
|
565 (if (string-match "#\\(.*\\)" url)
|
|
566 (progn
|
|
567 (push-mark (point) t)
|
|
568 (w3-find-specific-link (url-match url 1))))
|
70
|
569 (message "Reusing URL. To reload, type %s."
|
|
570 (substitute-command-keys "\\[w3-reload-document]")))))))
|
0
|
571
|
|
572
|
|
573 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
574 ;;; History for forward/back buttons
|
|
575 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
70
|
576 (defvar w3-node-history nil "History for forward and backward jumping")
|
0
|
577
|
70
|
578 (defun w3-plot-course ()
|
|
579 "Show a map of where the user has been in this session of W3. !!!!NYI!!!"
|
|
580 (interactive)
|
|
581 (error "Sorry, w3-plot-course is not yet implemented."))
|
0
|
582
|
70
|
583 (defun w3-forward-in-history ()
|
0
|
584 "Go forward in the history from this page"
|
|
585 (interactive)
|
70
|
586 (let* ((thisurl (url-view-url t))
|
|
587 (node (assoc (if (string= "" thisurl) (current-buffer) thisurl)
|
|
588 w3-node-history))
|
|
589 (url (cdr node))
|
|
590 (w3-reuse-buffers 'yes))
|
|
591 (cond
|
|
592 ((null url) (error "No forward found for %s" thisurl))
|
|
593 ((and (bufferp url) (buffer-name url))
|
|
594 (switch-to-buffer url))
|
|
595 ((stringp url)
|
|
596 (w3-fetch url))
|
|
597 ((bufferp url)
|
|
598 (setq w3-node-history (delete node w3-node-history))
|
|
599 (error "Killed buffer in history, removed."))
|
|
600 (t
|
|
601 (error "Something is very wrong with the history!")))))
|
0
|
602
|
70
|
603 (defun w3-backward-in-history ()
|
0
|
604 "Go backward in the history from this page"
|
|
605 (interactive)
|
70
|
606 (let* ((thisurl (url-view-url t))
|
|
607 (node (rassoc (if (string= thisurl "") (current-buffer) thisurl)
|
|
608 w3-node-history))
|
|
609 (url (car node))
|
|
610 (w3-reuse-buffers 'yes))
|
|
611 (cond
|
|
612 ((null url) (error "No backward found for %s" thisurl))
|
|
613 ((and (bufferp url) (buffer-name url))
|
|
614 (switch-to-buffer url))
|
|
615 ((stringp url)
|
|
616 (w3-fetch url))
|
|
617 ((bufferp url)
|
|
618 (setq w3-node-history (delete node w3-node-history))
|
|
619 (error "Killed buffer in history, removed."))
|
|
620 (t
|
|
621 (error "Something is very wrong with the history!")))))
|
0
|
622
|
70
|
623 (defun w3-add-urls-to-history (referer url)
|
0
|
624 "REFERER is the url we followed this link from. URL is the link we got to."
|
70
|
625 (let ((node (assoc referer w3-node-history)))
|
|
626 (if node
|
|
627 (setcdr node url)
|
|
628 (setq w3-node-history (cons (cons referer url) w3-node-history)))))
|
0
|
629
|
|
630
|
|
631 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
632 ;;; Miscellaneous functions
|
|
633 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
634 (defun w3-describe-entities ()
|
|
635 "Show an DTD fragment listing all the entities currently defined."
|
|
636 (interactive)
|
|
637 (switch-to-buffer (get-buffer-create "W3 Entities"))
|
|
638 (let ((buffer-file-name (concat (make-temp-name "entities") ".dtd")))
|
|
639 (set-auto-mode))
|
|
640 (erase-buffer)
|
|
641 (let (entity)
|
|
642 (mapatoms
|
|
643 (function
|
|
644 (lambda (x)
|
|
645 (setq entity (get x 'html-entity-expansion))
|
|
646 (if entity
|
|
647 (insert (format "<!entity %s %s \"%s\">\n" x (car entity)
|
|
648 (cdr entity))))))))
|
|
649 (goto-char (point-min)))
|
|
650
|
|
651 (defun w3-executable-exists-in-path (exec &optional path)
|
|
652 (let ((paths (if (consp path)
|
|
653 path
|
|
654 (mm-string-to-tokens (or path
|
|
655 (getenv "PATH")
|
|
656 (concat
|
|
657 "/usr/bin:/bin:/usr/local/bin:"
|
|
658 "/usr/bin/X11:"
|
|
659 (expand-file-name "~/bin"))) ?:)))
|
|
660 (done nil))
|
|
661 (while (and paths (not done))
|
|
662 (if (file-exists-p (expand-file-name exec (car paths)))
|
|
663 (setq done t))
|
|
664 (setq paths (cdr paths)))
|
|
665 done))
|
|
666
|
|
667 (defun w3-document-information (&optional buff)
|
|
668 "Display information on the document in buffer BUFF"
|
|
669 (interactive)
|
|
670 (if (interactive-p)
|
|
671 (let ((w3-notify 'friendly))
|
|
672 (if (get-buffer "Document Information")
|
|
673 (kill-buffer (get-buffer "Document Information")))
|
|
674 (w3-fetch "about:document"))
|
|
675 (setq buff (or buff (current-buffer)))
|
|
676 (save-excursion
|
|
677 (set-buffer buff)
|
|
678 (let* ((url (url-view-url t))
|
|
679 (cur-links w3-current-links)
|
|
680 (title (buffer-name))
|
|
681 (lastmod (or (cdr-safe (assoc "last-modified"
|
30
|
682 url-current-mime-headers))
|
70
|
683 (and (member url-current-type '("file" "ftp"))
|
|
684 (nth 5 (url-file-attributes url)))))
|
|
685 (hdrs url-current-mime-headers))
|
0
|
686 (set-buffer (get-buffer-create url-working-buffer))
|
70
|
687 (setq url-current-can-be-cached nil
|
|
688 url-current-type "about"
|
|
689 url-current-file "document")
|
0
|
690 (erase-buffer)
|
|
691 (cond
|
|
692 ((stringp lastmod) nil)
|
70
|
693 ((equal '(0 . 0) lastmod) (setq lastmod nil))
|
0
|
694 ((consp lastmod) (setq lastmod (current-time-string lastmod)))
|
70
|
695 (t (setq lastmod nil)))
|
0
|
696 (insert "<html>\n"
|
|
697 " <head>\n"
|
|
698 " <title>Document Information</title>\n"
|
|
699 " </head>\n"
|
|
700 " <body\n"
|
70
|
701 " <h1 align=\"center\">Document Information</h1>\n"
|
|
702 " <hr>\n"
|
|
703 " <pre>\n"
|
|
704 " Title: " title "\n"
|
|
705 " Location: " url "\n"
|
|
706 " Last Modified: " (or lastmod "None Given") "\n"
|
|
707 " </pre>\n")
|
0
|
708 (if hdrs
|
|
709 (let* ((maxlength (car (sort (mapcar (function (lambda (x)
|
|
710 (length (car x))))
|
|
711 hdrs)
|
|
712 '>)))
|
70
|
713 (fmtstring (format "%%%ds: %%s" maxlength)))
|
|
714 (insert " <hr label=\" MetaInformation \" textalign=\"left\">\n"
|
|
715 " <pre>\n"
|
0
|
716 (mapconcat
|
|
717 (function
|
|
718 (lambda (x)
|
|
719 (if (/= (length (car x)) 0)
|
|
720 (format fmtstring
|
|
721 (capitalize (car x))
|
|
722 (if (numberp (cdr x))
|
|
723 (int-to-string (cdr x))
|
|
724 (cdr x))))))
|
|
725 (sort hdrs
|
|
726 (function
|
|
727 (lambda (x y) (string-lessp (car x) (car y)))))
|
70
|
728 "\n")
|
|
729 " </pre>\n")))
|
|
730 (if cur-links
|
|
731 (while cur-links
|
|
732 (let* ((tmp (car cur-links))
|
|
733 (label (car tmp))
|
|
734 (nodes (cdr tmp))
|
|
735 (links nil)
|
|
736 (maxlength (car (sort (mapcar
|
|
737 (function (lambda (x)
|
|
738 (length (car x))))
|
|
739 nodes)
|
|
740 '>)))
|
|
741 (fmtstring (format "%%%ds: %%s" maxlength)))
|
|
742 (insert " \n"
|
|
743 " <hr width=\"50%\" label=\" "
|
|
744 label " \" align=\"left\" textalign=\"left\">\n"
|
|
745 " <pre>\n")
|
|
746 (while nodes
|
|
747 (setq label (car (car nodes))
|
|
748 links (cdr (car nodes))
|
|
749 nodes (cdr nodes))
|
|
750 (while links
|
|
751 (insert (format " %15s -- <a href=\"%s\">%s</a>\n"
|
|
752 label (car links) (car links)))
|
|
753 (setq links (cdr links)
|
|
754 label "")))
|
|
755 (insert " </pre>\n"))
|
|
756 (setq cur-links (cdr cur-links))))
|
|
757 (insert " </body>\n"
|
0
|
758 "</html>\n")))))
|
|
759
|
|
760 (defun w3-truncate-menu-item (string)
|
|
761 (if (<= (length string) w3-max-menu-width)
|
|
762 string
|
|
763 (concat (substring string 0 w3-max-menu-width) "$")))
|
|
764
|
70
|
765 (defun w3-use-starting-documents ()
|
|
766 "Use the list of predefined starting documents from w3-starting-documents"
|
|
767 (interactive)
|
|
768 (let ((w3-hotlist w3-starting-documents))
|
|
769 (w3-use-hotlist)))
|
|
770
|
|
771 (defun w3-show-starting-documents ()
|
|
772 "Show the list of predefined starting documents from w3-starting-documents"
|
|
773 (interactive)
|
|
774 (if (not w3-setup-done) (w3-do-setup))
|
|
775 (w3-fetch "www://auto/starting-points"))
|
|
776
|
0
|
777 (defun w3-insert-formatted-url (p)
|
|
778 "Insert a formatted url into a buffer. With prefix arg, insert the url
|
|
779 under point."
|
|
780 (interactive "P")
|
|
781 (let (buff str)
|
|
782 (cond
|
|
783 (p
|
|
784 (setq p (widget-at (point)))
|
|
785 (or p (error "No url under point"))
|
70
|
786 (setq str (format "<A HREF=\"%s\">%s</A>" (widget-get p 'href)
|
0
|
787 (read-string "Link text: "
|
|
788 (buffer-substring
|
2
|
789 (widget-get p :from)
|
|
790 (widget-get p :to))))))
|
0
|
791 (t
|
70
|
792 (setq str (format "<A HREF=\"%s\">%s</A>" (url-view-url t)
|
0
|
793 (read-string "Link text: " (buffer-name))))))
|
|
794 (setq buff (read-buffer "Insert into buffer: " nil t))
|
|
795 (if buff
|
|
796 (save-excursion
|
|
797 (set-buffer buff)
|
|
798 (insert str))
|
|
799 (message "Cancelled."))))
|
|
800
|
|
801 (defun w3-first-n-items (l n)
|
|
802 "Return the first N items from list L"
|
|
803 (let ((x 0)
|
|
804 y)
|
|
805 (if (> n (length l))
|
|
806 (setq y l)
|
|
807 (while (< x n)
|
|
808 (setq y (nconc y (list (nth x l)))
|
|
809 x (1+ x))))
|
|
810 y))
|
|
811
|
|
812 (defun w3-widget-button-press ()
|
|
813 (interactive)
|
|
814 (if (widget-at (point))
|
|
815 (widget-button-press (point))))
|
|
816
|
|
817 (defun w3-widget-button-click (e)
|
|
818 (interactive "@e")
|
70
|
819 (if (widget-at (event-point e))
|
|
820 (widget-button-click e)))
|
0
|
821
|
|
822 (defun w3-breakup-menu (menu-desc max-len)
|
|
823 (if (> (length menu-desc) max-len)
|
|
824 (cons (cons "More..." (w3-first-n-items menu-desc max-len))
|
|
825 (w3-breakup-menu (nthcdr max-len menu-desc) max-len))
|
|
826 menu-desc))
|
|
827
|
|
828 ;;;###autoload
|
|
829 (defun w3-maybe-follow-link-mouse (e)
|
|
830 "Maybe follow a hypertext link under point.
|
|
831 If there is no link under point, this will try using
|
|
832 url-get-url-at-point"
|
|
833 (interactive "e")
|
|
834 (save-excursion
|
|
835 (mouse-set-point e)
|
|
836 (w3-maybe-follow-link)))
|
|
837
|
|
838 ;;;###autoload
|
|
839 (defun w3-maybe-follow-link ()
|
|
840 "Maybe follow a hypertext link under point.
|
|
841 If there is no link under point, this will try using
|
|
842 url-get-url-at-point"
|
|
843 (interactive)
|
|
844 (require 'w3)
|
|
845 (if (not w3-setup-done) (w3-do-setup))
|
|
846 (let* ((widget (widget-at (point)))
|
|
847 (url1 (and widget (widget-get widget 'href)))
|
|
848 (url2 (url-get-url-at-point)))
|
|
849 (cond
|
|
850 (url1 (w3-follow-link))
|
|
851 ((and url2 (string-match url-nonrelative-link url2)) (w3-fetch url2))
|
|
852 (t (message "No URL could be found!")))))
|
|
853
|
|
854 ;;;###autoload
|
|
855 (defun w3-follow-url-at-point-other-frame (&optional pt)
|
|
856 "Follow the URL under PT, defaults to link under (point)"
|
|
857 (interactive "d")
|
|
858 (let ((url (url-get-url-at-point pt)))
|
|
859 (and url (w3-fetch-other-frame url))))
|
|
860
|
|
861 ;;;###autoload
|
|
862 (defun w3-follow-url-at-point (&optional pt)
|
|
863 "Follow the URL under PT, defaults to link under (point)"
|
|
864 (interactive "d")
|
|
865 (let ((url (url-get-url-at-point pt)))
|
|
866 (and url (w3-fetch url))))
|
|
867
|
70
|
868 ;;;###autoload
|
|
869 (defun w3-batch-fetch ()
|
|
870 "Fetch all the URLs on the command line and save them to files in
|
|
871 the current directory. The first argument after the -f w3-batch-fetch
|
|
872 on the command line should be a string specifying how to save the
|
|
873 information retrieved. If it is \"html\", then the page will be
|
|
874 unformatted when it is written to disk. If it is \"text\", then the
|
|
875 page will be formatted before it is written to disk. If it is
|
|
876 \"binary\" it will not mess with the file extensions, and just save
|
|
877 the data in raw binary format. If none of those, the default is
|
|
878 \"text\", and the first argument is treated as a normal URL."
|
|
879 (if (not w3-setup-done) (w3-do-setup))
|
|
880 (if (not noninteractive)
|
|
881 (error "`w3-batch-fetch' is to be used only with -batch"))
|
|
882 (let ((fname "")
|
|
883 (curname "")
|
|
884 (x 0)
|
|
885 (args command-line-args-left)
|
|
886 (w3-strict-width 80)
|
|
887 (w3-delimit-emphasis nil)
|
|
888 (w3-delimit-links nil)
|
|
889 (retrieval-function 'w3-fetch)
|
|
890 (file-format "text")
|
|
891 (header "")
|
|
892 (file-extn ".txt"))
|
|
893 (setq file-format (downcase (car args)))
|
|
894 (cond
|
|
895 ((string= file-format "html")
|
|
896 (message "Saving all text as raw HTML...")
|
|
897 (setq retrieval-function 'url-retrieve
|
|
898 file-extn ".html"
|
|
899 header "<BASE HREF=\"%s\">"
|
|
900 args (cdr args)))
|
|
901 ((string= file-format "binary")
|
|
902 (message "Saving as raw binary...")
|
|
903 (setq retrieval-function 'url-retrieve
|
|
904 file-extn ""
|
|
905 args (cdr args)))
|
|
906 ((string= file-format "text")
|
|
907 (setq header "Text from: %s\n---------------\n")
|
|
908 (message "Saving all text as formatted...")
|
|
909 (setq args (cdr args)))
|
|
910 (t
|
|
911 (setq header "Text from: %s\n---------------\n")
|
|
912 (message "Going with default, saving all text as formatted...")))
|
|
913 (while args
|
|
914 (funcall retrieval-function (car args))
|
|
915 (goto-char (point-min))
|
|
916 (if buffer-read-only (toggle-read-only))
|
|
917 (insert (format header (car args)))
|
|
918 (setq fname (url-basepath url-current-file t))
|
|
919 (if (string= file-extn "") nil
|
|
920 (setq fname (url-file-extension fname t)))
|
|
921 (if (string= (url-strip-leading-spaces fname) "")
|
|
922 (setq fname "root"))
|
|
923 (setq curname fname)
|
|
924 (while (file-exists-p (concat curname file-extn))
|
|
925 (setq curname (concat fname x)
|
|
926 x (1+ x)))
|
|
927 (setq fname (concat curname file-extn))
|
|
928 (write-region (point-min) (point-max) fname)
|
|
929 (setq args (cdr args)))))
|
|
930
|
0
|
931 (defun w3-fix-spaces (x)
|
|
932 "Remove spaces/tabs at the beginning of a string,
|
|
933 and convert newlines into spaces."
|
|
934 (url-convert-newlines-to-spaces
|
|
935 (url-strip-leading-spaces
|
|
936 (url-eat-trailing-space x))))
|
|
937
|
|
938 (defun w3-reload-all-files ()
|
|
939 "Reload all w3 files"
|
|
940 (interactive)
|
|
941 (setq w3-setup-done nil
|
|
942 url-setup-done nil
|
|
943 w3-hotlist nil
|
|
944 url-mime-accept-string nil)
|
70
|
945 (let ((x '(w3 w3-mule w3-e19 w3-xem20 mm url w3-xemac w3-toolbar font)))
|
0
|
946 (while x
|
|
947 (setq features (delq (car x) features)
|
|
948 x (cdr x)))
|
|
949 (require 'w3))
|
|
950 (w3-do-setup)
|
|
951 (url-do-setup)
|
|
952 )
|
|
953
|
|
954 (defun w3-source-document-at-point ()
|
|
955 "View source to the document pointed at by link under point"
|
|
956 (interactive)
|
|
957 (w3-source-document t))
|
|
958
|
70
|
959 (defun w3-my-safe-copy-face (old new locale)
|
|
960 (let ((fore (face-foreground old))
|
|
961 (back (face-background old))
|
|
962 (bpxm (face-background-pixmap old))
|
|
963 (font (face-font old))
|
|
964 (font-spec (get old 'font-specification)))
|
|
965 (if (color-specifier-p fore)
|
|
966 (setq fore (color-name fore)))
|
|
967 (if (color-specifier-p back)
|
|
968 (setq back (color-name back)))
|
|
969 (if (font-specifier-p font)
|
|
970 (setq font (font-name font)))
|
|
971 (and fore (set-face-foreground new fore locale))
|
|
972 (and back (set-face-background new back locale))
|
|
973 (and bpxm (set-face-background-pixmap new bpxm locale))
|
|
974 (and (or font-spec font) (set-face-font new (or font-spec font) locale))
|
|
975 new))
|
|
976
|
0
|
977 (defun w3-source-document (under)
|
|
978 "View this document's source"
|
|
979 (interactive "P")
|
|
980 (let* ((url (if under (w3-view-this-url) (url-view-url t)))
|
70
|
981 (fil (if under nil url-current-file))
|
|
982 (tag '$html-source) ; For the stylesheet info
|
|
983 (args nil) ; For the stylesheet info
|
|
984 (face nil) ; For the stylesheet info
|
0
|
985 (src
|
|
986 (cond
|
70
|
987 ((or (null url) (string= url "file:nil"))
|
|
988 (error "Not a w3 buffer!"))
|
0
|
989 ((and under (null url)) (error "No link at point!"))
|
|
990 ((and (not under) (equal url-current-mime-type "text/plain"))
|
|
991 (buffer-string))
|
|
992 ((and (not under) w3-current-source) w3-current-source)
|
|
993 (t
|
|
994 (prog2
|
|
995 (url-retrieve url)
|
|
996 (buffer-string)
|
70
|
997 (setq fil (or fil url-current-file))
|
0
|
998 (kill-buffer (current-buffer))))))
|
|
999 (tmp (url-generate-new-buffer-name url)))
|
|
1000 (if (and url (get-buffer url))
|
|
1001 (cond
|
|
1002 ((memq w3-reuse-buffers '(no never reload))
|
|
1003 (kill-buffer url))
|
|
1004 ((memq w3-reuse-buffers '(yes reuse always))
|
|
1005 (w3-notify-when-ready (get-buffer url))
|
|
1006 (setq url nil))
|
|
1007 ((funcall url-confirmation-func
|
|
1008 (concat "Source for " url " found, reuse? "))
|
|
1009 (w3-notify-when-ready (get-buffer url)))))
|
|
1010 (if (not url) nil
|
70
|
1011 (setq face (and w3-current-stylesheet (cdr (w3-face-for-element))))
|
0
|
1012 (set-buffer (get-buffer-create tmp))
|
|
1013 (insert src)
|
70
|
1014 (put-text-property (point-min) (point-max) 'face face)
|
0
|
1015 (put-text-property (point-min) (point-max) 'w3-base url)
|
|
1016 (goto-char (point-min))
|
70
|
1017 (setq buffer-file-truename nil
|
|
1018 buffer-file-name nil)
|
2
|
1019 ;; Null filename bugs `set-auto-mode' in Mule ...
|
|
1020 (condition-case ()
|
|
1021 (set-auto-mode)
|
|
1022 (error nil))
|
0
|
1023 (buffer-enable-undo)
|
|
1024 (set-buffer-modified-p nil)
|
|
1025 (w3-notify-when-ready (get-buffer tmp))))
|
|
1026 (run-hooks 'w3-source-file-hook))
|
|
1027
|
|
1028 (defun w3-mail-document-under-point ()
|
|
1029 "Mail the document pointed to by the hyperlink under point."
|
|
1030 (interactive)
|
|
1031 (w3-mail-current-document t))
|
|
1032
|
|
1033 (defun w3-mail-current-document (under &optional format)
|
|
1034 "Mail the current-document to someone"
|
|
1035 (interactive "P")
|
|
1036 (let* ((completion-ignore-case t)
|
|
1037 (format (or format
|
|
1038 (completing-read
|
|
1039 "Format: "
|
|
1040 '(("HTML Source")
|
|
1041 ("Formatted Text")
|
|
1042 ("PostScript")
|
|
1043 ("LaTeX Source")
|
|
1044 )
|
|
1045 nil t)))
|
|
1046 (url (cond
|
|
1047 ((stringp under) under)
|
|
1048 (under (w3-view-this-url t))
|
|
1049 (t (url-view-url t))))
|
|
1050 (content-type "text/plain; charset=iso-8859-1")
|
|
1051 (str
|
|
1052 (save-excursion
|
|
1053 (cond
|
|
1054 ((and (equal "HTML Source" format) under)
|
|
1055 (setq content-type "text/html; charset=iso-8859-1")
|
|
1056 (let ((url-source t))
|
|
1057 (url-retrieve url)))
|
|
1058 ((equal "HTML Source" format)
|
|
1059 (setq content-type "text/html; charset=iso-8859-1")
|
|
1060 (if w3-current-source
|
|
1061 (let ((x w3-current-source))
|
|
1062 (set-buffer (get-buffer-create url-working-buffer))
|
|
1063 (erase-buffer)
|
|
1064 (insert x))
|
|
1065 (url-retrieve url)))
|
|
1066 ((and under (equal "PostScript" format))
|
|
1067 (setq content-type "application/postscript")
|
|
1068 (w3-fetch url)
|
|
1069 (let ((ps-spool-buffer-name " *w3-temp*"))
|
|
1070 (if (get-buffer ps-spool-buffer-name)
|
|
1071 (kill-buffer ps-spool-buffer-name))
|
70
|
1072 (w3-print-with-ps-print (current-buffer)
|
|
1073 'ps-spool-buffer-with-faces)
|
0
|
1074 (set-buffer ps-spool-buffer-name)))
|
|
1075 ((equal "PostScript" format)
|
|
1076 (let ((ps-spool-buffer-name " *w3-temp*"))
|
|
1077 (if (get-buffer ps-spool-buffer-name)
|
|
1078 (kill-buffer ps-spool-buffer-name))
|
|
1079 (setq content-type "application/postscript")
|
70
|
1080 (w3-print-with-ps-print (current-buffer)
|
|
1081 'ps-spool-buffer-with-faces)
|
0
|
1082 (set-buffer ps-spool-buffer-name)))
|
|
1083 ((and under (equal "Formatted Text" format))
|
|
1084 (setq content-type "text/plain; charset=iso-8859-1")
|
|
1085 (w3-fetch url))
|
|
1086 ((equal "Formatted Text" format)
|
|
1087 (setq content-type "text/plain; charset=iso-8859-1"))
|
|
1088 ((and under (equal "LaTeX Source" format))
|
|
1089 (let ((old-asynch url-be-asynchronous))
|
|
1090 (setq content-type "application/x-latex; charset=iso-8859-1")
|
|
1091 (setq-default url-be-asynchronous nil)
|
|
1092 (url-retrieve url)
|
|
1093 (setq-default url-be-asynchronous old-asynch)
|
70
|
1094 (w3-parse-tree-to-latex (w3-parse-buffer (current-buffer) t)
|
0
|
1095 url)))
|
|
1096 ((equal "LaTeX Source" format)
|
|
1097 (setq content-type "application/x-latex; charset=iso-8859-1")
|
|
1098 (w3-parse-tree-to-latex w3-current-parse url)))
|
|
1099 (buffer-string))))
|
70
|
1100 (cond
|
|
1101 ((and w3-mutable-windows (fboundp w3-mail-other-window-command))
|
|
1102 (funcall w3-mail-other-window-command))
|
|
1103 ((fboundp w3-mail-command)
|
|
1104 (funcall w3-mail-command))
|
|
1105 (w3-mutable-windows (mail-other-window))
|
|
1106 (t (mail)))
|
0
|
1107 (mail-subject)
|
70
|
1108 (insert format " from URL " url "\n"
|
|
1109 "Mime-Version: 1.0\n"
|
|
1110 "Content-transfer-encoding: 8bit\n"
|
|
1111 "Content-type: " content-type)
|
|
1112
|
0
|
1113 (re-search-forward mail-header-separator nil)
|
|
1114 (forward-char 1)
|
70
|
1115 (insert (if (equal "HTML Source" format)
|
|
1116 (format "<BASE HREF=\"%s\">" url) "")
|
|
1117 str)
|
0
|
1118 (mail-to)))
|
|
1119
|
|
1120 (defun w3-internal-use-history (hist-item)
|
|
1121 ;; Go to the link in the history
|
|
1122 (let ((url (nth 0 hist-item))
|
|
1123 (buf (nth 1 hist-item))
|
|
1124 (pnt (nth 2 hist-item)))
|
|
1125 (cond
|
|
1126 ((null buf) ; Find a buffer with same url
|
|
1127 (let ((x (buffer-list))
|
|
1128 (found nil))
|
|
1129 (while (and x (not found))
|
|
1130 (save-excursion
|
|
1131 (set-buffer (car x))
|
|
1132 (setq found (string= (url-view-url t) url))
|
|
1133 (if (not found) (setq x (cdr x)))))
|
|
1134 (cond
|
|
1135 (found
|
|
1136 (switch-to-buffer (car x))
|
|
1137 (if (number-or-marker-p pnt) (goto-char pnt)))
|
|
1138 (t
|
|
1139 (w3-fetch url)))))
|
|
1140 ((buffer-name buf) ; Reuse the old buffer if possible
|
|
1141 (switch-to-buffer buf)
|
|
1142 (if (number-or-marker-p pnt) (goto-char pnt))
|
|
1143 (if (and url (= ?# (string-to-char url))) ; Destination link
|
|
1144 (progn
|
|
1145 (goto-char (point-min))
|
|
1146 (w3-find-specific-link (substring url 1 nil)))))
|
|
1147 (url (url-maybe-relative url)) ; Get the link
|
|
1148 (t (message "Couldn't understand whats in the history.")))))
|
|
1149
|
|
1150 (defun w3-relative-link (url)
|
|
1151 (if (equal "#" (substring url 0 1))
|
|
1152 (progn
|
|
1153 (push-mark (point) t)
|
|
1154 (goto-char (point-min))
|
|
1155 (w3-find-specific-link (substring url 1 nil)))
|
|
1156 (w3-fetch (url-expand-file-name url))))
|
|
1157
|
|
1158 (defun w3-maybe-eval ()
|
|
1159 ;; Maybe evaluate a buffer of emacs lisp code
|
|
1160 (if (funcall url-confirmation-func "This is emacs-lisp code, evaluate it?")
|
|
1161 (eval-buffer (current-buffer))
|
|
1162 (emacs-lisp-mode)))
|
|
1163
|
|
1164 (defun w3-build-continuation ()
|
|
1165 ;; Build a series of functions to be run on this file
|
|
1166 (save-excursion
|
|
1167 (set-buffer url-working-buffer)
|
|
1168 (let ((cont w3-default-continuation)
|
70
|
1169 (extn (url-file-extension url-current-file)))
|
0
|
1170 (if (assoc extn url-uncompressor-alist)
|
|
1171 (setq extn (url-file-extension
|
70
|
1172 (substring url-current-file 0 (- (length extn))))))
|
0
|
1173 (if w3-source
|
|
1174 (setq url-current-mime-viewer '(("viewer" . w3-source))))
|
|
1175 (if (not url-current-mime-viewer)
|
|
1176 (setq url-current-mime-viewer
|
|
1177 (mm-mime-info (or url-current-mime-type
|
|
1178 (mm-extension-to-mime extn)) nil 5)))
|
|
1179 (if url-current-mime-viewer
|
|
1180 (setq cont (append cont '(w3-pass-to-viewer)))
|
70
|
1181 (setq cont (append cont (list w3-default-action))))
|
0
|
1182 cont)))
|
|
1183
|
|
1184 (defun w3-use-links ()
|
|
1185 "Select one of the <LINK> tags from this document and fetch it."
|
|
1186 (interactive)
|
|
1187 (and (not w3-current-links)
|
|
1188 (error "No links defined for this document."))
|
|
1189 (w3-fetch "about:document"))
|
|
1190
|
|
1191 (defun w3-find-this-file ()
|
|
1192 "Do a find-file on the currently viewed html document if it is a file: or
|
|
1193 ftp: reference"
|
|
1194 (interactive)
|
70
|
1195 (cond
|
|
1196 ((and (or (null url-current-type) (equal url-current-type "file"))
|
|
1197 (eq major-mode 'w3-mode))
|
|
1198 (if w3-mutable-windows
|
|
1199 (find-file-other-window url-current-file)
|
|
1200 (find-file url-current-file)))
|
|
1201 ((equal url-current-type "ftp")
|
|
1202 (if w3-mutable-windows
|
|
1203 (find-file-other-window
|
|
1204 (format "/%s@%s:%s" url-current-user url-current-server
|
|
1205 url-current-file))
|
26
|
1206 (find-file
|
70
|
1207 (format "/%s@%s:%s" url-current-user url-current-server
|
|
1208 url-current-file))))
|
|
1209 (t (message "Sorry, I can't get that file so you can alter it."))))
|
0
|
1210
|
|
1211 (defun w3-insert-this-url (pref-arg)
|
|
1212 "Insert the current url in another buffer, with prefix ARG,
|
|
1213 insert URL under point"
|
|
1214 (interactive "P")
|
|
1215 (let ((thebuf (get-buffer (read-buffer "Insert into buffer: ")))
|
|
1216 (oldbuf (current-buffer))
|
|
1217 (url (if pref-arg (w3-view-this-url t) (url-view-url t))))
|
|
1218 (if (and url (not (equal "Not on a link!" url)))
|
|
1219 (progn
|
|
1220 (set-buffer thebuf)
|
|
1221 (insert url)
|
|
1222 (set-buffer oldbuf))
|
|
1223 (message "Not on a link!"))))
|
|
1224
|
|
1225 (defun w3-show-hotlist ()
|
|
1226 "View the hotlist in hypertext form"
|
|
1227 (interactive)
|
|
1228 (if (not w3-setup-done) (w3-do-setup))
|
|
1229 (if (not w3-hotlist)
|
|
1230 (error "Sorry, no hotlist is in memory.")
|
|
1231 (let ((x (url-buffer-visiting "www:/auto/hotlist")))
|
|
1232 (while x
|
|
1233 (kill-buffer x)
|
|
1234 (setq x (url-buffer-visiting "www:/auto/hotlist"))))
|
|
1235 (w3-fetch "www://auto/hotlist")))
|
|
1236
|
|
1237 (defun url-maybe-relative (url)
|
|
1238 "Take a url and either fetch it, or resolve relative refs, then fetch it"
|
|
1239 (cond
|
|
1240 ((not
|
|
1241 (string-match url-nonrelative-link url))
|
|
1242 (w3-relative-link url))
|
|
1243 (t (w3-fetch url))))
|
|
1244
|
|
1245 (defun w3-in-assoc (elt list)
|
|
1246 "Check to see if ELT matches any of the regexps in the car elements of LIST"
|
|
1247 (let (rslt)
|
|
1248 (while (and list (not rslt))
|
|
1249 (and (car (car list))
|
|
1250 (stringp (car (car list)))
|
|
1251 (not (string= (car (car list)) ""))
|
|
1252 (string-match (car (car list)) elt)
|
|
1253 (setq rslt (car list)))
|
|
1254 (setq list (cdr list)))
|
|
1255 rslt))
|
|
1256
|
|
1257 (defun w3-goto-last-buffer ()
|
|
1258 "Go to last WWW buffer visited"
|
|
1259 (interactive)
|
|
1260 (if w3-current-last-buffer
|
|
1261 (w3-notify-when-ready w3-current-last-buffer)
|
|
1262 (message "No previous buffer found.")))
|
|
1263
|
|
1264 (fset 'w3-replace-regexp 'url-replace-regexp)
|
|
1265
|
|
1266 ;;;###autoload
|
|
1267 (defun w3-preview-this-buffer ()
|
|
1268 "See what this buffer will look like when its formatted as HTML.
|
|
1269 HTML is the HyperText Markup Language used by the World Wide Web to
|
|
1270 specify formatting for text. More information on HTML can be found at
|
|
1271 ftp.w3.org:/pub/www/doc."
|
|
1272 (interactive)
|
|
1273 (w3-fetch (concat "www://preview/" (buffer-name))))
|
|
1274
|
70
|
1275 (defun w3-edit-source ()
|
|
1276 "Edit the html document just retrieved"
|
|
1277 (set-buffer url-working-buffer)
|
|
1278 (let ((ttl (format "Editing %s Annotation: %s"
|
|
1279 (cond
|
|
1280 ((eq w3-editing-annotation 'group) "Group")
|
|
1281 ((eq w3-editing-annotation 'personal) "Personal")
|
|
1282 (t "Unknown"))
|
|
1283 (url-basepath url-current-file t)))
|
|
1284 (str (buffer-string)))
|
|
1285 (set-buffer (get-buffer-create ttl))
|
|
1286 (insert str)
|
|
1287 (kill-buffer url-working-buffer)))
|
|
1288
|
0
|
1289 (defun w3-source ()
|
|
1290 "Show the source of a file"
|
|
1291 (let ((tmp (buffer-name (generate-new-buffer "Document Source"))))
|
|
1292 (set-buffer url-working-buffer)
|
|
1293 (kill-buffer tmp)
|
|
1294 (rename-buffer tmp)
|
|
1295 ;; Make the URL show in list-buffers output
|
|
1296 (make-local-variable 'list-buffers-directory)
|
|
1297 (setq list-buffers-directory (url-view-url t))
|
|
1298 (set-buffer-modified-p nil)
|
|
1299 (buffer-enable-undo)
|
|
1300 (w3-notify-when-ready (get-buffer tmp))))
|
|
1301
|
|
1302 (defun w3-sentinel (&optional proc string)
|
|
1303 (set-buffer url-working-buffer)
|
|
1304 (if (or (stringp proc)
|
|
1305 (bufferp proc)) (setq w3-current-last-buffer proc))
|
70
|
1306 (if (boundp 'after-change-functions)
|
|
1307 (remove-hook 'after-change-functions 'url-after-change-function))
|
0
|
1308 (if url-be-asynchronous
|
|
1309 (progn
|
|
1310 (url-clean-text)
|
|
1311 (cond
|
|
1312 ((not (get-buffer url-working-buffer)) nil)
|
|
1313 ((url-mime-response-p) (url-parse-mime-headers)))
|
|
1314 (if (not url-current-mime-type)
|
|
1315 (setq url-current-mime-type (or (mm-extension-to-mime
|
|
1316 (url-file-extension
|
70
|
1317 url-current-file))
|
0
|
1318 "text/html")))))
|
20
|
1319 (let ((x (w3-build-continuation))
|
70
|
1320 (done-mule-conversion nil))
|
0
|
1321 (while x
|
70
|
1322 (if (and (featurep 'mule) (not (eq 'url-uncompress (car x)))
|
|
1323 (not done-mule-conversion))
|
|
1324 (progn
|
|
1325 (if (string-match "^www:" (url-view-url t))
|
|
1326 (setq w3-mime-list-for-code-conversion nil))
|
|
1327 (w3-convert-code-for-mule url-current-mime-type)
|
|
1328 (setq done-mule-conversion t)))
|
|
1329 (funcall (car x))
|
|
1330 (setq x (cdr x)))))
|
0
|
1331
|
|
1332 (defun w3-show-history-list ()
|
|
1333 "Format the url-history-list prettily and show it to the user"
|
|
1334 (interactive)
|
|
1335 (w3-fetch "www://auto/history"))
|
|
1336
|
|
1337 (defun w3-save-as (&optional type)
|
|
1338 "Save a document to the local disk"
|
|
1339 (interactive)
|
70
|
1340 (let* ((completion-ignore-case t)
|
|
1341 (format (or type (completing-read
|
|
1342 "Format: "
|
|
1343 '(("HTML Source") ("Formatted Text")
|
|
1344 ("LaTeX Source") ("Binary"))
|
|
1345 nil t)))
|
|
1346 (fname (expand-file-name
|
|
1347 (read-file-name "File name: " default-directory)))
|
|
1348 (url (url-view-url t)))
|
|
1349 (cond
|
|
1350 ((equal "Binary" format)
|
|
1351 (if (not w3-current-source)
|
|
1352 (let ((url-be-asynchronous nil))
|
|
1353 (url-retrieve url))))
|
|
1354 ((equal "HTML Source" format)
|
|
1355 (if (not w3-current-source)
|
|
1356 (let ((url-be-asynchronous nil))
|
|
1357 (url-retrieve url)) ; Get the document if necessary
|
|
1358 (let ((txt w3-current-source))
|
|
1359 (set-buffer (get-buffer-create url-working-buffer))
|
|
1360 (insert txt)))
|
|
1361 (goto-char (point-min))
|
|
1362 (insert (format "<BASE HREF=\"%s\">\n" url)))
|
|
1363 ((or (equal "Formatted Text" format)
|
|
1364 (equal "" format))
|
|
1365 nil) ; Do nothing - we have the text already
|
|
1366 ((equal "LaTeX Source" format)
|
|
1367 (w3-parse-tree-to-latex w3-current-parse url)
|
|
1368 (insert-buffer url-working-buffer)))
|
|
1369 (write-region (point-min) (point-max) fname)))
|
0
|
1370
|
|
1371
|
|
1372 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1373 ;;; Functions to parse out <A> tags and replace it with a hyperlink zone
|
|
1374 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1375 (defun w3-popup-image-info (url)
|
|
1376 (interactive)
|
|
1377 (let* ((glyph (cdr-safe (assoc url w3-graphics-list)))
|
|
1378 image w h d info)
|
|
1379 (save-excursion
|
|
1380 (if (or (not glyph) (not (glyphp glyph)))
|
|
1381 (error "No information available."))
|
|
1382 (setq image (glyph-image-instance glyph))
|
|
1383 (if (or (not image) (not (image-instance-p image)))
|
|
1384 (error "No information available."))
|
|
1385 (setq w (glyph-width glyph)
|
|
1386 h (glyph-height glyph)
|
|
1387 d (image-instance-depth image)
|
|
1388 info (url-popup-info url)
|
|
1389 )
|
|
1390 (set-buffer (get-buffer-create "*Image Info*"))
|
|
1391 (erase-buffer)
|
|
1392 (insert
|
|
1393 "Information for: " url "\n"
|
|
1394 (make-string (1- (window-width)) ?-)
|
|
1395 (format "\n%-20s: %s\n" "Type" (image-instance-type image))
|
|
1396 (format "%-20s: %d x %d\n" "Dimensions" w h)
|
|
1397 (format "%-20s: %d-bit\n" "Color" d))
|
|
1398 (set-extent-begin-glyph (make-extent (point) (point)) glyph)
|
|
1399 (insert
|
|
1400 "\n"
|
|
1401 (make-string (1- (window-width)) ?-)
|
|
1402 (or info ""))
|
|
1403 (display-buffer (current-buffer) t))))
|
|
1404
|
|
1405 (defun w3-popup-info (&optional url)
|
|
1406 "Show information about the link under point. (All SGML attributes)"
|
70
|
1407 (interactive (list (w3-read-url-with-default)))
|
0
|
1408 (let (dat widget)
|
|
1409 (if (interactive-p)
|
|
1410 nil
|
|
1411 (setq widget (widget-at (point))
|
|
1412 dat (and widget (widget-get widget 'attributes))))
|
|
1413 (if url
|
|
1414 (save-excursion
|
|
1415 (set-buffer (get-buffer-create "*Header Info*"))
|
|
1416 (erase-buffer)
|
|
1417 (insert "URL: " url "\n" (make-string (1- (window-width)) ?-) "\n")
|
|
1418 (if (and dat (listp dat))
|
|
1419 (insert
|
|
1420 "Link attributes:\n"
|
|
1421 (make-string (1- (window-width)) ?-) "\n"
|
|
1422 (mapconcat
|
|
1423 (function
|
|
1424 (lambda (info)
|
|
1425 (format "%20s :== %s" (car info) (or (cdr info) "On"))))
|
|
1426 dat "\n")
|
|
1427 "\n" (make-string (1- (window-width)) ?-) "\n"))
|
|
1428 (insert (save-excursion (url-popup-info url)))
|
|
1429 (goto-char (point-min))
|
|
1430 (display-buffer (current-buffer) t))
|
|
1431 (message "No URL to get information on!"))))
|
|
1432
|
|
1433 (fset 'w3-document-information-this-url 'w3-popup-info)
|
|
1434
|
|
1435
|
|
1436 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1437 ;;; Functions for logging of bad HTML
|
|
1438 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1439 (defun w3-reconstruct-tag (tagname desc)
|
|
1440 (concat "<" tagname " "
|
|
1441 (mapconcat
|
|
1442 (function (lambda (x)
|
|
1443 (if (cdr x)
|
|
1444 (concat (car x) "=\"" (cdr x) "\"")
|
|
1445 (car x)))) desc " ") ">"))
|
|
1446
|
|
1447 (defun w3-debug-if-found (regexp type desc)
|
|
1448 (and w3-debug-html
|
|
1449 (save-excursion
|
|
1450 (if (re-search-forward regexp nil t)
|
|
1451 (w3-log-bad-html type desc)))))
|
|
1452
|
|
1453 (defun w3-log-bad-html (type desc)
|
|
1454 ;; Log bad HTML to the buffer specified by w3-debug-buffer
|
|
1455 (if w3-debug-html
|
|
1456 (save-excursion
|
|
1457 (set-buffer (get-buffer-create w3-debug-buffer))
|
|
1458 (goto-char (point-max))
|
|
1459 (insert (make-string (1- (window-width)) w3-horizontal-rule-char) "\n")
|
|
1460 (cond
|
|
1461 ((stringp type) (insert type "\n" desc "\n"))
|
|
1462 ((eq type 'bad-quote)
|
|
1463 (insert "Unterminated quoting character in SGML attribute value.\n"
|
|
1464 desc "\n"))
|
|
1465 ((eq type 'no-quote)
|
|
1466 (insert "Unquoted SGML attribute value.\n" desc "\n"))
|
|
1467 ((eq type 'no-textarea-end)
|
|
1468 (insert "Unterminated <textarea> tag.\n"
|
|
1469 (w3-reconstruct-tag "textarea" desc) "\n"))
|
|
1470 ((eq type 'bad-link-tag)
|
|
1471 (insert "Must specify either REL or REV with a <link> tag.\n"
|
|
1472 (w3-reconstruct-tag "link" desc) "\n"))
|
|
1473 ((eq type 'no-a-end)
|
|
1474 (insert "Unterminated <a> tag.\n"
|
|
1475 (w3-reconstruct-tag "a" desc) "\n"))
|
|
1476 ((eq type 'no-form-end)
|
|
1477 (insert "Unterminated <form> tag.\n"
|
|
1478 (w3-reconstruct-tag "form" desc) "\n"))
|
|
1479 ((eq type 'bad-base-tag)
|
|
1480 (insert "Malformed <base> tag.\n"
|
|
1481 (w3-reconstruct-tag "base" desc) "\n"))))))
|
|
1482
|
|
1483
|
|
1484 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1485 ;;; Functions to handle formatting an html buffer
|
|
1486 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
70
|
1487 (defun w3-insert-headers ()
|
|
1488 ;; Insert some HTTP/1.0 headers if necessary
|
|
1489 (url-lazy-message "Inserting HTTP/1.0 headers...")
|
|
1490 (let ((hdrs (if (eq t w3-show-headers) (mapcar 'car url-current-mime-headers)
|
|
1491 w3-show-headers))
|
|
1492 x y)
|
|
1493 (goto-char (setq y (point-max)))
|
|
1494 (while hdrs
|
|
1495 (if (setq x (w3-in-assoc (car hdrs) url-current-mime-headers))
|
|
1496 (insert "<LI> <B>" (car x) "</B>: " (url-insert-entities-in-string
|
|
1497 (if (numberp (cdr x))
|
|
1498 (int-to-string (cdr x))
|
|
1499 (cdr x)))))
|
|
1500 (setq hdrs (cdr hdrs)))
|
|
1501 (if (= y (point-max))
|
|
1502 nil
|
|
1503 (insert "</UL>")
|
|
1504 (goto-char y)
|
|
1505 (url-lazy-message "Inserting HTTP/1.0 headers... done.")
|
|
1506 (insert "<HR><UL>"))))
|
|
1507
|
2
|
1508 (defun w3-add-delayed-graphic (widget)
|
0
|
1509 ;; Add a delayed image for the current buffer.
|
2
|
1510 (setq w3-delayed-images (cons widget w3-delayed-images)))
|
0
|
1511
|
|
1512
|
|
1513 (defun w3-load-flavors ()
|
|
1514 ;; Load the correct zone/font info for each flavor of emacs
|
|
1515 (cond
|
|
1516 ((and w3-running-xemacs (eq system-type 'ms-windows))
|
|
1517 (error "WinEmacs no longer supported."))
|
|
1518 (w3-running-xemacs (require 'w3-xemac))
|
|
1519 (w3-running-FSF19 (require 'w3-e19))
|
|
1520 (t
|
|
1521 (error "Unable to determine the capabilities of this emacs.")))
|
70
|
1522 (cond
|
|
1523 ((boundp 'MULE)
|
|
1524 (require 'w3-mule))
|
|
1525 ((featurep 'mule)
|
|
1526 (require 'w3-xem20)
|
|
1527 ))
|
0
|
1528 (condition-case ()
|
|
1529 (require 'w3-site-init)
|
|
1530 (error nil)))
|
|
1531
|
|
1532 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1533 ;;; Automatic bug submission. ;;;
|
|
1534 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1535 (defun w3-submit-bug ()
|
|
1536 "Submit a bug on Emacs-w3"
|
|
1537 (interactive)
|
|
1538 (require 'reporter)
|
|
1539 (and (yes-or-no-p "Do you really want to submit a bug on Emacs-w3? ")
|
|
1540 (let ((url (url-view-url t))
|
|
1541 (vars '(window-system
|
|
1542 window-system-version
|
|
1543 system-type
|
|
1544 ange-ftp-version
|
|
1545 url-gateway-method
|
|
1546 efs-version
|
|
1547 ange-ftp-version
|
|
1548 url-version
|
|
1549 url-be-asynchronous
|
|
1550 url)))
|
|
1551 (if (and url (string= url "file:nil")) (setq url nil))
|
|
1552 (mapcar
|
|
1553 (function
|
|
1554 (lambda (x)
|
|
1555 (if (not (and (boundp x) (symbol-value x)))
|
|
1556 (setq vars (delq x vars))))) vars)
|
|
1557 (reporter-submit-bug-report w3-bug-address
|
|
1558 (concat "WWW v" w3-version-number " of "
|
|
1559 w3-version-date)
|
|
1560 vars
|
|
1561 nil nil
|
|
1562 "Description of Problem:"))))
|
|
1563
|
2
|
1564 (defalias 'w3-bug 'w3-submit-bug)
|
|
1565
|
0
|
1566 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1567 ;;; Support for searching ;;;
|
|
1568 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1569 (defun w3-nuke-spaces-in-search (x)
|
|
1570 "Remove spaces from search strings . . ."
|
|
1571 (let ((new ""))
|
|
1572 (while (not (equal x ""))
|
|
1573 (setq new (concat new (if (= (string-to-char x) 32) "+"
|
|
1574 (substring x 0 1)))
|
|
1575 x (substring x 1 nil)))
|
|
1576 new))
|
|
1577
|
|
1578 (defun w3-search ()
|
|
1579 "Perform a search, if this is a searchable index."
|
|
1580 (interactive)
|
70
|
1581 (or w3-current-isindex
|
|
1582 (error "Not a searchable index (via <isindex>)"))
|
0
|
1583 (let* (querystring ; The string to send to the server
|
|
1584 (data
|
|
1585 (cond
|
|
1586 ((null w3-current-isindex)
|
70
|
1587 (let ((rels (mapcar
|
|
1588 (function
|
|
1589 (lambda (data)
|
|
1590 (if (assoc "rel" data) data)))
|
|
1591 w3-current-links))
|
|
1592 val)
|
0
|
1593 (while rels
|
70
|
1594 (if (string-match "useindex"
|
|
1595 (or (cdr (assoc "rel" (car rels))) ""))
|
|
1596 (setq val (cdr (assoc "href" (car rels)))
|
0
|
1597 rels nil))
|
70
|
1598 (setq rels (cdr rels)))
|
|
1599 (cons val "Search on (+ separates keywords): ")))
|
0
|
1600 ((eq w3-current-isindex t)
|
|
1601 (cons (url-view-url t) "Search on (+ separates keywords): "))
|
|
1602 ((consp w3-current-isindex)
|
|
1603 w3-current-isindex)
|
|
1604 (t nil)))
|
|
1605 index)
|
|
1606 (if (null data) (error "Not a searchable index!"))
|
|
1607 (setq index (car data))
|
|
1608 (setq querystring (w3-nuke-spaces-in-search (read-string (cdr data))))
|
|
1609 (if (string-match "\\(.*\\)\\?.*" index)
|
|
1610 (setq index (url-match index 1)))
|
|
1611 (w3-fetch
|
|
1612 (concat index (if (= ?? (string-to-char (substring index -1 nil)))
|
|
1613 "" "?") querystring))))
|
|
1614
|
|
1615 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1616 ;;; Auto documentation, etc ;;;
|
|
1617 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1618 (defun w3-help ()
|
|
1619 "Print documentation on w3 mode."
|
|
1620 (interactive)
|
|
1621 (w3-fetch "about:"))
|
|
1622
|
|
1623 (defun w3-version (&optional here)
|
|
1624 "Show the version number of W3 in the minibuffer.
|
|
1625 If optional argument HERE is non-nil, insert info at point."
|
|
1626 (interactive "P")
|
|
1627 (let ((version-string
|
|
1628 (format "WWW %s, URL %s, MM %s"
|
|
1629 w3-version-number
|
|
1630 url-version
|
|
1631 mm-version)))
|
|
1632 (if here
|
|
1633 (insert version-string)
|
|
1634 (if (interactive-p)
|
|
1635 (message "%s" version-string)
|
|
1636 version-string))))
|
|
1637
|
|
1638 ;;;###autoload
|
|
1639 (defun w3 ()
|
|
1640 "Retrieve the default World Wide Web home page.
|
|
1641 The World Wide Web is a global hypertext system started by CERN in
|
|
1642 Switzerland in 1991.
|
|
1643
|
|
1644 The home page is specified by the variable w3-default-homepage. The
|
|
1645 document should be specified by its fully specified Uniform Resource
|
|
1646 Locator. The document will be parsed as HTML (if appropriate) and
|
|
1647 displayed in a new buffer."
|
|
1648 (interactive)
|
|
1649 (if (not w3-setup-done) (w3-do-setup))
|
|
1650 (if (and w3-track-last-buffer
|
|
1651 (bufferp w3-last-buffer)
|
|
1652 (buffer-name w3-last-buffer))
|
|
1653 (progn
|
|
1654 (switch-to-buffer w3-last-buffer)
|
|
1655 (message "Reusing buffer. To reload, type %s."
|
|
1656 (substitute-command-keys "\\[w3-reload-document]")))
|
|
1657 (cond
|
|
1658 ((null w3-default-homepage) (call-interactively 'w3-fetch))
|
|
1659 ((not (stringp w3-default-homepage))
|
|
1660 (error "Invalid setting for w3-default-homepage: %S"
|
|
1661 w3-default-homepage))
|
|
1662 ((not (string-match ".*:.*" w3-default-homepage))
|
|
1663 (w3-fetch (concat "file:" w3-default-homepage)))
|
|
1664 (t
|
|
1665 (w3-fetch w3-default-homepage)))))
|
|
1666
|
|
1667 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1668 ;;; Leftover stuff that didn't quite fit into url.el
|
|
1669 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1670
|
|
1671 (defun w3-generate-error (type data)
|
|
1672 ;; Generate an HTML error buffer for error TYPE with data DATA.
|
|
1673 (cond
|
|
1674 ((equal type "nofile")
|
|
1675 (let ((error (save-excursion
|
|
1676 (set-buffer (get-buffer-create " *url-error*"))
|
|
1677 (buffer-string))))
|
|
1678 (if (string= "" error)
|
|
1679 (setq error
|
|
1680 (format (concat "The file %s could not be found. "
|
|
1681 "Either it does not exist, or it "
|
|
1682 "is unreadable.") data)))
|
|
1683 (insert "<html>\n <head>\n"
|
|
1684 " <title>Error</title>\n"
|
|
1685 " </head>\n <body>\n"
|
|
1686 " <h1>Error accessing " data "</h1>\n"
|
|
1687 " <hr>\n <p>"
|
|
1688 error
|
|
1689 "\n </p>\n")))
|
|
1690 ((equal type "nobuf")
|
|
1691 (insert "<title>Error</title>\n"
|
|
1692 "<H1>No buffer " data " found</h1>\n"
|
|
1693 "<HR>\n"
|
|
1694 "The buffer " data " could not be found. It has either\n"
|
|
1695 "been killed or renamed.\n"))
|
|
1696 ((equal type "nohist")
|
|
1697 (insert "<TITLE>Error</TITLE>\n"
|
|
1698 "<H1>No history items found.</H1>\n"
|
|
1699 "<HR>\n"
|
|
1700 "There is no history list available at this time. Either\n"
|
|
1701 "you have not visited any nodes, or the variable <i>\n"
|
|
1702 "url-keep-history</i> is nil.\n"))
|
|
1703 )
|
|
1704 (insert "<hr>\n"
|
|
1705 "If you feel this is a bug in Emacs-W3, <a href=\"mailto:"
|
|
1706 w3-bug-address "\">send mail to " w3-bug-address
|
|
1707 "</a>\n<hr>"))
|
|
1708
|
|
1709 (defun w3-generate-auto-html (type)
|
|
1710 ;; Generate one of several automatic html pages
|
|
1711 (setq url-current-mime-type "text/html"
|
|
1712 url-current-mime-headers '(("content-type" . "text/html")))
|
|
1713 (cond
|
|
1714 ((equal type "hotlist")
|
|
1715 (let ((tmp (reverse w3-hotlist)))
|
|
1716 (insert "<html>\n\t<head>\n\t\t"
|
|
1717 "<title> Hotlist </title>\n\t</head>\n"
|
|
1718 "\t<body>\n\t\t<div>\n\t\t\t<h1>Hotlist from " w3-hotlist-file
|
|
1719 "</h1>\n\t\t\t<ol>\n")
|
|
1720 (while tmp
|
|
1721 (insert "\t\t\t\t<li> <a href=\"" (car (cdr (car tmp)))
|
2
|
1722 "\">" (url-insert-entities-in-string
|
0
|
1723 (car (car tmp))) "</a></li>\n")
|
|
1724 (setq tmp (cdr tmp)))
|
|
1725 (insert "\n\t\t\t</ol>\n\t\t</div>\n\t</body>\n</html>\n")))
|
70
|
1726 ((equal type "starting-points")
|
|
1727 (let ((tmp w3-starting-documents))
|
|
1728 (insert "<html>\n\t<head>\n\t\t"
|
|
1729 "<title> Starting Points </title>\n\t</head>\n"
|
|
1730 "\t<body>\n\t\t<div>\n\t\t\t<h1>Starting Point on the Web"
|
|
1731 "</h1>\n\t\t\t<ol>\n")
|
|
1732 (while tmp
|
|
1733 (insert (format "\t\t\t\t<li> <a href=\"%s\">%s</a></li>\n"
|
|
1734 (car (cdr (car tmp)))
|
|
1735 (car (car tmp))))
|
|
1736 (setq tmp (cdr tmp)))
|
|
1737 (insert "\n\t\t\t</ol>\n\t\t</div>\n\t</body>\n</html>\n")))
|
0
|
1738 ((equal type "history")
|
|
1739 (if (not url-history-list)
|
|
1740 (url-retrieve "www://error/nohist")
|
|
1741 (insert "<html>\n\t<head>\n\t\t"
|
|
1742 "<title> History List For This Session of W3</title>"
|
|
1743 "\n\t</head>\n\t<body>\n\t\t<div>\n\t\t\t<h1>"
|
|
1744 "History List For This Session of W3</h1>\n\t\t\t<ol>\n")
|
70
|
1745 (url-maphash
|
0
|
1746 (function
|
|
1747 (lambda (url desc)
|
|
1748 (insert (format "\t\t\t\t<li> <a href=\"%s\">%s</a>\n"
|
2
|
1749 url (url-insert-entities-in-string desc)))))
|
0
|
1750 url-history-list)
|
|
1751 (insert "\n\t\t\t</ol>\n\t\t</div>\n\t</body>\n</html>\n")))))
|
|
1752
|
|
1753 (defun w3-internal-handle-preview (buffer)
|
|
1754 (setq buffer (get-buffer buffer))
|
|
1755 (let ((base (get-text-property (point-min) 'w3-base buffer)))
|
|
1756 (if base
|
|
1757 (setq base (url-generic-parse-url base)))
|
|
1758 (insert-buffer buffer)
|
|
1759 (if (not base)
|
70
|
1760 (setq url-current-type "file"
|
|
1761 url-current-server nil
|
|
1762 url-current-file (buffer-file-name buffer))
|
|
1763 (setq url-current-object base
|
|
1764 url-current-type (url-type base)
|
|
1765 url-current-user (url-user base)
|
|
1766 url-current-port (url-port base)
|
|
1767 url-current-server (url-host base)
|
|
1768 url-current-file (url-filename base)))))
|
0
|
1769
|
|
1770 (defun w3-internal-url (url)
|
|
1771 ;; Handle internal urls (previewed buffers, etc)
|
|
1772 (if (not (string-match "www:/+\\([^/]+\\)/\\(.*\\)" url))
|
|
1773 (w3-fetch "www://error/")
|
|
1774 (let ((type (url-match url 1))
|
|
1775 (data (url-match url 2)))
|
|
1776 (set-buffer (get-buffer-create url-working-buffer))
|
70
|
1777 (setq url-current-type "www"
|
|
1778 url-current-server type
|
|
1779 url-current-file data)
|
0
|
1780 (cond
|
|
1781 ((equal type "preview") ; Previewing a document
|
|
1782 (if (get-buffer data) ; Buffer still exists
|
|
1783 (w3-internal-handle-preview data)
|
|
1784 (url-retrieve (concat "www://error/nobuf/" data))))
|
|
1785 ((equal type "error") ; Error message
|
|
1786 (if (string-match "\\([^/]+\\)/\\(.*\\)" data)
|
|
1787 (w3-generate-error (url-match data 1) (url-match data 2))
|
|
1788 (w3-generate-error data "")))
|
|
1789 ((equal type "auto") ; Hotlist or help stuff
|
|
1790 (w3-generate-auto-html data))))))
|
|
1791
|
|
1792 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1793 ;;; Stuff for good local file handling
|
|
1794 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1795 (defun w3-ff (file)
|
|
1796 "Find a file in any window already displaying it, otherwise just as
|
|
1797 display-buffer, and using this function"
|
|
1798 (if (not (eq 'tty (device-type)))
|
|
1799 (let ((f (window-frame (display-buffer (find-file-noselect file)))))
|
|
1800 (set-mouse-position f 1 0)
|
|
1801 (raise-frame f)
|
|
1802 (unfocus-frame))
|
|
1803 (display-buffer (find-file-noselect file))))
|
|
1804
|
|
1805 (defun w3-default-local-file()
|
|
1806 "Use find-file to open the local file"
|
70
|
1807 (w3-ff url-current-file))
|
0
|
1808
|
|
1809 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1810 ;;; Mode definition ;;;
|
|
1811 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1812 (defun w3-search-forward (string)
|
|
1813 (interactive "sSearch: ")
|
|
1814 (setq w3-last-search-item string)
|
|
1815 (if (and (not (search-forward string nil t))
|
|
1816 (funcall url-confirmation-func
|
|
1817 "End of document reached; continue from beginning? "))
|
|
1818 (progn
|
|
1819 (goto-char (point-min))
|
|
1820 (w3-search-forward string))))
|
|
1821
|
|
1822 (defun w3-search-again ()
|
|
1823 (interactive)
|
|
1824 (if (and w3-last-search-item
|
|
1825 (stringp w3-last-search-item))
|
|
1826 (if (and (not (search-forward w3-last-search-item nil t))
|
|
1827 (funcall url-confirmation-func
|
|
1828 "End of document reached; continue from beginning? "))
|
|
1829 (progn
|
|
1830 (goto-char (point-min))
|
|
1831 (w3-search-again)))))
|
|
1832
|
|
1833 (defun w3-find-specific-link (link)
|
|
1834 (let ((pos (assq (intern link) w3-id-positions)))
|
|
1835 (if pos
|
|
1836 (progn
|
|
1837 (goto-char (cdr pos))
|
|
1838 (if (and (eolp) (not (eobp)))
|
|
1839 (forward-char 1)))
|
|
1840 (error "Link #%s not found." link))))
|
|
1841
|
|
1842 (defun w3-force-reload-document ()
|
|
1843 "Reload the current document. Take it from the network, even if
|
|
1844 cached and in local mode."
|
|
1845 (let ((url-standalone-mode nil))
|
|
1846 (w3-reload-document)))
|
|
1847
|
|
1848 (defun w3-reload-document ()
|
|
1849 "Reload the current document"
|
|
1850 (interactive)
|
|
1851 (let ((tmp (url-view-url t))
|
|
1852 (pnt (point))
|
|
1853 (window-start (progn
|
|
1854 (move-to-window-line 0)
|
|
1855 (point)))
|
|
1856 (url-request-extra-headers '(("Pragma" . "no-cache"))))
|
|
1857 (kill-buffer (current-buffer))
|
|
1858 (w3-fetch tmp)
|
|
1859 (goto-char pnt)
|
|
1860 (set-window-start (selected-window) (min window-start (point-max)))))
|
|
1861
|
|
1862 (defun w3-leave-buffer ()
|
|
1863 "Bury this buffer, but don't kill it."
|
|
1864 (interactive)
|
|
1865 (let ((x w3-current-last-buffer))
|
|
1866 (bury-buffer nil)
|
|
1867 (if (and (bufferp x) (buffer-name x))
|
|
1868 (w3-notify-when-ready x))))
|
|
1869
|
|
1870 (defun w3-quit (&optional mega)
|
|
1871 "Quit WWW mode"
|
|
1872 (interactive "P")
|
|
1873 (if mega
|
|
1874 (mapcar
|
|
1875 (function
|
|
1876 (lambda (x)
|
|
1877 (save-excursion
|
|
1878 (set-buffer (get-buffer x))
|
|
1879 (if (eq major-mode 'w3-mode)
|
|
1880 (w3-quit nil)))))
|
|
1881 (buffer-list))
|
|
1882 (let ((x w3-current-last-buffer))
|
|
1883 (kill-buffer (current-buffer))
|
|
1884 (if (and (bufferp x) (buffer-name x))
|
|
1885 (w3-notify-when-ready x)))))
|
|
1886
|
|
1887 (defun w3-view-this-url (&optional no-show)
|
|
1888 "View the URL of the link under point"
|
|
1889 (interactive)
|
|
1890 (let* ((widget (widget-at (point)))
|
|
1891 (href (and widget (widget-get widget 'href))))
|
|
1892 (cond
|
|
1893 ((and no-show href)
|
|
1894 href)
|
|
1895 (href
|
|
1896 (message "%s" (url-truncate-url-for-viewing href)))
|
|
1897 (no-show
|
|
1898 nil)
|
|
1899 (t
|
|
1900 nil))))
|
|
1901
|
|
1902 (defun w3-load-delayed-images ()
|
2
|
1903 "Load inlined images that were delayed, if any."
|
0
|
1904 (interactive)
|
2
|
1905 (let ((w3-delay-image-loads nil)
|
|
1906 (todo w3-delayed-images))
|
|
1907 (setq w3-delayed-images nil)
|
|
1908 (while todo
|
|
1909 (w3-maybe-start-image-download (car todo))
|
|
1910 (setq todo (cdr todo)))))
|
0
|
1911
|
|
1912 (defun w3-save-this-url ()
|
|
1913 "Save url under point in the kill ring"
|
|
1914 (interactive)
|
|
1915 (w3-save-url t))
|
|
1916
|
|
1917 (defun w3-save-url (under-pt)
|
|
1918 "Save current url in the kill ring"
|
|
1919 (interactive "P")
|
|
1920 (let ((x (cond
|
|
1921 ((stringp under-pt) under-pt)
|
|
1922 (under-pt (w3-view-this-url t))
|
|
1923 (t (url-view-url t)))))
|
|
1924 (if x
|
|
1925 (progn
|
|
1926 (setq kill-ring (cons x kill-ring))
|
|
1927 (setq kill-ring-yank-pointer kill-ring)
|
|
1928 (message "Stored URL in kill-ring.")
|
|
1929 (if (fboundp 'w3-store-in-clipboard)
|
|
1930 (w3-store-in-clipboard x)))
|
|
1931 (error "No URL to store."))))
|
|
1932
|
|
1933 (fset 'w3-end-of-document 'end-of-buffer)
|
|
1934 (fset 'w3-start-of-document 'beginning-of-buffer)
|
|
1935
|
|
1936 (defun w3-scroll-up (&optional lines)
|
|
1937 "Scroll forward in View mode, or exit if end of text is visible.
|
|
1938 No arg means whole window full. Arg is number of lines to scroll."
|
|
1939 (interactive "P")
|
|
1940 (if (and (pos-visible-in-window-p (point-max))
|
|
1941 ;; Allow scrolling backward at the end of the buffer.
|
|
1942 (or (null lines)
|
|
1943 (> lines 0)))
|
|
1944 nil
|
|
1945 (let ((view-lines (1- (window-height))))
|
|
1946 (setq lines
|
|
1947 (if lines (prefix-numeric-value lines)
|
|
1948 view-lines))
|
|
1949 (if (>= lines view-lines)
|
|
1950 (scroll-up nil)
|
|
1951 (if (>= (- lines) view-lines)
|
|
1952 (scroll-down nil)
|
|
1953 (scroll-up lines)))
|
|
1954 (cond ((pos-visible-in-window-p (point-max))
|
|
1955 (goto-char (point-max))
|
|
1956 (recenter -1)))
|
|
1957 (move-to-window-line -1)
|
|
1958 (beginning-of-line))))
|
|
1959
|
|
1960 (defun w3-mail-document-author ()
|
|
1961 "Send mail to the author of this document, if possible."
|
|
1962 (interactive)
|
|
1963 (let ((x w3-current-links)
|
|
1964 (y nil)
|
|
1965 (found nil))
|
|
1966 (setq found (cdr-safe (assoc "reply-to" url-current-mime-headers)))
|
|
1967 (if (and found (not (string-match url-nonrelative-link found)))
|
70
|
1968 (setq found (concat "mailto:" found)))
|
0
|
1969 (while (and x (not found))
|
|
1970 (setq y (car x)
|
|
1971 x (cdr x)
|
|
1972 found (cdr-safe (assoc "made" y))))
|
|
1973 (if found
|
70
|
1974 (let ((possible nil))
|
0
|
1975 (setq x (car found)) ; Fallback if no mail(to|server) found
|
|
1976 (while found
|
70
|
1977 (if (string-match "^mail[^:]+:" (car found))
|
|
1978 (setq possible (cons (car found) possible)))
|
|
1979 (setq found (cdr found)))
|
0
|
1980 (case (length possible)
|
|
1981 (0 ; No mailto links found
|
|
1982 (w3-fetch x)) ; fall back onto first 'made' link
|
|
1983 (1 ; Only one found, get it
|
|
1984 (w3-fetch (car possible)))
|
|
1985 (otherwise
|
|
1986 (w3-fetch (completing-read "Choose an address: "
|
|
1987 (mapcar 'list possible)
|
|
1988 nil t (car possible))))))
|
70
|
1989 (message "Could not automatically determine authors address, sorry.")
|
|
1990 (sit-for 1)
|
|
1991 (w3-fetch (concat "mailto:"
|
|
1992 (read-string "Email address: "
|
|
1993 (if url-current-server
|
|
1994 (concat "@" url-current-server))))))))
|
0
|
1995
|
|
1996 (defun w3-kill-emacs-func ()
|
|
1997 "Routine called when exiting emacs. Do miscellaneous clean up."
|
|
1998 (and (eq url-keep-history t)
|
|
1999 url-global-history-hash-table
|
|
2000 (url-write-global-history))
|
|
2001 (message "Cleaning up w3 storage...")
|
|
2002 (let ((x (nconc
|
|
2003 (and (file-exists-p w3-temporary-directory)
|
|
2004 (directory-files w3-temporary-directory t "url-tmp.*"))
|
|
2005 (and (file-exists-p url-temporary-directory)
|
|
2006 (directory-files url-temporary-directory t
|
|
2007 (concat "url"
|
|
2008 (int-to-string
|
|
2009 (user-real-uid)) ".*")))
|
|
2010 (and (file-exists-p url-temporary-directory)
|
|
2011 (directory-files url-temporary-directory t "url-tmp.*")))))
|
|
2012 (while x
|
|
2013 (condition-case ()
|
|
2014 (delete-file (car x))
|
|
2015 (error nil))
|
|
2016 (setq x (cdr x))))
|
|
2017 (message "Cleaning up w3 storage... done."))
|
|
2018
|
|
2019 (cond
|
|
2020 ((fboundp 'display-warning)
|
|
2021 (fset 'w3-warn 'display-warning))
|
|
2022 ((fboundp 'warn)
|
|
2023 (defun w3-warn (class message &optional level)
|
|
2024 (if (and (eq class 'html)
|
|
2025 (not w3-debug-html))
|
|
2026 nil
|
|
2027 (warn "(%s/%s) %s" class (or level 'warning) message))))
|
|
2028 (t
|
|
2029 (defun w3-warn (class message &optional level)
|
|
2030 (if (and (eq class 'html)
|
|
2031 (not w3-debug-html))
|
|
2032 nil
|
|
2033 (save-excursion
|
|
2034 (set-buffer (get-buffer-create "*W3-WARNINGS*"))
|
|
2035 (goto-char (point-max))
|
|
2036 (save-excursion
|
|
2037 (insert (format "(%s/%s) %s\n" class (or level 'warning) message)))
|
|
2038 (display-buffer (current-buffer)))))))
|
|
2039
|
|
2040 (defun w3-internal-expander (urlobj defobj)
|
|
2041 ;; URL Expansion routine for internally handled routines
|
|
2042 (url-identity-expander urlobj defobj))
|
|
2043
|
|
2044 (defun w3-map-links (function &optional buffer from to maparg)
|
|
2045 "Map FUNCTION over the hypertext links which overlap region in BUFFER,
|
|
2046 starting at FROM and ending at TO. FUNCTION is called with the arguments
|
|
2047 WIDGET and MAPARG.
|
|
2048 The arguments FROM, TO, MAPARG, and BUFFER default to the beginning of
|
|
2049 BUFFER, the end of BUFFER, nil, and (current-buffer), respectively."
|
|
2050 (let ((cur (point-min))
|
|
2051 (widget nil)
|
70
|
2052 (url nil))
|
0
|
2053 (while (setq cur (next-single-property-change cur 'button))
|
70
|
2054 (setq widget (widget-at cur))
|
0
|
2055 ;; Check to see if its a push widget, its got the correct callback,
|
|
2056 ;; and actually has a URL. Remember the url as a side-effect of the
|
|
2057 ;; test for later use.
|
70
|
2058 (if (and (eq (car widget) 'push)
|
|
2059 (eq (widget-get widget :notify) 'w3-follow-hyperlink)
|
|
2060 (setq url (widget-get widget 'href)))
|
|
2061 (funcall function widget maparg)))))
|
0
|
2062
|
|
2063 (defun w3-emit-image-warnings-if-necessary ()
|
|
2064 (if (and (not w3-delay-image-loads)
|
|
2065 (fboundp 'w3-insert-graphic)
|
|
2066 (or (not (featurep 'gif))
|
|
2067 (not (featurep 'jpeg)))
|
|
2068 (not (w3-executable-exists-in-path "ppmtoxpm"))
|
|
2069 (not (or
|
|
2070 (w3-executable-exists-in-path "pbmtoxbm")
|
|
2071 (w3-executable-exists-in-path "ppmtoxbm"))))
|
|
2072 (w3-warn
|
|
2073 'image
|
|
2074 (concat
|
|
2075 "Could not find some vital ppm utilities in exec-path.\n"
|
|
2076 "This probably means that you will be unable to view any\n"
|
|
2077 "inlined images other than: "
|
|
2078 (mapconcat
|
|
2079 (function
|
|
2080 (lambda (x)
|
|
2081 (if (featurep x) (concat (symbol-name x) ",\n"))))
|
|
2082 '(png jpg gif xpm xbm) "")
|
|
2083 "\n\n"
|
|
2084 "If you do not have the PPM utilities from either the PBMPLUS\n"
|
|
2085 "or NETPBM distributions installed on your machine, then\n"
|
|
2086 "please set the variable `w3-delay-image-loads' to t with a\n"
|
|
2087 "line like:\n\n"
|
|
2088 "\t(setq w3-delay-image-loads t)\n\n"
|
|
2089 "in your ~/.emacs file.\n\n"
|
|
2090 "You can find the NETPBM utilities in:\n"
|
|
2091 "\tftp://ftp.cs.indiana.edu/pub/elisp/w3/images/\n"
|
|
2092 ))))
|
|
2093
|
2
|
2094 (defun w3-refresh-stylesheets ()
|
|
2095 "Reload all stylesheets."
|
|
2096 (interactive)
|
|
2097 (setq w3-user-stylesheet nil
|
|
2098 w3-face-cache nil)
|
|
2099 (w3-find-default-stylesheets)
|
70
|
2100 (w3-style-post-process-stylesheet w3-user-stylesheet))
|
30
|
2101
|
0
|
2102 (defun w3-find-default-stylesheets ()
|
|
2103 (let* ((lightp (w3-color-light-p 'default))
|
|
2104 (longname (if lightp "stylesheet-light" "stylesheet-dark"))
|
|
2105 (shortname (if lightp "light.css" "dark.css"))
|
|
2106 (directories (list
|
|
2107 data-directory
|
|
2108 (concat data-directory "w3/")
|
|
2109 (file-name-directory (locate-library "w3"))
|
|
2110 w3-configuration-directory))
|
|
2111 (total-found 0)
|
|
2112 (possible (append
|
|
2113 (apply
|
|
2114 'append
|
|
2115 (mapcar
|
|
2116 (function
|
|
2117 (lambda (dir)
|
|
2118 (list
|
|
2119 (expand-file-name shortname dir)
|
|
2120 (expand-file-name longname dir)
|
|
2121 (expand-file-name "stylesheet" dir)
|
|
2122 (expand-file-name "default.css" dir))))
|
|
2123 directories))
|
|
2124 (list w3-default-stylesheet)))
|
|
2125 (remember possible)
|
|
2126 (old-asynch (default-value 'url-be-asynchronous))
|
|
2127 (found nil)
|
|
2128 (cur nil)
|
|
2129 (url nil))
|
|
2130 (setq-default url-be-asynchronous nil)
|
|
2131 (while possible
|
|
2132 (setq cur (car possible)
|
|
2133 possible (cdr possible)
|
|
2134 found (and cur (file-exists-p cur) (file-readable-p cur)
|
|
2135 (not (file-directory-p cur)) cur))
|
|
2136 (if found
|
|
2137 (setq total-found (1+ total-found)
|
70
|
2138 w3-user-stylesheet (car
|
|
2139 (w3-style-parse-css
|
|
2140 (concat "file:" cur) nil
|
|
2141 w3-user-stylesheet)))))
|
0
|
2142 (setq-default url-be-asynchronous old-asynch)
|
|
2143 (if (= 0 total-found)
|
|
2144 (w3-warn
|
|
2145 'style
|
|
2146 (concat
|
|
2147 "No stylesheets found! Check configuration! DANGER DANGER!\n"
|
|
2148 "Emacs-W3 checked for its stylesheet in the following places\n"
|
|
2149 "and did not find one. This means that some formatting will\n"
|
|
2150 "be wrong, and most colors and fonts will not be set up correctly.\n"
|
|
2151 "------\n"
|
|
2152 (mapconcat 'identity remember "\n")
|
|
2153 "------")))))
|
|
2154
|
|
2155 ;;;###autoload
|
|
2156 (defun w3-do-setup ()
|
|
2157 "Do setup - this is to avoid conflict with user settings when W3 is
|
|
2158 dumped with emacs."
|
|
2159 (url-do-setup)
|
|
2160 (url-register-protocol 'about 'w3-about 'url-identity-expander)
|
|
2161 (url-register-protocol 'www 'w3-internal-url 'w3-internal-expander)
|
|
2162 (w3-load-flavors)
|
|
2163 (w3-setup-version-specifics)
|
|
2164 (setq w3-default-configuration-file (expand-file-name
|
|
2165 (or w3-default-configuration-file
|
|
2166 "profile")
|
|
2167 w3-configuration-directory))
|
|
2168
|
|
2169
|
70
|
2170 (if (and w3-default-configuration-file
|
0
|
2171 (file-exists-p w3-default-configuration-file))
|
|
2172 (condition-case e
|
|
2173 (load w3-default-configuration-file nil t)
|
|
2174 (error
|
|
2175 (let ((buf-name " *Configuration Error*"))
|
|
2176 (if (get-buffer buf-name)
|
|
2177 (kill-buffer (get-buffer buf-name)))
|
|
2178 (display-error e (get-buffer-create buf-name))
|
|
2179 (save-excursion
|
|
2180 (switch-to-buffer-other-window buf-name)
|
|
2181 (shrink-window-if-larger-than-buffer))
|
|
2182 (w3-warn 'configuration
|
|
2183 (format (eval-when-compile
|
|
2184 (concat
|
|
2185 "Configuration file `%s' contains an error.\n"
|
|
2186 "Please consult the `%s' buffer for details."))
|
|
2187 w3-default-configuration-file buf-name))))))
|
|
2188
|
70
|
2189 (setq w3-netscape-configuration-file
|
|
2190 (cond
|
|
2191 (w3-netscape-configuration-file
|
|
2192 w3-netscape-configuration-file)
|
|
2193 ((memq system-type '(ms-dos ms-windows))
|
|
2194 (expand-file-name "~/NETSCAPE.CFG"))
|
|
2195 (t (expand-file-name "~/.netscape/preferences"))))
|
|
2196
|
0
|
2197 (if (and (eq w3-user-colors-take-precedence 'guess)
|
|
2198 (not (eq (device-type) 'tty))
|
|
2199 (not (eq (device-class) 'mono)))
|
|
2200 (progn
|
|
2201 (setq w3-user-colors-take-precedence t)
|
|
2202 (w3-warn
|
|
2203 'html
|
2
|
2204 "Disabled document color specification because of mono display.")))
|
0
|
2205
|
2
|
2206 (w3-refresh-stylesheets)
|
0
|
2207 (if (not url-global-history-file)
|
|
2208 (setq url-global-history-file
|
|
2209 (expand-file-name "history"
|
|
2210 w3-configuration-directory)))
|
|
2211
|
70
|
2212 (if (and w3-use-netscape-configuration-file
|
|
2213 w3-netscape-configuration-file
|
|
2214 (fboundp 'w3-read-netscape-config))
|
|
2215 (w3-read-netscape-config w3-netscape-configuration-file))
|
|
2216
|
0
|
2217 (add-minor-mode 'w3-netscape-emulation-minor-mode " NS"
|
|
2218 w3-netscape-emulation-minor-mode-map)
|
70
|
2219 (add-minor-mode 'w3-annotation-minor-mode " Annotating"
|
|
2220 w3-annotation-minor-mode-map)
|
0
|
2221 (add-minor-mode 'w3-lynx-emulation-minor-mode " Lynx"
|
70
|
2222 w3-annotation-minor-mode-map)
|
0
|
2223
|
|
2224 (setq url-package-version w3-version-number
|
|
2225 url-package-name "Emacs-W3")
|
|
2226
|
|
2227 (w3-emit-image-warnings-if-necessary)
|
70
|
2228 (if (eq w3-color-use-reducing 'guess)
|
|
2229 (setq w3-color-use-reducing
|
|
2230 (cond
|
|
2231 ((eq (device-type) 'tty) nil)
|
|
2232 ((fboundp 'device-class)
|
|
2233 (not (and (memq (device-class) '(TrueColor true-color))
|
|
2234 (<= 16 (or (device-bitplanes) 0)))))
|
|
2235 (t t))))
|
0
|
2236
|
|
2237 (cond
|
|
2238 ((memq system-type '(ms-dos ms-windows))
|
70
|
2239 (setq w3-documents-menu-file (or w3-documents-menu-file
|
|
2240 (expand-file-name "~/mosaic.mnu"))
|
|
2241 w3-hotlist-file (or w3-hotlist-file
|
0
|
2242 (expand-file-name "~/mosaic.hot"))
|
70
|
2243 w3-personal-annotation-directory (or w3-personal-annotation-directory
|
|
2244 (expand-file-name
|
|
2245 "~/mosaic.ann"))))
|
0
|
2246 ((memq system-type '(axp-vms vax-vms))
|
70
|
2247 (setq w3-documents-menu-file
|
|
2248 (or w3-documents-menu-file
|
|
2249 (expand-file-name "decw$system_defaults:documents.menu"))
|
|
2250 w3-hotlist-file (or w3-hotlist-file
|
0
|
2251 (expand-file-name "~/mosaic.hotlist-default"))
|
70
|
2252 w3-personal-annotation-directory
|
|
2253 (or w3-personal-annotation-directory
|
|
2254 (expand-file-name "~/mosaic-annotations/"))))
|
0
|
2255 (t
|
70
|
2256 (setq w3-documents-menu-file
|
|
2257 (or w3-documents-menu-file
|
|
2258 (expand-file-name "/usr/local/lib/mosaic/documents.menu"))
|
|
2259 w3-hotlist-file (or w3-hotlist-file
|
0
|
2260 (expand-file-name "~/.mosaic-hotlist-default"))
|
70
|
2261 w3-personal-annotation-directory
|
|
2262 (or w3-personal-annotation-directory
|
|
2263 (expand-file-name "~/.mosaic-personal-annotations")))))
|
0
|
2264
|
70
|
2265 (if (eq w3-delimit-emphasis 'guess)
|
|
2266 (setq w3-delimit-emphasis
|
|
2267 (and (not w3-running-xemacs)
|
|
2268 (not (and w3-running-FSF19
|
|
2269 (memq (device-type) '(x ns pm)))))))
|
|
2270
|
|
2271 (if (eq w3-delimit-links 'guess)
|
|
2272 (setq w3-delimit-links
|
|
2273 (and (not w3-running-xemacs)
|
|
2274 (not (and w3-running-FSF19
|
|
2275 (memq (device-type) '(x ns pm)))))))
|
|
2276
|
0
|
2277 ; Set up a hook that will save the history list when
|
|
2278 ; exiting emacs
|
|
2279 (add-hook 'kill-emacs-hook 'w3-kill-emacs-func)
|
|
2280
|
|
2281 (mm-parse-mailcaps)
|
|
2282 (mm-parse-mimetypes)
|
|
2283
|
|
2284 ; Load in the hotlist if they haven't set it already
|
|
2285 (or w3-hotlist (w3-parse-hotlist))
|
|
2286
|
70
|
2287 ; Load in their personal annotations if they haven't set them already
|
|
2288 (or w3-personal-annotations (w3-parse-personal-annotations))
|
|
2289
|
0
|
2290 ; Set the default home page, honoring their defaults, then
|
|
2291 ; the standard WWW_HOME, then default to the documentation @ IU
|
|
2292 (or w3-default-homepage
|
|
2293 (setq w3-default-homepage
|
|
2294 (or (getenv "WWW_HOME")
|
|
2295 "http://www.cs.indiana.edu/elisp/w3/docs.html")))
|
|
2296
|
70
|
2297 ; Set up the documents menu
|
|
2298 (w3-parse-docs-menu)
|
|
2299
|
0
|
2300 ; Set up the entity definition for PGP and PEM authentication
|
|
2301
|
|
2302 (run-hooks 'w3-load-hook)
|
|
2303 (setq w3-setup-done t))
|
|
2304
|
|
2305 (defun w3-mark-link-as-followed (ext dat)
|
|
2306 ;; Mark a link as followed
|
70
|
2307 (let* ((st (w3-zone-start ext))
|
|
2308 (nd (w3-zone-end ext))
|
|
2309 (tag 'a)
|
|
2310 (args (list (cons 'class "visited")))
|
|
2311 (face (cdr (w3-face-for-element))))
|
|
2312 (w3-add-zone st nd face dat t)))
|
0
|
2313
|
|
2314 (defun w3-only-links ()
|
|
2315 (let* (result temp)
|
|
2316 (if (widget-at (point-min))
|
|
2317 (setq result (list (widget-at (point-min)))))
|
|
2318 (setq temp (w3-next-widget (point-min)))
|
|
2319 (while temp
|
|
2320 (if (widget-get temp 'href)
|
|
2321 (setq result (cons temp result)))
|
|
2322 (setq temp (w3-next-widget (widget-get temp :to))))
|
|
2323 result))
|
|
2324
|
|
2325 (defun w3-download-callback (fname buff)
|
|
2326 (if (and (get-buffer buff) (buffer-name buff))
|
|
2327 (save-excursion
|
|
2328 (set-buffer buff)
|
|
2329 (let ((require-final-newline nil)
|
|
2330 (file-name-handler-alist nil)
|
|
2331 (write-file-hooks nil)
|
2
|
2332 (write-contents-hooks nil)
|
70
|
2333 (mc-flag t)
|
|
2334 (file-coding-system url-mule-no-coding-system))
|
2
|
2335 (write-file fname)
|
0
|
2336 (message "Download of %s complete." (url-view-url t))
|
|
2337 (sit-for 3)
|
|
2338 (kill-buffer buff)))))
|
|
2339
|
|
2340 (defun w3-download-url (url)
|
|
2341 (let* ((old-asynch url-be-asynchronous)
|
|
2342 (url-inhibit-uncompression t)
|
|
2343 (url-mime-accept-string "*/*")
|
|
2344 (urlobj (url-generic-parse-url url))
|
|
2345 (url-working-buffer
|
|
2346 (generate-new-buffer (concat " *" url " download*")))
|
70
|
2347 (stub-fname (url-remove-compressed-extensions
|
|
2348 (url-basepath (or (url-filename urlobj) "") t)))
|
|
2349 (fname (read-file-name "Filename to save as: "
|
|
2350 (or mm-download-directory "~/")
|
|
2351 stub-fname
|
|
2352 nil
|
|
2353 stub-fname)))
|
0
|
2354 (setq-default url-be-asynchronous t)
|
|
2355 (save-excursion
|
|
2356 (set-buffer url-working-buffer)
|
|
2357 (setq url-current-callback-data (list fname (current-buffer))
|
|
2358 url-be-asynchronous t
|
|
2359 url-current-callback-func 'w3-download-callback)
|
|
2360 (url-retrieve url))
|
|
2361 (setq-default url-be-asynchronous old-asynch)))
|
|
2362
|
|
2363 ;;;###autoload
|
|
2364 (defun w3-follow-link-other-frame (&optional p)
|
|
2365 "Attempt to follow the hypertext reference under point in a new frame.
|
|
2366 With prefix-arg P, ignore viewers and dump the link straight
|
|
2367 to disk."
|
|
2368 (cond
|
|
2369 ((and (fboundp 'make-frame)
|
|
2370 (fboundp 'select-frame))
|
|
2371 (let ((frm (make-frame)))
|
|
2372 (select-frame frm)
|
|
2373 (w3-follow-link p)))
|
|
2374 (t (w3-follow-link p))))
|
|
2375
|
|
2376 ;;;###autoload
|
|
2377 (defun w3-follow-link (&optional p)
|
|
2378 "Attempt to follow the hypertext reference under point.
|
|
2379 With prefix-arg P, ignore viewers and dump the link straight
|
|
2380 to disk."
|
|
2381 (interactive "P")
|
|
2382 (let* ((widget (widget-at (point)))
|
|
2383 (href (and widget (widget-get widget 'href))))
|
|
2384 (cond
|
|
2385 ((null href) nil)
|
|
2386 ((or p w3-dump-to-disk)
|
|
2387 (w3-download-url href))
|
|
2388 (t
|
|
2389 (w3-fetch href)))))
|
|
2390
|
|
2391 (defun w3-complete-link ()
|
|
2392 "Choose a link from the current buffer and follow it"
|
|
2393 (interactive)
|
|
2394 (let (links-alist
|
|
2395 link-at-point
|
|
2396 choice
|
|
2397 (completion-ignore-case t))
|
|
2398 (setq link-at-point (widget-at (point))
|
|
2399 link-at-point (and
|
|
2400 link-at-point
|
|
2401 (widget-get link-at-point 'href)
|
|
2402 (w3-fix-spaces
|
|
2403 (buffer-substring
|
70
|
2404 (car (widget-get link-at-point 'title))
|
|
2405 (cdr (widget-get link-at-point 'title))))))
|
0
|
2406 (w3-map-links (function
|
|
2407 (lambda (widget arg)
|
70
|
2408 (setq links-alist (cons
|
|
2409 (cons
|
|
2410 (w3-fix-spaces
|
|
2411 (buffer-substring-no-properties
|
|
2412 (widget-get widget :from)
|
|
2413 (widget-get widget :to)))
|
|
2414 (widget-get widget 'href))
|
|
2415 links-alist)))))
|
0
|
2416 (if (not links-alist) (error "No links in current document."))
|
|
2417 (setq links-alist (sort links-alist (function
|
|
2418 (lambda (x y)
|
|
2419 (string< (car x) (car y))))))
|
|
2420 ;; Destructively remove duplicate entries from links-alist.
|
|
2421 (let ((remaining-links links-alist))
|
|
2422 (while remaining-links
|
|
2423 (if (equal (car remaining-links) (car (cdr remaining-links)))
|
|
2424 (setcdr remaining-links (cdr (cdr remaining-links)))
|
|
2425 (setq remaining-links (cdr remaining-links)))))
|
|
2426 (setq choice (completing-read
|
|
2427 (if link-at-point
|
|
2428 (concat "Link (default "
|
|
2429 (if (< (length link-at-point) 20)
|
|
2430 link-at-point
|
|
2431 (concat
|
|
2432 (substring link-at-point 0 17) "..."))
|
|
2433 "): ")
|
|
2434 "Link: ") links-alist nil t))
|
70
|
2435 (if (string= choice "")
|
|
2436 (w3-follow-link)
|
|
2437 (w3-fetch (cdr (assoc choice links-alist))))))
|
|
2438
|
|
2439 (defun w3-widget-motion-hook (widget)
|
|
2440 (assert widget nil "Bad data to w3-widget-motion-hook! Bad hook bad!")
|
|
2441 (case w3-echo-link
|
|
2442 (text
|
|
2443 (message "%s" (w3-fix-spaces (buffer-substring (widget-get widget :from)
|
|
2444 (widget-get widget :to)))))
|
|
2445 (url
|
|
2446 (if (widget-get widget 'href)
|
|
2447 (message "%s" (widget-get widget 'href))))
|
|
2448 (otherwise nil)))
|
0
|
2449
|
|
2450 (defun w3-mode ()
|
|
2451 "Mode for viewing HTML documents. If called interactively, will
|
|
2452 display the current buffer as HTML.
|
|
2453
|
|
2454 Current keymap is:
|
|
2455 \\{w3-mode-map}"
|
|
2456 (interactive)
|
|
2457 (or w3-setup-done (w3-do-setup))
|
|
2458 (if (interactive-p)
|
|
2459 (w3-preview-this-buffer)
|
|
2460 (let ((tmp (mapcar (function (lambda (x) (cons x (symbol-value x))))
|
|
2461 w3-persistent-variables)))
|
70
|
2462 (kill-all-local-variables)
|
0
|
2463 (use-local-map w3-mode-map)
|
|
2464 (setq major-mode 'w3-mode)
|
|
2465 (setq mode-name "WWW")
|
|
2466 (mapcar (function (lambda (x) (set-variable (car x) (cdr x)))) tmp)
|
|
2467 (w3-mode-version-specifics)
|
|
2468 (w3-menu-install-menus)
|
70
|
2469 (make-local-hook 'widget-motion-hook)
|
|
2470 (add-hook 'widget-motion-hook 'w3-widget-motion-hook)
|
32
|
2471 (run-hooks 'w3-mode-hook)
|
|
2472 (widget-setup)
|
70
|
2473 (setq url-current-passwd-count 0
|
|
2474 mode-line-format w3-modeline-format)
|
|
2475 (if (and w3-current-isindex (equal url-current-type "http"))
|
0
|
2476 (setq mode-line-process "-Searchable")))))
|
|
2477
|
|
2478 (require 'mm)
|
|
2479 (require 'url)
|
70
|
2480 (require 'url-hash)
|
0
|
2481 (require 'w3-parse)
|
70
|
2482 (require 'w3-draw)
|
0
|
2483 (require 'w3-auto)
|
|
2484 (require 'w3-emulate)
|
|
2485 (require 'w3-menu)
|
|
2486 (require 'w3-mouse)
|
|
2487 (provide 'w3)
|