diff options
| author | F. Jason Park | 2023-10-31 16:50:16 -0700 |
|---|---|---|
| committer | F. Jason Park | 2023-11-01 16:14:10 -0700 |
| commit | 078cfe807295038fa321c9297e24de5145065622 (patch) | |
| tree | ab5c79b733cd8d5ec1c9dae9b0c597a8090af040 | |
| parent | 11e42b405ca222a037b7b3d215ef5d14a97ab929 (diff) | |
| download | emacs-078cfe807295038fa321c9297e24de5145065622.tar.gz emacs-078cfe807295038fa321c9297e24de5145065622.zip | |
Preserve point when inserting date stamps in ERC
* lisp/erc/erc-stamp.el (erc-stamp-mode, erc-stamp-disable): Move
remaining local teardown business to `erc-stamp--setup' and use
`erc-buffer-do' instead of `erc-with-all-buffers-of-server' to
emphasize that all ERC buffers are affected.
(erc-stamp--insert-date-stamp-as-phony-message): Move `erc--msg-props'
binding to `erc-stamp--lr-date-on-pre-modify'.
(erc-stamp--lr-date-on-pre-modify): Bind `erc--msg-props' here so that
the related guard condition in `erc-add-timestamp' is satisfied and
`erc-insert-timestamp-function' runs. This fixes a regression new in
ERC 5.6 and introduced by c68dc778 "Manage some text props for ERC
insertion-hook members". Also, `save-excursion' when narrowing to
prevent point from being dislodged after submitting input at the
prompt.
(erc-insert-timestamp-left-and-right): Don't initialize date stamps
when `erc-timestamp-format-left' is nil or consists only of newlines,
and enable fallback behavior in such cases on behalf of users without
informing them. Allow global hook members to run first so that those
owned by `scrolltobottom' and similar can see the unadulterated input.
Fix wrong hook name.
(erc-stamp--setup): Fix wrong hook name. Kill all local vars here
instead of sharing this duty with the minor-mode toggle. (Bug#60936)
| -rw-r--r-- | lisp/erc/erc-stamp.el | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/lisp/erc/erc-stamp.el b/lisp/erc/erc-stamp.el index b3812470a4d..412740ac192 100644 --- a/lisp/erc/erc-stamp.el +++ b/lisp/erc/erc-stamp.el | |||
| @@ -187,12 +187,7 @@ from entering them and instead jump over them." | |||
| 187 | (remove-hook 'erc-send-modify-hook #'erc-add-timestamp) | 187 | (remove-hook 'erc-send-modify-hook #'erc-add-timestamp) |
| 188 | (remove-hook 'erc-mode-hook #'erc-stamp--recover-on-reconnect) | 188 | (remove-hook 'erc-mode-hook #'erc-stamp--recover-on-reconnect) |
| 189 | (remove-hook 'erc--pre-clear-functions #'erc-stamp--reset-on-clear) | 189 | (remove-hook 'erc--pre-clear-functions #'erc-stamp--reset-on-clear) |
| 190 | (erc-with-all-buffers-of-server nil nil | 190 | (erc-buffer-do #'erc-stamp--setup))) |
| 191 | (erc-stamp--setup) | ||
| 192 | (kill-local-variable 'erc-stamp--last-stamp) | ||
| 193 | (kill-local-variable 'erc-timestamp-last-inserted) | ||
| 194 | (kill-local-variable 'erc-timestamp-last-inserted-left) | ||
| 195 | (kill-local-variable 'erc-timestamp-last-inserted-right)))) | ||
| 196 | 191 | ||
| 197 | (defvar erc-stamp--invisible-property nil | 192 | (defvar erc-stamp--invisible-property nil |
| 198 | "Existing `invisible' property value and/or symbol `timestamp'.") | 193 | "Existing `invisible' property value and/or symbol `timestamp'.") |
| @@ -664,11 +659,7 @@ printed just after each line's text (no alignment)." | |||
| 664 | (defun erc-stamp--insert-date-stamp-as-phony-message (string) | 659 | (defun erc-stamp--insert-date-stamp-as-phony-message (string) |
| 665 | (cl-assert (string-empty-p string)) | 660 | (cl-assert (string-empty-p string)) |
| 666 | (setq string erc-stamp--current-datestamp-left) | 661 | (setq string erc-stamp--current-datestamp-left) |
| 667 | (cl-assert string) | ||
| 668 | (let ((erc-stamp--skip t) | 662 | (let ((erc-stamp--skip t) |
| 669 | (erc--msg-props (map-into `((erc-msg . datestamp) | ||
| 670 | (erc-ts . ,(erc-stamp--current-time))) | ||
| 671 | 'hash-table)) | ||
| 672 | (erc-insert-modify-hook `(,@erc-insert-modify-hook | 663 | (erc-insert-modify-hook `(,@erc-insert-modify-hook |
| 673 | erc-stamp--propertize-left-date-stamp)) | 664 | erc-stamp--propertize-left-date-stamp)) |
| 674 | ;; Don't run hooks that aren't expecting a narrowed buffer. | 665 | ;; Don't run hooks that aren't expecting a narrowed buffer. |
| @@ -684,11 +675,17 @@ printed just after each line's text (no alignment)." | |||
| 684 | (erc-stamp--current-datestamp-left rendered) | 675 | (erc-stamp--current-datestamp-left rendered) |
| 685 | (erc-insert-timestamp-function | 676 | (erc-insert-timestamp-function |
| 686 | #'erc-stamp--insert-date-stamp-as-phony-message)) | 677 | #'erc-stamp--insert-date-stamp-as-phony-message)) |
| 687 | (save-restriction | 678 | (save-excursion |
| 688 | (narrow-to-region (or erc--insert-marker erc-insert-marker) | 679 | (save-restriction |
| 689 | (or erc--insert-marker erc-insert-marker)) | 680 | (narrow-to-region (or erc--insert-marker erc-insert-marker) |
| 690 | (let (erc-timestamp-format erc-away-timestamp-format) | 681 | (or erc--insert-marker erc-insert-marker)) |
| 691 | (erc-add-timestamp))))) | 682 | ;; Forget current `erc-cmd', etc. |
| 683 | (let ((erc--msg-props | ||
| 684 | (map-into `((erc-msg . datestamp) | ||
| 685 | (erc-ts . ,(erc-stamp--current-time))) | ||
| 686 | 'hash-table)) | ||
| 687 | erc-timestamp-format erc-away-timestamp-format) | ||
| 688 | (erc-add-timestamp)))))) | ||
| 692 | 689 | ||
| 693 | (defvar erc-stamp-prepend-date-stamps-p nil | 690 | (defvar erc-stamp-prepend-date-stamps-p nil |
| 694 | "When non-nil, date stamps are not independent messages. | 691 | "When non-nil, date stamps are not independent messages. |
| @@ -714,9 +711,13 @@ requirements related to `erc-legacy-invisible-bounds-p'. | |||
| 714 | Additionally, ensure every date stamp is identifiable as such so | 711 | Additionally, ensure every date stamp is identifiable as such so |
| 715 | that internal modules can easily distinguish between other | 712 | that internal modules can easily distinguish between other |
| 716 | left-sided stamps and date stamps inserted by this function." | 713 | left-sided stamps and date stamps inserted by this function." |
| 717 | (unless (or erc-stamp--date-format-end erc-stamp-prepend-date-stamps-p) | 714 | (unless (or erc-stamp--date-format-end erc-stamp-prepend-date-stamps-p |
| 718 | (add-hook 'erc-insert-pre-hook #'erc-stamp--lr-date-on-pre-modify -95 t) | 715 | (and (or (null erc-timestamp-format-left) |
| 719 | (add-hook 'erc-send-pre-functions #'erc-stamp--lr-date-on-pre-modify -95 t) | 716 | (string-empty-p ; compat |
| 717 | (string-trim erc-timestamp-format-left "\n"))) | ||
| 718 | (setq erc-stamp-prepend-date-stamps-p t))) | ||
| 719 | (add-hook 'erc-insert-pre-hook #'erc-stamp--lr-date-on-pre-modify 10 t) | ||
| 720 | (add-hook 'erc-pre-send-functions #'erc-stamp--lr-date-on-pre-modify 10 t) | ||
| 720 | (let ((erc--insert-marker (point-min-marker)) | 721 | (let ((erc--insert-marker (point-min-marker)) |
| 721 | (end-marker (point-max-marker))) | 722 | (end-marker (point-max-marker))) |
| 722 | (set-marker-insertion-type erc--insert-marker t) | 723 | (set-marker-insertion-type erc--insert-marker t) |
| @@ -817,7 +818,11 @@ Return the empty string if FORMAT is nil." | |||
| 817 | (erc-munge-invisibility-spec)) | 818 | (erc-munge-invisibility-spec)) |
| 818 | ;; Undo local mods from `erc-insert-timestamp-left-and-right'. | 819 | ;; Undo local mods from `erc-insert-timestamp-left-and-right'. |
| 819 | (remove-hook 'erc-insert-pre-hook #'erc-stamp--lr-date-on-pre-modify t) | 820 | (remove-hook 'erc-insert-pre-hook #'erc-stamp--lr-date-on-pre-modify t) |
| 820 | (remove-hook 'erc-send-pre-functions #'erc-stamp--lr-date-on-pre-modify t) | 821 | (remove-hook 'erc-pre-send-functions #'erc-stamp--lr-date-on-pre-modify t) |
| 822 | (kill-local-variable 'erc-stamp--last-stamp) | ||
| 823 | (kill-local-variable 'erc-timestamp-last-inserted) | ||
| 824 | (kill-local-variable 'erc-timestamp-last-inserted-left) | ||
| 825 | (kill-local-variable 'erc-timestamp-last-inserted-right) | ||
| 821 | (kill-local-variable 'erc-stamp--date-format-end))) | 826 | (kill-local-variable 'erc-stamp--date-format-end))) |
| 822 | 827 | ||
| 823 | (defun erc-hide-timestamps () | 828 | (defun erc-hide-timestamps () |