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