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)
This commit is contained in:
parent
75b3fb3cb4
commit
b93757029c
4 changed files with 53 additions and 9 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -24,10 +24,8 @@
|
|||
|
||||
;;; 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)
|
||||
|
|
|
@ -202,6 +202,7 @@
|
|||
(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
|
||||
|
|
Loading…
Add table
Reference in a new issue