From 91fcae659fd6193475f5c92c95837072e8e717da Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Thu, 20 Jul 2023 05:39:13 -0700 Subject: [PATCH 0/1] *** NOT A PATCH *** *** BLURB HERE *** F. Jason Park (1): [5.6] Make erc-fill-wrap work with left-sided stamps etc/ERC-NEWS | 20 +- lisp/erc/erc-backend.el | 23 +- lisp/erc/erc-compat.el | 1 + lisp/erc/erc-fill.el | 126 ++++++++--- lisp/erc/erc-stamp.el | 210 +++++++++++++----- lisp/erc/erc.el | 26 ++- test/lisp/erc/erc-fill-tests.el | 37 +++ test/lisp/erc/erc-stamp-tests.el | 29 ++- test/lisp/erc/erc-tests.el | 6 + .../fill/snapshots/stamps-left-01.eld | 1 + 10 files changed, 362 insertions(+), 117 deletions(-) create mode 100644 test/lisp/erc/resources/fill/snapshots/stamps-left-01.eld Interdiff: diff --git a/etc/ERC-NEWS b/etc/ERC-NEWS index 2369aeeabc2..13e49a9123d 100644 --- a/etc/ERC-NEWS +++ b/etc/ERC-NEWS @@ -225,7 +225,8 @@ Chiefly, 'rear-sticky' has been replaced by 'erc-command', which records the IRC command (or numeric) associated with a message. Less impactfully, the value of the 'field' property for ERC's prompt has changed from 't' to the more useful 'erc-prompt', although the -property of the same name has been retained. +property of the same name has been retained and now has a value of +'hidden' when disconnected. *** Members of insert- and send-related hooks have been reordered. Built-in and third-party modules rely on certain hooks for adjusting @@ -258,6 +259,16 @@ Additionally, the 'stamp' module now merges its 'invisible' property with existing ones, when present, and it includes all white space around stamps when doing so. +Moreover, such "propertizing" of surrounding white space now extends +to all 'stamp'-applied properties, like 'field', in all intervening +space between message text and timestamps. This constitutes a +breaking change from the perspective of detecting a timestamp's +bounds. For example, ERC has always propertized leading space before +right-sided stamps on the same line as message text but not those +folded onto the next line. This inconsistency made stamp detection +overly complex and produced uneven results when toggling stamp +visibility. + *** The role of a module's Custom group is now more clearly defined. Associating built-in modules with Custom groups and provided library features has improved. More specifically, a module's group now enjoys diff --git a/lisp/erc/erc-fill.el b/lisp/erc/erc-fill.el index 6c2228f6337..2c5be590c60 100644 --- a/lisp/erc/erc-fill.el +++ b/lisp/erc/erc-fill.el @@ -355,28 +355,33 @@ fill-wrap "Fill style leveraging `visual-line-mode'. This local module displays nicks overhanging leftward to a common offset, as determined by the option `erc-fill-static-center'. It -depends on the `fill' and `button' modules and assumes users -who've defined their own `erc-insert-timestamp-function' have -also customized the option `erc-fill-wrap-margin-side' to an +depends on the `fill', `stamp', and `button' modules and assumes +users who've defined their own `erc-insert-timestamp-function' +have also customized the option `erc-fill-wrap-margin-side' to an explicit side. To use this module, either include `fill-wrap' in -`erc-modules' or set `erc-fill-function' to -`erc-fill-wrap' (recommended). You can also manually invoke one -of the minor-mode toggles if really necessary. - -When stamps appear in the right margin, which they do by default, -users may find that ERC actually appends them to copy-as-killed -messages without an intervening space. This normally poses at -most a minor nuisance, however users of the `log' module may -prefer a workaround provided by `erc-stamp-prefix-log-filter', -which strips trailing stamps from logged messages and instead -prepends them to every line." +`erc-modules' or set `erc-fill-function' to `erc-fill-wrap'. +Manually invoking one of the minor-mode toggles is not +recommended. + +This module imposes various restrictions on the appearance of +timestamps. Most notably, it insists on displaying them in the +margins. Users preferring left-sided stamps may notice that ERC +also displays the prompt in the left margin, possibly truncating +or padding it to constrain it to the margin's width. When stamps +appear in the right margin, which they do by default, users may +find that ERC actually appends them to copy-as-killed messages +without an intervening space. This normally poses at most a +minor inconvenience, however users of the `log' module may prefer +a workaround provided by `erc-stamp-prefix-log-filter', which +strips trailing stamps from logged messages and instead prepends +them to every line." ((erc-fill--wrap-ensure-dependencies) (erc--restore-initialize-priors erc-fill-wrap-mode erc-fill--wrap-visual-keys erc-fill-wrap-visual-keys erc-fill--wrap-value erc-fill-static-center erc-stamp--margin-width erc-fill-wrap-margin-width - left-margin-width 0 - right-margin-width 0) + left-margin-width left-margin-width + right-margin-width right-margin-width) ;; Only give this a local binding if known for sure. (when erc-fill-wrap-margin-side (setq erc-stamp--margin-left-p @@ -384,8 +389,7 @@ fill-wrap (setq erc-fill--function #'erc-fill-wrap) (add-function :after (local 'erc-stamp--insert-date-function) #'erc-fill--wrap-stamp-insert-prefixed-date) - (when (or erc-stamp-mode (memq 'stamp erc-modules)) - (erc-stamp--display-margin-mode +1)) + (erc-stamp--display-margin-mode +1) (when (or (bound-and-true-p erc-match-mode) (memq 'match erc-modules)) (require 'erc-match) (setq erc-match--hide-fools-offset-bounds t)) @@ -393,16 +397,15 @@ fill-wrap (add-hook 'erc-button--prev-next-predicate-functions #'erc-fill--wrap-merged-button-p nil t)) (visual-line-mode +1)) - ((when erc-stamp--display-margin-mode - (erc-stamp--display-margin-mode -1)) + ((visual-line-mode -1) + (erc-stamp--display-margin-mode -1) (kill-local-variable 'erc-fill--wrap-value) (kill-local-variable 'erc-fill--function) (kill-local-variable 'erc-fill--wrap-visual-keys) (remove-hook 'erc-button--prev-next-predicate-functions #'erc-fill--wrap-merged-button-p t) (remove-function (local 'erc-stamp--insert-date-function) - #'erc-fill--wrap-stamp-insert-prefixed-date) - (visual-line-mode -1)) + #'erc-fill--wrap-stamp-insert-prefixed-date)) 'local) (defvar-local erc-fill--wrap-length-function nil diff --git a/lisp/erc/erc-stamp.el b/lisp/erc/erc-stamp.el index eff99766d81..f98e0b04426 100644 --- a/lisp/erc/erc-stamp.el +++ b/lisp/erc/erc-stamp.el @@ -404,7 +404,8 @@ erc-stamp--display-margin-mode #'erc-stamp--display-prompt-in-left-margin nil t))) (remove-function (local 'filter-buffer-substring-function) #'erc--remove-text-properties) - (add-hook 'erc-after-connect #'erc-stamp--init-margins-on-connect t) + (remove-hook 'erc-after-connect + #'erc-stamp--init-margins-on-connect t) (remove-hook 'erc--refresh-prompt-hook #'erc-stamp--display-prompt-in-left-margin t) (remove-hook 'erc--setup-buffer-hook @@ -413,7 +414,6 @@ erc-stamp--display-margin-mode 'left-margin-width 'right-margin-width)) (kill-local-variable 'fringes-outside-margins) - (kill-local-variable 'erc-stamp--margin-prompt-width) (kill-local-variable 'erc-stamp--margin-left-p) (kill-local-variable 'erc-stamp--margin-width) (when (eq (current-buffer) (window-buffer)) @@ -504,6 +504,12 @@ erc-insert-aligned ;; Silence byte-compiler (defvar erc-fill-column) +(defvar erc-stamp--omit-properties-on-folded-lines nil + "Skip properties before right stamps occupying their own line. +This escape hatch restores pre-5.6 behavior that left leading +white space alone (unpropertized) for right-sided stamps folded +onto their own line.") + (defun erc-insert-timestamp-right (string) "Insert timestamp on the right side of the screen. STRING is the timestamp to insert. This function is a possible @@ -572,7 +578,8 @@ erc-insert-timestamp-right (let ((s (+ erc-timestamp-use-align-to (string-width string)))) (put-text-property from (point) 'display `(space :align-to (- right ,s))))) - ((guard (>= col pos)) (newline) (indent-to pos) (setq from (point))) + ((guard (>= col pos)) (newline) (indent-to pos) + (when erc-stamp--omit-properties-on-folded-lines (setq from (point)))) (_ (indent-to pos))) (insert string) (dolist (p erc-stamp--inherited-props) diff --git a/test/lisp/erc/erc-stamp-tests.el b/test/lisp/erc/erc-stamp-tests.el index f6de087a09a..c448416cd69 100644 --- a/test/lisp/erc/erc-stamp-tests.el +++ b/test/lisp/erc/erc-stamp-tests.el @@ -56,7 +56,7 @@ erc-stamp-tests--insert-right (advice-remove 'erc-format-timestamp 'ert-deftest--erc-timestamp-use-align-to))) -(ert-deftest erc-timestamp-use-align-to--nil () +(defun erc-stamp-tests--use-align-to--nil (compat) (erc-stamp-tests--insert-right (lambda () @@ -83,12 +83,20 @@ erc-timestamp-use-align-to--nil (erc-display-message nil 'notice (current-buffer) "twenty characters")) (should (search-forward-regexp (rx bol (+ "\t") (* " ") "[") nil t)) - ;; Field excludes leading whitespace (arguably undesirable). - (should (eql ?\[ (char-after (field-beginning (point))))) + ;; Field includes leading whitespace. + (should (eql (if compat ?\[ ?\n) + (char-after (field-beginning (point))))) ;; Timestamp extends to the end of the line. (should (eql ?\n (char-after (field-end (point))))))))) -(ert-deftest erc-timestamp-use-align-to--t () +(ert-deftest erc-timestamp-use-align-to--nil () + (ert-info ("Field starts on stamp text (compat)") + (let ((erc-stamp--omit-properties-on-folded-lines t)) + (erc-stamp-tests--use-align-to--nil 'compat))) + (ert-info ("Field includes leaidng white space") + (erc-stamp-tests--use-align-to--nil nil))) + +(defun erc-stamp-tests--use-align-to--t (compat) (erc-stamp-tests--insert-right (lambda () @@ -110,10 +118,17 @@ erc-timestamp-use-align-to--t (erc-display-message nil nil (current-buffer) msg))) ;; Indented to pos (this is arguably a bug). (should (search-forward-regexp (rx bol (+ "\t") (* " ") "[") nil t)) - ;; Field starts *after* leading space (arguably bad). - (should (eql ?\[ (char-after (field-beginning (point))))) + ;; Field includes leading space. + (should (eql (if compat ?\[ ?\n) (char-after (field-beginning (point))))) (should (eql ?\n (char-after (field-end (point))))))))) +(ert-deftest erc-timestamp-use-align-to--t () + (ert-info ("Field starts on stamp text (compat)") + (let ((erc-stamp--omit-properties-on-folded-lines t)) + (erc-stamp-tests--use-align-to--t 'compat))) + (ert-info ("Field includes leaidng white space") + (erc-stamp-tests--use-align-to--t nil))) + (ert-deftest erc-timestamp-use-align-to--integer () (erc-stamp-tests--insert-right (lambda () -- 2.41.0