diff options
| author | F. Jason Park | 2023-07-14 06:12:30 -0700 |
|---|---|---|
| committer | F. Jason Park | 2023-07-22 07:33:07 -0700 |
| commit | 63d8b2a59a4f395ca64adb698cdb4764d80dfbee (patch) | |
| tree | bdd38bda05c4c50da66c9c9ae3c988e7396aa313 /test | |
| parent | d09464e50482a792cc11c20916167d3f62637c2d (diff) | |
| download | emacs-63d8b2a59a4f395ca64adb698cdb4764d80dfbee.tar.gz emacs-63d8b2a59a4f395ca64adb698cdb4764d80dfbee.zip | |
Make erc-fill-wrap work with left-sided stamps
* etc/ERC-NEWS: Remove all mention of option `erc-timestamp-align-to'
supporting a value of `margin', which has been abandoned. Do mention
leading white space before stamps now having stamp-related properties.
* lisp/erc/erc-backend.el (erc--reveal-prompt, erc--conceal-prompt):
New generic functions with default implementations factored out from
`erc--unhide-prompt' and `erc--hide-prompt'.
(erc--prompt-hidden-p): New internal predicate function.
(erc--unhide-prompt): Defer to `erc--reveal-prompt', and set
`erc-prompt' text property to t.
(erc--hide-prompt): Defer to `erc--conceal-prompt', and set
`erc-prompt' text property to `hidden'.
* lisp/erc/erc-compat.el (erc-compat--29-browse-url-irc): Don't
use `function-equal'.
* lisp/erc/erc-fill.el (erc-fill-wrap-margin-width,
erc-fill-wrap-margin-side): New options to control side and initial
width of `fill-wrap' margin.
(erc-fill--wrap-beginning-of-line): Fix bug involving non-string
valued `display' props.
(erc-fill-wrap-toggle-truncate-lines): New command to re-enable
`visual-line-mode' when toggling off `truncate-lines'.
(erc-fill-wrap-mode-map): Remap `toggle-truncate-lines' to
`erc-fill-wrap-toggle-truncate-lines'.
(erc-fill-wrap-mode, erc-fill-wrap-enable, erc-fill-wrap-disable):
Update doc string, persist a few local vars, and conditionally set
`erc-stamp--margin-left-p'. When deactivating, disable
`visual-line-mode' first.
(erc-fill--wrap-continued-message-p): Use `erc-speaker' instead of
heuristics when comparing nicks between consecutive messages.
(erc-fill-wrap-nudge): Update doc string and account for left-sided
stamps.
(erc-timestamp-offset): Add comment regarding conditional guard based
on function-valued option.
* lisp/erc/erc-stamp.el (erc-timestamp-use-align-to): Remove value
variant `margin', which was originally intended to be new in ERC 5.6.
This functionality was all but useless without the internal minor mode
`erc-stamp--display-margin-mode' active.
(erc-stamp-right-margin-width): Remove unused option new in 5.6.
(erc-stamp--display-margin-force): Remove unused function.
(erc-stamp--margin-width, erc-stamp--margin-left-p): New internal
variables.
(erc-stamp--init-margins-on-connect): New function for initializing
mode-managed margin after connecting.
(erc-stamp--adjust-right-margin, erc-stamp--adjust-margin): Rename
function to latter and accommodate left-hand stamps.
(erc-stamp--inherited-props): Move definition higher up in same file.
(erc-stamp--display-margin-mode): Update function name, and adjust
setup and teardown to accommodate left-handed stamps. Don't add
advice around `erc-insert-timestamp-function'.
(erc-stamp--last-prompt, erc-stamp--display-prompt-in-left-margin):
New function and helper var to convert a normal inserted prompt so
that it appears in the left margin.
(erc-stamp--refresh-left-margin-prompt): Helper for other modules to
quickly refresh prompt outside of insert hooks.
(erc--reveal-prompt, erc--conceal-prompt): New implementations for
when `erc-stamp--display-margin-mode' is active.
(erc-insert-timestamp-left): Convert to generic function and provide
implementation for `erc-stamp--display-margin-mode'.
(erc-stamp--omit-properties-on-folded-lines): New variable, an escape
hatch for propertizing white space before right-side stamps folded
over onto another line.
(erc-insert-timestamp-right): Don't expect `erc-timestamp-align-to' to
ever be the symbol `margin'. Move handling for that case to one
contingent on the internal minor mode `erc-stamp--display-margin-mode'
being active. Add text properties preceding stamps that occupy a line
by their lonesome. See related news entry for rationale. This is
arguably a breaking change.
* lisp/erc/erc.el (erc--refresh-prompt-hook): New hook variable for
modules to adjust prompt properties whenever it's refreshed.
(erc--refresh-prompt): Fix bug in which user-defined prompt functions
failed to hide when quitting in server buffers. Run new hook
`erc--refresh-prompt-hook'.
(erc-display-prompt): Add comment noting that the text property
`erc-prompt' now actually matters: it's t while a session is running
and `hidden' when disconnected.
* test/lisp/erc/erc-fill-tests.el (erc-fill--left-hand-stamps): New
test.
* test/lisp/erc/erc-stamp-tests.el
(erc-stamp-tests--use-align-to--nil,
erc-stamp-tests--use-align-to--t): New functions forged from old test
bodies to allow optionally asserting pre-5.6 behavior regarding
leading white space on right-hand stamps that exist on their own line.
(erc-timestamp-use-align-to--nil, erc-timestamp-use-align-to--t):
Parameterize with compatibility flag.
(erc-timestamp-use-align-to--margin,
erc-stamp--display-margin-mode--right): Rename test to latter.
* test/lisp/erc/erc-tests.el (erc-hide-prompt): Add some assertions
for new possible value of `erc-prompt' text property.
* test/lisp/erc/resources/fill/snapshots/stamps-left-01.eld: New test
data file. (Bug#60936)
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/erc/erc-fill-tests.el | 37 | ||||
| -rw-r--r-- | test/lisp/erc/erc-stamp-tests.el | 29 | ||||
| -rw-r--r-- | test/lisp/erc/erc-tests.el | 6 | ||||
| -rw-r--r-- | test/lisp/erc/resources/fill/snapshots/stamps-left-01.eld | 1 |
4 files changed, 66 insertions, 7 deletions
diff --git a/test/lisp/erc/erc-fill-tests.el b/test/lisp/erc/erc-fill-tests.el index 99ec4a9635e..67622da9f3d 100644 --- a/test/lisp/erc/erc-fill-tests.el +++ b/test/lisp/erc/erc-fill-tests.el | |||
| @@ -340,4 +340,41 @@ | |||
| 340 | (should (search-backward "ERC> " nil t)) | 340 | (should (search-backward "ERC> " nil t)) |
| 341 | (execute-kbd-macro "\C-a"))))) | 341 | (execute-kbd-macro "\C-a"))))) |
| 342 | 342 | ||
| 343 | (ert-deftest erc-fill--left-hand-stamps () | ||
| 344 | :tags '(:unstable) | ||
| 345 | (unless (>= emacs-major-version 29) | ||
| 346 | (ert-skip "Emacs version too low, missing `buffer-text-pixel-size'")) | ||
| 347 | |||
| 348 | (let ((erc-timestamp-only-if-changed-flag nil) | ||
| 349 | (erc-insert-timestamp-function #'erc-insert-timestamp-left)) | ||
| 350 | (erc-fill-tests--wrap-populate | ||
| 351 | (lambda () | ||
| 352 | (should (= 8 left-margin-width)) | ||
| 353 | (pcase-let ((`((margin left-margin) ,displayed) | ||
| 354 | (get-text-property erc-insert-marker 'display))) | ||
| 355 | (should (equal-including-properties | ||
| 356 | displayed #(" ERC>" 4 8 | ||
| 357 | ( read-only t | ||
| 358 | front-sticky t | ||
| 359 | field erc-prompt | ||
| 360 | erc-prompt t | ||
| 361 | rear-nonsticky t | ||
| 362 | font-lock-face erc-prompt-face))))) | ||
| 363 | (erc-fill-tests--compare "stamps-left-01") | ||
| 364 | |||
| 365 | (ert-info ("Shrink left margin by 1 col") | ||
| 366 | (erc-stamp--adjust-margin -1) | ||
| 367 | (with-silent-modifications (erc--refresh-prompt)) | ||
| 368 | (should (= 7 left-margin-width)) | ||
| 369 | (pcase-let ((`((margin left-margin) ,displayed) | ||
| 370 | (get-text-property erc-insert-marker 'display))) | ||
| 371 | (should (equal-including-properties | ||
| 372 | displayed #(" ERC>" 3 7 | ||
| 373 | ( read-only t | ||
| 374 | front-sticky t | ||
| 375 | field erc-prompt | ||
| 376 | erc-prompt t | ||
| 377 | rear-nonsticky t | ||
| 378 | font-lock-face erc-prompt-face)))))))))) | ||
| 379 | |||
| 343 | ;;; erc-fill-tests.el ends here | 380 | ;;; erc-fill-tests.el ends here |
diff --git a/test/lisp/erc/erc-stamp-tests.el b/test/lisp/erc/erc-stamp-tests.el index 6da7ed4503d..c448416cd69 100644 --- a/test/lisp/erc/erc-stamp-tests.el +++ b/test/lisp/erc/erc-stamp-tests.el | |||
| @@ -56,7 +56,7 @@ | |||
| 56 | (advice-remove 'erc-format-timestamp | 56 | (advice-remove 'erc-format-timestamp |
| 57 | 'ert-deftest--erc-timestamp-use-align-to))) | 57 | 'ert-deftest--erc-timestamp-use-align-to))) |
| 58 | 58 | ||
| 59 | (ert-deftest erc-timestamp-use-align-to--nil () | 59 | (defun erc-stamp-tests--use-align-to--nil (compat) |
| 60 | (erc-stamp-tests--insert-right | 60 | (erc-stamp-tests--insert-right |
| 61 | (lambda () | 61 | (lambda () |
| 62 | 62 | ||
| @@ -83,12 +83,20 @@ | |||
| 83 | (erc-display-message nil 'notice (current-buffer) | 83 | (erc-display-message nil 'notice (current-buffer) |
| 84 | "twenty characters")) | 84 | "twenty characters")) |
| 85 | (should (search-forward-regexp (rx bol (+ "\t") (* " ") "[") nil t)) | 85 | (should (search-forward-regexp (rx bol (+ "\t") (* " ") "[") nil t)) |
| 86 | ;; Field excludes leading whitespace (arguably undesirable). | 86 | ;; Field includes leading whitespace. |
| 87 | (should (eql ?\[ (char-after (field-beginning (point))))) | 87 | (should (eql (if compat ?\[ ?\n) |
| 88 | (char-after (field-beginning (point))))) | ||
| 88 | ;; Timestamp extends to the end of the line. | 89 | ;; Timestamp extends to the end of the line. |
| 89 | (should (eql ?\n (char-after (field-end (point))))))))) | 90 | (should (eql ?\n (char-after (field-end (point))))))))) |
| 90 | 91 | ||
| 91 | (ert-deftest erc-timestamp-use-align-to--t () | 92 | (ert-deftest erc-timestamp-use-align-to--nil () |
| 93 | (ert-info ("Field starts on stamp text (compat)") | ||
| 94 | (let ((erc-stamp--omit-properties-on-folded-lines t)) | ||
| 95 | (erc-stamp-tests--use-align-to--nil 'compat))) | ||
| 96 | (ert-info ("Field includes leaidng white space") | ||
| 97 | (erc-stamp-tests--use-align-to--nil nil))) | ||
| 98 | |||
| 99 | (defun erc-stamp-tests--use-align-to--t (compat) | ||
| 92 | (erc-stamp-tests--insert-right | 100 | (erc-stamp-tests--insert-right |
| 93 | (lambda () | 101 | (lambda () |
| 94 | 102 | ||
| @@ -110,10 +118,17 @@ | |||
| 110 | (erc-display-message nil nil (current-buffer) msg))) | 118 | (erc-display-message nil nil (current-buffer) msg))) |
| 111 | ;; Indented to pos (this is arguably a bug). | 119 | ;; Indented to pos (this is arguably a bug). |
| 112 | (should (search-forward-regexp (rx bol (+ "\t") (* " ") "[") nil t)) | 120 | (should (search-forward-regexp (rx bol (+ "\t") (* " ") "[") nil t)) |
| 113 | ;; Field starts *after* leading space (arguably bad). | 121 | ;; Field includes leading space. |
| 114 | (should (eql ?\[ (char-after (field-beginning (point))))) | 122 | (should (eql (if compat ?\[ ?\n) (char-after (field-beginning (point))))) |
| 115 | (should (eql ?\n (char-after (field-end (point))))))))) | 123 | (should (eql ?\n (char-after (field-end (point))))))))) |
| 116 | 124 | ||
| 125 | (ert-deftest erc-timestamp-use-align-to--t () | ||
| 126 | (ert-info ("Field starts on stamp text (compat)") | ||
| 127 | (let ((erc-stamp--omit-properties-on-folded-lines t)) | ||
| 128 | (erc-stamp-tests--use-align-to--t 'compat))) | ||
| 129 | (ert-info ("Field includes leaidng white space") | ||
| 130 | (erc-stamp-tests--use-align-to--t nil))) | ||
| 131 | |||
| 117 | (ert-deftest erc-timestamp-use-align-to--integer () | 132 | (ert-deftest erc-timestamp-use-align-to--integer () |
| 118 | (erc-stamp-tests--insert-right | 133 | (erc-stamp-tests--insert-right |
| 119 | (lambda () | 134 | (lambda () |
| @@ -140,7 +155,7 @@ | |||
| 140 | (should (eql ?\s (char-after (field-beginning (point))))) | 155 | (should (eql ?\s (char-after (field-beginning (point))))) |
| 141 | (should (eql ?\n (char-after (field-end (point))))))))) | 156 | (should (eql ?\n (char-after (field-end (point))))))))) |
| 142 | 157 | ||
| 143 | (ert-deftest erc-timestamp-use-align-to--margin () | 158 | (ert-deftest erc-stamp--display-margin-mode--right () |
| 144 | (erc-stamp-tests--insert-right | 159 | (erc-stamp-tests--insert-right |
| 145 | (lambda () | 160 | (lambda () |
| 146 | (erc-stamp--display-margin-mode +1) | 161 | (erc-stamp--display-margin-mode +1) |
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el index b5db5fe8764..fff3c4cb704 100644 --- a/test/lisp/erc/erc-tests.el +++ b/test/lisp/erc/erc-tests.el | |||
| @@ -219,6 +219,7 @@ | |||
| 219 | (setq erc-hide-prompt '(server)) | 219 | (setq erc-hide-prompt '(server)) |
| 220 | (with-current-buffer "ServNet" | 220 | (with-current-buffer "ServNet" |
| 221 | (erc--hide-prompt erc-server-process) | 221 | (erc--hide-prompt erc-server-process) |
| 222 | (should (eq (get-text-property erc-insert-marker 'erc-prompt) 'hidden)) | ||
| 222 | (should (string= ">" (get-text-property erc-insert-marker 'display)))) | 223 | (should (string= ">" (get-text-property erc-insert-marker 'display)))) |
| 223 | 224 | ||
| 224 | (with-current-buffer "#chan" | 225 | (with-current-buffer "#chan" |
| @@ -229,6 +230,7 @@ | |||
| 229 | 230 | ||
| 230 | (with-current-buffer "ServNet" | 231 | (with-current-buffer "ServNet" |
| 231 | (erc--unhide-prompt) | 232 | (erc--unhide-prompt) |
| 233 | (should (eq (get-text-property erc-insert-marker 'erc-prompt) t)) | ||
| 232 | (should-not (get-text-property erc-insert-marker 'display)))) | 234 | (should-not (get-text-property erc-insert-marker 'display)))) |
| 233 | 235 | ||
| 234 | (ert-info ("Value: channel") | 236 | (ert-info ("Value: channel") |
| @@ -242,7 +244,9 @@ | |||
| 242 | 244 | ||
| 243 | (with-current-buffer "#chan" | 245 | (with-current-buffer "#chan" |
| 244 | (should (string= ">" (get-text-property erc-insert-marker 'display))) | 246 | (should (string= ">" (get-text-property erc-insert-marker 'display))) |
| 247 | (should (eq (get-text-property erc-insert-marker 'erc-prompt) 'hidden)) | ||
| 245 | (erc--unhide-prompt) | 248 | (erc--unhide-prompt) |
| 249 | (should (eq (get-text-property erc-insert-marker 'erc-prompt) t)) | ||
| 246 | (should-not (get-text-property erc-insert-marker 'display)))) | 250 | (should-not (get-text-property erc-insert-marker 'display)))) |
| 247 | 251 | ||
| 248 | (ert-info ("Value: query") | 252 | (ert-info ("Value: query") |
| @@ -253,7 +257,9 @@ | |||
| 253 | 257 | ||
| 254 | (with-current-buffer "bob" | 258 | (with-current-buffer "bob" |
| 255 | (should (string= ">" (get-text-property erc-insert-marker 'display))) | 259 | (should (string= ">" (get-text-property erc-insert-marker 'display))) |
| 260 | (should (eq (get-text-property erc-insert-marker 'erc-prompt) 'hidden)) | ||
| 256 | (erc--unhide-prompt) | 261 | (erc--unhide-prompt) |
| 262 | (should (eq (get-text-property erc-insert-marker 'erc-prompt) t)) | ||
| 257 | (should-not (get-text-property erc-insert-marker 'display))) | 263 | (should-not (get-text-property erc-insert-marker 'display))) |
| 258 | 264 | ||
| 259 | (with-current-buffer "#chan" | 265 | (with-current-buffer "#chan" |
diff --git a/test/lisp/erc/resources/fill/snapshots/stamps-left-01.eld b/test/lisp/erc/resources/fill/snapshots/stamps-left-01.eld new file mode 100644 index 00000000000..f62b65cd170 --- /dev/null +++ b/test/lisp/erc/resources/fill/snapshots/stamps-left-01.eld | |||
| @@ -0,0 +1 @@ | |||
| #("\n\n[00:00]*** This server is in debug mode and is logging all user I/O. If you do not wish for everything you send to be readable by the server owner(s), please disconnect.\n[00:00]<alice> bob: come, you are a tedious fool: to the purpose. What was done to Elbow's wife, that he hath cause to complain of? Come me to what was done to her.\n[00:00]<bob> alice: Either your unparagoned mistress is dead, or she's outprized by a trifle.\n" 2 9 (erc-timestamp 0 display (#4=(margin left-margin) #("[00:00]" 0 7 (invisible timestamp font-lock-face erc-timestamp-face))) field erc-timestamp wrap-prefix #1=(space :width 27) line-prefix #2=(space :width (- 27 (4)))) 9 171 (erc-timestamp 0 wrap-prefix #1# line-prefix #2#) 172 179 (erc-timestamp 0 display (#4# #("[00:00]" 0 7 (invisible timestamp font-lock-face erc-timestamp-face))) field erc-timestamp wrap-prefix #1# line-prefix #3=(space :width (- 27 (8)))) 179 180 (erc-timestamp 0 wrap-prefix #1# line-prefix #3# erc-command PRIVMSG) 180 185 (erc-timestamp 0 wrap-prefix #1# line-prefix #3# erc-command PRIVMSG) 185 187 (erc-timestamp 0 wrap-prefix #1# line-prefix #3# erc-command PRIVMSG) 187 190 (erc-timestamp 0 wrap-prefix #1# line-prefix #3# erc-command PRIVMSG) 190 303 (erc-timestamp 0 wrap-prefix #1# line-prefix #3# erc-command PRIVMSG) 303 304 (erc-timestamp 0 erc-command PRIVMSG) 304 336 (erc-timestamp 0 wrap-prefix #1# line-prefix #3# erc-command PRIVMSG) 337 344 (erc-timestamp 0 display (#4# #("[00:00]" 0 7 (invisible timestamp font-lock-face erc-timestamp-face))) field erc-timestamp wrap-prefix #1# line-prefix #5=(space :width (- 27 (6)))) 344 345 (erc-timestamp 0 wrap-prefix #1# line-prefix #5# erc-command PRIVMSG) 345 348 (erc-timestamp 0 wrap-prefix #1# line-prefix #5# erc-command PRIVMSG) 348 350 (erc-timestamp 0 wrap-prefix #1# line-prefix #5# erc-command PRIVMSG) 350 355 (erc-timestamp 0 wrap-prefix #1# line-prefix #5# erc-command PRIVMSG) 355 430 (erc-timestamp 0 wrap-prefix #1# line-prefix #5# erc-command PRIVMSG)) \ No newline at end of file | |||