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