(gnus-article-mode): Turn off the "\ " non-break space.
[bpt/emacs.git] / lisp / gnus / gnus-bcklg.el
CommitLineData
eec82323 1;;; gnus-bcklg.el --- backlog functions for Gnus
23f87bed
MB
2;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003
3;; Free Software Foundation, Inc.
eec82323 4
6748645f 5;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
eec82323
LMI
6;; Keywords: news
7
8;; This file is part of GNU Emacs.
9
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)
13;; any later version.
14
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.
19
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.
24
25;;; Commentary:
26
27;;; Code:
28
7df7482d
RS
29(eval-when-compile (require 'cl))
30
eec82323
LMI
31(require 'gnus)
32
33;;;
34;;; Buffering of read articles.
35;;;
36
37(defvar gnus-backlog-buffer " *Gnus Backlog*")
38(defvar gnus-backlog-articles nil)
39(defvar gnus-backlog-hashtb nil)
40
41(defun gnus-backlog-buffer ()
42 "Return the backlog buffer."
43 (or (get-buffer gnus-backlog-buffer)
44 (save-excursion
6748645f 45 (set-buffer (gnus-get-buffer-create gnus-backlog-buffer))
16409b0b 46 (buffer-disable-undo)
eec82323 47 (setq buffer-read-only t)
eec82323
LMI
48 (get-buffer gnus-backlog-buffer))))
49
50(defun gnus-backlog-setup ()
51 "Initialize backlog variables."
52 (unless gnus-backlog-hashtb
53 (setq gnus-backlog-hashtb (gnus-make-hashtable 1024))))
54
55(gnus-add-shutdown 'gnus-backlog-shutdown 'gnus)
56
57(defun gnus-backlog-shutdown ()
58 "Clear all backlog variables and buffers."
23f87bed 59 (interactive)
eec82323 60 (when (get-buffer gnus-backlog-buffer)
23f87bed 61 (gnus-kill-buffer gnus-backlog-buffer))
eec82323
LMI
62 (setq gnus-backlog-hashtb nil
63 gnus-backlog-articles nil))
64
65(defun gnus-backlog-enter-article (group number buffer)
23f87bed
MB
66 (when (and (numberp number)
67 (not (string-match "^nnvirtual" group)))
68 (gnus-backlog-setup)
69 (let ((ident (intern (concat group ":" (int-to-string number))
70 gnus-backlog-hashtb))
71 b)
72 (if (memq ident gnus-backlog-articles)
73 () ; It's already kept.
eec82323 74 ;; Remove the oldest article, if necessary.
23f87bed
MB
75 (and (numberp gnus-keep-backlog)
76 (>= (length gnus-backlog-articles) gnus-keep-backlog)
eec82323 77 (gnus-backlog-remove-oldest-article))
23f87bed
MB
78 (push ident gnus-backlog-articles)
79 ;; Insert the new article.
80 (save-excursion
81 (set-buffer (gnus-backlog-buffer))
82 (let (buffer-read-only)
83 (goto-char (point-max))
84 (unless (bolp)
85 (insert "\n"))
86 (setq b (point))
87 (insert-buffer-substring buffer)
88 ;; Tag the beginning of the article with the ident.
89 (if (> (point-max) b)
16409b0b 90 (gnus-put-text-property b (1+ b) 'gnus-backlog ident)
23f87bed 91 (gnus-error 3 "Article %d is blank" number))))))))
eec82323
LMI
92
93(defun gnus-backlog-remove-oldest-article ()
94 (save-excursion
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))
100 buffer-read-only)
101 ;; Remove the ident from the list of articles.
102 (when ident
103 (setq gnus-backlog-articles (delq ident gnus-backlog-articles)))
104 ;; Delete the article itself.
105 (delete-region
106 (point) (next-single-property-change
107 (1+ (point)) 'gnus-backlog nil (point-max)))))))
108
109(defun gnus-backlog-remove-article (group number)
110 "Remove article NUMBER in GROUP from the backlog."
111 (when (numberp number)
112 (gnus-backlog-setup)
113 (let ((ident (intern (concat group ":" (int-to-string number))
114 gnus-backlog-hashtb))
115 beg end)
116 (when (memq ident gnus-backlog-articles)
117 ;; It was in the backlog.
118 (save-excursion
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
123 ident))
124 ;; Find the end (i. e., the beginning of the next article).
125 (setq end
126 (next-single-property-change
127 (1+ beg) 'gnus-backlog (current-buffer) (point-max)))
128 (delete-region beg end)
129 ;; Return success.
6748645f
LMI
130 t))
131 (setq gnus-backlog-articles (delq ident gnus-backlog-articles)))))))
eec82323 132
16409b0b 133(defun gnus-backlog-request-article (group number &optional buffer)
23f87bed
MB
134 (when (and (numberp number)
135 (not (string-match "^nnvirtual" group)))
eec82323
LMI
136 (gnus-backlog-setup)
137 (let ((ident (intern (concat group ":" (int-to-string number))
138 gnus-backlog-hashtb))
139 beg end)
140 (when (memq ident gnus-backlog-articles)
141 ;; It was in the backlog.
142 (save-excursion
143 (set-buffer (gnus-backlog-buffer))
144 (if (not (setq beg (text-property-any
145 (point-min) (point-max) 'gnus-backlog
146 ident)))
147 ;; It wasn't in the backlog after all.
148 (ignore
149 (setq gnus-backlog-articles (delq ident gnus-backlog-articles)))
150 ;; Find the end (i. e., the beginning of the next article).
151 (setq end
152 (next-single-property-change
153 (1+ beg) 'gnus-backlog (current-buffer) (point-max)))))
16409b0b
GM
154 (save-excursion
155 (and buffer (set-buffer buffer))
156 (let ((buffer-read-only nil))
157 (erase-buffer)
158 (insert-buffer-substring gnus-backlog-buffer beg end)))
159 t))))
eec82323
LMI
160
161(provide 'gnus-bcklg)
162
ab5796a9 163;;; arch-tag: 66259e56-505a-4bba-8a0d-3552c5b94e39
eec82323 164;;; gnus-bcklg.el ends here