Merge remote-tracking branch 'sourceforge/master'
[emacs-jabber.git] / jabber-truncate.el
blobbbb7b5129bb9bddc650f119ce87fe5e7cbcd6b49
1 ;; jabber-truncate.el - cleanup top lines in chatbuffers
3 ;; Copyright (C) 2007 - Kirill A. Korinskiy - catap@catap.ru
5 ;; This file is a part of jabber.el.
7 ;; This program is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 2 of the License, or
10 ;; (at your option) any later version.
12 ;; This program is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program; if not, write to the Free Software
19 ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 (require 'jabber-chat)
22 (require 'jabber-alert)
24 (require 'cl)
26 (defvar jabber-log-lines-to-keep 1000
27 "Maximum number of lines in chat buffer")
29 (defun jabber-truncate-top (buffer &optional ewoc)
30 "Clean old history from a chat BUFFER.
31 Optional EWOC is ewoc-widget to work. Default is jabber-chat-ewoc
32 `jabber-log-lines-to-keep' specifies the number of lines to
33 keep.
35 Note that this might interfer with
36 `jabber-chat-display-more-backlog': you ask for more history, you
37 get it, and then it just gets deleted."
38 (interactive)
39 (let* ((inhibit-read-only t)
40 (work-ewoc (if ewoc ewoc jabber-chat-ewoc))
41 (delete-before
42 ;; go back one node, to make this function "idempotent"
43 (ewoc-prev
44 work-ewoc
45 (ewoc-locate work-ewoc
46 (save-excursion
47 (set-buffer buffer)
48 (goto-char (point-max))
49 (forward-line (- jabber-log-lines-to-keep))
50 (point))))))
51 (while delete-before
52 (setq delete-before
53 (prog1
54 (ewoc-prev work-ewoc delete-before)
55 (ewoc-delete work-ewoc delete-before))))))
57 (defun jabber-truncate-muc (nick group buffer text proposed-alert)
58 "Clean old history from MUC buffers.
59 `jabber-log-lines-to-keep' specifies the number of lines to
60 keep."
61 (jabber-truncate-top buffer))
63 (defun jabber-truncate-chat (from buffer text proposed-alert)
64 "Clean old history from chat buffers.
65 `jabber-log-lines-to-keep' specifies the number of lines to
66 keep.
68 Note that this might interfer with
69 `jabber-chat-display-more-backlog': you ask for more history, you
70 get it, and then it just gets deleted."
71 (jabber-truncate-top buffer))
73 (provide 'jabber-truncate)
75 ;; arch-tag: 3d1e3428-f598-11db-a314-000a95c2fcd0