--- /dev/null
+;;; riece-shrink-buffer.el --- free old IRC messages to save memory usage
+;; Copyright (C) 1998-2005 Daiki Ueno
+
+;; Author: Daiki Ueno <ueno@unixuser.org>
+;; Created: 1998-09-28
+;; Keywords: IRC, riece
+
+;; This file is part of Riece.
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING. If not, write to the
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
+
+;;; Commentary:
+
+;; NOTE: This is an add-on module for Riece.
+
+;;; Code:
+
+(require 'riece-globals)
+
+(defgroup riece-shrink-buffer nil
+ "Free old IRC messages to save memory usage."
+ :prefix "riece-"
+ :group 'riece)
+
+(defcustom riece-shrink-buffer-idle-time-delay 5
+ "Number of idle seconds to wait before shrinking channel buffers."
+ :type 'integer
+ :group 'riece-shrink-buffer)
+
+(defcustom riece-max-buffer-size 65536
+ "Maximum size of channel buffers."
+ :type '(integer :tag "Number of characters")
+ :group 'riece-shrink-buffer)
+
+(defcustom riece-shrink-buffer-remove-chars (/ riece-max-buffer-size 2)
+ "Number of chars removed when shrinking channel buffers."
+ :type 'integer
+ :group 'riece-shrink-buffer)
+
+(defvar riece-shrink-buffer-idle-timer nil
+ "Timer object to periodically shrink channel buffers.")
+
+(defconst riece-shrink-buffer-description
+ "Free old IRC messages to save memory usage.")
+
+(defvar riece-shrink-buffer-enabled nil)
+
+(defun riece-shrink-buffer-idle-timer ()
+ (let ((buffers riece-buffer-list))
+ (while buffers
+ (if (and riece-shrink-buffer-enabled
+ (buffer-live-p (car buffers))
+ (eq (derived-mode-class
+ (with-current-buffer (car buffers)
+ major-mode))
+ 'riece-dialogue-mode))
+ (riece-shrink-buffer (car buffers)))
+ (setq buffers (cdr buffers)))))
+
+(defun riece-shrink-buffer (buffer)
+ (save-excursion
+ (set-buffer buffer)
+ (goto-char (point-min))
+ (while (> (buffer-size) riece-max-buffer-size)
+ (let* ((inhibit-read-only t)
+ buffer-read-only
+ (end (progn
+ (goto-char riece-shrink-buffer-remove-chars)
+ (beginning-of-line 2)
+ (point)))
+ (overlays (riece-overlays-in (point-min) end)))
+ (while overlays
+ (riece-delete-overlay (car overlays))
+ (setq overlays (cdr overlays)))
+ (delete-region (point-min) end)))))
+
+(defun riece-shrink-buffer-startup-hook ()
+ (setq riece-shrink-buffer-idle-timer
+ (riece-run-with-idle-timer
+ riece-shrink-buffer-idle-time-delay t
+ 'riece-shrink-buffer-idle-timer)))
+
+(defun riece-shrink-buffer-exit-hook ()
+ (if riece-shrink-buffer-idle-timer
+ (riece-cancel-timer riece-shrink-buffer-idle-timer)))
+
+(defun riece-shrink-buffer-insinuate ()
+ (add-hook 'riece-startup-hook
+ 'riece-shrink-buffer-startup-hook)
+ ;; Reset the timer since riece-shrink-buffer-insinuate will be
+ ;; called before running riece-startup-hook.
+ (unless riece-shrink-buffer-idle-timer
+ (riece-shrink-buffer-startup-hook))
+ (add-hook 'riece-exit-hook
+ 'riece-shrink-buffer-exit-hook))
+
+(defun riece-shrink-buffer-uninstall ()
+ (riece-shrink-buffer-exit-hook)
+ (remove-hook 'riece-startup-hook
+ 'riece-shrink-buffer-startup-hook)
+ (remove-hook 'riece-exit-hook
+ 'riece-shrink-buffer-exit-hook))
+
+(defun riece-shrink-buffer-enable ()
+ (setq riece-shrink-buffer-enabled t))
+
+(defun riece-shrink-buffer-disable ()
+ (setq riece-shrink-buffer-enabled nil))
+
+(provide 'riece-shrink-buffer)
+
+;;; riece-shrink-buffer.el ends here
(riece-temp-buffer " *Temp*")
(riece-debug-buffer " *Debug*")))
-(defvar riece-shrink-buffer-idle-timer nil
- "Timer object to periodically shrink channel buffers.")
-
(defvar riece-select-keys
`("#" riece-command-switch-to-channel-by-number
"1" riece-command-switch-to-channel-by-number-1
(if (stringp riece-server)
(setq riece-server (riece-server-name-to-server riece-server)))
(riece-create-buffers)
- (if riece-max-buffer-size
- (setq riece-shrink-buffer-idle-timer
- (riece-run-with-idle-timer
- riece-shrink-buffer-idle-time-delay t
- (lambda ()
- (let ((buffers riece-buffer-list))
- (while buffers
- (if (buffer-live-p (car buffers))
- (if (eq (derived-mode-class
- (with-current-buffer (car buffers)
- major-mode))
- 'riece-dialogue-mode)
- (riece-shrink-buffer (car buffers)))
- (delq (car buffers) riece-buffer-list))
- (setq buffers (cdr buffers))))))))
(switch-to-buffer riece-command-buffer)
(riece-display-connect-signals)
(riece-redisplay-buffers)
(message "%s" (substitute-command-keys
"Type \\[describe-mode] for help")))))
-(defun riece-shrink-buffer (buffer)
- (save-excursion
- (set-buffer buffer)
- (goto-char (point-min))
- (while (> (buffer-size) riece-max-buffer-size)
- (let* ((inhibit-read-only t)
- buffer-read-only
- (end (progn
- (goto-char riece-shrink-buffer-remove-chars)
- (beginning-of-line 2)
- (point)))
- (overlays (riece-overlays-in (point-min) end)))
- (while overlays
- (riece-delete-overlay (car overlays))
- (setq overlays (cdr overlays)))
- (delete-region (point-min) end)))))
-
(defun riece-exit ()
(if riece-save-variables-are-dirty
(riece-save-variables-files))
(buffer-live-p (car riece-buffer-list)))
(funcall riece-buffer-dispose-function (car riece-buffer-list)))
(setq riece-buffer-list (cdr riece-buffer-list)))
- (if riece-shrink-buffer-idle-timer
- (riece-cancel-timer riece-shrink-buffer-idle-timer))
(riece-clear-signal-slots)
(setq riece-server nil
riece-current-channels nil