aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/erc
diff options
context:
space:
mode:
authorF. Jason Park2023-08-17 19:18:50 -0700
committerF. Jason Park2023-08-25 14:47:07 -0700
commitb93757029c9d8a7e401f7eeb0bc32ca508c212ee (patch)
treed191c60c07d6c3e34311d4f4f44c36a60fa61c2f /lisp/erc
parent75b3fb3cb42385612d446ee1907b87e64d988c2f (diff)
downloademacs-b93757029c9d8a7e401f7eeb0bc32ca508c212ee.tar.gz
emacs-b93757029c9d8a7e401f7eeb0bc32ca508c212ee.zip
Warn about implicit logging in erc-truncate-mode
* etc/ERC-NEWS: Add entry explaining that `erc-truncate-mode' no longer quasi-activates `erc-log-mode' under certain conditions. * lisp/erc/erc-log.el (erc-log--call-when-logging-enabled-sans-module): Add helper for use by the `truncate' module during initialization. * lisp/erc/erc-truncate.el (erc-truncate-mode, erc-truncate-enable, erc-truncate-disable): Warn on `erc-connect-pre-hook' when conditions exist that would have seen logging transparently activated in older ERC versions. (erc-truncate--warn-about-logging): New function to warn about implicit logging on pre-connect. (erc-truncate-buffer-to-size): Clarify some comments and revise doc string. * test/lisp/erc/erc-scenarios-log.el (erc-scenarios-log--truncate): Disable `erc-truncate-mode' even though `erc-modules' is shadowed so that `erc-insert-done-hook' and friends are not contaminated. `(Bug#60936)
Diffstat (limited to 'lisp/erc')
-rw-r--r--lisp/erc/erc-log.el9
-rw-r--r--lisp/erc/erc-truncate.el45
2 files changed, 45 insertions, 9 deletions
diff --git a/lisp/erc/erc-log.el b/lisp/erc/erc-log.el
index d3106da4017..472cc1388a4 100644
--- a/lisp/erc/erc-log.el
+++ b/lisp/erc/erc-log.el
@@ -445,6 +445,15 @@ You can save every individual message by putting this function on
445 (set-buffer-modified-p nil)))))) 445 (set-buffer-modified-p nil))))))
446 t) 446 t)
447 447
448;; This is a kludge to avoid littering erc-truncate.el with forward
449;; declarations needed only for a corner-case compatibility check.
450(defun erc-log--call-when-logging-enabled-sans-module (fn)
451 (when (and (erc-logging-enabled)
452 (not (or erc-log-mode (memq 'log erc-modules))))
453 (let ((dirfile (and (stringp erc-log-channels-directory)
454 erc-log-channels-directory)))
455 (funcall fn dirfile))))
456
448(provide 'erc-log) 457(provide 'erc-log)
449 458
450;;; erc-log.el ends here 459;;; erc-log.el ends here
diff --git a/lisp/erc/erc-truncate.el b/lisp/erc/erc-truncate.el
index 8430a68d92b..48d8408a85a 100644
--- a/lisp/erc/erc-truncate.el
+++ b/lisp/erc/erc-truncate.el
@@ -24,10 +24,8 @@
24 24
25;;; Commentary: 25;;; Commentary:
26 26
27;; This implements buffer truncation (and optional log file writing 27;; This file implements buffer truncation through the `truncate'
28;; support for the Emacs IRC client. Use `erc-truncate-mode' to switch 28;; module, with optional `log' module integration.
29;; on. Use `erc-enable-logging' to enable logging of the stuff which
30;; is getting truncated.
31 29
32;;; Code: 30;;; Code:
33 31
@@ -50,15 +48,41 @@ This prevents the query buffer from getting too large, which can
50bring any grown Emacs to its knees after a few days worth of 48bring any grown Emacs to its knees after a few days worth of
51tracking heavy-traffic channels." 49tracking heavy-traffic channels."
52 ;;enable 50 ;;enable
53 ((add-hook 'erc-insert-done-hook #'erc-truncate-buffer)) 51 ((add-hook 'erc-insert-done-hook #'erc-truncate-buffer)
52 (add-hook 'erc-connect-pre-hook #'erc-truncate--warn-about-logging))
54 ;; disable 53 ;; disable
55 ((remove-hook 'erc-insert-done-hook #'erc-truncate-buffer))) 54 ((remove-hook 'erc-insert-done-hook #'erc-truncate-buffer)
55 (remove-hook 'erc-connect-pre-hook #'erc-truncate--warn-about-logging)))
56
57(defun erc-truncate--warn-about-logging (&rest _)
58 (when (and (not erc--target)
59 (fboundp 'erc-log--call-when-logging-enabled-sans-module))
60 ;; We could also enable `erc-log-mode' here, but the risk of
61 ;; lasting damage is nonzero.
62 (erc-log--call-when-logging-enabled-sans-module
63 (lambda (dirfile)
64 ;; Emit a real Emacs warning because the message may be
65 ;; truncated away before it can be read if merely inserted.
66 (erc-button--display-error-notice-with-keys-and-warn
67 "The `truncate' module no longer enables logging implicitly."
68 " If you want ERC to write logs before truncating, add `log' to"
69 " `erc-modules' using something like \\[customize-option]."
70 " To silence this message, don't `require' `erc-log'."
71 (and dirfile " Alternatively, change the value of")
72 (and dirfile " `erc-log-channels-directory', or move ")
73 dirfile (and dirfile " elsewhere."))))))
56 74
57;;;###autoload 75;;;###autoload
58(defun erc-truncate-buffer-to-size (size &optional buffer) 76(defun erc-truncate-buffer-to-size (size &optional buffer)
59 "Truncates the buffer to the size SIZE. 77 "Truncate BUFFER or the current buffer to SIZE.
60If BUFFER is not provided, the current buffer is assumed. The deleted 78Log the deleted region when the `log' module is active and
61region is logged if `erc-logging-enabled' returns non-nil." 79`erc-logging-enabled' returns non-nil.
80
81Note that prior to ERC 5.6, whenever erc-log.el happened to be
82loaded and the option `erc-enable-logging' was left at its
83default value, this function would cause logging to commence
84regardless of whether `erc-log-mode' was enabled or `log' was
85present in `erc-modules'."
62 ;; If buffer is non-nil, but get-buffer does not return anything, 86 ;; If buffer is non-nil, but get-buffer does not return anything,
63 ;; then this is a bug. If buffer is a buffer name, get the buffer 87 ;; then this is a bug. If buffer is a buffer name, get the buffer
64 ;; object. If buffer is nil, use the current buffer. 88 ;; object. If buffer is nil, use the current buffer.
@@ -93,6 +117,9 @@ region is logged if `erc-logging-enabled' returns non-nil."
93 ;; (not (memq 'erc-save-buffer-in-logs 117 ;; (not (memq 'erc-save-buffer-in-logs
94 ;; erc-insert-post-hook)) 118 ;; erc-insert-post-hook))
95 ;; Comments? 119 ;; Comments?
120 ;; The comments above concern pre-5.6 behavior and reflect
121 ;; an obsolete understanding of how `erc-logging-enabled'
122 ;; behaves in practice.
96 (run-hook-with-args 'erc--pre-clear-functions end) 123 (run-hook-with-args 'erc--pre-clear-functions end)
97 ;; disable undoing for the truncating 124 ;; disable undoing for the truncating
98 (buffer-disable-undo) 125 (buffer-disable-undo)