1 ;;; gnus-bcklg.el --- backlog functions for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
28 (eval-when-compile (require 'cl))
33 ;;; Buffering of read articles.
36 (defvar gnus-backlog-buffer " *Gnus Backlog*")
37 (defvar gnus-backlog-articles nil)
38 (defvar gnus-backlog-hashtb nil)
40 (defun gnus-backlog-buffer ()
41 "Return the backlog buffer."
42 (or (get-buffer gnus-backlog-buffer)
44 (set-buffer (gnus-get-buffer-create gnus-backlog-buffer))
46 (setq buffer-read-only t)
47 (get-buffer gnus-backlog-buffer))))
49 (defun gnus-backlog-setup ()
50 "Initialize backlog variables."
51 (unless gnus-backlog-hashtb
52 (setq gnus-backlog-hashtb (gnus-make-hashtable 1024))))
54 (gnus-add-shutdown 'gnus-backlog-shutdown 'gnus)
56 (defun gnus-backlog-shutdown ()
57 "Clear all backlog variables and buffers."
59 (when (get-buffer gnus-backlog-buffer)
60 (kill-buffer gnus-backlog-buffer))
61 (setq gnus-backlog-hashtb nil
62 gnus-backlog-articles nil))
64 (defun gnus-backlog-enter-article (group number buffer)
65 (when (and (numberp number)
66 (not (string-match "^nnvirtual" group)))
68 (let ((ident (intern (concat group ":" (int-to-string number))
71 (if (memq ident gnus-backlog-articles)
72 () ; It's already kept.
73 ;; Remove the oldest article, if necessary.
74 (and (numberp gnus-keep-backlog)
75 (>= (length gnus-backlog-articles) gnus-keep-backlog)
76 (gnus-backlog-remove-oldest-article))
77 (push ident gnus-backlog-articles)
78 ;; Insert the new article.
80 (set-buffer (gnus-backlog-buffer))
81 (let (buffer-read-only)
82 (goto-char (point-max))
86 (insert-buffer-substring buffer)
87 ;; Tag the beginning of the article with the ident.
89 (gnus-put-text-property b (1+ b) 'gnus-backlog ident)
90 (gnus-error 3 "Article %d is blank" number))))))))
92 (defun gnus-backlog-remove-oldest-article ()
94 (set-buffer (gnus-backlog-buffer))
95 (goto-char (point-min))
96 (if (zerop (buffer-size))
97 () ; The buffer is empty.
98 (let ((ident (get-text-property (point) 'gnus-backlog))
100 ;; Remove the ident from the list of articles.
102 (setq gnus-backlog-articles (delq ident gnus-backlog-articles)))
103 ;; Delete the article itself.
105 (point) (next-single-property-change
106 (1+ (point)) 'gnus-backlog nil (point-max)))))))
108 (defun gnus-backlog-remove-article (group number)
109 "Remove article NUMBER in GROUP from the backlog."
110 (when (numberp number)
112 (let ((ident (intern (concat group ":" (int-to-string number))
113 gnus-backlog-hashtb))
115 (when (memq ident gnus-backlog-articles)
116 ;; It was in the backlog.
118 (set-buffer (gnus-backlog-buffer))
119 (let (buffer-read-only)
120 (when (setq beg (text-property-any
121 (point-min) (point-max) 'gnus-backlog
123 ;; Find the end (i. e., the beginning of the next article).
125 (next-single-property-change
126 (1+ beg) 'gnus-backlog (current-buffer) (point-max)))
127 (delete-region beg end)
130 (setq gnus-backlog-articles (delq ident gnus-backlog-articles)))))))
132 (defun gnus-backlog-request-article (group number &optional buffer)
133 (when (and (numberp number)
134 (not (string-match "^nnvirtual" group)))
136 (let ((ident (intern (concat group ":" (int-to-string number))
137 gnus-backlog-hashtb))
139 (when (memq ident gnus-backlog-articles)
140 ;; It was in the backlog.
142 (set-buffer (gnus-backlog-buffer))
143 (if (not (setq beg (text-property-any
144 (point-min) (point-max) 'gnus-backlog
146 ;; It wasn't in the backlog after all.
148 (setq gnus-backlog-articles (delq ident gnus-backlog-articles)))
149 ;; Find the end (i. e., the beginning of the next article).
151 (next-single-property-change
152 (1+ beg) 'gnus-backlog (current-buffer) (point-max)))))
154 (and buffer (set-buffer buffer))
155 (let ((buffer-read-only nil))
157 (insert-buffer-substring gnus-backlog-buffer beg end)))
160 (provide 'gnus-bcklg)
162 ;;; gnus-bcklg.el ends here