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