;;; erc-log.el --- Logging facilities for ERC.
-;; Copyright (C) 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
+;; Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
;; Author: Lawrence Mitchell <wence@gmx.li>
;; Keywords: IRC, chat, client, Internet, logging
;; This file is part of GNU Emacs.
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs 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 3, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; 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., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
`emacs-mule', or `iso-2022-7bit'."
:group 'erc-log)
+(defcustom erc-log-filter-function nil
+ "*If non-nil, pass text through the given function before writing it to
+a log file.
+
+The function should take one argument, which is the text to filter."
+ :group 'erc-log
+ :type '(choice (function "Function")
+ (const :tag "No filtering" nil)))
+
+
;;;###autoload (autoload 'erc-log-mode "erc-log" nil t)
(define-erc-module log nil
"Automatically logs things you receive on IRC into files.
Since automatic logging is not always a Good Thing (especially if
people say things in different coding systems), you can turn logging
-behaviour on and off with the variable `erc-enable-logging', which can
-also be a predicate function. To only log when you are not set away, use:
+behavior on and off with the variable `erc-enable-logging', which can
+also be a predicate function. To only log when you are not set away, use:
\(setq erc-enable-logging
(lambda (buffer)
(with-current-buffer buffer
(auto-save-mode -1)
(setq buffer-file-name nil)
- (cond ((boundp 'write-file-functions)
- (set (make-local-variable 'write-file-functions)
- '(erc-save-buffer-in-logs)))
- ((boundp 'local-write-file-hooks)
- (setq local-write-file-hooks '(erc-save-buffer-in-logs)))
- (t
- (set (make-local-variable 'write-file-hooks)
- '(erc-save-buffer-in-logs))))
+ (erc-set-write-file-functions '(erc-save-buffer-in-logs))
(when erc-log-insert-log-on-open
(ignore-errors (insert-file-contents (erc-current-logfile))
(move-marker erc-last-saved-position
(or buffer (setq buffer (current-buffer)))
(when (erc-logging-enabled buffer)
(let ((file (erc-current-logfile buffer))
- (coding-system-for-write erc-log-file-coding-system))
+ (coding-system erc-log-file-coding-system)
+ (inhibit-clash-detection t)) ; needed for XEmacs
(save-excursion
(with-current-buffer buffer
(save-restriction
(widen)
- ;; early on in the initalisation, don't try and write the log out
+ ;; early on in the initialization, don't try and write the log out
(when (and (markerp erc-last-saved-position)
(> erc-insert-marker (1+ erc-last-saved-position)))
- (write-region (1+ (marker-position erc-last-saved-position))
- (marker-position erc-insert-marker)
- file t 'nomessage)
+ (let ((start (1+ (marker-position erc-last-saved-position)))
+ (end (marker-position erc-insert-marker)))
+ (if (functionp erc-log-filter-function)
+ (let ((text (buffer-substring start end)))
+ (with-temp-buffer
+ (insert (funcall erc-log-filter-function text))
+ (let ((coding-system-for-write coding-system))
+ (write-region (point-min) (point-max)
+ file t 'nomessage))))
+ (let ((coding-system-for-write coding-system))
+ (write-region start end file t 'nomessage))))
(if (and erc-truncate-buffer-on-save (interactive-p))
(progn
(let ((inhibit-read-only t)) (erase-buffer))