]> code.delx.au - gnu-emacs/blobdiff - lisp/erc/erc-log.el
Add 2007 to copyright years.
[gnu-emacs] / lisp / erc / erc-log.el
index 418e45060bdd219bcacd05a07606dc9531dbce57..22c9b3622d3eb83fee73bd20f85b1b976600d6bd 100644 (file)
@@ -1,6 +1,6 @@
 ;;; erc-log.el --- Logging facilities for ERC.
 
-;; Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+;; Copyright (C) 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
 
 ;; Author: Lawrence Mitchell <wence@gmx.li>
 ;; Keywords: IRC, chat, client, Internet, logging
 ;;
 ;; (require 'erc-log)
 ;;
-;; You may optionally want the following code, to save all ERC buffers
-;; without confirmation when exiting emacs:
-;;
-;; (defadvice save-buffers-kill-emacs (before save-logs (&rest args) activate)
-;;  (save-some-buffers t (lambda ()
-;;                         (when (and (eq major-mode 'erc-mode)
-;;                                    (not (null buffer-file-name))) t))))
-;;
 ;; If you only want to save logs for some buffers, customise the
 ;; variable `erc-enable-logging'.
 
@@ -71,8 +63,6 @@
 ;; markers.
 
 ;;; TODO:
-;; * Erc needs a generalised make-safe-file-name function, so that
-;;   generated file names don't contain any invalid file characters.
 ;;
 ;; * Really, we need to lock the logfiles somehow, so that if a user
 ;;   is running multiple emacsen and/or on the same channel as more
@@ -215,6 +205,7 @@ also be a predicate function. To only log when you are not set away, use:
      (add-hook 'erc-send-post-hook 'erc-save-buffer-in-logs))
    (add-hook 'erc-kill-buffer-hook 'erc-save-buffer-in-logs)
    (add-hook 'erc-kill-channel-hook 'erc-save-buffer-in-logs)
+   (add-hook 'kill-emacs-hook 'erc-log-save-all-buffers)
    (add-hook 'erc-quit-hook 'erc-conditional-save-queries)
    (add-hook 'erc-part-hook 'erc-conditional-save-buffer)
    ;; append, so that 'erc-initialize-log-marker runs first
@@ -227,6 +218,7 @@ also be a predicate function. To only log when you are not set away, use:
    (remove-hook 'erc-send-post-hook 'erc-save-buffer-in-logs)
    (remove-hook 'erc-kill-buffer-hook 'erc-save-buffer-in-logs)
    (remove-hook 'erc-kill-channel-hook 'erc-save-buffer-in-logs)
+   (remove-hook 'kill-emacs-hook 'erc-log-save-all-buffers)
    (remove-hook 'erc-quit-hook 'erc-conditional-save-queries)
    (remove-hook 'erc-part-hook 'erc-conditional-save-buffer)
    (remove-hook 'erc-connect-pre-hook 'erc-log-setup-logging)
@@ -265,7 +257,7 @@ Returns nil iff `erc-server-buffer-p' returns t."
       (not (erc-server-buffer-p)))))
 
 (defun erc-save-query-buffers (process)
-  "Save all buffers process."
+  "Save all buffers of the given PROCESS."
   (erc-with-all-buffers-of-server process
                                  nil
                                  (erc-save-buffer-in-logs)))
@@ -280,6 +272,12 @@ Returns nil iff `erc-server-buffer-p' returns t."
   (when erc-save-queries-on-quit
     (erc-save-query-buffers process)))
 
+;; Make sure that logs get saved, even if someone overrides the active
+;; process prompt for a quick exit from Emacs
+(defun erc-log-save-all-buffers ()
+  (dolist (buffer (erc-buffer-list))
+    (erc-save-buffer-in-logs buffer)))
+
 ;;;###autoload
 (defun erc-logging-enabled (&optional buffer)
   "Return non-nil if logging is enabled for BUFFER.
@@ -293,17 +291,27 @@ is writeable (it will be created as necessary) and
           (funcall erc-enable-logging (or buffer (current-buffer)))
         erc-enable-logging)))
 
+(defun erc-log-standardize-name (filename)
+  "Make FILENAME safe to use as the name of an ERC log.
+This will not work with full paths, only names.
+
+Any unsafe characters in the name are replaced with \"!\".  The
+filename is downcased."
+  (downcase (erc-replace-regexp-in-string
+            "[/\\]" "!" (convert-standard-filename filename))))
+
 (defun erc-current-logfile (&optional buffer)
   "Return the logfile to use for BUFFER.
 If BUFFER is nil, the value of `current-buffer' is used.
 This is determined by `erc-generate-log-file-name-function'.
 The result is converted to lowercase, as IRC is case-insensitive"
   (expand-file-name
-   (downcase (funcall erc-generate-log-file-name-function
-                     (or buffer (current-buffer))
-                     (or (erc-default-target) (buffer-name buffer))
-                     (erc-current-nick)
-                     erc-session-server erc-session-port))
+   (erc-log-standardize-name
+    (funcall erc-generate-log-file-name-function
+            (or buffer (current-buffer))
+            (or (buffer-name buffer) (erc-default-target))
+            (erc-current-nick)
+            erc-session-server erc-session-port))
    erc-log-channels-directory))
 
 (defun erc-generate-log-file-name-with-date (buffer &rest ignore)