comparison lisp/w3/w3.el @ 30:ec9a17fef872 r19-15b98

Import from CVS: tag r19-15b98
author cvs
date Mon, 13 Aug 2007 08:52:29 +0200
parents 441bb1e64a06
children e04119814345
comparison
equal deleted inserted replaced
29:7976500f47f9 30:ec9a17fef872
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: 1997/02/20 21:50:57 3 ;; Created: 1997/03/07 16:44:12
4 ;; Version: 1.82 4 ;; Version: 1.93
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, 1997 Free Software Foundation, Inc. 9 ;;; Copyright (c) 1996, 1997 Free Software Foundation, Inc.
443 (url-view-url t)) 443 (url-view-url t))
444 (url-get-url-at-point)))) 444 (url-get-url-at-point))))
445 url)) 445 url))
446 446
447 ;;;###autoload 447 ;;;###autoload
448 (defun w3-fetch (&optional url) 448 (defun w3-fetch (&optional url target)
449 "Retrieve a document over the World Wide Web. 449 "Retrieve a document over the World Wide Web.
450 Defaults to URL of the current document, if any. 450 Defaults to URL of the current document, if any.
451 With prefix argument, use the URL of the hyperlink under point instead." 451 With prefix argument, use the URL of the hyperlink under point instead."
452 (interactive (list (w3-read-url-with-default))) 452 (interactive (list (w3-read-url-with-default)))
453 (if (not w3-setup-done) (w3-do-setup)) 453 (if (not w3-setup-done) (w3-do-setup))
465 url-current-object)) 465 url-current-object))
466 (substring url 4)))) 466 (substring url 4))))
467 ;; In the common case, this is probably cheaper than searching. 467 ;; In the common case, this is probably cheaper than searching.
468 (while (= (string-to-char url) ? ) 468 (while (= (string-to-char url) ? )
469 (setq url (substring url 1))) 469 (setq url (substring url 1)))
470 (or target (setq target w3-base-target))
471 (if (stringp target)
472 (setq target (intern (downcase target))))
473 (and target
474 (let ((window-distance (cdr-safe (assq target w3-target-window-distances))))
475 (if (numberp window-distance)
476 (other-window window-distance)
477 (error "target %S not found." target))))
470 (cond 478 (cond
471 ((= (string-to-char url) ?#) 479 ((= (string-to-char url) ?#)
472 (w3-relative-link url)) 480 (w3-relative-link url))
473 ((or (and (interactive-p) current-prefix-arg) w3-dump-to-disk) 481 ((or (and (interactive-p) current-prefix-arg) w3-dump-to-disk)
474 (w3-download-url url)) 482 (w3-download-url url))
631 (save-excursion 639 (save-excursion
632 (set-buffer buff) 640 (set-buffer buff)
633 (let* ((url (url-view-url t)) 641 (let* ((url (url-view-url t))
634 (cur-links w3-current-links) 642 (cur-links w3-current-links)
635 (title (buffer-name)) 643 (title (buffer-name))
644 (case-fold-search t)
645 (possible-lastmod (save-excursion
646 (goto-char (point-min))
647 (if (re-search-forward "^Last modified:\\(.*\\)" nil t)
648 (buffer-substring (match-beginning 1)
649 (match-end 1)))))
650 (attributes (url-file-attributes url))
636 (lastmod (or (cdr-safe (assoc "last-modified" 651 (lastmod (or (cdr-safe (assoc "last-modified"
637 url-current-mime-headers)))) 652 url-current-mime-headers))
653 (nth 5 attributes)))
638 (hdrs url-current-mime-headers) 654 (hdrs url-current-mime-headers)
655 (size (or (cdr (assoc "content-length" url-current-mime-headers))
656 (point-max)))
639 (info w3-current-metainfo)) 657 (info w3-current-metainfo))
640 (set-buffer (get-buffer-create url-working-buffer)) 658 (set-buffer (get-buffer-create url-working-buffer))
641 (setq url-current-can-be-cached nil) 659 (setq url-current-can-be-cached nil)
642 (erase-buffer) 660 (erase-buffer)
643 (cond 661 (cond
644 ((stringp lastmod) nil) 662 ((stringp lastmod) nil)
645 ((equal '(0 . 0) lastmod) (setq lastmod nil)) 663 ((equal '(0 . 0) lastmod) (setq lastmod possible-lastmod))
646 ((consp lastmod) (setq lastmod (current-time-string lastmod))) 664 ((consp lastmod) (setq lastmod (current-time-string lastmod)))
647 (t (setq lastmod nil))) 665 (t (setq lastmod possible-lastmod)))
648 (insert "<html>\n" 666 (insert "<html>\n"
649 " <head>\n" 667 " <head>\n"
650 " <title>Document Information</title>\n" 668 " <title>Document Information</title>\n"
651 " </head>\n" 669 " </head>\n"
652 " <body\n" 670 " <body\n"
653 " <table border>\n" 671 " <table border>\n"
654 " <tr><th colspan=2>Document Information</th></tr>\n" 672 " <tr><th colspan=2>Document Information</th></tr>\n"
655 " <tr><td>Title:</td><td>" title "</td></tr>\n" 673 " <tr><td>Title:</td><td>" title "</td></tr>\n"
656 " <tr><td>Location:</td><td>" url "</td></tr>\n" 674 " <tr><td>Location:</td><td>" url "</td></tr>\n"
675 " <tr><td>Size:</td><td>" (url-pretty-length
676 (if (stringp size)
677 (string-to-int size)
678 size)) "</td></tr>\n"
657 " <tr><td>Last Modified:</td><td>" (or lastmod "None Given") 679 " <tr><td>Last Modified:</td><td>" (or lastmod "None Given")
658 "</td></tr>\n") 680 "</td></tr>\n")
659 (if hdrs 681 (if hdrs
660 (let* ((maxlength (car (sort (mapcar (function (lambda (x) 682 (let* ((maxlength (car (sort (mapcar (function (lambda (x)
661 (length (car x)))) 683 (length (car x))))
825 847
826 (defun w3-source-document-at-point () 848 (defun w3-source-document-at-point ()
827 "View source to the document pointed at by link under point" 849 "View source to the document pointed at by link under point"
828 (interactive) 850 (interactive)
829 (w3-source-document t)) 851 (w3-source-document t))
830
831 (defun w3-my-safe-copy-face (old new locale)
832 (let ((fore (face-foreground old))
833 (back (face-background old))
834 (bpxm (face-background-pixmap old))
835 (font (face-font old))
836 (font-spec (get old 'font-specification)))
837 (if (color-specifier-p fore)
838 (setq fore (color-name fore)))
839 (if (color-specifier-p back)
840 (setq back (color-name back)))
841 (if (font-specifier-p font)
842 (setq font (font-name font)))
843 (and fore (set-face-foreground new fore locale))
844 (and back (set-face-background new back locale))
845 (and bpxm (set-face-background-pixmap new bpxm locale))
846 (and (or font-spec font) (set-face-font new (or font-spec font) locale))
847 new))
848 852
849 (defun w3-source-document (under) 853 (defun w3-source-document (under)
850 "View this document's source" 854 "View this document's source"
851 (interactive "P") 855 (interactive "P")
852 (let* ((url (if under (w3-view-this-url) (url-view-url t))) 856 (let* ((url (if under (w3-view-this-url) (url-view-url t)))
908 ("Formatted Text") 912 ("Formatted Text")
909 ("PostScript") 913 ("PostScript")
910 ("LaTeX Source") 914 ("LaTeX Source")
911 ) 915 )
912 nil t))) 916 nil t)))
917 (case-fold-search t)
913 (url (cond 918 (url (cond
914 ((stringp under) under) 919 ((stringp under) under)
915 (under (w3-view-this-url t)) 920 (under (w3-view-this-url t))
916 (t (url-view-url t)))) 921 (t (url-view-url t))))
917 (content-type "text/plain; charset=iso-8859-1") 922 (content-type "text/plain; charset=iso-8859-1")
962 (setq content-type "application/x-latex; charset=iso-8859-1") 967 (setq content-type "application/x-latex; charset=iso-8859-1")
963 (w3-parse-tree-to-latex w3-current-parse url))) 968 (w3-parse-tree-to-latex w3-current-parse url)))
964 (buffer-string)))) 969 (buffer-string))))
965 (funcall w3-mail-command) 970 (funcall w3-mail-command)
966 (mail-subject) 971 (mail-subject)
967 (insert format " from URL " url "\n" 972 (if (and (boundp 'mime/editor-mode-flag) mime/editor-mode-flag)
968 "Mime-Version: 1.0\n" 973 (insert format " from <URL: " url ">")
969 "Content-transfer-encoding: 8bit\n" 974 (insert format " from <URL: " url ">\n"
970 "Content-type: " content-type) 975 "Mime-Version: 1.0\n"
976 "Content-transfer-encoding: 8bit\n"
977 "Content-type: " content-type))
971 (re-search-forward mail-header-separator nil) 978 (re-search-forward mail-header-separator nil)
972 (forward-char 1) 979 (forward-char 1)
973 (insert (if (equal "HTML Source" format) 980 (if (and (boundp 'mime/editor-mode-flag) mime/editor-mode-flag)
974 (format "<BASE HREF=\"%s\">" url) "") 981 (insert (format mime-tag-format content-type) "\n"))
975 str) 982 (save-excursion
983 (insert str))
984 (cond ((equal "HTML Source" format)
985 (if (or (search-forward "<head>" nil t)
986 (search-forward "<html>" nil t))
987 (insert "\n"))
988 (insert (format "<base href=\"%s\">" url))))
976 (mail-to))) 989 (mail-to)))
977 990
978 (defun w3-internal-use-history (hist-item) 991 (defun w3-internal-use-history (hist-item)
979 ;; Go to the link in the history 992 ;; Go to the link in the history
980 (let ((url (nth 0 hist-item)) 993 (let ((url (nth 0 hist-item))
1583 (setq buffer (get-buffer buffer)) 1596 (setq buffer (get-buffer buffer))
1584 (let ((base (get-text-property (point-min) 'w3-base buffer))) 1597 (let ((base (get-text-property (point-min) 'w3-base buffer)))
1585 (if base 1598 (if base
1586 (setq base (url-generic-parse-url base))) 1599 (setq base (url-generic-parse-url base)))
1587 (insert-buffer buffer) 1600 (insert-buffer buffer)
1601 (let ((inhibit-read-only t))
1602 (set-text-properties (point-min) (point-max) nil))
1588 (if (not base) 1603 (if (not base)
1589 (setq url-current-object 1604 (setq url-current-object
1590 (url-generic-parse-url (concat "file:" 1605 (url-generic-parse-url (concat "file:"
1591 (buffer-file-name buffer)))) 1606 (buffer-file-name buffer))))
1592 (setq url-current-object base)))) 1607 (setq url-current-object base))))
1792 (while (and x (not found)) 1807 (while (and x (not found))
1793 (setq y (car x) 1808 (setq y (car x)
1794 x (cdr x) 1809 x (cdr x)
1795 found (cdr-safe (assoc "made" y)))) 1810 found (cdr-safe (assoc "made" y))))
1796 (if found 1811 (if found
1797 (let ((possible nil)) 1812 (let ((possible nil)
1813 (href nil))
1798 (setq x (car found)) ; Fallback if no mail(to|server) found 1814 (setq x (car found)) ; Fallback if no mail(to|server) found
1799 (while found 1815 (while found
1800 (if (string-match "^mail[^:]+:" (car found)) 1816 (setq href (plist-get (pop found) 'href))
1801 (setq possible (cons (car found) possible))) 1817 (if (and href (string-match "^mail[^:]+:" href))
1802 (setq found (cdr found))) 1818 (setq possible (cons href possible))))
1803 (case (length possible) 1819 (case (length possible)
1804 (0 ; No mailto links found 1820 (0 ; No mailto links found
1805 (w3-fetch x)) ; fall back onto first 'made' link 1821 (w3-fetch x)) ; fall back onto first 'made' link
1806 (1 ; Only one found, get it 1822 (1 ; Only one found, get it
1807 (w3-fetch (car possible))) 1823 (w3-fetch (car possible)))
1918 (setq w3-user-stylesheet nil 1934 (setq w3-user-stylesheet nil
1919 w3-face-cache nil) 1935 w3-face-cache nil)
1920 (w3-find-default-stylesheets) 1936 (w3-find-default-stylesheets)
1921 ) 1937 )
1922 1938
1939 (defvar w3-loaded-stylesheets nil
1940 "A list of all the stylesheets Emacs-W3 loaded at startup.")
1941
1923 (defun w3-find-default-stylesheets () 1942 (defun w3-find-default-stylesheets ()
1943 (setq w3-loaded-stylesheets nil)
1924 (let* ((lightp (w3-color-light-p 'default)) 1944 (let* ((lightp (w3-color-light-p 'default))
1925 (longname (if lightp "stylesheet-light" "stylesheet-dark")) 1945 (longname (if lightp "stylesheet-light" "stylesheet-dark"))
1926 (shortname (if lightp "light.css" "dark.css")) 1946 (shortname (if lightp "light.css" "dark.css"))
1927 (directories (list 1947 (directories (list
1928 data-directory 1948 data-directory
1955 possible (cdr possible) 1975 possible (cdr possible)
1956 found (and cur (file-exists-p cur) (file-readable-p cur) 1976 found (and cur (file-exists-p cur) (file-readable-p cur)
1957 (not (file-directory-p cur)) cur)) 1977 (not (file-directory-p cur)) cur))
1958 (if found 1978 (if found
1959 (setq total-found (1+ total-found) 1979 (setq total-found (1+ total-found)
1980 w3-loaded-stylesheets (cons cur w3-loaded-stylesheets)
1960 w3-user-stylesheet (css-parse (concat "file:" cur) nil 1981 w3-user-stylesheet (css-parse (concat "file:" cur) nil
1961 w3-user-stylesheet)))) 1982 w3-user-stylesheet))))
1962 (setq-default url-be-asynchronous old-asynch) 1983 (setq-default url-be-asynchronous old-asynch)
1963 (if (= 0 total-found) 1984 (if (= 0 total-found)
1964 (w3-warn 1985 (w3-warn
2186 (completion-ignore-case t)) 2207 (completion-ignore-case t))
2187 (setq link-at-point (widget-at (point)) 2208 (setq link-at-point (widget-at (point))
2188 link-at-point (and 2209 link-at-point (and
2189 link-at-point 2210 link-at-point
2190 (widget-get link-at-point 'href) 2211 (widget-get link-at-point 'href)
2212 (widget-get link-at-point :from)
2213 (widget-get link-at-point :to)
2191 (w3-fix-spaces 2214 (w3-fix-spaces
2192 (buffer-substring 2215 (buffer-substring
2193 (widget-get link-at-point :from) 2216 (widget-get link-at-point :from)
2194 (widget-get link-at-point :to))))) 2217 (widget-get link-at-point :to)))))
2195 (w3-map-links (function 2218 (w3-map-links (function
2196 (lambda (widget arg) 2219 (lambda (widget arg)
2197 (setq links-alist (cons 2220 (if (and (widget-get widget :from)
2198 (cons 2221 (widget-get widget :to))
2199 (w3-fix-spaces 2222 (setq links-alist (cons
2200 (buffer-substring-no-properties 2223 (cons
2201 (widget-get widget :from) 2224 (w3-fix-spaces
2202 (widget-get widget :to))) 2225 (buffer-substring-no-properties
2203 (widget-get widget 'href)) 2226 (widget-get widget :from)
2204 links-alist))))) 2227 (widget-get widget :to)))
2228 (widget-get widget 'href))
2229 links-alist))))))
2205 (if (not links-alist) (error "No links in current document.")) 2230 (if (not links-alist) (error "No links in current document."))
2206 (setq links-alist (sort links-alist (function 2231 (setq links-alist (sort links-alist (function
2207 (lambda (x y) 2232 (lambda (x y)
2208 (string< (car x) (car y)))))) 2233 (string< (car x) (car y))))))
2209 ;; Destructively remove duplicate entries from links-alist. 2234 ;; Destructively remove duplicate entries from links-alist.