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