Mercurial > emacs
annotate lisp/gnus/gnus-bcklg.el @ 86444:49cdf6b61ecb
*** empty log message ***
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Mon, 26 Nov 2007 03:49:23 +0000 |
parents | 24202b793a08 |
children | 1cb31606209f f55f9811f5d7 |
rev | line source |
---|---|
17493 | 1 ;;; gnus-bcklg.el --- backlog functions for Gnus |
64754
fafd692d1e40
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64085
diff
changeset
|
2 |
fafd692d1e40
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64085
diff
changeset
|
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, |
75347 | 4 ;; 2005, 2006, 2007 Free Software Foundation, Inc. |
17493 | 5 |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19493
diff
changeset
|
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org> |
17493 | 7 ;; Keywords: news |
8 | |
9 ;; This file is part of GNU Emacs. | |
10 | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
78224
24202b793a08
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
75347
diff
changeset
|
13 ;; the Free Software Foundation; either version 3, or (at your option) |
17493 | 14 ;; any later version. |
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 | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
64085 | 23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
24 ;; Boston, MA 02110-1301, USA. | |
17493 | 25 |
26 ;;; Commentary: | |
27 | |
28 ;;; Code: | |
29 | |
19493
8d840c4548c0
Require cl at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
17493
diff
changeset
|
30 (eval-when-compile (require 'cl)) |
8d840c4548c0
Require cl at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
17493
diff
changeset
|
31 |
17493 | 32 (require 'gnus) |
33 | |
34 ;;; | |
35 ;;; Buffering of read articles. | |
36 ;;; | |
37 | |
38 (defvar gnus-backlog-buffer " *Gnus Backlog*") | |
39 (defvar gnus-backlog-articles nil) | |
40 (defvar gnus-backlog-hashtb nil) | |
41 | |
42 (defun gnus-backlog-buffer () | |
43 "Return the backlog buffer." | |
44 (or (get-buffer gnus-backlog-buffer) | |
45 (save-excursion | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19493
diff
changeset
|
46 (set-buffer (gnus-get-buffer-create gnus-backlog-buffer)) |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
47 (buffer-disable-undo) |
17493 | 48 (setq buffer-read-only t) |
49 (get-buffer gnus-backlog-buffer)))) | |
50 | |
51 (defun gnus-backlog-setup () | |
52 "Initialize backlog variables." | |
53 (unless gnus-backlog-hashtb | |
54 (setq gnus-backlog-hashtb (gnus-make-hashtable 1024)))) | |
55 | |
56 (gnus-add-shutdown 'gnus-backlog-shutdown 'gnus) | |
57 | |
58 (defun gnus-backlog-shutdown () | |
59 "Clear all backlog variables and buffers." | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
60 (interactive) |
17493 | 61 (when (get-buffer gnus-backlog-buffer) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
62 (gnus-kill-buffer gnus-backlog-buffer)) |
17493 | 63 (setq gnus-backlog-hashtb nil |
64 gnus-backlog-articles nil)) | |
65 | |
66 (defun gnus-backlog-enter-article (group number buffer) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
67 (when (and (numberp number) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
68 (not (string-match "^nnvirtual" group))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
69 (gnus-backlog-setup) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
70 (let ((ident (intern (concat group ":" (int-to-string number)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
71 gnus-backlog-hashtb)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
72 b) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
73 (if (memq ident gnus-backlog-articles) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
74 () ; It's already kept. |
17493 | 75 ;; Remove the oldest article, if necessary. |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
76 (and (numberp gnus-keep-backlog) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
77 (>= (length gnus-backlog-articles) gnus-keep-backlog) |
17493 | 78 (gnus-backlog-remove-oldest-article)) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
79 (push ident gnus-backlog-articles) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
80 ;; Insert the new article. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
81 (save-excursion |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
82 (set-buffer (gnus-backlog-buffer)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
83 (let (buffer-read-only) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
84 (goto-char (point-max)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
85 (unless (bolp) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
86 (insert "\n")) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
87 (setq b (point)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
88 (insert-buffer-substring buffer) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
89 ;; Tag the beginning of the article with the ident. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
90 (if (> (point-max) b) |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
91 (gnus-put-text-property b (1+ b) 'gnus-backlog ident) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
92 (gnus-error 3 "Article %d is blank" number)))))))) |
17493 | 93 |
94 (defun gnus-backlog-remove-oldest-article () | |
95 (save-excursion | |
96 (set-buffer (gnus-backlog-buffer)) | |
97 (goto-char (point-min)) | |
98 (if (zerop (buffer-size)) | |
99 () ; The buffer is empty. | |
100 (let ((ident (get-text-property (point) 'gnus-backlog)) | |
101 buffer-read-only) | |
102 ;; Remove the ident from the list of articles. | |
103 (when ident | |
104 (setq gnus-backlog-articles (delq ident gnus-backlog-articles))) | |
105 ;; Delete the article itself. | |
106 (delete-region | |
107 (point) (next-single-property-change | |
108 (1+ (point)) 'gnus-backlog nil (point-max))))))) | |
109 | |
110 (defun gnus-backlog-remove-article (group number) | |
111 "Remove article NUMBER in GROUP from the backlog." | |
112 (when (numberp number) | |
113 (gnus-backlog-setup) | |
114 (let ((ident (intern (concat group ":" (int-to-string number)) | |
115 gnus-backlog-hashtb)) | |
116 beg end) | |
117 (when (memq ident gnus-backlog-articles) | |
118 ;; It was in the backlog. | |
119 (save-excursion | |
120 (set-buffer (gnus-backlog-buffer)) | |
121 (let (buffer-read-only) | |
122 (when (setq beg (text-property-any | |
123 (point-min) (point-max) 'gnus-backlog | |
124 ident)) | |
125 ;; Find the end (i. e., the beginning of the next article). | |
126 (setq end | |
127 (next-single-property-change | |
128 (1+ beg) 'gnus-backlog (current-buffer) (point-max))) | |
129 (delete-region beg end) | |
130 ;; Return success. | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19493
diff
changeset
|
131 t)) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19493
diff
changeset
|
132 (setq gnus-backlog-articles (delq ident gnus-backlog-articles))))))) |
17493 | 133 |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
134 (defun gnus-backlog-request-article (group number &optional buffer) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
135 (when (and (numberp number) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
136 (not (string-match "^nnvirtual" group))) |
17493 | 137 (gnus-backlog-setup) |
138 (let ((ident (intern (concat group ":" (int-to-string number)) | |
139 gnus-backlog-hashtb)) | |
140 beg end) | |
141 (when (memq ident gnus-backlog-articles) | |
142 ;; It was in the backlog. | |
143 (save-excursion | |
144 (set-buffer (gnus-backlog-buffer)) | |
145 (if (not (setq beg (text-property-any | |
146 (point-min) (point-max) 'gnus-backlog | |
147 ident))) | |
148 ;; It wasn't in the backlog after all. | |
149 (ignore | |
150 (setq gnus-backlog-articles (delq ident gnus-backlog-articles))) | |
151 ;; Find the end (i. e., the beginning of the next article). | |
152 (setq end | |
153 (next-single-property-change | |
154 (1+ beg) 'gnus-backlog (current-buffer) (point-max))))) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
155 (save-excursion |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
156 (and buffer (set-buffer buffer)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
157 (let ((buffer-read-only nil)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
158 (erase-buffer) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
159 (insert-buffer-substring gnus-backlog-buffer beg end))) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
160 t)))) |
17493 | 161 |
162 (provide 'gnus-bcklg) | |
163 | |
52401 | 164 ;;; arch-tag: 66259e56-505a-4bba-8a0d-3552c5b94e39 |
17493 | 165 ;;; gnus-bcklg.el ends here |