diff options
Diffstat (limited to 'lisp/erc/erc-log.el')
| -rw-r--r-- | lisp/erc/erc-log.el | 41 |
1 files changed, 30 insertions, 11 deletions
diff --git a/lisp/erc/erc-log.el b/lisp/erc/erc-log.el index b316a8588bd..2fe29e82fe5 100644 --- a/lisp/erc/erc-log.el +++ b/lisp/erc/erc-log.el | |||
| @@ -71,8 +71,6 @@ | |||
| 71 | ;; markers. | 71 | ;; markers. |
| 72 | 72 | ||
| 73 | ;;; TODO: | 73 | ;;; TODO: |
| 74 | ;; * Erc needs a generalised make-safe-file-name function, so that | ||
| 75 | ;; generated file names don't contain any invalid file characters. | ||
| 76 | ;; | 74 | ;; |
| 77 | ;; * Really, we need to lock the logfiles somehow, so that if a user | 75 | ;; * Really, we need to lock the logfiles somehow, so that if a user |
| 78 | ;; is running multiple emacsen and/or on the same channel as more | 76 | ;; is running multiple emacsen and/or on the same channel as more |
| @@ -218,7 +216,10 @@ also be a predicate function. To only log when you are not set away, use: | |||
| 218 | (add-hook 'erc-quit-hook 'erc-conditional-save-queries) | 216 | (add-hook 'erc-quit-hook 'erc-conditional-save-queries) |
| 219 | (add-hook 'erc-part-hook 'erc-conditional-save-buffer) | 217 | (add-hook 'erc-part-hook 'erc-conditional-save-buffer) |
| 220 | ;; append, so that 'erc-initialize-log-marker runs first | 218 | ;; append, so that 'erc-initialize-log-marker runs first |
| 221 | (add-hook 'erc-connect-pre-hook 'erc-log-setup-logging 'append)) | 219 | (add-hook 'erc-connect-pre-hook 'erc-log-setup-logging 'append) |
| 220 | (dolist (buffer (erc-buffer-list)) | ||
| 221 | (when (buffer-live-p buffer) | ||
| 222 | (with-current-buffer buffer (erc-log-setup-logging))))) | ||
| 222 | ;; disable | 223 | ;; disable |
| 223 | ((remove-hook 'erc-insert-post-hook 'erc-save-buffer-in-logs) | 224 | ((remove-hook 'erc-insert-post-hook 'erc-save-buffer-in-logs) |
| 224 | (remove-hook 'erc-send-post-hook 'erc-save-buffer-in-logs) | 225 | (remove-hook 'erc-send-post-hook 'erc-save-buffer-in-logs) |
| @@ -226,7 +227,10 @@ also be a predicate function. To only log when you are not set away, use: | |||
| 226 | (remove-hook 'erc-kill-channel-hook 'erc-save-buffer-in-logs) | 227 | (remove-hook 'erc-kill-channel-hook 'erc-save-buffer-in-logs) |
| 227 | (remove-hook 'erc-quit-hook 'erc-conditional-save-queries) | 228 | (remove-hook 'erc-quit-hook 'erc-conditional-save-queries) |
| 228 | (remove-hook 'erc-part-hook 'erc-conditional-save-buffer) | 229 | (remove-hook 'erc-part-hook 'erc-conditional-save-buffer) |
| 229 | (remove-hook 'erc-connect-pre-hook 'erc-log-setup-logging))) | 230 | (remove-hook 'erc-connect-pre-hook 'erc-log-setup-logging) |
| 231 | (dolist (buffer (erc-buffer-list)) | ||
| 232 | (when (buffer-live-p buffer) | ||
| 233 | (with-current-buffer buffer (erc-log-disable-logging)))))) | ||
| 230 | 234 | ||
| 231 | (define-key erc-mode-map "\C-c\C-l" 'erc-save-buffer-in-logs) | 235 | (define-key erc-mode-map "\C-c\C-l" 'erc-save-buffer-in-logs) |
| 232 | 236 | ||
| @@ -236,8 +240,7 @@ also be a predicate function. To only log when you are not set away, use: | |||
| 236 | This function is destined to be run from `erc-connect-pre-hook'." | 240 | This function is destined to be run from `erc-connect-pre-hook'." |
| 237 | (when (erc-logging-enabled) | 241 | (when (erc-logging-enabled) |
| 238 | (auto-save-mode -1) | 242 | (auto-save-mode -1) |
| 239 | (setq buffer-offer-save t | 243 | (setq buffer-file-name nil) |
| 240 | buffer-file-name "") | ||
| 241 | (set (make-local-variable 'write-file-functions) | 244 | (set (make-local-variable 'write-file-functions) |
| 242 | '(erc-save-buffer-in-logs)) | 245 | '(erc-save-buffer-in-logs)) |
| 243 | (when erc-log-insert-log-on-open | 246 | (when erc-log-insert-log-on-open |
| @@ -245,6 +248,12 @@ This function is destined to be run from `erc-connect-pre-hook'." | |||
| 245 | (move-marker erc-last-saved-position | 248 | (move-marker erc-last-saved-position |
| 246 | (1- (point-max))))))) | 249 | (1- (point-max))))))) |
| 247 | 250 | ||
| 251 | (defun erc-log-disable-logging () | ||
| 252 | "Disable logging in the current buffer." | ||
| 253 | (when (erc-logging-enabled) | ||
| 254 | (setq buffer-offer-save nil | ||
| 255 | erc-enable-logging nil))) | ||
| 256 | |||
| 248 | (defun erc-log-all-but-server-buffers (buffer) | 257 | (defun erc-log-all-but-server-buffers (buffer) |
| 249 | "Returns t if logging should be enabled in BUFFER. | 258 | "Returns t if logging should be enabled in BUFFER. |
| 250 | Returns nil iff `erc-server-buffer-p' returns t." | 259 | Returns nil iff `erc-server-buffer-p' returns t." |
| @@ -282,17 +291,27 @@ is writeable (it will be created as necessary) and | |||
| 282 | (funcall erc-enable-logging (or buffer (current-buffer))) | 291 | (funcall erc-enable-logging (or buffer (current-buffer))) |
| 283 | erc-enable-logging))) | 292 | erc-enable-logging))) |
| 284 | 293 | ||
| 294 | (defun erc-log-standardize-name (filename) | ||
| 295 | "Make FILENAME safe to use as the name of an ERC log. | ||
| 296 | This will not work with full paths, only names. | ||
| 297 | |||
| 298 | Any unsafe characters in the name are replaced with \"!\". The | ||
| 299 | filename is downcased." | ||
| 300 | (downcase (erc-replace-regexp-in-string | ||
| 301 | "[/\\]" "!" (convert-standard-filename filename)))) | ||
| 302 | |||
| 285 | (defun erc-current-logfile (&optional buffer) | 303 | (defun erc-current-logfile (&optional buffer) |
| 286 | "Return the logfile to use for BUFFER. | 304 | "Return the logfile to use for BUFFER. |
| 287 | If BUFFER is nil, the value of `current-buffer' is used. | 305 | If BUFFER is nil, the value of `current-buffer' is used. |
| 288 | This is determined by `erc-generate-log-file-name-function'. | 306 | This is determined by `erc-generate-log-file-name-function'. |
| 289 | The result is converted to lowercase, as IRC is case-insensitive" | 307 | The result is converted to lowercase, as IRC is case-insensitive" |
| 290 | (expand-file-name | 308 | (expand-file-name |
| 291 | (downcase (funcall erc-generate-log-file-name-function | 309 | (erc-log-standardize-name |
| 292 | (or buffer (current-buffer)) | 310 | (funcall erc-generate-log-file-name-function |
| 293 | (or (erc-default-target) (buffer-name buffer)) | 311 | (or buffer (current-buffer)) |
| 294 | (erc-current-nick) | 312 | (or (erc-default-target) (buffer-name buffer)) |
| 295 | erc-session-server erc-session-port)) | 313 | (erc-current-nick) |
| 314 | erc-session-server erc-session-port)) | ||
| 296 | erc-log-channels-directory)) | 315 | erc-log-channels-directory)) |
| 297 | 316 | ||
| 298 | (defun erc-generate-log-file-name-with-date (buffer &rest ignore) | 317 | (defun erc-generate-log-file-name-with-date (buffer &rest ignore) |