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