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