1 ;;; gnus-bcklg.el --- backlog functions for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
29 (eval-when-compile (require 'cl
))
34 ;;; Buffering of read articles.
37 (defvar gnus-backlog-buffer
" *Gnus Backlog*")
38 (defvar gnus-backlog-articles nil
)
39 (defvar gnus-backlog-hashtb nil
)
41 (defun gnus-backlog-buffer ()
42 "Return the backlog buffer."
43 (or (get-buffer gnus-backlog-buffer
)
45 (set-buffer (gnus-get-buffer-create gnus-backlog-buffer
))
47 (setq buffer-read-only t
)
48 (get-buffer gnus-backlog-buffer
))))
50 (defun gnus-backlog-setup ()
51 "Initialize backlog variables."
52 (unless gnus-backlog-hashtb
53 (setq gnus-backlog-hashtb
(gnus-make-hashtable 1024))))
55 (gnus-add-shutdown 'gnus-backlog-shutdown
'gnus
)
57 (defun gnus-backlog-shutdown ()
58 "Clear all backlog variables and buffers."
60 (when (get-buffer gnus-backlog-buffer
)
61 (gnus-kill-buffer gnus-backlog-buffer
))
62 (setq gnus-backlog-hashtb nil
63 gnus-backlog-articles nil
))
65 (defun gnus-backlog-enter-article (group number buffer
)
66 (when (and (numberp number
)
67 (not (string-match "^nnvirtual" group
)))
69 (let ((ident (intern (concat group
":" (int-to-string number
))
72 (if (memq ident gnus-backlog-articles
)
73 () ; It's already kept.
74 ;; Remove the oldest article, if necessary.
75 (and (numberp gnus-keep-backlog
)
76 (>= (length gnus-backlog-articles
) gnus-keep-backlog
)
77 (gnus-backlog-remove-oldest-article))
78 (push ident gnus-backlog-articles
)
79 ;; Insert the new article.
81 (set-buffer (gnus-backlog-buffer))
82 (let (buffer-read-only)
83 (goto-char (point-max))
87 (insert-buffer-substring buffer
)
88 ;; Tag the beginning of the article with the ident.
90 (gnus-put-text-property b
(1+ b
) 'gnus-backlog ident
)
91 (gnus-error 3 "Article %d is blank" number
))))))))
93 (defun gnus-backlog-remove-oldest-article ()
95 (set-buffer (gnus-backlog-buffer))
96 (goto-char (point-min))
97 (if (zerop (buffer-size))
98 () ; The buffer is empty.
99 (let ((ident (get-text-property (point) 'gnus-backlog
))
101 ;; Remove the ident from the list of articles.
103 (setq gnus-backlog-articles
(delq ident gnus-backlog-articles
)))
104 ;; Delete the article itself.
106 (point) (next-single-property-change
107 (1+ (point)) 'gnus-backlog nil
(point-max)))))))
109 (defun gnus-backlog-remove-article (group number
)
110 "Remove article NUMBER in GROUP from the backlog."
111 (when (numberp number
)
113 (let ((ident (intern (concat group
":" (int-to-string number
))
114 gnus-backlog-hashtb
))
116 (when (memq ident gnus-backlog-articles
)
117 ;; It was in the backlog.
119 (set-buffer (gnus-backlog-buffer))
120 (let (buffer-read-only)
121 (when (setq beg
(text-property-any
122 (point-min) (point-max) 'gnus-backlog
124 ;; Find the end (i. e., the beginning of the next article).
126 (next-single-property-change
127 (1+ beg
) 'gnus-backlog
(current-buffer) (point-max)))
128 (delete-region beg end
)
131 (setq gnus-backlog-articles
(delq ident gnus-backlog-articles
)))))))
133 (defun gnus-backlog-request-article (group number
&optional buffer
)
134 (when (and (numberp number
)
135 (not (string-match "^nnvirtual" group
)))
137 (let ((ident (intern (concat group
":" (int-to-string number
))
138 gnus-backlog-hashtb
))
140 (when (memq ident gnus-backlog-articles
)
141 ;; It was in the backlog.
143 (set-buffer (gnus-backlog-buffer))
144 (if (not (setq beg
(text-property-any
145 (point-min) (point-max) 'gnus-backlog
147 ;; It wasn't in the backlog after all.
149 (setq gnus-backlog-articles
(delq ident gnus-backlog-articles
)))
150 ;; Find the end (i. e., the beginning of the next article).
152 (next-single-property-change
153 (1+ beg
) 'gnus-backlog
(current-buffer) (point-max)))))
155 (and buffer
(set-buffer buffer
))
156 (let ((buffer-read-only nil
))
158 (insert-buffer-substring gnus-backlog-buffer beg end
)))
161 (provide 'gnus-bcklg
)
163 ;;; arch-tag: 66259e56-505a-4bba-8a0d-3552c5b94e39
164 ;;; gnus-bcklg.el ends here