;;; 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'.
;; 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
(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
(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)
(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)))
(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.
(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)