]> git.eshelyaron.com Git - emacs.git/commitdiff
Warn about implicit logging in erc-truncate-mode
authorF. Jason Park <jp@neverwas.me>
Fri, 18 Aug 2023 02:18:50 +0000 (19:18 -0700)
committerF. Jason Park <jp@neverwas.me>
Fri, 25 Aug 2023 21:47:07 +0000 (14:47 -0700)
* 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)

etc/ERC-NEWS
lisp/erc/erc-log.el
lisp/erc/erc-truncate.el
test/lisp/erc/erc-scenarios-log.el

index 94452514e6d3ae0baac12cc90de1473047a7138c..7ee55982b1793c50ad3ab1338b252d2c5619f156 100644 (file)
@@ -196,6 +196,13 @@ these changes has been the deprecation of the ancient option
 'erc-truncate-buffer-on-save'.  Users of the 'log' module can achieve
 the same effect by issuing a "/CLEAR" at the prompt.
 
+** The 'truncate' module no longer enables logging automatically.
+Users expecting 'truncate' to perform logging based on the option
+'erc-enable-logging' need to instead add 'log' to 'erc-modules' for
+continued integration.  With the existing design, merely loading the
+library 'erc-log' caused 'truncate' to start writing logs, possibly
+against a user's wishes.
+
 ** Miscellaneous UX changes.
 Some minor quality-of-life niceties have finally made their way to
 ERC.  For example, the function 'erc-echo-timestamp' is now
index d3106da40179d7d8982df944a1fb54d5c6c01d9d..472cc1388a4661c38edbcb19b96070fede33cfa6 100644 (file)
@@ -445,6 +445,15 @@ You can save every individual message by putting this function on
            (set-buffer-modified-p nil))))))
   t)
 
+;; This is a kludge to avoid littering erc-truncate.el with forward
+;; declarations needed only for a corner-case compatibility check.
+(defun erc-log--call-when-logging-enabled-sans-module (fn)
+  (when (and (erc-logging-enabled)
+             (not (or erc-log-mode (memq 'log erc-modules))))
+    (let ((dirfile (and (stringp erc-log-channels-directory)
+                        erc-log-channels-directory)))
+      (funcall fn dirfile))))
+
 (provide 'erc-log)
 
 ;;; erc-log.el ends here
index 8430a68d92b7e6c3a60da8168c7cf04a7841e850..48d8408a85a4c31e3e486041cf346d633927c754 100644 (file)
 
 ;;; Commentary:
 
-;; This implements buffer truncation (and optional log file writing
-;; support for the Emacs IRC client.  Use `erc-truncate-mode' to switch
-;; on.  Use `erc-enable-logging' to enable logging of the stuff which
-;; is getting truncated.
+;; This file implements buffer truncation through the `truncate'
+;; module, with optional `log' module integration.
 
 ;;; Code:
 
@@ -50,15 +48,41 @@ This prevents the query buffer from getting too large, which can
 bring any grown Emacs to its knees after a few days worth of
 tracking heavy-traffic channels."
   ;;enable
-  ((add-hook 'erc-insert-done-hook #'erc-truncate-buffer))
+  ((add-hook 'erc-insert-done-hook #'erc-truncate-buffer)
+   (add-hook 'erc-connect-pre-hook #'erc-truncate--warn-about-logging))
   ;; disable
-  ((remove-hook 'erc-insert-done-hook #'erc-truncate-buffer)))
+  ((remove-hook 'erc-insert-done-hook #'erc-truncate-buffer)
+   (remove-hook 'erc-connect-pre-hook #'erc-truncate--warn-about-logging)))
+
+(defun erc-truncate--warn-about-logging (&rest _)
+  (when (and (not erc--target)
+             (fboundp 'erc-log--call-when-logging-enabled-sans-module))
+    ;; We could also enable `erc-log-mode' here, but the risk of
+    ;; lasting damage is nonzero.
+    (erc-log--call-when-logging-enabled-sans-module
+     (lambda (dirfile)
+       ;; Emit a real Emacs warning because the message may be
+       ;; truncated away before it can be read if merely inserted.
+       (erc-button--display-error-notice-with-keys-and-warn
+        "The `truncate' module no longer enables logging implicitly."
+        " If you want ERC to write logs before truncating, add `log' to"
+        " `erc-modules' using something like \\[customize-option]."
+        " To silence this message, don't `require' `erc-log'."
+        (and dirfile " Alternatively, change the value of")
+        (and dirfile " `erc-log-channels-directory', or move ")
+        dirfile (and dirfile " elsewhere."))))))
 
 ;;;###autoload
 (defun erc-truncate-buffer-to-size (size &optional buffer)
-  "Truncates the buffer to the size SIZE.
-If BUFFER is not provided, the current buffer is assumed.  The deleted
-region is logged if `erc-logging-enabled' returns non-nil."
+  "Truncate BUFFER or the current buffer to SIZE.
+Log the deleted region when the `log' module is active and
+`erc-logging-enabled' returns non-nil.
+
+Note that prior to ERC 5.6, whenever erc-log.el happened to be
+loaded and the option `erc-enable-logging' was left at its
+default value, this function would cause logging to commence
+regardless of whether `erc-log-mode' was enabled or `log' was
+present in `erc-modules'."
   ;; If buffer is non-nil, but get-buffer does not return anything,
   ;; then this is a bug.  If buffer is a buffer name, get the buffer
   ;; object.  If buffer is nil, use the current buffer.
@@ -93,6 +117,9 @@ region is logged if `erc-logging-enabled' returns non-nil."
          ;; (not (memq 'erc-save-buffer-in-logs
          ;;             erc-insert-post-hook))
          ;; Comments?
+          ;; The comments above concern pre-5.6 behavior and reflect
+          ;; an obsolete understanding of how `erc-logging-enabled'
+          ;; behaves in practice.
           (run-hook-with-args 'erc--pre-clear-functions end)
          ;; disable undoing for the truncating
          (buffer-disable-undo)
index c37e6b323aad1aee0bbdce943649645aea208498..fd030d90c2fc078c3924ada6f20f8b57f0cb1dba 100644 (file)
         (funcall expect -0.1 "please your lordship")))
 
     (erc-log-mode -1)
+    (erc-truncate-mode -1)
     (when noninteractive (delete-directory tempdir :recursive))))
 
 ;;; erc-scenarios-log.el ends here