]> code.delx.au - gnu-emacs/blobdiff - lisp/erc/erc-log.el
Fix typos.
[gnu-emacs] / lisp / erc / erc-log.el
index 856f1dca89e2fc85d6a2739006b1f2d26d0b7c24..7c9c8442e1d817fa17575a9170de523cae4a070b 100644 (file)
@@ -1,6 +1,6 @@
 ;;; 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
@@ -21,9 +21,7 @@
 ;; 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:
 
@@ -205,6 +203,16 @@ This should ideally, be a \"catch-all\" coding system, like
 `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.
@@ -214,8 +222,8 @@ format is defined through a formatting function on
 
 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)
@@ -258,14 +266,7 @@ The current buffer is given by 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
@@ -405,17 +406,26 @@ You can save every individual message by putting this function on
   (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))