comparison lisp/w3/w3.el @ 14:9ee227acff29 r19-15b90

Import from CVS: tag r19-15b90
author cvs
date Mon, 13 Aug 2007 08:48:42 +0200
parents ac2d302a0011
children 0293115a14e9
comparison
equal deleted inserted replaced
13:13c6d0aaafe5 14:9ee227acff29
1 ;;; w3.el --- Main functions for emacs-w3 on all platforms/versions 1 ;;; w3.el --- Main functions for emacs-w3 on all platforms/versions
2 ;; Author: wmperry 2 ;; Author: wmperry
3 ;; Created: 1996/08/19 03:30:47 3 ;; Created: 1996/12/30 20:37:55
4 ;; Version: 1.22 4 ;; Version: 1.48
5 ;; Keywords: faces, help, comm, news, mail, processes, mouse, hypermedia 5 ;; Keywords: faces, help, comm, news, mail, processes, mouse, hypermedia
6 6
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8 ;;; Copyright (c) 1993 - 1996 by William M. Perry (wmperry@cs.indiana.edu) 8 ;;; Copyright (c) 1993 - 1996 by William M. Perry (wmperry@cs.indiana.edu)
9 ;;; Copyright (c) 1996 Free Software Foundation, Inc.
9 ;;; 10 ;;;
10 ;;; This file is not part of GNU Emacs, but the same permissions apply. 11 ;;; This file is part of GNU Emacs.
11 ;;; 12 ;;;
12 ;;; GNU Emacs is free software; you can redistribute it and/or modify 13 ;;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;;; it under the terms of the GNU General Public License as published by 14 ;;; it under the terms of the GNU General Public License as published by
14 ;;; the Free Software Foundation; either version 2, or (at your option) 15 ;;; the Free Software Foundation; either version 2, or (at your option)
15 ;;; any later version. 16 ;;; any later version.
18 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of 19 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;;; GNU General Public License for more details. 21 ;;; GNU General Public License for more details.
21 ;;; 22 ;;;
22 ;;; You should have received a copy of the GNU General Public License 23 ;;; You should have received a copy of the GNU General Public License
23 ;;; along with GNU Emacs; see the file COPYING. If not, write to 24 ;;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 25 ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 ;;; Boston, MA 02111-1307, USA.
25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 27 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26 28
27 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 29 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
28 ;;; This is a major mode for browsing documents written in Hypertext Markup ;;; 30 ;;; This is a major mode for browsing documents written in Hypertext Markup ;;;
29 ;;; Language (HTML). These documents are typicallly part of the World Wide ;;; 31 ;;; Language (HTML). These documents are typicallly part of the World Wide ;;;
65 (expand-file-name 67 (expand-file-name
66 name (car p2))))))))))) 68 name (car p2)))))))))))
67 ) 69 )
68 70
69 71
70 (load-library "w3-sysdp") 72 (require 'w3-sysdp)
73 (require 'mule-sysdp)
74
71 (or (featurep 'efs) 75 (or (featurep 'efs)
72 (featurep 'efs-auto) 76 (featurep 'efs-auto)
73 (condition-case () 77 (condition-case ()
74 (require 'ange-ftp) 78 (require 'ange-ftp)
75 (error nil))) 79 (error nil)))
76 80
77 (require 'cl) 81 (require 'cl)
82 (require 'css)
78 (require 'w3-vars) 83 (require 'w3-vars)
79 (eval-and-compile 84 (eval-and-compile
80 (require 'w3-draw)) 85 (require 'w3-display))
81 86
82 87
83 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 88 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
84 ;;; Code for printing out roman numerals 89 ;;; Code for printing out roman numerals
85 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 90 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
284 (funcall view) 289 (funcall view)
285 (w3-notify-when-ready bufnam)) 290 (w3-notify-when-ready bufnam))
286 (funcall view))) 291 (funcall view)))
287 ((stringp view) 292 ((stringp view)
288 (let ((fname (url-generate-unique-filename fmt)) 293 (let ((fname (url-generate-unique-filename fmt))
289 (proc nil) 294 (proc nil))
290 (file-coding-system url-mule-no-coding-system))
291 (if (url-file-directly-accessible-p (url-view-url t)) 295 (if (url-file-directly-accessible-p (url-view-url t))
292 (make-symbolic-link url-current-file fname t) 296 (make-symbolic-link url-current-file fname t)
293 (write-region (point-min) (point-max) fname)) 297 (mule-write-region-no-coding-system (point-min) (point-max) fname))
294 (if (get-buffer url-working-buffer) 298 (if (get-buffer url-working-buffer)
295 (kill-buffer url-working-buffer)) 299 (kill-buffer url-working-buffer))
296 (setq view (mm-viewer-unescape view fname url)) 300 (setq view (mm-viewer-unescape view fname url))
297 (message "Passing to viewer %s " view) 301 (message "Passing to viewer %s " view)
298 (setq proc (w3-start-viewer fname view)) 302 (setq proc (w3-start-viewer fname view))
321 nil 325 nil
322 (url-remove-compressed-extensions 326 (url-remove-compressed-extensions
323 (file-name-nondirectory (url-view-url t))))) 327 (file-name-nondirectory (url-view-url t)))))
324 (require-final-newline nil)) 328 (require-final-newline nil))
325 (set-buffer old-buff) 329 (set-buffer old-buff)
326 (let ((mc-flag t) 330 (mule-write-region-no-coding-system (point-min) (point-max) file)
327 (file-coding-system url-mule-no-coding-system))
328 (write-region (point-min) (point-max) file))
329 (kill-buffer (current-buffer)))) 331 (kill-buffer (current-buffer))))
330 332
331 (defun w3-build-url (protocol) 333 (defun w3-build-url (protocol)
332 "Build a url for PROTOCOL, return it as a string" 334 "Build a url for PROTOCOL, return it as a string"
333 (interactive (list (cdr (assoc (completing-read 335 (interactive (list (cdr (assoc (completing-read
384 It will prompt for an existing file or directory, and retrieve it as a 386 It will prompt for an existing file or directory, and retrieve it as a
385 hypertext document. If it is a directory, and url-use-hypertext-dired 387 hypertext document. If it is a directory, and url-use-hypertext-dired
386 is non-nil, then an HTML directory listing is created on the fly. 388 is non-nil, then an HTML directory listing is created on the fly.
387 Otherwise, dired-mode is used to visit the buffer." 389 Otherwise, dired-mode is used to visit the buffer."
388 (interactive "FLocal file: ") 390 (interactive "FLocal file: ")
391 (setq fname (expand-file-name fname))
389 (if (not w3-setup-done) (w3-do-setup)) 392 (if (not w3-setup-done) (w3-do-setup))
390 (w3-fetch (concat "file:" fname))) 393 (w3-fetch (concat "file:" fname)))
391 394
392 ;;;###autoload 395 ;;;###autoload
393 (defun w3-find-file (fname) 396 (defun w3-find-file (fname)
424 (w3-fetch url)) 427 (w3-fetch url))
425 428
426 (defun w3-url-completion-function (string predicate function) 429 (defun w3-url-completion-function (string predicate function)
427 (if (not w3-setup-done) (w3-do-setup)) 430 (if (not w3-setup-done) (w3-do-setup))
428 (cond 431 (cond
429 ((null function) 432 ((eq function nil)
430 (cond 433 (let ((list nil))
431 ((get 'url-gethash 'sysdep-defined-this) 434 (cl-maphash (function (lambda (key val)
432 ;; Cheat! If we know that these are the sysdep-defined version 435 (setq list (cons (cons key val)
433 ;; of hashtables, they are an obarray. 436 list))))
434 (try-completion string url-global-history-hash-table predicate)) 437 url-global-history-hash-table)
435 ((url-hashtablep url-global-history-hash-table) 438 (try-completion string (nreverse list) predicate)))
436 (let ((list nil))
437 (url-maphash (function (lambda (key val)
438 (setq list (cons (cons (symbol-name key) val)
439 list))))
440 url-global-history-hash-table)
441 (try-completion string (nreverse list) predicate)))
442 (t nil)))
443 ((eq function t) 439 ((eq function t)
444 (cond 440 (let ((stub (concat "^" (regexp-quote string)))
445 ((get 'url-gethash 'sysdep-defined-this) 441 (retval nil))
446 ;; Cheat! If we know that these are the sysdep-defined version 442 (cl-maphash
447 ;; of hashtables, they are an obarray. 443 (function
448 (all-completions string url-global-history-hash-table predicate)) 444 (lambda (url time)
449 ((url-hashtablep url-global-history-hash-table) 445 (if (string-match stub url)
450 (let ((stub (concat "^" (regexp-quote string))) 446 (setq retval (cons url retval)))))
451 (retval nil)) 447 url-global-history-hash-table)
452 (url-maphash 448 retval))
453 (function
454 (lambda (url time)
455 (setq url (symbol-name url))
456 (if (string-match stub url)
457 (setq retval (cons url retval)))))
458 url-global-history-hash-table)
459 retval))
460 (t nil)))
461 ((eq function 'lambda) 449 ((eq function 'lambda)
462 (and (url-hashtablep url-global-history-hash-table) 450 (and url-global-history-hash-table
463 (url-gethash string url-global-history-hash-table) 451 (cl-gethash string url-global-history-hash-table)
464 t)))) 452 t))
453 (t
454 (error "w3-url-completion-function very confused."))))
465 455
466 (defun w3-read-url-with-default () 456 (defun w3-read-url-with-default ()
467 (url-do-setup) 457 (url-do-setup)
468 (let* ((completion-ignore-case t) 458 (let* ((completion-ignore-case t)
469 (default 459 (default
538 (prin1-to-string w3-reuse-buffers)) 528 (prin1-to-string w3-reuse-buffers))
539 (sit-for 2))) 529 (sit-for 2)))
540 (not (funcall url-confirmation-func 530 (not (funcall url-confirmation-func
541 (format "Reuse URL in buffer %s? " 531 (format "Reuse URL in buffer %s? "
542 (buffer-name buf))))))) 532 (buffer-name buf)))))))
543 (let ((cached (url-retrieve url))) 533 (let* ((status (url-retrieve url))
534 (cached (car status))
535 (url-working-buffer (cdr status)))
544 (if w3-track-last-buffer 536 (if w3-track-last-buffer
545 (setq w3-last-buffer (get-buffer url-working-buffer))) 537 (setq w3-last-buffer (get-buffer url-working-buffer)))
546 (if (get-buffer url-working-buffer) 538 (if (get-buffer url-working-buffer)
547 (cond 539 (cond
548 ((and url-be-asynchronous (string-match "^http:" url) 540 ((and url-be-asynchronous
549 (not cached)) 541 (not cached))
550 (save-excursion 542 (save-excursion
551 (set-buffer url-working-buffer) 543 (set-buffer url-working-buffer)
552 (if x 544 (if x
553 (w3-add-urls-to-history x (url-view-url t))) 545 (w3-add-urls-to-history x (url-view-url t)))
554 (setq w3-current-last-buffer lastbuf))) 546 (setq w3-current-last-buffer lastbuf)))
555 (t 547 (t
556 (w3-add-urls-to-history x url) 548 (w3-add-urls-to-history x url)
557 (w3-sentinel lastbuf))))) 549 (w3-sentinel lastbuf)
550 ))))
558 (if w3-track-last-buffer 551 (if w3-track-last-buffer
559 (setq w3-last-buffer buf)) 552 (setq w3-last-buffer buf))
560 (let ((w3-notify (if (memq w3-notify '(newframe bully 553 (let ((w3-notify (if (memq w3-notify '(newframe bully
561 semibully aggressive)) 554 semibully aggressive))
562 w3-notify 555 w3-notify
680 (title (buffer-name)) 673 (title (buffer-name))
681 (lastmod (or (cdr-safe (assoc "last-modified" 674 (lastmod (or (cdr-safe (assoc "last-modified"
682 url-current-mime-headers)) 675 url-current-mime-headers))
683 (and (member url-current-type '("file" "ftp")) 676 (and (member url-current-type '("file" "ftp"))
684 (nth 5 (url-file-attributes url))))) 677 (nth 5 (url-file-attributes url)))))
685 (hdrs url-current-mime-headers)) 678 (hdrs url-current-mime-headers)
679 (info w3-current-metainfo))
686 (set-buffer (get-buffer-create url-working-buffer)) 680 (set-buffer (get-buffer-create url-working-buffer))
687 (setq url-current-can-be-cached nil 681 (setq url-current-can-be-cached nil
688 url-current-type "about" 682 url-current-type "about"
689 url-current-file "document") 683 url-current-file "document")
690 (erase-buffer) 684 (erase-buffer)
696 (insert "<html>\n" 690 (insert "<html>\n"
697 " <head>\n" 691 " <head>\n"
698 " <title>Document Information</title>\n" 692 " <title>Document Information</title>\n"
699 " </head>\n" 693 " </head>\n"
700 " <body\n" 694 " <body\n"
701 " <h1 align=\"center\">Document Information</h1>\n" 695 " <table border>\n"
702 " <hr>\n" 696 " <tr><th colspan=2>Document Information</th></tr>\n"
703 " <pre>\n" 697 " <tr><td>Title:</td><td>" title "</td></tr>\n"
704 " Title: " title "\n" 698 " <tr><td>Location:</td><td>" url "</td></tr>\n"
705 " Location: " url "\n" 699 " <tr><td>Last Modified:</td><td>" (or lastmod "None Given")
706 " Last Modified: " (or lastmod "None Given") "\n" 700 "</td></tr>\n")
707 " </pre>\n")
708 (if hdrs 701 (if hdrs
709 (let* ((maxlength (car (sort (mapcar (function (lambda (x) 702 (let* ((maxlength (car (sort (mapcar (function (lambda (x)
710 (length (car x)))) 703 (length (car x))))
711 hdrs) 704 hdrs)
712 '>))) 705 '>)))
713 (fmtstring (format "%%%ds: %%s" maxlength))) 706 (fmtstring (format " <tr><td align=right>%%%ds:</td><td>%%s</td></tr>" maxlength)))
714 (insert " <hr label=\" MetaInformation \" textalign=\"left\">\n" 707 (insert " <tr><th>MetaInformation</th></tr>\n"
715 " <pre>\n"
716 (mapconcat 708 (mapconcat
717 (function 709 (function
718 (lambda (x) 710 (lambda (x)
719 (if (/= (length (car x)) 0) 711 (if (/= (length (car x)) 0)
720 (format fmtstring 712 (format fmtstring
723 (int-to-string (cdr x)) 715 (int-to-string (cdr x))
724 (cdr x)))))) 716 (cdr x))))))
725 (sort hdrs 717 (sort hdrs
726 (function 718 (function
727 (lambda (x y) (string-lessp (car x) (car y))))) 719 (lambda (x y) (string-lessp (car x) (car y)))))
728 "\n") 720 "\n"))))
729 " </pre>\n"))) 721
730 (if cur-links 722 ;; FIXME!!! Need to reimplement showing rel/rev links for the new
731 (while cur-links 723 ;; storage format.
732 (let* ((tmp (car cur-links)) 724
733 (label (car tmp)) 725 (if info
734 (nodes (cdr tmp)) 726 (let* ((maxlength (car (sort (mapcar (function (lambda (x)
735 (links nil) 727 (length (car x))))
736 (maxlength (car (sort (mapcar 728 info)
737 (function (lambda (x) 729 '>)))
738 (length (car x)))) 730 (fmtstring (format " <tr><td>%%%ds:</td><td>%%s</td></tr>" maxlength)))
739 nodes) 731 (insert " <tr><th>Miscellaneous Variables</th></tr>\n")
740 '>))) 732 (while info
741 (fmtstring (format "%%%ds: %%s" maxlength))) 733 (insert (format fmtstring (capitalize (caar info))
742 (insert " \n" 734 (cdar info)) "\n")
743 " <hr width=\"50%\" label=\" " 735 (setq info (cdr info))
744 label " \" align=\"left\" textalign=\"left\">\n" 736 )
745 " <pre>\n") 737 )
746 (while nodes 738 )
747 (setq label (car (car nodes)) 739 (insert " </table>\n"
748 links (cdr (car nodes)) 740 " </body>\n"
749 nodes (cdr nodes))
750 (while links
751 (insert (format " %15s -- <a href=\"%s\">%s</a>\n"
752 label (car links) (car links)))
753 (setq links (cdr links)
754 label "")))
755 (insert " </pre>\n"))
756 (setq cur-links (cdr cur-links))))
757 (insert " </body>\n"
758 "</html>\n"))))) 741 "</html>\n")))))
759 742
760 (defun w3-truncate-menu-item (string) 743 (defun w3-truncate-menu-item (string)
761 (if (<= (length string) w3-max-menu-width) 744 (if (<= (length string) w3-max-menu-width)
762 string 745 string
940 (interactive) 923 (interactive)
941 (setq w3-setup-done nil 924 (setq w3-setup-done nil
942 url-setup-done nil 925 url-setup-done nil
943 w3-hotlist nil 926 w3-hotlist nil
944 url-mime-accept-string nil) 927 url-mime-accept-string nil)
945 (let ((x '(w3 w3-mule w3-e19 w3-xem20 mm url w3-xemac w3-toolbar font))) 928 (let ((x '(w3 mule-sysdp w3-e19 mm url w3-xemac w3-toolbar font)))
946 (while x 929 (while x
947 (setq features (delq (car x) features) 930 (setq features (delq (car x) features)
948 x (cdr x))) 931 x (cdr x)))
949 (require 'w3)) 932 (require 'w3))
950 (w3-do-setup) 933 (w3-do-setup)
1006 (setq url nil)) 989 (setq url nil))
1007 ((funcall url-confirmation-func 990 ((funcall url-confirmation-func
1008 (concat "Source for " url " found, reuse? ")) 991 (concat "Source for " url " found, reuse? "))
1009 (w3-notify-when-ready (get-buffer url))))) 992 (w3-notify-when-ready (get-buffer url)))))
1010 (if (not url) nil 993 (if (not url) nil
1011 (setq face (and w3-current-stylesheet (cdr (w3-face-for-element))))
1012 (set-buffer (get-buffer-create tmp)) 994 (set-buffer (get-buffer-create tmp))
1013 (insert src) 995 (insert src)
1014 (put-text-property (point-min) (point-max) 'face face)
1015 (put-text-property (point-min) (point-max) 'w3-base url) 996 (put-text-property (point-min) (point-max) 'w3-base url)
1016 (goto-char (point-min)) 997 (goto-char (point-min))
1017 (setq buffer-file-truename nil 998 (setq buffer-file-truename nil
1018 buffer-file-name nil) 999 buffer-file-name nil)
1019 ;; Null filename bugs `set-auto-mode' in Mule ... 1000 ;; Null filename bugs `set-auto-mode' in Mule ...
1297 (setq list-buffers-directory (url-view-url t)) 1278 (setq list-buffers-directory (url-view-url t))
1298 (set-buffer-modified-p nil) 1279 (set-buffer-modified-p nil)
1299 (buffer-enable-undo) 1280 (buffer-enable-undo)
1300 (w3-notify-when-ready (get-buffer tmp)))) 1281 (w3-notify-when-ready (get-buffer tmp))))
1301 1282
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
1302 (defun w3-sentinel (&optional proc string) 1295 (defun w3-sentinel (&optional proc string)
1303 (set-buffer url-working-buffer) 1296 (set-buffer url-working-buffer)
1304 (if (or (stringp proc) 1297 (if (or (stringp proc)
1305 (bufferp proc)) (setq w3-current-last-buffer proc)) 1298 (bufferp proc)) (setq w3-current-last-buffer proc))
1306 (if (boundp 'after-change-functions) 1299 (if (boundp 'after-change-functions)
1314 (if (not url-current-mime-type) 1307 (if (not url-current-mime-type)
1315 (setq url-current-mime-type (or (mm-extension-to-mime 1308 (setq url-current-mime-type (or (mm-extension-to-mime
1316 (url-file-extension 1309 (url-file-extension
1317 url-current-file)) 1310 url-current-file))
1318 "text/html"))))) 1311 "text/html")))))
1319 (let ((x (w3-build-continuation)) 1312 (if (not (string-match "^www:" (or (url-view-url t) "")))
1320 (done-mule-conversion nil)) 1313 (w3-convert-code-for-mule url-current-mime-type))
1314
1315 (let ((x (w3-build-continuation)))
1321 (while x 1316 (while x
1322 (if (and (featurep 'mule) (not (eq 'url-uncompress (car x))) 1317 (funcall (pop x)))))
1323 (not done-mule-conversion))
1324 (progn
1325 (if (string-match "^www:" (url-view-url t))
1326 (setq w3-mime-list-for-code-conversion nil))
1327 (w3-convert-code-for-mule url-current-mime-type)
1328 (setq done-mule-conversion t)))
1329 (funcall (car x))
1330 (setq x (cdr x)))))
1331 1318
1332 (defun w3-show-history-list () 1319 (defun w3-show-history-list ()
1333 "Format the url-history-list prettily and show it to the user" 1320 "Format the url-history-list prettily and show it to the user"
1334 (interactive) 1321 (interactive)
1335 (w3-fetch "www://auto/history")) 1322 (w3-fetch "www://auto/history"))
1355 (if (not w3-current-source) 1342 (if (not w3-current-source)
1356 (let ((url-be-asynchronous nil)) 1343 (let ((url-be-asynchronous nil))
1357 (url-retrieve url)) ; Get the document if necessary 1344 (url-retrieve url)) ; Get the document if necessary
1358 (let ((txt w3-current-source)) 1345 (let ((txt w3-current-source))
1359 (set-buffer (get-buffer-create url-working-buffer)) 1346 (set-buffer (get-buffer-create url-working-buffer))
1347 (erase-buffer)
1360 (insert txt))) 1348 (insert txt)))
1361 (goto-char (point-min)) 1349 (goto-char (point-min))
1350 (if (re-search-forward "<head>" nil t)
1351 (insert "\n"))
1362 (insert (format "<BASE HREF=\"%s\">\n" url))) 1352 (insert (format "<BASE HREF=\"%s\">\n" url)))
1363 ((or (equal "Formatted Text" format) 1353 ((or (equal "Formatted Text" format)
1364 (equal "" format)) 1354 (equal "" format))
1365 nil) ; Do nothing - we have the text already 1355 nil) ; Do nothing - we have the text already
1366 ((equal "LaTeX Source" format) 1356 ((equal "LaTeX Source" format)
1517 (error "WinEmacs no longer supported.")) 1507 (error "WinEmacs no longer supported."))
1518 (w3-running-xemacs (require 'w3-xemac)) 1508 (w3-running-xemacs (require 'w3-xemac))
1519 (w3-running-FSF19 (require 'w3-e19)) 1509 (w3-running-FSF19 (require 'w3-e19))
1520 (t 1510 (t
1521 (error "Unable to determine the capabilities of this emacs."))) 1511 (error "Unable to determine the capabilities of this emacs.")))
1522 (cond 1512 (if (featurep 'emacspeak)
1523 ((boundp 'MULE) 1513 (condition-case ()
1524 (require 'w3-mule)) 1514 (progn
1525 ((featurep 'mule) 1515 (require 'dtk-css-speech)
1526 (require 'w3-xem20) 1516 (require 'w3-speak))))
1527 ))
1528 (condition-case () 1517 (condition-case ()
1529 (require 'w3-site-init) 1518 (require 'w3-site-init)
1530 (error nil))) 1519 (error nil)))
1531 1520
1532 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1521 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1576 new)) 1565 new))
1577 1566
1578 (defun w3-search () 1567 (defun w3-search ()
1579 "Perform a search, if this is a searchable index." 1568 "Perform a search, if this is a searchable index."
1580 (interactive) 1569 (interactive)
1581 (or w3-current-isindex
1582 (error "Not a searchable index (via <isindex>)"))
1583 (let* (querystring ; The string to send to the server 1570 (let* (querystring ; The string to send to the server
1584 (data 1571 (data
1585 (cond 1572 (cond
1586 ((null w3-current-isindex) 1573 ((null w3-current-isindex)
1587 (let ((rels (mapcar 1574 (let ((rels (cdr-safe (assq 'rel w3-current-links)))
1588 (function 1575 val cur)
1589 (lambda (data)
1590 (if (assoc "rel" data) data)))
1591 w3-current-links))
1592 val)
1593 (while rels 1576 (while rels
1594 (if (string-match "useindex" 1577 (setq cur (car rels)
1595 (or (cdr (assoc "rel" (car rels))) "")) 1578 rels (cdr rels))
1596 (setq val (cdr (assoc "href" (car 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)
1597 rels nil)) 1583 rels nil))
1598 (setq rels (cdr rels))) 1584 )
1599 (cons val "Search on (+ separates keywords): "))) 1585 (if val
1586 (cons val "Search on (+ separates keywords): "))))
1600 ((eq w3-current-isindex t) 1587 ((eq w3-current-isindex t)
1601 (cons (url-view-url t) "Search on (+ separates keywords): ")) 1588 (cons (url-view-url t) "Search on (+ separates keywords): "))
1602 ((consp w3-current-isindex) 1589 ((consp w3-current-isindex)
1603 w3-current-isindex) 1590 w3-current-isindex)
1604 (t nil))) 1591 (t nil)))
1740 (url-retrieve "www://error/nohist") 1727 (url-retrieve "www://error/nohist")
1741 (insert "<html>\n\t<head>\n\t\t" 1728 (insert "<html>\n\t<head>\n\t\t"
1742 "<title> History List For This Session of W3</title>" 1729 "<title> History List For This Session of W3</title>"
1743 "\n\t</head>\n\t<body>\n\t\t<div>\n\t\t\t<h1>" 1730 "\n\t</head>\n\t<body>\n\t\t<div>\n\t\t\t<h1>"
1744 "History List For This Session of W3</h1>\n\t\t\t<ol>\n") 1731 "History List For This Session of W3</h1>\n\t\t\t<ol>\n")
1745 (url-maphash 1732 (cl-maphash
1746 (function 1733 (function
1747 (lambda (url desc) 1734 (lambda (url desc)
1748 (insert (format "\t\t\t\t<li> <a href=\"%s\">%s</a>\n" 1735 (insert (format "\t\t\t\t<li> <a href=\"%s\">%s</a>\n"
1749 url (url-insert-entities-in-string desc))))) 1736 url (url-insert-entities-in-string desc)))))
1750 url-history-list) 1737 url-history-list)
1963 (let ((x w3-current-links) 1950 (let ((x w3-current-links)
1964 (y nil) 1951 (y nil)
1965 (found nil)) 1952 (found nil))
1966 (setq found (cdr-safe (assoc "reply-to" url-current-mime-headers))) 1953 (setq found (cdr-safe (assoc "reply-to" url-current-mime-headers)))
1967 (if (and found (not (string-match url-nonrelative-link found))) 1954 (if (and found (not (string-match url-nonrelative-link found)))
1968 (setq found (concat "mailto:" found))) 1955 (setq found (list (concat "mailto:" found))))
1969 (while (and x (not found)) 1956 (while (and x (not found))
1970 (setq y (car x) 1957 (setq y (car x)
1971 x (cdr x) 1958 x (cdr x)
1972 found (cdr-safe (assoc "made" y)))) 1959 found (cdr-safe (assoc "made" y))))
1973 (if found 1960 (if found
2047 WIDGET and MAPARG. 2034 WIDGET and MAPARG.
2048 The arguments FROM, TO, MAPARG, and BUFFER default to the beginning of 2035 The arguments FROM, TO, MAPARG, and BUFFER default to the beginning of
2049 BUFFER, the end of BUFFER, nil, and (current-buffer), respectively." 2036 BUFFER, the end of BUFFER, nil, and (current-buffer), respectively."
2050 (let ((cur (point-min)) 2037 (let ((cur (point-min))
2051 (widget nil) 2038 (widget nil)
2052 (url nil)) 2039 (parent nil))
2053 (while (setq cur (next-single-property-change cur 'button)) 2040 (while (setq cur (next-single-property-change cur 'button))
2054 (setq widget (widget-at cur)) 2041 (setq widget (widget-at cur)
2042 parent (and widget (widget-get widget :parent)))
2055 ;; Check to see if its a push widget, its got the correct callback, 2043 ;; Check to see if its a push widget, its got the correct callback,
2056 ;; and actually has a URL. Remember the url as a side-effect of the 2044 ;; and actually has a URL. Remember the url as a side-effect of the
2057 ;; test for later use. 2045 ;; test for later use.
2058 (if (and (eq (car widget) 'push) 2046 (cond
2059 (eq (widget-get widget :notify) 'w3-follow-hyperlink) 2047 ((and widget (widget-get widget 'href))
2060 (setq url (widget-get widget 'href))) 2048 (funcall function widget maparg))
2061 (funcall function widget maparg))))) 2049 ((and parent (widget-get parent 'href))
2050 (funcall function parent maparg))
2051 (t nil)))))
2062 2052
2063 (defun w3-emit-image-warnings-if-necessary () 2053 (defun w3-emit-image-warnings-if-necessary ()
2064 (if (and (not w3-delay-image-loads) 2054 (if (and (not w3-delay-image-loads)
2065 (fboundp 'w3-insert-graphic) 2055 (fboundp 'w3-insert-graphic)
2066 (or (not (featurep 'gif)) 2056 (or (not (featurep 'gif))
2095 "Reload all stylesheets." 2085 "Reload all stylesheets."
2096 (interactive) 2086 (interactive)
2097 (setq w3-user-stylesheet nil 2087 (setq w3-user-stylesheet nil
2098 w3-face-cache nil) 2088 w3-face-cache nil)
2099 (w3-find-default-stylesheets) 2089 (w3-find-default-stylesheets)
2100 (w3-style-post-process-stylesheet w3-user-stylesheet)) 2090 )
2101 2091
2102 (defun w3-find-default-stylesheets () 2092 (defun w3-find-default-stylesheets ()
2103 (let* ((lightp (w3-color-light-p 'default)) 2093 (let* ((lightp (w3-color-light-p 'default))
2104 (longname (if lightp "stylesheet-light" "stylesheet-dark")) 2094 (longname (if lightp "stylesheet-light" "stylesheet-dark"))
2105 (shortname (if lightp "light.css" "dark.css")) 2095 (shortname (if lightp "light.css" "dark.css"))
2106 (directories (list 2096 (directories (list
2107 data-directory 2097 data-directory
2108 (concat data-directory "w3/") 2098 (concat data-directory "w3/")
2099 (expand-file-name "../../w3" data-directory)
2109 (file-name-directory (locate-library "w3")) 2100 (file-name-directory (locate-library "w3"))
2110 w3-configuration-directory)) 2101 w3-configuration-directory))
2111 (total-found 0) 2102 (total-found 0)
2112 (possible (append 2103 (possible (append
2113 (apply 2104 (apply
2133 possible (cdr possible) 2124 possible (cdr possible)
2134 found (and cur (file-exists-p cur) (file-readable-p cur) 2125 found (and cur (file-exists-p cur) (file-readable-p cur)
2135 (not (file-directory-p cur)) cur)) 2126 (not (file-directory-p cur)) cur))
2136 (if found 2127 (if found
2137 (setq total-found (1+ total-found) 2128 (setq total-found (1+ total-found)
2138 w3-user-stylesheet (car 2129 w3-user-stylesheet (css-parse (concat "file:" cur) nil
2139 (w3-style-parse-css 2130 w3-user-stylesheet))))
2140 (concat "file:" cur) nil
2141 w3-user-stylesheet)))))
2142 (setq-default url-be-asynchronous old-asynch) 2131 (setq-default url-be-asynchronous old-asynch)
2143 (if (= 0 total-found) 2132 (if (= 0 total-found)
2144 (w3-warn 2133 (w3-warn
2145 'style 2134 'style
2146 (concat 2135 (concat
2302 (run-hooks 'w3-load-hook) 2291 (run-hooks 'w3-load-hook)
2303 (setq w3-setup-done t)) 2292 (setq w3-setup-done t))
2304 2293
2305 (defun w3-mark-link-as-followed (ext dat) 2294 (defun w3-mark-link-as-followed (ext dat)
2306 ;; Mark a link as followed 2295 ;; Mark a link as followed
2307 (let* ((st (w3-zone-start ext)) 2296 (message "Reimplement w3-mark-link-as-followed"))
2308 (nd (w3-zone-end ext))
2309 (tag 'a)
2310 (args (list (cons 'class "visited")))
2311 (face (cdr (w3-face-for-element))))
2312 (w3-add-zone st nd face dat t)))
2313 2297
2314 (defun w3-only-links () 2298 (defun w3-only-links ()
2315 (let* (result temp) 2299 (let* (result temp)
2316 (if (widget-at (point-min)) 2300 (if (widget-at (point-min))
2317 (setq result (list (widget-at (point-min))))) 2301 (setq result (list (widget-at (point-min)))))
2328 (set-buffer buff) 2312 (set-buffer buff)
2329 (let ((require-final-newline nil) 2313 (let ((require-final-newline nil)
2330 (file-name-handler-alist nil) 2314 (file-name-handler-alist nil)
2331 (write-file-hooks nil) 2315 (write-file-hooks nil)
2332 (write-contents-hooks nil) 2316 (write-contents-hooks nil)
2333 (mc-flag t) 2317 (enable-multibyte-characters t) ; mule 2.4
2334 (file-coding-system url-mule-no-coding-system)) 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
2335 (write-file fname) 2321 (write-file fname)
2336 (message "Download of %s complete." (url-view-url t)) 2322 (message "Download of %s complete." (url-view-url t))
2337 (sit-for 3) 2323 (sit-for 3)
2338 (kill-buffer buff))))) 2324 (kill-buffer buff)))))
2339 2325
2386 ((or p w3-dump-to-disk) 2372 ((or p w3-dump-to-disk)
2387 (w3-download-url href)) 2373 (w3-download-url href))
2388 (t 2374 (t
2389 (w3-fetch href))))) 2375 (w3-fetch href)))))
2390 2376
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
2391 (defun w3-complete-link () 2390 (defun w3-complete-link ()
2392 "Choose a link from the current buffer and follow it" 2391 "Choose a link from the current buffer and follow it"
2393 (interactive) 2392 (interactive)
2394 (let (links-alist 2393 (let (links-alist
2395 link-at-point 2394 link-at-point
2399 link-at-point (and 2398 link-at-point (and
2400 link-at-point 2399 link-at-point
2401 (widget-get link-at-point 'href) 2400 (widget-get link-at-point 'href)
2402 (w3-fix-spaces 2401 (w3-fix-spaces
2403 (buffer-substring 2402 (buffer-substring
2404 (car (widget-get link-at-point 'title)) 2403 (widget-get link-at-point :from)
2405 (cdr (widget-get link-at-point 'title)))))) 2404 (widget-get link-at-point :to)))))
2406 (w3-map-links (function 2405 (w3-map-links (function
2407 (lambda (widget arg) 2406 (lambda (widget arg)
2408 (setq links-alist (cons 2407 (setq links-alist (cons
2409 (cons 2408 (cons
2410 (w3-fix-spaces 2409 (w3-fix-spaces
2434 "Link: ") links-alist nil t)) 2433 "Link: ") links-alist nil t))
2435 (if (string= choice "") 2434 (if (string= choice "")
2436 (w3-follow-link) 2435 (w3-follow-link)
2437 (w3-fetch (cdr (assoc choice links-alist)))))) 2436 (w3-fetch (cdr (assoc choice links-alist))))))
2438 2437
2439 (defun w3-widget-motion-hook (widget)
2440 (assert widget nil "Bad data to w3-widget-motion-hook! Bad hook bad!")
2441 (case w3-echo-link
2442 (text
2443 (message "%s" (w3-fix-spaces (buffer-substring (widget-get widget :from)
2444 (widget-get widget :to)))))
2445 (url
2446 (if (widget-get widget 'href)
2447 (message "%s" (widget-get widget 'href))))
2448 (otherwise nil)))
2449
2450 (defun w3-mode () 2438 (defun w3-mode ()
2451 "Mode for viewing HTML documents. If called interactively, will 2439 "Mode for viewing HTML documents. If called interactively, will
2452 display the current buffer as HTML. 2440 display the current buffer as HTML.
2453 2441
2454 Current keymap is: 2442 Current keymap is:
2464 (setq major-mode 'w3-mode) 2452 (setq major-mode 'w3-mode)
2465 (setq mode-name "WWW") 2453 (setq mode-name "WWW")
2466 (mapcar (function (lambda (x) (set-variable (car x) (cdr x)))) tmp) 2454 (mapcar (function (lambda (x) (set-variable (car x) (cdr x)))) tmp)
2467 (w3-mode-version-specifics) 2455 (w3-mode-version-specifics)
2468 (w3-menu-install-menus) 2456 (w3-menu-install-menus)
2469 (make-local-hook 'widget-motion-hook)
2470 (add-hook 'widget-motion-hook 'w3-widget-motion-hook)
2471 (run-hooks 'w3-mode-hook) 2457 (run-hooks 'w3-mode-hook)
2472 (widget-setup) 2458 (widget-setup)
2473 (setq url-current-passwd-count 0 2459 (setq url-current-passwd-count 0
2474 mode-line-format w3-modeline-format) 2460 mode-line-format w3-modeline-format)
2475 (if (and w3-current-isindex (equal url-current-type "http")) 2461 (if (and w3-current-isindex (equal url-current-type "http"))
2476 (setq mode-line-process "-Searchable"))))) 2462 (setq mode-line-process "-Searchable")))))
2477 2463
2478 (require 'mm) 2464 (require 'mm)
2479 (require 'url) 2465 (require 'url)
2480 (require 'url-hash)
2481 (require 'w3-parse) 2466 (require 'w3-parse)
2482 (require 'w3-draw) 2467 (require 'w3-display)
2483 (require 'w3-auto) 2468 (require 'w3-auto)
2484 (require 'w3-emulate) 2469 (require 'w3-emulate)
2485 (require 'w3-menu) 2470 (require 'w3-menu)
2486 (require 'w3-mouse) 2471 (require 'w3-mouse)
2487 (provide 'w3) 2472 (provide 'w3)