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