1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
;;; erc-scenarios-keep-place-indicator.el --- erc-keep-place-indicator-mode -*- lexical-binding: t -*-
;; Copyright (C) 2023-2025 Free Software Foundation, Inc.
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
;;; Code:
(require 'ert-x)
(eval-and-compile
(let ((load-path (cons (ert-resource-directory) load-path)))
(require 'erc-scenarios-common)))
(require 'erc-goodies)
;; This test shows that the indicator does not update when at least
;; one window remains. When the last window showing a buffer switches
;; away, the indicator is updated if it's earlier in the buffer.
(ert-deftest erc-scenarios-keep-place-indicator--follow ()
:tags `(:expensive-test
,@(and (getenv "ERC_TESTS_GRAPHICAL") '(:erc--graphical)))
(when (version< emacs-version "29") (ert-skip "Times out"))
;; XXX verify that this continues to be the case ^.
(should-not erc-scrolltobottom-all)
(should-not erc-scrolltobottom-mode)
(should-not erc-keep-place-mode)
(erc-scenarios-common-with-noninteractive-in-term
((erc-scenarios-common-dialog "keep-place")
(dumb-server (erc-d-run "localhost" t 'follow))
(port (process-contact dumb-server :service))
(erc-modules `( keep-place-indicator scrolltobottom fill-wrap
,@erc-modules))
(erc-keep-place-indicator-follow t)
(erc-scrolltobottom-all t)
(erc-server-flood-penalty 0.1)
(erc-autojoin-channels-alist '((foonet "#chan" "#spam")))
(expect (erc-d-t-make-expecter)))
(ert-info ("Connect")
(with-current-buffer (erc :server "127.0.0.1"
:port port
:full-name "tester"
:nick "tester"
:user "tester")
(funcall expect 10 "debug mode")))
(with-current-buffer (erc-d-t-wait-for 10 (get-buffer "#chan"))
(set-window-buffer nil (current-buffer))
(delete-other-windows)
(split-window-below)
(funcall expect 10 "<bob> tester, welcome!")
(recenter 0)
(other-window 1)
(funcall expect 10 "<alice> tester, welcome!")
(recenter 0)
(should (= 2 (length (window-list))))
(ert-info ("Last window to switch away has point earlier in buffer")
;; Lower window, with point later in buffer, switches away first.
(switch-to-buffer (erc-d-t-wait-for 10 (get-buffer "#spam"))) ; lower
(other-window 1)
(switch-to-buffer "#spam") ; upper
(erc-scenarios-common-say "one")
(funcall expect 10 "Ay, the heads")
;; Overlay has moved to upper window start.
(switch-to-buffer "#chan")
(redisplay) ; force overlay to update
(save-excursion
(goto-char (window-point))
(should (looking-back (rx "<bob> tester, welcome!")))
(should (= (pos-bol) (window-start)))
(erc-d-t-wait-for 20
(= (overlay-start erc--keep-place-indicator-overlay) (pos-bol))))
;; Lower window is still centered at start.
(other-window 1)
(switch-to-buffer "#chan")
(save-excursion
(goto-char (window-point))
(should (looking-back (rx "<alice> tester, welcome!")))
(should (= (pos-bol) (window-start)))))
(ert-info ("Last window to switch away has point later in buffer")
;; Lower window advances.
(funcall expect 10 "<bob> alice: Since you can cog")
(recenter 0)
(redisplay) ; force ^ to appear on first line
(other-window 1) ; upper still at indicator, switches first
(switch-to-buffer "#spam")
(other-window 1)
(switch-to-buffer "#spam") ; lower follows, speaks to sync
(erc-scenarios-common-say "two")
(funcall expect 10 "<bob> Cause they take")
(goto-char (point-max))
;; Upper switches back first, finds indicator gone.
(other-window 1)
(switch-to-buffer "#chan")
(save-excursion
(goto-char (window-point))
(should (looking-back (rx "<bob> tester, welcome!")))
(should (= (pos-bol) (window-start)))
(should (> (overlay-start erc--keep-place-indicator-overlay)
(pos-eol))))
;; Lower window follows, window-start preserved.
(other-window 1)
(switch-to-buffer "#chan")
(save-excursion
(goto-char (window-point))
(should (looking-back (rx "you can cog")))
(should (= (pos-bol) (window-start)))
(should (= (overlay-start erc--keep-place-indicator-overlay)
(pos-bol)))))
(ert-info ("description")
(erc-send-input-line "#spam" "three")
(save-excursion (erc-d-t-search-for 10 "Ready"))
(switch-to-buffer "#spam")
(should (< (point) erc-input-marker))))
(erc-keep-place-mode -1)
(erc-scrolltobottom-mode -1)))
;;; erc-scenarios-keep-place-indicator.el ends here
|