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