comparison lisp/w3/w3.el @ 16:0293115a14e9 r19-15b91

Import from CVS: tag r19-15b91
author cvs
date Mon, 13 Aug 2007 08:49:20 +0200
parents 9ee227acff29
children 859a2309aef8
comparison
equal deleted inserted replaced
15:ad457d5f7d04 16:0293115a14e9
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/12/30 20:37:55 3 ;; Created: 1997/01/29 06:25:59
4 ;; Version: 1.48 4 ;; Version: 1.61
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 ;;; Copyright (c) 1996, 1997 Free Software Foundation, Inc.
10 ;;; 10 ;;;
11 ;;; This file is part of GNU Emacs. 11 ;;; This file is part of GNU Emacs.
12 ;;; 12 ;;;
13 ;;; 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
14 ;;; 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
424 to disk." 424 to disk."
425 (interactive (list (w3-read-url-with-default))) 425 (interactive (list (w3-read-url-with-default)))
426 (split-window) 426 (split-window)
427 (w3-fetch url)) 427 (w3-fetch url))
428 428
429 ;; Ripped off from red gnus
430 (defun w3-find-etc-directory (package &optional file)
431 "Go through the path and find the \".../etc/PACKAGE\" directory.
432 If FILE, find the \".../etc/PACKAGE\" file instead."
433 (let ((path load-path)
434 dir result)
435 ;; We try to find the dir by looking at the load path,
436 ;; stripping away the last component and adding "etc/".
437 (while path
438 (if (and (car path)
439 (file-exists-p
440 (setq dir (concat
441 (file-name-directory
442 (directory-file-name (car path)))
443 "etc/" package
444 (if file "" "/"))))
445 (or file (file-directory-p dir)))
446 (setq result dir
447 path nil)
448 (setq path (cdr path))))
449 result))
450
429 (defun w3-url-completion-function (string predicate function) 451 (defun w3-url-completion-function (string predicate function)
430 (if (not w3-setup-done) (w3-do-setup)) 452 (if (not w3-setup-done) (w3-do-setup))
431 (cond 453 (cond
432 ((eq function nil) 454 ((eq function nil)
433 (let ((list nil)) 455 (let ((list nil))
455 477
456 (defun w3-read-url-with-default () 478 (defun w3-read-url-with-default ()
457 (url-do-setup) 479 (url-do-setup)
458 (let* ((completion-ignore-case t) 480 (let* ((completion-ignore-case t)
459 (default 481 (default
460 (if (eq major-mode 'w3-mode) 482 (cond
461 (if (and current-prefix-arg (w3-view-this-url t)) 483 ((null w3-fetch-with-default) nil)
462 (w3-view-this-url t) 484 ((eq major-mode 'w3-mode)
463 (url-view-url t)) 485 (or (and current-prefix-arg (w3-view-this-url t))
464 (url-get-url-at-point))) 486 (url-view-url t)))
487 ((url-get-url-at-point)
488 (url-get-url-at-point))
489 (t "http://www.")))
465 (url nil)) 490 (url nil))
466 (if (not default)
467 (setq default "http://www."))
468 (setq url 491 (setq url
469 (completing-read "URL: " 'w3-url-completion-function 492 (completing-read "URL: " 'w3-url-completion-function
470 nil nil default)) 493 nil nil default))
471 (if (string= url "") 494 (if (string= url "")
472 (setq url (if (eq major-mode 'w3-mode) 495 (setq url (if (eq major-mode 'w3-mode)
477 url)) 500 url))
478 501
479 ;;;###autoload 502 ;;;###autoload
480 (defun w3-fetch (&optional url) 503 (defun w3-fetch (&optional url)
481 "Retrieve a document over the World Wide Web. 504 "Retrieve a document over the World Wide Web.
482 The World Wide Web is a global hypertext system started by CERN in 505 Defaults to URL of the current document, if any.
483 Switzerland in 1991. 506 With prefix argument, use the URL of the hyperlink under point instead."
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."
489 (interactive (list (w3-read-url-with-default))) 507 (interactive (list (w3-read-url-with-default)))
490 (if (not w3-setup-done) (w3-do-setup)) 508 (if (not w3-setup-done) (w3-do-setup))
491 (if (boundp 'w3-working-buffer) 509 (if (boundp 'w3-working-buffer)
492 (setq w3-working-buffer url-working-buffer)) 510 (setq w3-working-buffer url-working-buffer))
493 (if (and (boundp 'command-line-args-left) 511 (if (and (boundp 'command-line-args-left)
960 (defun w3-source-document (under) 978 (defun w3-source-document (under)
961 "View this document's source" 979 "View this document's source"
962 (interactive "P") 980 (interactive "P")
963 (let* ((url (if under (w3-view-this-url) (url-view-url t))) 981 (let* ((url (if under (w3-view-this-url) (url-view-url t)))
964 (fil (if under nil url-current-file)) 982 (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
968 (src 983 (src
969 (cond 984 (cond
970 ((or (null url) (string= url "file:nil")) 985 ((null url)
971 (error "Not a w3 buffer!")) 986 (error "No URL found!"))
972 ((and under (null url)) (error "No link at point!")) 987 ((and under (null url)) (error "No link at point!"))
973 ((and (not under) (equal url-current-mime-type "text/plain")) 988 ((and (not under) (equal url-current-mime-type "text/plain"))
974 (buffer-string)) 989 (buffer-string))
975 ((and (not under) w3-current-source) w3-current-source) 990 ((and (not under) w3-current-source) w3-current-source)
976 (t 991 (t
993 (if (not url) nil 1008 (if (not url) nil
994 (set-buffer (get-buffer-create tmp)) 1009 (set-buffer (get-buffer-create tmp))
995 (insert src) 1010 (insert src)
996 (put-text-property (point-min) (point-max) 'w3-base url) 1011 (put-text-property (point-min) (point-max) 'w3-base url)
997 (goto-char (point-min)) 1012 (goto-char (point-min))
998 (setq buffer-file-truename nil 1013 (setq buffer-file-truename url
999 buffer-file-name nil) 1014 buffer-file-name url)
1000 ;; Null filename bugs `set-auto-mode' in Mule ... 1015 ;; Null filename bugs `set-auto-mode' in Mule ...
1001 (condition-case () 1016 (condition-case ()
1002 (set-auto-mode) 1017 (set-auto-mode)
1003 (error nil)) 1018 (error nil))
1019 (setq buffer-file-truename nil
1020 buffer-file-name nil)
1004 (buffer-enable-undo) 1021 (buffer-enable-undo)
1005 (set-buffer-modified-p nil) 1022 (set-buffer-modified-p nil)
1006 (w3-notify-when-ready (get-buffer tmp)))) 1023 (w3-notify-when-ready (get-buffer tmp))))
1007 (run-hooks 'w3-source-file-hook)) 1024 (run-hooks 'w3-source-file-hook))
1008 1025
1286 1303
1287 (defun w3-convert-code-for-mule (mmtype) 1304 (defun w3-convert-code-for-mule (mmtype)
1288 "Convert current data into the appropriate coding system" 1305 "Convert current data into the appropriate coding system"
1289 (and (or (not mmtype) 1306 (and (or (not mmtype)
1290 (member mmtype w3-mime-list-for-code-conversion)) 1307 (member mmtype w3-mime-list-for-code-conversion))
1291 (let* ((c (mule-detect-coding-version (point-min) (point-max))) 1308 (mule-code-convert-region
1292 (code (or (and (listp c) (car c)) c))) 1309 (point-min) (point-max)
1293 (mule-code-convert-region (point-min) (point-max) code)))) 1310 (mule-detect-coding-version (point-min) (point-max)))))
1294 1311
1295 (defun w3-sentinel (&optional proc string) 1312 (defun w3-sentinel (&optional proc string)
1296 (set-buffer url-working-buffer) 1313 (set-buffer url-working-buffer)
1297 (if (or (stringp proc) 1314 (if (or (stringp proc)
1298 (bufferp proc)) (setq w3-current-last-buffer proc)) 1315 (bufferp proc)) (setq w3-current-last-buffer proc))
1299 (if (boundp 'after-change-functions) 1316 (remove-hook 'after-change-functions 'url-after-change-function)
1300 (remove-hook 'after-change-functions 'url-after-change-function))
1301 (if url-be-asynchronous 1317 (if url-be-asynchronous
1302 (progn 1318 (progn
1303 (url-clean-text) 1319 (url-clean-text)
1304 (cond 1320 (cond
1305 ((not (get-buffer url-working-buffer)) nil) 1321 ((not (get-buffer url-working-buffer)) nil)
1322 (w3-fetch "www://auto/history")) 1338 (w3-fetch "www://auto/history"))
1323 1339
1324 (defun w3-save-as (&optional type) 1340 (defun w3-save-as (&optional type)
1325 "Save a document to the local disk" 1341 "Save a document to the local disk"
1326 (interactive) 1342 (interactive)
1327 (let* ((completion-ignore-case t) 1343 (save-excursion
1328 (format (or type (completing-read 1344 (let* ((completion-ignore-case t)
1329 "Format: " 1345 (format (or type (completing-read
1330 '(("HTML Source") ("Formatted Text") 1346 "Format: "
1331 ("LaTeX Source") ("Binary")) 1347 '(("HTML Source")
1332 nil t))) 1348 ("Formatted Text")
1333 (fname (expand-file-name 1349 ("LaTeX Source")
1334 (read-file-name "File name: " default-directory))) 1350 ("PostScript")
1335 (url (url-view-url t))) 1351 ("Binary"))
1336 (cond 1352 nil t)))
1337 ((equal "Binary" format) 1353 (fname (expand-file-name
1338 (if (not w3-current-source) 1354 (read-file-name "File name: " default-directory)))
1339 (let ((url-be-asynchronous nil)) 1355 (url (url-view-url t)))
1340 (url-retrieve url)))) 1356 (cond
1341 ((equal "HTML Source" format) 1357 ((equal "Binary" format)
1342 (if (not w3-current-source) 1358 (if (not w3-current-source)
1343 (let ((url-be-asynchronous nil)) 1359 (let ((url-be-asynchronous nil))
1344 (url-retrieve url)) ; Get the document if necessary 1360 (url-retrieve url))))
1345 (let ((txt w3-current-source)) 1361 ((equal "HTML Source" format)
1346 (set-buffer (get-buffer-create url-working-buffer)) 1362 (if (not w3-current-source)
1347 (erase-buffer) 1363 (let ((url-be-asynchronous nil))
1348 (insert txt))) 1364 (url-retrieve url)) ; Get the document if necessary
1349 (goto-char (point-min)) 1365 (let ((txt w3-current-source))
1350 (if (re-search-forward "<head>" nil t) 1366 (set-buffer (get-buffer-create url-working-buffer))
1351 (insert "\n")) 1367 (erase-buffer)
1352 (insert (format "<BASE HREF=\"%s\">\n" url))) 1368 (insert txt)))
1353 ((or (equal "Formatted Text" format) 1369 (goto-char (point-min))
1354 (equal "" format)) 1370 (if (re-search-forward "<head>" nil t)
1355 nil) ; Do nothing - we have the text already 1371 (insert "\n"))
1356 ((equal "LaTeX Source" format) 1372 (insert (format "<BASE HREF=\"%s\">\n" url)))
1357 (w3-parse-tree-to-latex w3-current-parse url) 1373 ((or (equal "Formatted Text" format)
1358 (insert-buffer url-working-buffer))) 1374 (equal "" format))
1359 (write-region (point-min) (point-max) fname))) 1375 nil) ; Do nothing - we have the text already
1376 ((equal "PostScript" format)
1377 (let ((ps-spool-buffer-name " *w3-temp*"))
1378 (if (get-buffer ps-spool-buffer-name)
1379 (kill-buffer ps-spool-buffer-name))
1380 (w3-print-with-ps-print (current-buffer)
1381 'ps-spool-buffer-with-faces)
1382 (set-buffer ps-spool-buffer-name)))
1383 ((equal "LaTeX Source" format)
1384 (w3-parse-tree-to-latex w3-current-parse url)
1385 (insert-buffer url-working-buffer)))
1386 (write-region (point-min) (point-max) fname))))
1360 1387
1361 1388
1362 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1389 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1363 ;;; Functions to parse out <A> tags and replace it with a hyperlink zone 1390 ;;; Functions to parse out <A> tags and replace it with a hyperlink zone
1364 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1391 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2206 (add-minor-mode 'w3-netscape-emulation-minor-mode " NS" 2233 (add-minor-mode 'w3-netscape-emulation-minor-mode " NS"
2207 w3-netscape-emulation-minor-mode-map) 2234 w3-netscape-emulation-minor-mode-map)
2208 (add-minor-mode 'w3-annotation-minor-mode " Annotating" 2235 (add-minor-mode 'w3-annotation-minor-mode " Annotating"
2209 w3-annotation-minor-mode-map) 2236 w3-annotation-minor-mode-map)
2210 (add-minor-mode 'w3-lynx-emulation-minor-mode " Lynx" 2237 (add-minor-mode 'w3-lynx-emulation-minor-mode " Lynx"
2211 w3-annotation-minor-mode-map) 2238 w3-lynx-emulation-minor-mode-map)
2212 2239
2213 (setq url-package-version w3-version-number 2240 (setq url-package-version w3-version-number
2214 url-package-name "Emacs-W3") 2241 url-package-name "Emacs-W3")
2215 2242
2216 (w3-emit-image-warnings-if-necessary) 2243 (w3-emit-image-warnings-if-necessary)
2429 link-at-point 2456 link-at-point
2430 (concat 2457 (concat
2431 (substring link-at-point 0 17) "...")) 2458 (substring link-at-point 0 17) "..."))
2432 "): ") 2459 "): ")
2433 "Link: ") links-alist nil t)) 2460 "Link: ") links-alist nil t))
2434 (if (string= choice "") 2461 (if (setq choice (try-completion choice links-alist))
2435 (w3-follow-link) 2462 (w3-fetch (cdr (assoc choice links-alist))))))
2436 (w3-fetch (cdr (assoc choice links-alist))))))
2437 2463
2438 (defun w3-mode () 2464 (defun w3-mode ()
2439 "Mode for viewing HTML documents. If called interactively, will 2465 "Mode for viewing HTML documents. If called interactively, will
2440 display the current buffer as HTML. 2466 display the current buffer as HTML.
2441 2467
2455 (w3-mode-version-specifics) 2481 (w3-mode-version-specifics)
2456 (w3-menu-install-menus) 2482 (w3-menu-install-menus)
2457 (run-hooks 'w3-mode-hook) 2483 (run-hooks 'w3-mode-hook)
2458 (widget-setup) 2484 (widget-setup)
2459 (setq url-current-passwd-count 0 2485 (setq url-current-passwd-count 0
2486 truncate-lines t
2460 mode-line-format w3-modeline-format) 2487 mode-line-format w3-modeline-format)
2461 (if (and w3-current-isindex (equal url-current-type "http")) 2488 (if (and w3-current-isindex (equal url-current-type "http"))
2462 (setq mode-line-process "-Searchable"))))) 2489 (setq mode-line-process "-Searchable")))))
2463 2490
2464 (require 'mm) 2491 (require 'mm)