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