annotate lisp/w3/w3-hot.el @ 102:a145efe76779 r20-1b3

Import from CVS: tag r20-1b3
author cvs
date Mon, 13 Aug 2007 09:15:49 +0200
parents 6a378aca36af
children fe104dbd9147
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1 ;;; w3-hot.el --- Main functions for emacs-w3 on all platforms/versions
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2 ;; Author: wmperry
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
3 ;; Created: 1997/02/18 23:36:48
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
4 ;; Version: 1.12
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5 ;; Keywords: faces, help, comm, news, mail, processes, mouse, hypermedia
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
6
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
8 ;;; Copyright (c) 1993 - 1996 by William M. Perry (wmperry@cs.indiana.edu)
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
9 ;;; Copyright (c) 1996, 1997 Free Software Foundation, Inc.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;;;
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 70
diff changeset
11 ;;; This file is part of GNU Emacs.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;;; GNU Emacs is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;;; it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;;; GNU Emacs is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;;; You should have received a copy of the GNU General Public License
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 70
diff changeset
24 ;;; along with GNU Emacs; see the file COPYING. If not, write to the
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 70
diff changeset
25 ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 70
diff changeset
26 ;;; Boston, MA 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;;; Structure for hotlists
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;;; (
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;; ("name of item1" . "http://foo.bar.com/") ;; A single item in hotlist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;;; ("name of item2" . ( ;; A sublist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;;; ("name of item3" . "http://www.ack.com/")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;;; ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;;; ) ; end of hotlist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (require 'w3-vars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;;; Hotlist Handling Code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (defvar w3-html-bookmarks nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
46 (defun w3-hotlist-break-shit ()
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
47 (let ((todo '(w3-hotlist-apropos
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
48 w3-hotlist-delete
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
49 w3-hotlist-rename-entry
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
50 w3-hotlist-append
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
51 w3-use-hotlist
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
52 w3-hotlist-add-document
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
53 w3-hotlist-add-document-at-point
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
54 ))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
55 (cur nil))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
56 (while todo
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
57 (setq cur (car todo)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
58 todo (cdr todo))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
59 (fset cur
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
60 (`
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
61 (lambda (&rest ignore)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
62 (error "Sorry, `%s' does not work with html bookmarks"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
63 (quote (, cur)))))))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
64
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (defun w3-read-html-bookmarks (fname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 "Import an HTML file into the Emacs-w3 format."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (interactive "fBookmark file: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (if (not (file-readable-p fname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (error "Can not read %s..." fname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (set-buffer (get-buffer-create " *bookmark-work*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (insert-file-contents fname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (let* ((w3-debug-html nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (bkmarks nil)
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 70
diff changeset
76 (parse (w3-parse-buffer (current-buffer))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (setq parse w3-last-parse-tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 bkmarks (nreverse (w3-grok-html-bookmarks parse))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
79 w3-html-bookmarks bkmarks)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
80 (w3-hotlist-break-shit))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (eval-when-compile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (defvar cur-stack nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (defvar cur-title nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (defmacro push-new-menu ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 '(setq cur-stack (cons (list "") cur-stack)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (defmacro push-new-item (title href)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (` (setcar cur-stack (cons (vector (, title) (list 'w3-fetch (, href)) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (car cur-stack)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 ;;(` (setcar cur-stack (cons (cons (, title) (, href)) (car cur-stack)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (defmacro finish-submenu ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 '(let ((x (nreverse (car cur-stack))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (and x (setcar x (car cur-title)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (setq cur-stack (cdr cur-stack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 cur-title (cdr cur-title))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (if cur-stack
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (setcar cur-stack (cons x (car cur-stack)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (setq cur-stack (list x)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (defun w3-grok-html-bookmarks-internal (tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (let (node tag content args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (while tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (setq node (car tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 tree (cdr tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 tag (and (listp node) (nth 0 node))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 args (and (listp node) (nth 1 node))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 content (and (listp node) (nth 2 node)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 ((eq tag 'title)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (setq cur-title (list (w3-normalize-spaces (car content))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (w3-grok-html-bookmarks-internal content))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
115 ((memq tag '(dl ol ul))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (push-new-menu)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (w3-grok-html-bookmarks-internal content)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (finish-submenu))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
119 ((and (memq tag '(dt li))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (stringp (car content)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (setq cur-title (cons (w3-normalize-spaces (car content))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 cur-title)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 ((and (eq tag 'a)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (stringp (car-safe content))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (cdr-safe (assq 'href args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (push-new-item (w3-normalize-spaces (car-safe content))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (cdr-safe (assq 'href args))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (content
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (w3-grok-html-bookmarks-internal content))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (defun w3-grok-html-bookmarks (chunk)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (let (
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 cur-title
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 cur-stack
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (w3-grok-html-bookmarks-internal chunk)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (reverse (car cur-stack))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (defun w3-hotlist-apropos (regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 "Show hotlist entries matching REGEXP."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (interactive "sW3 Hotlist Apropos (regexp): ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (or w3-setup-done (w3-do-setup))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (let ((save-buf (get-buffer "Hotlist")) ; avoid killing this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (w3-hotlist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (apply
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 'nconc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (lambda (entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (if (or (string-match regexp (car entry))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (string-match regexp (car (cdr entry))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (list entry))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 w3-hotlist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (if (not w3-hotlist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (message "No w3-hotlist entries match \"%s\"" regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (and save-buf (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (set-buffer save-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (rename-buffer (concat "Hotlist during " regexp))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (w3-show-hotlist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (rename-buffer (concat "Hotlist \"" regexp "\""))
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
163 (url-set-filename url-current-object (concat "hotlist/" regexp)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (and save-buf (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (set-buffer save-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (rename-buffer "Hotlist")))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (defun w3-hotlist-refresh ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 "Reload the default hotlist file into memory"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (interactive)
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 70
diff changeset
171 (w3-parse-hotlist))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (defun w3-delete-from-alist (x alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 ;; Remove X from ALIST, return new alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (if (eq (assoc x alist) (car alist)) (cdr alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (delq (assoc x alist) alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (defun w3-hotlist-delete ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 "Deletes a document from your hotlist file"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (if (not w3-hotlist) (message "No hotlist in memory!")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (if (not (file-exists-p w3-hotlist-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (message "Hotlist file %s does not exist." w3-hotlist-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (let* ((completion-ignore-case t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (title (car (assoc (completing-read "Delete Document: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 w3-hotlist nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 w3-hotlist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (case-fold-search nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (buffer (get-buffer-create " *HOTW3*")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (and (string= title "") (error "No document specified."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (insert-file-contents w3-hotlist-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (if (re-search-forward (concat "^" (regexp-quote title) "\r*$")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (let ((make-backup-files nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (version-control nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (require-final-newline t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (previous-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (delete-region (point) (progn (forward-line 2) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (write-file w3-hotlist-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (setq w3-hotlist (w3-delete-from-alist title w3-hotlist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (kill-buffer (current-buffer)))
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 70
diff changeset
207 (message "%s was not found in %s" title w3-hotlist-file)))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (defun w3-hotlist-rename-entry (title)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 "Rename a hotlist item"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (interactive (list (let ((completion-ignore-case t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (completing-read "Rename entry: " w3-hotlist nil t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (cond ; Do the error handling first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 ((string= title "") (error "No document specified!"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 ((not w3-hotlist) (error "No hotlist in memory!"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 ((not (file-exists-p (expand-file-name w3-hotlist-file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (error "Hotlist file %s does not exist." w3-hotlist-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 ((not (file-readable-p (expand-file-name w3-hotlist-file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (error "Hotlist file %s exists, but is unreadable." w3-hotlist-file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (let ((obj (assoc title w3-hotlist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (used (mapcar 'car w3-hotlist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (buff (get-buffer-create " *HOTW3*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (new nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (while (or (null new) (member new used))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (setq new (read-string "New name: ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (set-buffer buff)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (insert-file-contents (expand-file-name w3-hotlist-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (if (re-search-forward (regexp-quote title) nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (let ((make-backup-files nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (version-control nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (require-final-newline t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (previous-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (delete-region (point) (progn (forward-line 2) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (insert (format "%s %s\n%s\n" (nth 1 obj) (current-time-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 new))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (setq w3-hotlist (cons (list new (nth 1 obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (w3-delete-from-alist title w3-hotlist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (write-file w3-hotlist-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (kill-buffer (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (if (and w3-running-FSF19 (not (eq 'tty (device-type))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (delete-menu-item '("Go"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (w3-build-FSF19-menu))))
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 70
diff changeset
249 (message "%s was not found in %s" title w3-hotlist-file)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (defun w3-hotlist-append (fname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 "Append a hotlist to the one in memory"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (interactive "fAppend hotlist file: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (let ((x w3-hotlist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (w3-parse-hotlist fname)
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 70
diff changeset
256 (setq w3-hotlist (nconc x w3-hotlist))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
258 (defun w3-hotlist-parse-old-mosaic-format ()
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
259 (let (cur-link cur-alias)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
260 (while (re-search-forward "^\n" nil t) (replace-match ""))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
261 (goto-line 3)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
262 (while (not (eobp))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
263 (re-search-forward "^[^ ]*" nil t)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
264 (setq cur-link (buffer-substring (match-beginning 0) (match-end 0)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
265 (setq cur-alias (buffer-substring (progn
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
266 (forward-line 1)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
267 (beginning-of-line)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
268 (point))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
269 (progn
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
270 (end-of-line)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
271 (point))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
272 (if (not (equal cur-alias ""))
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 70
diff changeset
273 (setq w3-hotlist (cons (list cur-alias cur-link) w3-hotlist))))))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
274
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (defun w3-parse-hotlist (&optional fname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 "Read in the hotlist specified by FNAME"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (if (not fname) (setq fname w3-hotlist-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (setq w3-hotlist nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (if (not (file-exists-p fname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (message "%s does not exist!" fname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (let* ((old-buffer (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (buffer (get-buffer-create " *HOTW3*"))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
283 (case-fold-search t))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (insert-file-contents fname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (goto-char (point-min))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
288 (cond
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
289 ((looking-at "ncsa-xmosaic-hotlist-format-1");; Old-style NCSA Mosaic
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
290 (w3-hotlist-parse-old-mosaic-format))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
291 ((or (looking-at "<!DOCTYPE") ; Some HTML style, including netscape
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
292 (re-search-forward "<a[ \n]+href" nil t))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
293 (w3-read-html-bookmarks fname))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
294 (t
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
295 (message "Cannot determine format of hotlist file: %s" fname)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
296 (set-buffer-modified-p nil)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (kill-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (set-buffer old-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (defun w3-use-hotlist ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 "Possibly go to a link in your W3/Mosaic hotlist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 This is part of the emacs World Wide Web browser. It will prompt for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 one of the items in your 'hotlist'. A hotlist is a list of often
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 visited or interesting items you have found on the World Wide Web."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (if (not w3-setup-done) (w3-do-setup))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (if (not w3-hotlist) (message "No hotlist in memory!")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (let* ((completion-ignore-case t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (url (car (cdr (assoc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (completing-read "Goto Document: " w3-hotlist nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 w3-hotlist)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (if (string= "" url) (error "No document specified!"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (w3-fetch url))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (defun w3-hotlist-add-document-at-point (pref-arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 "Add the document pointed to by the hyperlink under point to the hotlist."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (interactive "P")
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 32
diff changeset
319 (let ((url (w3-view-this-url t)) title)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (or url (error "No link under point."))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 32
diff changeset
321 (setq title (get-text-property (point) 'title))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 32
diff changeset
322 (if (and title
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 32
diff changeset
323 (marker-buffer (car title))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 32
diff changeset
324 (marker-buffer (cdr title)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 32
diff changeset
325 (setq title (buffer-substring-no-properties (car title) (cdr title)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 32
diff changeset
326 (setq title "None"))
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 70
diff changeset
327 (w3-hotlist-add-document pref-arg title url)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (defun w3-hotlist-add-document (pref-arg &optional the-title the-url)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 "Add this documents url to the hotlist"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (let* ((buffer (get-buffer-create " *HOTW3*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (title (or the-title
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (and pref-arg (read-string "Title: "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (buffer-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (make-backup-files nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (version-control nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (require-final-newline t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (url (or the-url (url-view-url t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (if (rassoc (list url) w3-hotlist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (error "That item already in hotlist, use w3-hotlist-rename-entry."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (setq w3-hotlist (cons (list title url) w3-hotlist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 url (url-unhex-string url))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (if (not (file-exists-p w3-hotlist-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (message "Creating hotlist file %s" w3-hotlist-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (insert "ncsa-xmosaic-hotlist-format-1\nDefault\n\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (backward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (insert-file-contents w3-hotlist-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (backward-char 1)))
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 70
diff changeset
356 (insert "\n" url " " (current-time-string) "\n" title)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (write-file w3-hotlist-file)
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 70
diff changeset
358 (kill-buffer (current-buffer)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (provide 'w3-hot)