annotate lisp/w3/w3-hot.el @ 0:376386a54a3c r19-14

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