diff options
| -rw-r--r-- | lisp/erc/erc-button.el | 7 | ||||
| -rw-r--r-- | lisp/erc/erc-log.el | 5 | ||||
| -rw-r--r-- | lisp/erc/erc-stamp.el | 7 | ||||
| -rw-r--r-- | lisp/erc/erc.el | 16 | ||||
| -rw-r--r-- | test/lisp/erc/erc-scenarios-log.el | 55 |
5 files changed, 77 insertions, 13 deletions
diff --git a/lisp/erc/erc-button.el b/lisp/erc/erc-button.el index a62dd520860..c290e76843c 100644 --- a/lisp/erc/erc-button.el +++ b/lisp/erc/erc-button.el | |||
| @@ -829,6 +829,7 @@ argument when calling `erc-display-message'. Otherwise, add it | |||
| 829 | to STRINGS. If STRINGS contains any trailing non-nil | 829 | to STRINGS. If STRINGS contains any trailing non-nil |
| 830 | non-strings, concatenate leading string members before applying | 830 | non-strings, concatenate leading string members before applying |
| 831 | `format'. Otherwise, just concatenate everything." | 831 | `format'. Otherwise, just concatenate everything." |
| 832 | (defvar erc-stamp--skip) | ||
| 832 | (let* ((buffer (if (bufferp maybe-buffer) | 833 | (let* ((buffer (if (bufferp maybe-buffer) |
| 833 | maybe-buffer | 834 | maybe-buffer |
| 834 | (when (stringp maybe-buffer) | 835 | (when (stringp maybe-buffer) |
| @@ -844,8 +845,10 @@ non-strings, concatenate leading string members before applying | |||
| 844 | (push head strings)) | 845 | (push head strings)) |
| 845 | #'format)) | 846 | #'format)) |
| 846 | (string (apply op strings)) | 847 | (string (apply op strings)) |
| 847 | (erc-insert-modify-hook (remove 'erc-add-timestamp | 848 | ;; Avoid timestamps unless left-sided. |
| 848 | erc-insert-modify-hook)) | 849 | (erc-stamp--skip (or (bound-and-true-p erc-stamp--display-margin-mode) |
| 850 | (not (fboundp 'erc-timestamp-offset)) | ||
| 851 | (zerop (erc-timestamp-offset)))) | ||
| 849 | (erc-insert-post-hook | 852 | (erc-insert-post-hook |
| 850 | (cons (lambda () | 853 | (cons (lambda () |
| 851 | (setq string (buffer-substring (point-min) | 854 | (setq string (buffer-substring (point-min) |
diff --git a/lisp/erc/erc-log.el b/lisp/erc/erc-log.el index 79fece5779e..5efde6cad11 100644 --- a/lisp/erc/erc-log.el +++ b/lisp/erc/erc-log.el | |||
| @@ -231,7 +231,7 @@ also be a predicate function. To only log when you are not set away, use: | |||
| 231 | (add-hook 'erc-part-hook #'erc-conditional-save-buffer) | 231 | (add-hook 'erc-part-hook #'erc-conditional-save-buffer) |
| 232 | ;; append, so that 'erc-initialize-log-marker runs first | 232 | ;; append, so that 'erc-initialize-log-marker runs first |
| 233 | (add-hook 'erc-connect-pre-hook #'erc-log-setup-logging 'append) | 233 | (add-hook 'erc-connect-pre-hook #'erc-log-setup-logging 'append) |
| 234 | (add-hook 'erc--pre-clear-functions #'erc-save-buffer-in-logs) | 234 | (add-hook 'erc--pre-clear-functions #'erc-save-buffer-in-logs 50) |
| 235 | (dolist (buffer (erc-buffer-list)) | 235 | (dolist (buffer (erc-buffer-list)) |
| 236 | (erc-log-setup-logging buffer)) | 236 | (erc-log-setup-logging buffer)) |
| 237 | (erc--modify-local-map t "C-c C-l" #'erc-save-buffer-in-logs)) | 237 | (erc--modify-local-map t "C-c C-l" #'erc-save-buffer-in-logs)) |
| @@ -430,7 +430,8 @@ You can save every individual message by putting this function on | |||
| 430 | (if (and erc-truncate-buffer-on-save | 430 | (if (and erc-truncate-buffer-on-save |
| 431 | (called-interactively-p 'interactive)) | 431 | (called-interactively-p 'interactive)) |
| 432 | (let ((erc-log--save-in-progress-p t)) | 432 | (let ((erc-log--save-in-progress-p t)) |
| 433 | (erc-cmd-CLEAR) | 433 | (save-excursion (goto-char erc-insert-marker) |
| 434 | (erc-cmd-CLEAR)) | ||
| 434 | (erc-button--display-error-notice-with-keys | 435 | (erc-button--display-error-notice-with-keys |
| 435 | (erc-server-buffer) "Option `%s' is deprecated." | 436 | (erc-server-buffer) "Option `%s' is deprecated." |
| 436 | " Use /CLEAR instead." 'erc-truncate-buffer-on-save)) | 437 | " Use /CLEAR instead." 'erc-truncate-buffer-on-save)) |
diff --git a/lisp/erc/erc-stamp.el b/lisp/erc/erc-stamp.el index 9ca3ea320a0..a65b564ba6c 100644 --- a/lisp/erc/erc-stamp.el +++ b/lisp/erc/erc-stamp.el | |||
| @@ -182,7 +182,7 @@ from entering them and instead jump over them." | |||
| 182 | (add-hook 'erc-insert-modify-hook #'erc-add-timestamp 70) | 182 | (add-hook 'erc-insert-modify-hook #'erc-add-timestamp 70) |
| 183 | (add-hook 'erc-send-modify-hook #'erc-add-timestamp 70) | 183 | (add-hook 'erc-send-modify-hook #'erc-add-timestamp 70) |
| 184 | (add-hook 'erc-mode-hook #'erc-stamp--recover-on-reconnect) | 184 | (add-hook 'erc-mode-hook #'erc-stamp--recover-on-reconnect) |
| 185 | (add-hook 'erc--pre-clear-functions #'erc-stamp--reset-on-clear) | 185 | (add-hook 'erc--pre-clear-functions #'erc-stamp--reset-on-clear 40) |
| 186 | (unless erc--updating-modules-p (erc-buffer-do #'erc-stamp--setup))) | 186 | (unless erc--updating-modules-p (erc-buffer-do #'erc-stamp--setup))) |
| 187 | ((remove-hook 'erc-mode-hook #'erc-munge-invisibility-spec) | 187 | ((remove-hook 'erc-mode-hook #'erc-munge-invisibility-spec) |
| 188 | (remove-hook 'erc-insert-modify-hook #'erc-add-timestamp) | 188 | (remove-hook 'erc-insert-modify-hook #'erc-add-timestamp) |
| @@ -973,8 +973,9 @@ with the option `erc-echo-timestamps', see the companion option | |||
| 973 | (defun erc-stamp--reset-on-clear (pos) | 973 | (defun erc-stamp--reset-on-clear (pos) |
| 974 | "Forget last-inserted stamps when POS is at insert marker." | 974 | "Forget last-inserted stamps when POS is at insert marker." |
| 975 | (when (= pos (1- erc-insert-marker)) | 975 | (when (= pos (1- erc-insert-marker)) |
| 976 | (add-hook 'erc-stamp--insert-date-hook | 976 | (when erc-stamp--date-mode |
| 977 | #'erc-stamp--update-saved-position 0 t) | 977 | (add-hook 'erc-stamp--insert-date-hook |
| 978 | #'erc-stamp--update-saved-position 0 t)) | ||
| 978 | (setq erc-timestamp-last-inserted nil | 979 | (setq erc-timestamp-last-inserted nil |
| 979 | erc-timestamp-last-inserted-left nil | 980 | erc-timestamp-last-inserted-left nil |
| 980 | erc-timestamp-last-inserted-right nil))) | 981 | erc-timestamp-last-inserted-right nil))) |
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 64629026704..6eee8bcae92 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el | |||
| @@ -4160,12 +4160,16 @@ If no USER argument is specified, list the contents of `erc-ignore-list'." | |||
| 4160 | Called with position indicating boundary of interval to be excised.") | 4160 | Called with position indicating boundary of interval to be excised.") |
| 4161 | 4161 | ||
| 4162 | (defun erc-cmd-CLEAR () | 4162 | (defun erc-cmd-CLEAR () |
| 4163 | "Clear the window content." | 4163 | "Clear messages in current buffer after informing active modules. |
| 4164 | (let ((inhibit-read-only t)) | 4164 | Expect modules to perform housekeeping tasks to withstand the |
| 4165 | (run-hook-with-args 'erc--pre-clear-functions (1- erc-insert-marker)) | 4165 | disruption. When called from lisp code, only clear messages up |
| 4166 | ;; Ostensibly, `line-beginning-position' is for use in lisp code. | 4166 | to but not including the one occupying the current line." |
| 4167 | (delete-region (point-min) (min (line-beginning-position) | 4167 | (with-silent-modifications |
| 4168 | (1- erc-insert-marker)))) | 4168 | (let ((max (if (>= (point) erc-insert-marker) |
| 4169 | (1- erc-insert-marker) | ||
| 4170 | (or (erc--get-inserted-msg-bounds 'beg) (pos-bol))))) | ||
| 4171 | (run-hook-with-args 'erc--pre-clear-functions max) | ||
| 4172 | (delete-region (point-min) max))) | ||
| 4169 | t) | 4173 | t) |
| 4170 | (put 'erc-cmd-CLEAR 'process-not-needed t) | 4174 | (put 'erc-cmd-CLEAR 'process-not-needed t) |
| 4171 | 4175 | ||
diff --git a/test/lisp/erc/erc-scenarios-log.el b/test/lisp/erc/erc-scenarios-log.el index cd28ea54b2e..cff88d59c85 100644 --- a/test/lisp/erc/erc-scenarios-log.el +++ b/test/lisp/erc/erc-scenarios-log.el | |||
| @@ -206,4 +206,59 @@ | |||
| 206 | (erc-truncate-mode -1) | 206 | (erc-truncate-mode -1) |
| 207 | (when noninteractive (delete-directory tempdir :recursive)))) | 207 | (when noninteractive (delete-directory tempdir :recursive)))) |
| 208 | 208 | ||
| 209 | (defvar erc-insert-timestamp-function) | ||
| 210 | (declare-function erc-insert-timestamp-left "erc-stamp" (string)) | ||
| 211 | |||
| 212 | (ert-deftest erc-scenarios-log--save-buffer-in-logs/truncate-on-save () | ||
| 213 | :tags '(:expensive-test) | ||
| 214 | (erc-scenarios-common-with-cleanup | ||
| 215 | ((erc-scenarios-common-dialog "base/assoc/bouncer-history") | ||
| 216 | (dumb-server (erc-d-run "localhost" t 'foonet)) | ||
| 217 | (tempdir (make-temp-file "erc-tests-log." t nil nil)) | ||
| 218 | (erc-log-channels-directory tempdir) | ||
| 219 | (erc-modules (cons 'log erc-modules)) | ||
| 220 | (port (process-contact dumb-server :service)) | ||
| 221 | (erc-truncate-buffer-on-save t) | ||
| 222 | (logchan (expand-file-name (format "#chan!tester@127.0.0.1:%d.txt" port) | ||
| 223 | tempdir)) | ||
| 224 | (erc-server-flood-penalty 0.1) | ||
| 225 | (erc-insert-timestamp-function #'erc-insert-timestamp-left) | ||
| 226 | (expect (erc-d-t-make-expecter))) | ||
| 227 | |||
| 228 | (unless noninteractive | ||
| 229 | (add-hook 'kill-emacs-hook | ||
| 230 | (lambda () (delete-directory tempdir :recursive)))) | ||
| 231 | |||
| 232 | (ert-info ("Connect to foonet") | ||
| 233 | (with-current-buffer (erc :server "127.0.0.1" | ||
| 234 | :port port | ||
| 235 | :nick "tester" | ||
| 236 | :password "foonet:changeme" | ||
| 237 | :full-name "tester") | ||
| 238 | (should (string= (buffer-name) (format "127.0.0.1:%d" port))))) | ||
| 239 | |||
| 240 | (with-current-buffer (erc-d-t-wait-for 5 (get-buffer "#chan")) | ||
| 241 | (funcall expect 10 "<someone> [07:04:10] hi everyone") | ||
| 242 | (should-not (file-exists-p logchan)) | ||
| 243 | ;; Simulate an M-x erc-save-buffer-in-logs RET | ||
| 244 | (cl-letf (((symbol-function 'called-interactively-p) #'always)) | ||
| 245 | (call-interactively #'erc-save-buffer-in-logs)) | ||
| 246 | (should (file-exists-p logchan)) | ||
| 247 | (funcall expect 10 "<alice> bob: As't please your lordship") | ||
| 248 | (erc-save-buffer-in-logs) | ||
| 249 | ;; Not truncated when called by lisp code. | ||
| 250 | (should (> (buffer-size) 400))) | ||
| 251 | |||
| 252 | (ert-info ("No double entries") | ||
| 253 | (with-temp-buffer | ||
| 254 | (insert-file-contents logchan) | ||
| 255 | (funcall expect 0.1 "hi everyone") | ||
| 256 | (funcall expect -0.1 "hi everyone") | ||
| 257 | (funcall expect 0.1 "Playback Complete") | ||
| 258 | (funcall expect -0.1 "Playback Complete") | ||
| 259 | (funcall expect 10 "<alice> bob: As't"))) | ||
| 260 | |||
| 261 | (erc-log-mode -1) | ||
| 262 | (when noninteractive (delete-directory tempdir :recursive)))) | ||
| 263 | |||
| 209 | ;;; erc-scenarios-log.el ends here | 264 | ;;; erc-scenarios-log.el ends here |