1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

Fix overlapping logs from erc-truncate-buffer-on-save

* lisp/erc/erc-button.el (erc-button--display-error-notice-with-keys):
Currently, internal "error notices" do not have timestamps.  However,
this causes alignment issues for non-`fill-wrap' users of left-sided
stamps.  The heuristic used by this change for detecting such stamps
is weak and prone to false negatives.
* lisp/erc/erc-log.el (erc-log-mode, erc-log-enable): Set explicit
depth for `erc--pre-clear-functions' to 50.
(erc-save-buffer-in-logs): Fix partial regression in which redundant
text would appear in logs that have undergone truncation via an
interactive call to this command when the deprecated option
`erc-truncate-on-save' is non-nil.
* lisp/erc/erc-stamp.el (erc-stamp-mode, erc-stamp-enable): Set
depth for `erc--pre-clear-functions' to 40.
(erc-stamp--reset-on-clear): Only add `erc-stamp--insert-date-hook'
when `erc-stamp--date-mode' is active.
* lisp/erc/erc.el (erc-cmd-CLEAR): Rework to honor but improve upon
the old behavior when called from lisp.  Do this by attempting to find
the beginning of the current message and excluding it from the
truncated portion of the buffer.  A NEWS entry describing this
behavior already exists for 5.6.
* test/lisp/erc/erc-scenarios-log.el
(erc-scenarios-log--save-buffer-in-logs/truncate-on-save): New test.
These changes originate from bug#60936.
This commit is contained in:
F. Jason Park 2023-12-19 22:33:48 -08:00
parent 34fe0b5c87
commit 9cd47017c7
5 changed files with 77 additions and 13 deletions

View file

@ -206,4 +206,59 @@
(erc-truncate-mode -1)
(when noninteractive (delete-directory tempdir :recursive))))
(defvar erc-insert-timestamp-function)
(declare-function erc-insert-timestamp-left "erc-stamp" (string))
(ert-deftest erc-scenarios-log--save-buffer-in-logs/truncate-on-save ()
:tags '(:expensive-test)
(erc-scenarios-common-with-cleanup
((erc-scenarios-common-dialog "base/assoc/bouncer-history")
(dumb-server (erc-d-run "localhost" t 'foonet))
(tempdir (make-temp-file "erc-tests-log." t nil nil))
(erc-log-channels-directory tempdir)
(erc-modules (cons 'log erc-modules))
(port (process-contact dumb-server :service))
(erc-truncate-buffer-on-save t)
(logchan (expand-file-name (format "#chan!tester@127.0.0.1:%d.txt" port)
tempdir))
(erc-server-flood-penalty 0.1)
(erc-insert-timestamp-function #'erc-insert-timestamp-left)
(expect (erc-d-t-make-expecter)))
(unless noninteractive
(add-hook 'kill-emacs-hook
(lambda () (delete-directory tempdir :recursive))))
(ert-info ("Connect to foonet")
(with-current-buffer (erc :server "127.0.0.1"
:port port
:nick "tester"
:password "foonet:changeme"
:full-name "tester")
(should (string= (buffer-name) (format "127.0.0.1:%d" port)))))
(with-current-buffer (erc-d-t-wait-for 5 (get-buffer "#chan"))
(funcall expect 10 "<someone> [07:04:10] hi everyone")
(should-not (file-exists-p logchan))
;; Simulate an M-x erc-save-buffer-in-logs RET
(cl-letf (((symbol-function 'called-interactively-p) #'always))
(call-interactively #'erc-save-buffer-in-logs))
(should (file-exists-p logchan))
(funcall expect 10 "<alice> bob: As't please your lordship")
(erc-save-buffer-in-logs)
;; Not truncated when called by lisp code.
(should (> (buffer-size) 400)))
(ert-info ("No double entries")
(with-temp-buffer
(insert-file-contents logchan)
(funcall expect 0.1 "hi everyone")
(funcall expect -0.1 "hi everyone")
(funcall expect 0.1 "Playback Complete")
(funcall expect -0.1 "Playback Complete")
(funcall expect 10 "<alice> bob: As't")))
(erc-log-mode -1)
(when noninteractive (delete-directory tempdir :recursive))))
;;; erc-scenarios-log.el ends here