Mercurial > emacs
annotate lisp/gnus/gnus-bcklg.el @ 82951:0fde48feb604
Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
author | Andreas Schwab <schwab@suse.de> |
---|---|
date | Thu, 22 Jul 2004 16:45:51 +0000 |
parents | 695cf19ef79e |
children | 18a818a2ee7c cce1c0ee76ee |
rev | line source |
---|---|
17493 | 1 ;;; gnus-bcklg.el --- backlog functions for Gnus |
82951
0fde48feb604
Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
52401
diff
changeset
|
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003 |
0fde48feb604
Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
52401
diff
changeset
|
3 ;; Free Software Foundation, Inc. |
17493 | 4 |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19493
diff
changeset
|
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org> |
17493 | 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 | |
19493
8d840c4548c0
Require cl at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
17493
diff
changeset
|
29 (eval-when-compile (require 'cl)) |
8d840c4548c0
Require cl at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
17493
diff
changeset
|
30 |
17493 | 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 | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19493
diff
changeset
|
45 (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
|
46 (buffer-disable-undo) |
17493 | 47 (setq buffer-read-only t) |
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." | |
82951
0fde48feb604
Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
52401
diff
changeset
|
59 (interactive) |
17493 | 60 (when (get-buffer gnus-backlog-buffer) |
82951
0fde48feb604
Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
52401
diff
changeset
|
61 (gnus-kill-buffer gnus-backlog-buffer)) |
17493 | 62 (setq gnus-backlog-hashtb nil |
63 gnus-backlog-articles nil)) | |
64 | |
65 (defun gnus-backlog-enter-article (group number buffer) | |
82951
0fde48feb604
Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
52401
diff
changeset
|
66 (when (and (numberp number) |
0fde48feb604
Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
52401
diff
changeset
|
67 (not (string-match "^nnvirtual" group))) |
0fde48feb604
Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
52401
diff
changeset
|
68 (gnus-backlog-setup) |
0fde48feb604
Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
52401
diff
changeset
|
69 (let ((ident (intern (concat group ":" (int-to-string number)) |
0fde48feb604
Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
52401
diff
changeset
|
70 gnus-backlog-hashtb)) |
0fde48feb604
Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
52401
diff
changeset
|
71 b) |
0fde48feb604
Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
52401
diff
changeset
|
72 (if (memq ident gnus-backlog-articles) |
0fde48feb604
Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
52401
diff
changeset
|
73 () ; It's already kept. |
17493 | 74 ;; Remove the oldest article, if necessary. |
82951
0fde48feb604
Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
52401
diff
changeset
|
75 (and (numberp gnus-keep-backlog) |
0fde48feb604
Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
52401
diff
changeset
|
76 (>= (length gnus-backlog-articles) gnus-keep-backlog) |
17493 | 77 (gnus-backlog-remove-oldest-article)) |
82951
0fde48feb604
Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
52401
diff
changeset
|
78 (push ident gnus-backlog-articles) |
0fde48feb604
Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
52401
diff
changeset
|
79 ;; Insert the new article. |
0fde48feb604
Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
52401
diff
changeset
|
80 (save-excursion |
0fde48feb604
Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
52401
diff
changeset
|
81 (set-buffer (gnus-backlog-buffer)) |
0fde48feb604
Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
52401
diff
changeset
|
82 (let (buffer-read-only) |
0fde48feb604
Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
52401
diff
changeset
|
83 (goto-char (point-max)) |
0fde48feb604
Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
52401
diff
changeset
|
84 (unless (bolp) |
0fde48feb604
Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
52401
diff
changeset
|
85 (insert "\n")) |
0fde48feb604
Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
52401
diff
changeset
|
86 (setq b (point)) |
0fde48feb604
Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
52401
diff
changeset
|
87 (insert-buffer-substring buffer) |
0fde48feb604
Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
52401
diff
changeset
|
88 ;; Tag the beginning of the article with the ident. |
0fde48feb604
Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
52401
diff
changeset
|
89 (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
|
90 (gnus-put-text-property b (1+ b) 'gnus-backlog ident) |
82951
0fde48feb604
Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
52401
diff
changeset
|
91 (gnus-error 3 "Article %d is blank" number)))))))) |
17493 | 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. | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19493
diff
changeset
|
130 t)) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19493
diff
changeset
|
131 (setq gnus-backlog-articles (delq ident gnus-backlog-articles))))))) |
17493 | 132 |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
133 (defun gnus-backlog-request-article (group number &optional buffer) |
82951
0fde48feb604
Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
52401
diff
changeset
|
134 (when (and (numberp number) |
0fde48feb604
Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
52401
diff
changeset
|
135 (not (string-match "^nnvirtual" group))) |
17493 | 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))))) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
154 (save-excursion |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
155 (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
|
156 (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
|
157 (erase-buffer) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
158 (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
|
159 t)))) |
17493 | 160 |
161 (provide 'gnus-bcklg) | |
162 | |
52401 | 163 ;;; arch-tag: 66259e56-505a-4bba-8a0d-3552c5b94e39 |
17493 | 164 ;;; gnus-bcklg.el ends here |