1 ;;; gnus-bcklg.el --- backlog functions for Gnus
3 ;; Copyright (C) 1996-2012 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 3 of the License, or
13 ;; (at your option) any later version.
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. If not, see <http://www.gnu.org/licenses/>.
27 (eval-when-compile (require 'cl
))
32 ;;; Buffering of read articles.
35 (defvar gnus-backlog-buffer
" *Gnus Backlog*")
36 (defvar gnus-backlog-articles nil
)
37 (defvar gnus-backlog-hashtb nil
)
39 (defun gnus-backlog-buffer ()
40 "Return the backlog buffer."
41 (or (get-buffer gnus-backlog-buffer
)
42 (with-current-buffer (gnus-get-buffer-create gnus-backlog-buffer
)
44 (setq buffer-read-only t
)
45 (get-buffer gnus-backlog-buffer
))))
47 (defun gnus-backlog-setup ()
48 "Initialize backlog variables."
49 (unless gnus-backlog-hashtb
50 (setq gnus-backlog-hashtb
(gnus-make-hashtable 1024))))
52 (gnus-add-shutdown 'gnus-backlog-shutdown
'gnus
)
54 (defun gnus-backlog-shutdown ()
55 "Clear all backlog variables and buffers."
57 (when (get-buffer gnus-backlog-buffer
)
58 (gnus-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
)
63 (when (and (numberp number
)
64 (not (string-match "^nnvirtual" group
)))
66 (let ((ident (intern (concat group
":" (int-to-string number
))
69 (if (memq ident gnus-backlog-articles
)
70 () ; It's already kept.
71 ;; Remove the oldest article, if necessary.
72 (and (numberp gnus-keep-backlog
)
73 (>= (length gnus-backlog-articles
) gnus-keep-backlog
)
74 (gnus-backlog-remove-oldest-article))
75 (push ident gnus-backlog-articles
)
76 ;; Insert the new article.
77 (with-current-buffer (gnus-backlog-buffer)
78 (let (buffer-read-only)
79 (goto-char (point-max))
83 (insert-buffer-substring buffer
)
84 ;; Tag the beginning of the article with the ident.
86 (gnus-put-text-property b
(1+ b
) 'gnus-backlog ident
)
87 (gnus-error 3 "Article %d is blank" number
))))))))
89 (defun gnus-backlog-remove-oldest-article ()
90 (with-current-buffer (gnus-backlog-buffer)
91 (goto-char (point-min))
92 (if (zerop (buffer-size))
93 () ; The buffer is empty.
94 (let ((ident (get-text-property (point) 'gnus-backlog
))
96 ;; Remove the ident from the list of articles.
98 (setq gnus-backlog-articles
(delq ident gnus-backlog-articles
)))
99 ;; Delete the article itself.
101 (point) (next-single-property-change
102 (1+ (point)) 'gnus-backlog nil
(point-max)))))))
104 (defun gnus-backlog-remove-article (group number
)
105 "Remove article NUMBER in GROUP from the backlog."
106 (when (numberp number
)
108 (let ((ident (intern (concat group
":" (int-to-string number
))
109 gnus-backlog-hashtb
))
111 (when (memq ident gnus-backlog-articles
)
112 ;; It was in the backlog.
113 (with-current-buffer (gnus-backlog-buffer)
114 (let (buffer-read-only)
115 (when (setq beg
(text-property-any
116 (point-min) (point-max) 'gnus-backlog
118 ;; Find the end (i. e., the beginning of the next article).
120 (next-single-property-change
121 (1+ beg
) 'gnus-backlog
(current-buffer) (point-max)))
122 (delete-region beg end
)
125 (setq gnus-backlog-articles
(delq ident gnus-backlog-articles
)))))))
127 (defun gnus-backlog-request-article (group number
&optional buffer
)
128 (when (and (numberp number
)
129 (not (string-match "^nnvirtual" group
)))
131 (let ((ident (intern (concat group
":" (int-to-string number
))
132 gnus-backlog-hashtb
))
134 (when (memq ident gnus-backlog-articles
)
135 ;; It was in the backlog.
136 (with-current-buffer (gnus-backlog-buffer)
137 (if (not (setq beg
(text-property-any
138 (point-min) (point-max) 'gnus-backlog
140 ;; It wasn't in the backlog after all.
142 (setq gnus-backlog-articles
(delq ident gnus-backlog-articles
)))
143 ;; Find the end (i. e., the beginning of the next article).
145 (next-single-property-change
146 (1+ beg
) 'gnus-backlog
(current-buffer) (point-max)))))
147 (with-current-buffer (or (current-buffer) buffer
)
148 (let ((buffer-read-only nil
))
150 (insert-buffer-substring gnus-backlog-buffer beg end
)))
153 (provide 'gnus-bcklg
)
155 ;;; gnus-bcklg.el ends here