* riece-options.el (riece-shrink-buffer-idle-time-delay):
authorueno <ueno>
Sat, 27 Aug 2005 08:27:42 +0000 (08:27 +0000)
committerueno <ueno>
Sat, 27 Aug 2005 08:27:42 +0000 (08:27 +0000)
Abolished; moved to riece-shrink-buffer.el.
(riece-max-buffer-size): Ditto.
(riece-shrink-buffer-remove-chars): Ditto.

* riece.el (riece-shrink-buffer-idle-timer): Abolished; moved to
riece-shrink-buffer.el.
(riece): Don't set riece-shrink-buffer-idle-timer here.
(riece-exit): Don't cancel riece-shrink-buffer-idle-timer here.

* riece-shrink-buffer.el: New add-on.
* riece-addon-modules.el (riece-addon-modules): Added
riece-shrink-buffer.
* Makefile.am (EXTRA_DIST): Added riece-shrink-buffer.el.

lisp/ChangeLog
lisp/Makefile.am
lisp/riece-addon-modules.el
lisp/riece-options.el
lisp/riece-shrink-buffer.el [new file with mode: 0644]
lisp/riece.el

index 2b34cf0..e92f700 100644 (file)
@@ -1,5 +1,22 @@
 2005-08-27  Daiki Ueno  <ueno@unixuser.org>
 
+       * riece-options.el (riece-shrink-buffer-idle-time-delay):
+       Abolished; moved to riece-shrink-buffer.el.
+       (riece-max-buffer-size): Ditto.
+       (riece-shrink-buffer-remove-chars): Ditto.
+
+       * riece.el (riece-shrink-buffer-idle-timer): Abolished; moved to
+       riece-shrink-buffer.el.
+       (riece): Don't set riece-shrink-buffer-idle-timer here.
+       (riece-exit): Don't cancel riece-shrink-buffer-idle-timer here.
+
+       * riece-shrink-buffer.el: New add-on.
+       * riece-addon-modules.el (riece-addon-modules): Added
+       riece-shrink-buffer.
+       * Makefile.am (EXTRA_DIST): Added riece-shrink-buffer.el.
+
+2005-08-27  Daiki Ueno  <ueno@unixuser.org>
+
        * riece-highlight.el (riece-highlight-uninstall): Use
        riece-remprop instead of remprop.
 
index 281c79b..5b7f1b6 100644 (file)
@@ -17,7 +17,7 @@ EXTRA_DIST = COMPILE ChangeLog ChangeLog.Liece \
        riece-ctlseq.el riece-ignore.el riece-hangman.el riece-biff.el \
        riece-kakasi.el riece-foolproof.el riece-yank.el riece-toolbar.el \
        riece-eval.el riece-google.el riece-keepalive.el riece-eval-ruby.el \
-       url-riece.el \
+       riece-shrink-buffer.el url-riece.el \
        riece-command-previous-channel.xpm riece-command-next-channel.xpm \
        riece-submit-bug-report.xpm \
        server.rb aproxy.rb
index 7b9adb7..7cb2107 100644 (file)
@@ -25,6 +25,7 @@
     (riece-mini . "Use Riece only on the minibuffer.")
     ;;(riece-ndcc . "DCC file sending protocol support (written in elisp.)")
     (riece-rdcc . "DCC file sending protocol support (written in Ruby.)")
+    (riece-shrink-buffer . "Free old IRC messages to save memory usage.")
     (riece-skk-kakutei . "Remove SKK's preedit mark before sending messages.")
     (riece-toolbar . "Display toolbar icons.")
     (riece-unread . "Mark channels where new messages arrived.")
index 7e6815b..8330ff5 100644 (file)
@@ -310,22 +310,6 @@ way is to put Riece variables on .emacs or file loaded from there."
   :type 'function
   :group 'riece-options)
 
-(defcustom riece-shrink-buffer-idle-time-delay 5
-  "Number of idle seconds to wait before shrinking channel buffers."
-  :type 'integer
-  :group 'riece-options)
-
-(defcustom riece-max-buffer-size nil
-  "Maximum size of channel buffers."
-  :type '(radio (integer :tag "Number of characters")
-               (const nil))
-  :group 'riece-options)
-
-(defcustom riece-shrink-buffer-remove-chars (/ riece-max-send-size 2)
-  "Number of chars removed when shrinking channel buffers."
-  :type 'integer
-  :group 'riece-options)
-
 (defcustom riece-format-time-function #'current-time-string
   "Function to convert the specified time to the human readable form."
   :type 'function
diff --git a/lisp/riece-shrink-buffer.el b/lisp/riece-shrink-buffer.el
new file mode 100644 (file)
index 0000000..020d06f
--- /dev/null
@@ -0,0 +1,125 @@
+;;; 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
index 2fe80de..adcd0c4 100644 (file)
@@ -62,9 +62,6 @@
     (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
@@ -290,21 +287,6 @@ If optional argument CONFIRM is non-nil, ask which IRC server to connect."
     (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)
@@ -333,23 +315,6 @@ If optional argument CONFIRM is non-nil, ask which IRC server to connect."
       (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))
@@ -358,8 +323,6 @@ If optional argument CONFIRM is non-nil, ask which IRC server to connect."
             (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