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