annotate lisp/w3/w3-annotat.el @ 97:498bf5da1c90

Added tag r20-0final for changeset dbb370e3c29e
author cvs
date Mon, 13 Aug 2007 09:12:43 +0200
parents 6a378aca36af
children 0d2f883870bc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1 ;;; w3-annotat.el --- Annotation functions for Emacs-W3
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
2 ;; Author: wmperry
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
3 ;; Created: 1997/01/10 00:13:05
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
4 ;; Version: 1.6
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
5 ;; Keywords: faces, help, comm, news, mail, processes, mouse, hypermedia
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
6
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
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.
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
10 ;;;
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 70
diff changeset
11 ;;; This file is part of GNU Emacs.
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
12 ;;;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
13 ;;; GNU Emacs is free software; you can redistribute it and/or modify
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
14 ;;; it under the terms of the GNU General Public License as published by
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
15 ;;; the Free Software Foundation; either version 2, or (at your option)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
16 ;;; any later version.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
17 ;;;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
18 ;;; GNU Emacs is distributed in the hope that it will be useful,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
19 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
20 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
21 ;;; GNU General Public License for more details.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
22 ;;;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
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.
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
27 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
28
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
29 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
30 ;;; Private annotation support
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
31 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
32 (defun w3-parse-personal-annotations ()
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
33 ;; Read in personal annotation file
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
34 (if (and
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
35 (file-exists-p (format "%s/LOG" w3-personal-annotation-directory))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
36 (file-readable-p (format "%s/LOG" w3-personal-annotation-directory)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
37 (save-excursion
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
38 (setq w3-personal-annotations nil);; nuke the old list
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
39 (let ((start nil)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
40 (end nil)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
41 (txt nil)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
42 (url nil)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
43 (num nil))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
44 (set-buffer (get-buffer-create " *panno*"))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
45 (erase-buffer)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
46 (insert-file-contents-literally
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
47 (format "%s/LOG" w3-personal-annotation-directory))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
48 (goto-char (point-min))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
49 (w3-replace-regexp "\n+" "\n")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
50 (goto-char (point-min))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
51 ;; nuke the header lines
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
52 (delete-region (point-min) (progn (forward-line 2) (point)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
53 (cond
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
54 ((eobp) nil) ; Empty LOG file
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
55 (t
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
56 (if (/= (char-after (1- (point-max))) ?\n)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
57 (save-excursion
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
58 (goto-char (point-max))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
59 (insert "\n")))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
60 (while (not (eobp))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
61 (setq start (point)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
62 end (prog2 (end-of-line) (point) (forward-char 1))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
63 txt (buffer-substring start end)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
64 url (substring txt 0 (string-match " " txt))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
65 num (url-split
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
66 (substring txt (1+ (string-match " " txt)) nil)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
67 "[ \t]"))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
68 (while num
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
69 (setq w3-personal-annotations
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
70 (cons
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
71 (list url
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
72 (list (car (car num))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
73 (w3-grok-annotation-format
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
74 (car (car num)))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
75 w3-personal-annotations)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
76 num (cdr num))))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
77 (kill-buffer " *panno*")))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
78
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
79 (defun w3-grok-annotation-format (anno)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
80 ;; Grab the title from an annotation
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
81 (let ((fname (format "%s/PAN-%s.html"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
82 w3-personal-annotation-directory anno)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
83 (save-excursion
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
84 (set-buffer (get-buffer-create " *annotmp*"))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
85 (erase-buffer)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
86 (if (file-exists-p fname)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
87 (insert-file-contents-literally fname))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
88 (goto-char (point-min))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
89 (prog1
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
90 (if (re-search-forward "<title>\\(.*\\)</title>" nil t)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
91 (buffer-substring (match-beginning 1) (match-end 1))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
92 (concat "Annotation on "
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
93 (current-time-string (nth 5 (file-attributes fname)))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
94 (kill-buffer " *annotmp*")))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
95
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
96 (defun w3-is-personal-annotation (url)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
97 ;; Is URL a personal annotation?
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
98 (string-match "file:/.*/PAN-.*\\.html" url))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
99
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
100 (defun w3-delete-personal-annotation-internal (url num)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
101 (save-excursion
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
102 (set-buffer (get-buffer-create " *annotmp*"))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
103 (erase-buffer)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
104 (insert-file-contents-literally (format "%s/LOG"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
105 w3-personal-annotation-directory))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
106 (replace-regexp (format "[ \t]+\\b%s\\b[ \t]*" num) " ")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
107 (goto-char (point-min))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
108 (delete-matching-lines (format "^%s +$" url))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
109 (let ((make-backup-files nil)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
110 (version-control nil)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
111 (require-final-newline t))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
112 (write-region (point-min) (point-max)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
113 (format "%s/LOG"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
114 w3-personal-annotation-directory)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
115 (kill-buffer " *annotmp*")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
116 (let ((anno w3-personal-annotations))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
117 (setq w3-personal-annotations nil)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
118 (while anno
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
119 (if (not (string= num (car (car (cdr (car anno))))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
120 (setq w3-personal-annotations
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
121 (cons (car anno) w3-personal-annotations)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
122 (setq anno (cdr anno)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
123 (delete-file (format "%s/PAN-%s.html"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
124 w3-personal-annotation-directory num)))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
125
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
126 (defun w3-delete-personal-annotation ()
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
127 "Delete a personal annotation."
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
128 (interactive)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
129 (let ((url (url-view-url t)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
130 (cond
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
131 ((w3-is-personal-annotation (url-view-url t))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
132 (let ((num nil)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
133 (annotated-url nil)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
134 (anno w3-personal-annotations))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
135 (string-match "file:/.*/PAN-\\(.*\\)\\.html" url)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
136 (setq num (match-string 1 url))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
137 (while anno
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
138 (if (equal num (car (car (cdr (car anno)))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
139 (setq annotated-url (car (car anno))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
140 (setq anno (cdr anno)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
141 (if (not annotated-url)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
142 (message "Couldn't find url that this is annotating!")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
143 (w3-delete-personal-annotation-internal annotated-url num)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
144 (w3-quit))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
145 (t
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
146 (let* ((tmp w3-personal-annotations)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
147 (thelist nil)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
148 (node nil)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
149 (todel nil))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
150 (if (not (assoc url tmp))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
151 (message "No personal annotations.")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
152 (while tmp
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
153 (setq node (car tmp))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
154 (if (string= (car node) url)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
155 (setq thelist (cons (cons (nth 1 (nth 1 node)) "") thelist)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
156 (setq tmp (cdr tmp)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
157 (setq todel (completing-read "Delete annotation: " thelist nil t))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
158 ;; WORK ;;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
159 (message "I should delete %s, but can't." todel)))))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
160
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
161 (defun w3-personal-annotation-add ()
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
162 "Add an annotation to this document."
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
163 (interactive)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
164 (let ((url (url-view-url t))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
165 (buf (get-buffer-create "*Personal Annotation*"))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
166 (title (read-string "Title: "
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
167 (format "Annotation by %s on %s"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
168 (user-real-login-name)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
169 (current-time-string)))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
170 (set-buffer buf)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
171 (switch-to-buffer buf)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
172 (erase-buffer)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
173 (if (and w3-annotation-mode (fboundp w3-annotation-mode))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
174 (funcall w3-annotation-mode)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
175 (message "%S is undefined, using %s" w3-annotation-mode
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
176 default-major-mode)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
177 (funcall default-major-mode))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
178 (w3-annotation-minor-mode 1)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
179 (setq w3-current-annotation (cons url title))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
180 (insert "<html>\n"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
181 " <head>\n"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
182 " <title>" (url-insert-entities-in-string title) "</title>"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
183 " </head>\n"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
184 " <h1>" (url-insert-entities-in-string title) "</h1>\n"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
185 " <p>\n"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
186 " <address>" (url-insert-entities-in-string (user-full-name))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
187 (if (stringp url-personal-mail-address)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
188 (concat " &lt;" (url-insert-entities-in-string
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
189 url-personal-mail-address) "&gt;")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
190 "")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
191 "</address>\n"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
192 " <address>" (current-time-string) "</address>\n"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
193 " </p>\n"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
194 " <pre>\n")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
195 (save-excursion
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
196 (insert "\n\n\n </pre>\n"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
197 "</html>"))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
198 (message "Hit C-cC-c to send this annotation.")))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
199
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
200 (defun w3-annotation-minor-mode (&optional arg)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
201 "Minimal minor mode for entering annotations. Just rebinds C-cC-c to
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
202 finish the annotation."
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
203 (interactive "P")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
204 (cond
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
205 ((null arg) (setq w3-annotation-minor-mode (not w3-annotation-minor-mode)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
206 ((= 0 arg) (setq w3-annotation-minor-mode nil))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
207 (t (setq w3-annotation-minor-mode t)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
208 (cond
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
209 ((or w3-running-FSF19 w3-running-xemacs))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
210 (t (local-set-key "\C-c\C-c" 'w3-personal-annotation-finish)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
211 )
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
212
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
213 (defun w3-annotation-find-highest-number ()
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
214 ;; Find the highest annotation number in this buffer
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
215 (let (x)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
216 (goto-char (point-min))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
217 (while (re-search-forward "[^ \t\n]*[ \t]\\(.*\\)" nil t)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
218 (setq x (nconc (mapcar (function (lambda (x) (string-to-int (car x))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
219 (url-split (buffer-substring (match-beginning 1)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
220 (match-end 1))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
221 "[ \t]")) x)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
222 (if (not x) (setq x '(0)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
223 (1+ (car (sort x '>)))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
224
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
225 (defun w3-personal-annotation-finish ()
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
226 "Finish doing a personal annotation."
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
227 (interactive)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
228 (cond
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
229 ((or w3-running-FSF19 w3-running-xemacs))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
230 (t (local-set-key "\C-c\C-c" 'undefined)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
231 (if (or (not w3-personal-annotation-directory)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
232 (not (file-exists-p w3-personal-annotation-directory))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
233 (not (file-directory-p w3-personal-annotation-directory)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
234 (error "No personal annotation directory!")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
235 (let ((url (car w3-current-annotation))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
236 (txt (buffer-string))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
237 (title (cdr w3-current-annotation))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
238 (fname nil)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
239 (num nil))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
240 (save-excursion
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
241 (not-modified)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
242 (kill-buffer (current-buffer))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
243 (set-buffer (get-buffer-create " *annotmp*"))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
244 (erase-buffer)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
245 (if (file-exists-p ; Insert current LOG file if
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
246 ; it exists.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
247 (format "%s/LOG" w3-personal-annotation-directory))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
248 (insert-file-contents-literally
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
249 (format "%s/LOG" w3-personal-annotation-directory))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
250 (progn ; Otherwise, create a file
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
251 (goto-char (point-min)) ; that conforms to first
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
252 ; annotation format from NCSA
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
253 (insert "ncsa-mosaic-personal-annotation-log-format-1\n")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
254 (insert "Personal\n")))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
255 (goto-char (point-min))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
256 (setq num (int-to-string (w3-annotation-find-highest-number))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
257 fname (format "%s/PAN-%s.html"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
258 w3-personal-annotation-directory num))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
259 (goto-char (point-min))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
260 (if (re-search-forward (regexp-quote url) nil t)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
261 (progn
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
262 (end-of-line)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
263 (insert " "))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
264 (goto-char (point-max))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
265 (insert "\n" url " "))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
266 (insert num)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
267 (let ((make-backup-files nil)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
268 (version-control nil)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
269 (require-final-newline t))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
270 (write-region (point-min) (point-max)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
271 (format "%s/LOG" w3-personal-annotation-directory))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
272 (erase-buffer)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
273 (insert w3-annotation-marker txt)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
274 (write-region (point-min) (point-max) fname))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
275 (setq w3-personal-annotations
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
276 (cons (list url (list num title)) w3-personal-annotations))))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
277
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
278 (defun w3-annotation-add ()
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
279 "Add an annotation to the current document."
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
280 (interactive)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
281 (w3-personal-annotation-add))