Commit | Line | Data |
---|---|---|
eec82323 | 1 | ;;; gnus-bcklg.el --- backlog functions for Gnus |
e84b4b86 TTN |
2 | |
3 | ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, | |
5df4f04c | 4 | ;; 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. |
eec82323 | 5 | |
6748645f | 6 | ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org> |
eec82323 LMI |
7 | ;; Keywords: news |
8 | ||
9 | ;; This file is part of GNU Emacs. | |
10 | ||
5e809f55 | 11 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
eec82323 | 12 | ;; it under the terms of the GNU General Public License as published by |
5e809f55 GM |
13 | ;; the Free Software Foundation, either version 3 of the License, or |
14 | ;; (at your option) any later version. | |
eec82323 LMI |
15 | |
16 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
5e809f55 | 18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
eec82323 LMI |
19 | ;; GNU General Public License for more details. |
20 | ||
21 | ;; You should have received a copy of the GNU General Public License | |
5e809f55 | 22 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
eec82323 LMI |
23 | |
24 | ;;; Commentary: | |
25 | ||
26 | ;;; Code: | |
27 | ||
7df7482d RS |
28 | (eval-when-compile (require 'cl)) |
29 | ||
eec82323 LMI |
30 | (require 'gnus) |
31 | ||
32 | ;;; | |
33 | ;;; Buffering of read articles. | |
34 | ;;; | |
35 | ||
36 | (defvar gnus-backlog-buffer " *Gnus Backlog*") | |
37 | (defvar gnus-backlog-articles nil) | |
38 | (defvar gnus-backlog-hashtb nil) | |
39 | ||
40 | (defun gnus-backlog-buffer () | |
41 | "Return the backlog buffer." | |
42 | (or (get-buffer gnus-backlog-buffer) | |
20a673b2 | 43 | (with-current-buffer (gnus-get-buffer-create gnus-backlog-buffer) |
16409b0b | 44 | (buffer-disable-undo) |
eec82323 | 45 | (setq buffer-read-only t) |
eec82323 LMI |
46 | (get-buffer gnus-backlog-buffer)))) |
47 | ||
48 | (defun gnus-backlog-setup () | |
49 | "Initialize backlog variables." | |
50 | (unless gnus-backlog-hashtb | |
51 | (setq gnus-backlog-hashtb (gnus-make-hashtable 1024)))) | |
52 | ||
53 | (gnus-add-shutdown 'gnus-backlog-shutdown 'gnus) | |
54 | ||
55 | (defun gnus-backlog-shutdown () | |
56 | "Clear all backlog variables and buffers." | |
23f87bed | 57 | (interactive) |
eec82323 | 58 | (when (get-buffer gnus-backlog-buffer) |
23f87bed | 59 | (gnus-kill-buffer gnus-backlog-buffer)) |
eec82323 LMI |
60 | (setq gnus-backlog-hashtb nil |
61 | gnus-backlog-articles nil)) | |
62 | ||
63 | (defun gnus-backlog-enter-article (group number buffer) | |
23f87bed MB |
64 | (when (and (numberp number) |
65 | (not (string-match "^nnvirtual" group))) | |
66 | (gnus-backlog-setup) | |
67 | (let ((ident (intern (concat group ":" (int-to-string number)) | |
68 | gnus-backlog-hashtb)) | |
69 | b) | |
70 | (if (memq ident gnus-backlog-articles) | |
71 | () ; It's already kept. | |
eec82323 | 72 | ;; Remove the oldest article, if necessary. |
23f87bed MB |
73 | (and (numberp gnus-keep-backlog) |
74 | (>= (length gnus-backlog-articles) gnus-keep-backlog) | |
eec82323 | 75 | (gnus-backlog-remove-oldest-article)) |
23f87bed MB |
76 | (push ident gnus-backlog-articles) |
77 | ;; Insert the new article. | |
20a673b2 | 78 | (with-current-buffer (gnus-backlog-buffer) |
23f87bed MB |
79 | (let (buffer-read-only) |
80 | (goto-char (point-max)) | |
81 | (unless (bolp) | |
82 | (insert "\n")) | |
83 | (setq b (point)) | |
84 | (insert-buffer-substring buffer) | |
85 | ;; Tag the beginning of the article with the ident. | |
86 | (if (> (point-max) b) | |
16409b0b | 87 | (gnus-put-text-property b (1+ b) 'gnus-backlog ident) |
23f87bed | 88 | (gnus-error 3 "Article %d is blank" number)))))))) |
eec82323 LMI |
89 | |
90 | (defun gnus-backlog-remove-oldest-article () | |
20a673b2 | 91 | (with-current-buffer (gnus-backlog-buffer) |
eec82323 LMI |
92 | (goto-char (point-min)) |
93 | (if (zerop (buffer-size)) | |
94 | () ; The buffer is empty. | |
95 | (let ((ident (get-text-property (point) 'gnus-backlog)) | |
96 | buffer-read-only) | |
97 | ;; Remove the ident from the list of articles. | |
98 | (when ident | |
99 | (setq gnus-backlog-articles (delq ident gnus-backlog-articles))) | |
100 | ;; Delete the article itself. | |
101 | (delete-region | |
102 | (point) (next-single-property-change | |
103 | (1+ (point)) 'gnus-backlog nil (point-max))))))) | |
104 | ||
105 | (defun gnus-backlog-remove-article (group number) | |
106 | "Remove article NUMBER in GROUP from the backlog." | |
107 | (when (numberp number) | |
108 | (gnus-backlog-setup) | |
109 | (let ((ident (intern (concat group ":" (int-to-string number)) | |
110 | gnus-backlog-hashtb)) | |
111 | beg end) | |
112 | (when (memq ident gnus-backlog-articles) | |
113 | ;; It was in the backlog. | |
20a673b2 | 114 | (with-current-buffer (gnus-backlog-buffer) |
eec82323 LMI |
115 | (let (buffer-read-only) |
116 | (when (setq beg (text-property-any | |
117 | (point-min) (point-max) 'gnus-backlog | |
118 | ident)) | |
119 | ;; Find the end (i. e., the beginning of the next article). | |
120 | (setq end | |
121 | (next-single-property-change | |
122 | (1+ beg) 'gnus-backlog (current-buffer) (point-max))) | |
123 | (delete-region beg end) | |
124 | ;; Return success. | |
6748645f LMI |
125 | t)) |
126 | (setq gnus-backlog-articles (delq ident gnus-backlog-articles))))))) | |
eec82323 | 127 | |
16409b0b | 128 | (defun gnus-backlog-request-article (group number &optional buffer) |
23f87bed MB |
129 | (when (and (numberp number) |
130 | (not (string-match "^nnvirtual" group))) | |
eec82323 LMI |
131 | (gnus-backlog-setup) |
132 | (let ((ident (intern (concat group ":" (int-to-string number)) | |
133 | gnus-backlog-hashtb)) | |
134 | beg end) | |
135 | (when (memq ident gnus-backlog-articles) | |
136 | ;; It was in the backlog. | |
20a673b2 | 137 | (with-current-buffer (gnus-backlog-buffer) |
eec82323 LMI |
138 | (if (not (setq beg (text-property-any |
139 | (point-min) (point-max) 'gnus-backlog | |
140 | ident))) | |
141 | ;; It wasn't in the backlog after all. | |
142 | (ignore | |
143 | (setq gnus-backlog-articles (delq ident gnus-backlog-articles))) | |
144 | ;; Find the end (i. e., the beginning of the next article). | |
145 | (setq end | |
146 | (next-single-property-change | |
147 | (1+ beg) 'gnus-backlog (current-buffer) (point-max))))) | |
20a673b2 | 148 | (with-current-buffer (or (current-buffer) buffer) |
16409b0b GM |
149 | (let ((buffer-read-only nil)) |
150 | (erase-buffer) | |
151 | (insert-buffer-substring gnus-backlog-buffer beg end))) | |
152 | t)))) | |
eec82323 LMI |
153 | |
154 | (provide 'gnus-bcklg) | |
155 | ||
156 | ;;; gnus-bcklg.el ends here |