1 ;;; gnus-bcklg.el --- backlog functions for Gnus
2 ;; Copyright (C) 1996,97 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
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.
31 ;;; Buffering of read articles.
34 (defvar gnus-backlog-buffer " *Gnus Backlog*")
35 (defvar gnus-backlog-articles nil)
36 (defvar gnus-backlog-hashtb nil)
38 (defun gnus-backlog-buffer ()
39 "Return the backlog buffer."
40 (or (get-buffer gnus-backlog-buffer)
42 (set-buffer (get-buffer-create gnus-backlog-buffer))
43 (buffer-disable-undo (current-buffer))
44 (setq buffer-read-only t)
45 (gnus-add-current-to-buffer-list)
46 (get-buffer gnus-backlog-buffer))))
48 (defun gnus-backlog-setup ()
49 "Initialize backlog variables."
50 (unless gnus-backlog-hashtb
51 (setq gnus-backlog-hashtb (gnus-make-hashtable 1024))))
53 (gnus-add-shutdown 'gnus-backlog-shutdown 'gnus)
55 (defun gnus-backlog-shutdown ()
56 "Clear all backlog variables and buffers."
57 (when (get-buffer gnus-backlog-buffer)
58 (kill-buffer gnus-backlog-buffer))
59 (setq gnus-backlog-hashtb nil
60 gnus-backlog-articles nil))
62 (defun gnus-backlog-enter-article (group number buffer)
64 (let ((ident (intern (concat group ":" (int-to-string number))
67 (if (memq ident gnus-backlog-articles)
68 () ; It's already kept.
69 ;; Remove the oldest article, if necessary.
70 (and (numberp gnus-keep-backlog)
71 (>= (length gnus-backlog-articles) gnus-keep-backlog)
72 (gnus-backlog-remove-oldest-article))
73 (push ident gnus-backlog-articles)
74 ;; Insert the new article.
76 (set-buffer (gnus-backlog-buffer))
77 (let (buffer-read-only)
78 (goto-char (point-max))
82 (insert-buffer-substring buffer)
83 ;; Tag the beginning of the article with the ident.
84 (gnus-put-text-property b (1+ b) 'gnus-backlog ident))))))
86 (defun gnus-backlog-remove-oldest-article ()
88 (set-buffer (gnus-backlog-buffer))
89 (goto-char (point-min))
90 (if (zerop (buffer-size))
91 () ; The buffer is empty.
92 (let ((ident (get-text-property (point) 'gnus-backlog))
94 ;; Remove the ident from the list of articles.
96 (setq gnus-backlog-articles (delq ident gnus-backlog-articles)))
97 ;; Delete the article itself.
99 (point) (next-single-property-change
100 (1+ (point)) 'gnus-backlog nil (point-max)))))))
102 (defun gnus-backlog-remove-article (group number)
103 "Remove article NUMBER in GROUP from the backlog."
104 (when (numberp number)
106 (let ((ident (intern (concat group ":" (int-to-string number))
107 gnus-backlog-hashtb))
109 (when (memq ident gnus-backlog-articles)
110 ;; It was in the backlog.
112 (set-buffer (gnus-backlog-buffer))
113 (let (buffer-read-only)
114 (when (setq beg (text-property-any
115 (point-min) (point-max) 'gnus-backlog
117 ;; Find the end (i. e., the beginning of the next article).
119 (next-single-property-change
120 (1+ beg) 'gnus-backlog (current-buffer) (point-max)))
121 (delete-region beg end)
125 (defun gnus-backlog-request-article (group number buffer)
126 (when (numberp number)
128 (let ((ident (intern (concat group ":" (int-to-string number))
129 gnus-backlog-hashtb))
131 (when (memq ident gnus-backlog-articles)
132 ;; It was in the backlog.
134 (set-buffer (gnus-backlog-buffer))
135 (if (not (setq beg (text-property-any
136 (point-min) (point-max) 'gnus-backlog
138 ;; It wasn't in the backlog after all.
140 (setq gnus-backlog-articles (delq ident gnus-backlog-articles)))
141 ;; Find the end (i. e., the beginning of the next article).
143 (next-single-property-change
144 (1+ beg) 'gnus-backlog (current-buffer) (point-max)))))
145 (let ((buffer-read-only nil))
147 (insert-buffer-substring gnus-backlog-buffer beg end)
150 (provide 'gnus-bcklg)
152 ;;; gnus-bcklg.el ends here