diff options
| author | F. Jason Park | 2025-03-10 19:02:48 -0700 |
|---|---|---|
| committer | F. Jason Park | 2025-03-11 18:28:38 -0700 |
| commit | 3db65ff5cb3d6f58b83052760b4ce04eb77db1bc (patch) | |
| tree | 79b9103447914a44968ed56ab6ddd98d9d79c475 | |
| parent | 261205dbb57f77e3426df9f27fcc5429aae48c05 (diff) | |
| download | emacs-3db65ff5cb3d6f58b83052760b4ce04eb77db1bc.tar.gz emacs-3db65ff5cb3d6f58b83052760b4ce04eb77db1bc.zip | |
Suppress log module when inserting date stamps in ERC
* lisp/erc/erc-log.el (erc-truncate-buffer-on-save): Use
`make-obsolete-variable' because `erc-truncate-buffer-on-save' is an
option, not a function. Already mentioned in etc/ERC-NEWS.
(erc-logging-enabled): Return nil if `log' appears in the `erc--skip'
msg prop.
* lisp/erc/erc-stamp.el (erc-stamp--defer-date-insertion-on-post-modify):
Add `log' to `erc--skip' msg prop. This tells the log module to defer
advancing the `erc-last-saved-position' marker until after stamps have
been inserted, thus ensuring they're included in logs when
`erc-log-write-after-insert' is non-nil.
* test/lisp/erc/erc-scenarios-log.el
(erc-scenarios-log--save-buffer-in-logs/truncate-on-save): Suppress
warning for `erc-truncate-buffer-on-save'.
(erc-scenarios-log--write-after-insert): New test. (Bug#76875)
| -rw-r--r-- | lisp/erc/erc-log.el | 4 | ||||
| -rw-r--r-- | lisp/erc/erc-stamp.el | 3 | ||||
| -rw-r--r-- | test/lisp/erc/erc-scenarios-log.el | 116 |
3 files changed, 103 insertions, 20 deletions
diff --git a/lisp/erc/erc-log.el b/lisp/erc/erc-log.el index b960eaeca9d..173e6724a8f 100644 --- a/lisp/erc/erc-log.el +++ b/lisp/erc/erc-log.el | |||
| @@ -124,7 +124,8 @@ custom function which returns the directory part and set | |||
| 124 | (defcustom erc-truncate-buffer-on-save nil | 124 | (defcustom erc-truncate-buffer-on-save nil |
| 125 | "Erase the contents of any ERC (channel, query, server) buffer when it is saved." | 125 | "Erase the contents of any ERC (channel, query, server) buffer when it is saved." |
| 126 | :type 'boolean) | 126 | :type 'boolean) |
| 127 | (make-obsolete 'erc-truncate-buffer-on-save 'erc-cmd-CLEAR "30.1") | 127 | (make-obsolete-variable 'erc-truncate-buffer-on-save |
| 128 | "maybe see command `erc-cmd-CLEAR'" "30.1") | ||
| 128 | 129 | ||
| 129 | (defcustom erc-enable-logging t | 130 | (defcustom erc-enable-logging t |
| 130 | "If non-nil, ERC will log IRC conversations. | 131 | "If non-nil, ERC will log IRC conversations. |
| @@ -322,6 +323,7 @@ is writable (it will be created as necessary) and | |||
| 322 | (or buffer (setq buffer (current-buffer))) | 323 | (or buffer (setq buffer (current-buffer))) |
| 323 | (and erc-log-channels-directory | 324 | (and erc-log-channels-directory |
| 324 | (not erc-log--save-in-progress-p) | 325 | (not erc-log--save-in-progress-p) |
| 326 | (not (erc--memq-msg-prop 'erc--skip 'log)) | ||
| 325 | (or (functionp erc-log-channels-directory) | 327 | (or (functionp erc-log-channels-directory) |
| 326 | (if erc-log--check-writable-nocreate-p | 328 | (if erc-log--check-writable-nocreate-p |
| 327 | (file-writable-p erc-log-channels-directory) | 329 | (file-writable-p erc-log-channels-directory) |
diff --git a/lisp/erc/erc-stamp.el b/lisp/erc/erc-stamp.el index 5b6550c4a88..c3ab155cb24 100644 --- a/lisp/erc/erc-stamp.el +++ b/lisp/erc/erc-stamp.el | |||
| @@ -732,6 +732,9 @@ non-nil." | |||
| 732 | (symbol (make-symbol "erc-stamp--insert-date")) | 732 | (symbol (make-symbol "erc-stamp--insert-date")) |
| 733 | (marker (setf (erc-stamp--date-marker data) (point-min-marker)))) | 733 | (marker (setf (erc-stamp--date-marker data) (point-min-marker)))) |
| 734 | (setf (erc-stamp--date-fn data) symbol) | 734 | (setf (erc-stamp--date-fn data) symbol) |
| 735 | ;; Disable logging in case `erc-log-write-after-insert' is in effect. | ||
| 736 | (when erc--msg-props | ||
| 737 | (push 'log (gethash 'erc--skip erc--msg-props))) | ||
| 735 | (fset symbol | 738 | (fset symbol |
| 736 | (lambda (&rest _) | 739 | (lambda (&rest _) |
| 737 | (remove-hook hook-var symbol) | 740 | (remove-hook hook-var symbol) |
diff --git a/test/lisp/erc/erc-scenarios-log.el b/test/lisp/erc/erc-scenarios-log.el index 1e95e98e073..3c95018dd26 100644 --- a/test/lisp/erc/erc-scenarios-log.el +++ b/test/lisp/erc/erc-scenarios-log.el | |||
| @@ -332,18 +332,78 @@ | |||
| 332 | 332 | ||
| 333 | (ert-deftest erc-scenarios-log--save-buffer-in-logs/truncate-on-save () | 333 | (ert-deftest erc-scenarios-log--save-buffer-in-logs/truncate-on-save () |
| 334 | :tags '(:expensive-test) | 334 | :tags '(:expensive-test) |
| 335 | (with-suppressed-warnings ((obsolete erc-truncate-buffer-on-save)) | ||
| 336 | (erc-scenarios-common-with-cleanup | ||
| 337 | ((erc-scenarios-common-dialog "base/assoc/bouncer-history") | ||
| 338 | (dumb-server (erc-d-run "localhost" t 'foonet)) | ||
| 339 | (tempdir (make-temp-file "erc-tests-log." t nil nil)) | ||
| 340 | (erc-log-channels-directory tempdir) | ||
| 341 | (erc-modules (cons 'log erc-modules)) | ||
| 342 | (port (process-contact dumb-server :service)) | ||
| 343 | (erc-truncate-buffer-on-save t) | ||
| 344 | (logchan (expand-file-name (format "#chan!tester@127.0.0.1:%d.txt" | ||
| 345 | port) | ||
| 346 | tempdir)) | ||
| 347 | (erc-server-flood-penalty 0.1) | ||
| 348 | (erc-insert-timestamp-function #'erc-insert-timestamp-left) | ||
| 349 | (expect (erc-d-t-make-expecter))) | ||
| 350 | |||
| 351 | (unless noninteractive | ||
| 352 | (add-hook 'kill-emacs-hook | ||
| 353 | (lambda () (delete-directory tempdir :recursive)))) | ||
| 354 | |||
| 355 | (ert-info ("Connect to foonet") | ||
| 356 | (with-current-buffer (erc :server "127.0.0.1" | ||
| 357 | :port port | ||
| 358 | :nick "tester" | ||
| 359 | :password "foonet:changeme" | ||
| 360 | :full-name "tester") | ||
| 361 | (should (string= (buffer-name) (format "127.0.0.1:%d" port))))) | ||
| 362 | |||
| 363 | (with-current-buffer (erc-d-t-wait-for 5 (get-buffer "#chan")) | ||
| 364 | (funcall expect 10 "<someone> [07:04:10] hi everyone") | ||
| 365 | (should-not (file-exists-p logchan)) | ||
| 366 | ;; Simulate an M-x erc-save-buffer-in-logs RET | ||
| 367 | (cl-letf (((symbol-function 'called-interactively-p) #'always)) | ||
| 368 | (call-interactively #'erc-save-buffer-in-logs)) | ||
| 369 | (should (file-exists-p logchan)) | ||
| 370 | (funcall expect 10 "<alice> bob: As't please your lordship") | ||
| 371 | (erc-save-buffer-in-logs) | ||
| 372 | ;; Not truncated when called by lisp code. | ||
| 373 | (should (> (buffer-size) 400))) | ||
| 374 | |||
| 375 | (ert-info ("No double entries") | ||
| 376 | (with-temp-buffer | ||
| 377 | (insert-file-contents logchan) | ||
| 378 | (funcall expect 0.1 "hi everyone") | ||
| 379 | (funcall expect -0.1 "hi everyone") | ||
| 380 | (funcall expect 0.1 "Playback Complete") | ||
| 381 | (funcall expect -0.1 "Playback Complete") | ||
| 382 | (funcall expect 10 "<alice> bob: As't"))) | ||
| 383 | |||
| 384 | (erc-log-mode -1) | ||
| 385 | (when noninteractive (delete-directory tempdir :recursive))))) | ||
| 386 | |||
| 387 | (ert-deftest erc-scenarios-log--write-after-insert () | ||
| 388 | :tags '(:expensive-test :unstable) | ||
| 389 | |||
| 335 | (erc-scenarios-common-with-cleanup | 390 | (erc-scenarios-common-with-cleanup |
| 336 | ((erc-scenarios-common-dialog "base/assoc/bouncer-history") | 391 | ((erc-scenarios-common-dialog "base/assoc/bouncer-history") |
| 337 | (dumb-server (erc-d-run "localhost" t 'foonet)) | 392 | (dumb-server (erc-d-run "localhost" t 'foonet)) |
| 338 | (tempdir (make-temp-file "erc-tests-log." t nil nil)) | 393 | (tempdir (make-temp-file "erc-tests-log." t nil nil)) |
| 339 | (erc-log-channels-directory tempdir) | 394 | (erc-log-channels-directory tempdir) |
| 340 | (erc-modules (cons 'log erc-modules)) | 395 | (erc-modules `(truncate log ,@erc-modules)) |
| 396 | (erc-max-buffer-size 512) | ||
| 397 | (erc-log-write-after-insert t) | ||
| 398 | (erc-timestamp-format-left "\n[@@DATE__STAMP@@]\n") | ||
| 399 | (erc-truncate-padding-size 512) | ||
| 341 | (port (process-contact dumb-server :service)) | 400 | (port (process-contact dumb-server :service)) |
| 342 | (erc-truncate-buffer-on-save t) | ||
| 343 | (logchan (expand-file-name (format "#chan!tester@127.0.0.1:%d.txt" port) | 401 | (logchan (expand-file-name (format "#chan!tester@127.0.0.1:%d.txt" port) |
| 344 | tempdir)) | 402 | tempdir)) |
| 403 | (logserv (expand-file-name | ||
| 404 | (format "127.0.0.1:%d!tester@127.0.0.1:%d.txt" port port) | ||
| 405 | tempdir)) | ||
| 345 | (erc-server-flood-penalty 0.1) | 406 | (erc-server-flood-penalty 0.1) |
| 346 | (erc-insert-timestamp-function #'erc-insert-timestamp-left) | ||
| 347 | (expect (erc-d-t-make-expecter))) | 407 | (expect (erc-d-t-make-expecter))) |
| 348 | 408 | ||
| 349 | (unless noninteractive | 409 | (unless noninteractive |
| @@ -356,30 +416,48 @@ | |||
| 356 | :nick "tester" | 416 | :nick "tester" |
| 357 | :password "foonet:changeme" | 417 | :password "foonet:changeme" |
| 358 | :full-name "tester") | 418 | :full-name "tester") |
| 359 | (should (string= (buffer-name) (format "127.0.0.1:%d" port))))) | 419 | (should (string= (buffer-name) (format "127.0.0.1:%d" port))) |
| 420 | ;; File already exists because `erc-log-write-after-insert' is | ||
| 421 | ;; non-nil. | ||
| 422 | (should (file-exists-p logserv)) | ||
| 423 | (should-not (file-exists-p logchan)) | ||
| 424 | ;; Verify that truncation actually happens where it should. | ||
| 425 | (funcall expect 10 "*** MAXLIST=beI:60") | ||
| 426 | (should (= (pos-bol) 22)) | ||
| 427 | ;; Exactly two + 1 (for date stamp) newlines preserved. | ||
| 428 | (should (string-prefix-p "\n\n\n[" (buffer-string))))) | ||
| 429 | |||
| 430 | (ert-info ("Log file ahead of truncation point") | ||
| 431 | ;; Log contains lines still present in buffer. | ||
| 432 | (with-temp-buffer | ||
| 433 | (insert-file-contents logserv) | ||
| 434 | (funcall expect 10 "@@DATE__STAMP@@") | ||
| 435 | (funcall expect 10 "*** MAXLIST=beI:60"))) | ||
| 360 | 436 | ||
| 361 | (with-current-buffer (erc-d-t-wait-for 5 (get-buffer "#chan")) | 437 | (with-current-buffer (erc-d-t-wait-for 5 (get-buffer "#chan")) |
| 362 | (funcall expect 10 "<someone> [07:04:10] hi everyone") | 438 | (funcall expect 10 "@@DATE__STAMP@@") |
| 363 | (should-not (file-exists-p logchan)) | 439 | (funcall expect 10 "please your lordship") |
| 364 | ;; Simulate an M-x erc-save-buffer-in-logs RET | ||
| 365 | (cl-letf (((symbol-function 'called-interactively-p) #'always)) | ||
| 366 | (call-interactively #'erc-save-buffer-in-logs)) | ||
| 367 | (should (file-exists-p logchan)) | 440 | (should (file-exists-p logchan)) |
| 368 | (funcall expect 10 "<alice> bob: As't please your lordship") | 441 | (funcall expect -0.1 "[07:04:37] alice: Here," (point-min))) |
| 369 | (erc-save-buffer-in-logs) | ||
| 370 | ;; Not truncated when called by lisp code. | ||
| 371 | (should (> (buffer-size) 400))) | ||
| 372 | 442 | ||
| 373 | (ert-info ("No double entries") | 443 | (ert-info ("Log ahead of truncation point") |
| 374 | (with-temp-buffer | 444 | (with-temp-buffer |
| 375 | (insert-file-contents logchan) | 445 | (insert-file-contents logchan) |
| 376 | (funcall expect 0.1 "hi everyone") | 446 | (funcall expect 10 "@@DATE__STAMP@@") |
| 377 | (funcall expect -0.1 "hi everyone") | 447 | (funcall expect 1 "You have joined") |
| 378 | (funcall expect 0.1 "Playback Complete") | 448 | ;; No unwanted duplicates. |
| 379 | (funcall expect -0.1 "Playback Complete") | 449 | (funcall expect 1 "<bob> [07:04:37] alice: Here,") |
| 380 | (funcall expect 10 "<alice> bob: As't"))) | 450 | (funcall expect -0.001 "<bob> [07:04:37] alice: Here,") |
| 451 | (funcall expect 1 "<alice> [07:04:42] bob: By my troth") | ||
| 452 | (funcall expect -0.001 "<alice> [07:04:42] bob: By my troth") | ||
| 453 | (funcall expect 1 "I will grant it") | ||
| 454 | |||
| 455 | ;; Writes happen instantly because `erc-log-write-after-insert' | ||
| 456 | ;; is non-nil. Compare to `erc-scenarios-log--truncate' above. | ||
| 457 | (funcall expect 1 "loathed enemy"))) | ||
| 381 | 458 | ||
| 382 | (erc-log-mode -1) | 459 | (erc-log-mode -1) |
| 460 | (erc-truncate-mode -1) | ||
| 383 | (when noninteractive (delete-directory tempdir :recursive)))) | 461 | (when noninteractive (delete-directory tempdir :recursive)))) |
| 384 | 462 | ||
| 385 | ;;; erc-scenarios-log.el ends here | 463 | ;;; erc-scenarios-log.el ends here |