aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorF. Jason Park2023-10-18 23:20:07 -0700
committerF. Jason Park2023-10-20 14:53:24 -0700
commitbcebda5eec2166e475579c2aa2ee425aeabbb505 (patch)
treecfc3e9646f1d30639bae321292da52c3bf974dd1
parent47612514a9e04d6f41568c3f0cdeae837c2eae19 (diff)
downloademacs-bcebda5eec2166e475579c2aa2ee425aeabbb505.tar.gz
emacs-bcebda5eec2166e475579c2aa2ee425aeabbb505.zip
Respect user markers in erc-insert-timestamp-left
* lisp/erc/erc-stamp.el (erc-insert-timestamp-left): Convert to normal function, a mere wrapper that defers to existing generic variants, in order to dissuade users from adding their own methods, which could complicate troubleshooting, etc. (erc--insert-timestamp-left): Rename both methods using internal double-hyphen convention. In `erc-stamp--display-margin-mode' implementation, don't displace third-party markers. * test/lisp/erc/erc-scenarios-stamp.el: New file. (Bug#60936)
-rw-r--r--lisp/erc/erc-stamp.el10
-rw-r--r--test/lisp/erc/erc-scenarios-stamp.el90
2 files changed, 96 insertions, 4 deletions
diff --git a/lisp/erc/erc-stamp.el b/lisp/erc/erc-stamp.el
index c8fd7c35392..b515513dcb7 100644
--- a/lisp/erc/erc-stamp.el
+++ b/lisp/erc/erc-stamp.el
@@ -492,8 +492,11 @@ and `erc-stamp--margin-left-p', before activating the mode."
492 (put-text-property erc-insert-marker (1- erc-input-marker) 492 (put-text-property erc-insert-marker (1- erc-input-marker)
493 'display `((margin left-margin) ,prompt)))) 493 'display `((margin left-margin) ,prompt))))
494 494
495(cl-defmethod erc-insert-timestamp-left (string) 495(defun erc-insert-timestamp-left (string)
496 "Insert timestamps at the beginning of the line." 496 "Insert timestamps at the beginning of the line."
497 (erc--insert-timestamp-left string))
498
499(cl-defmethod erc--insert-timestamp-left (string)
497 (goto-char (point-min)) 500 (goto-char (point-min))
498 (let* ((ignore-p (and erc-timestamp-only-if-changed-flag 501 (let* ((ignore-p (and erc-timestamp-only-if-changed-flag
499 (string-equal string erc-timestamp-last-inserted))) 502 (string-equal string erc-timestamp-last-inserted)))
@@ -504,13 +507,12 @@ and `erc-stamp--margin-left-p', before activating the mode."
504 (erc-put-text-property 0 len 'invisible erc-stamp--invisible-property s) 507 (erc-put-text-property 0 len 'invisible erc-stamp--invisible-property s)
505 (insert s))) 508 (insert s)))
506 509
507(cl-defmethod erc-insert-timestamp-left 510(cl-defmethod erc--insert-timestamp-left
508 (string &context (erc-stamp--display-margin-mode (eql t))) 511 (string &context (erc-stamp--display-margin-mode (eql t)))
509 (unless (and erc-timestamp-only-if-changed-flag 512 (unless (and erc-timestamp-only-if-changed-flag
510 (string-equal string erc-timestamp-last-inserted)) 513 (string-equal string erc-timestamp-last-inserted))
511 (goto-char (point-min)) 514 (goto-char (point-min))
512 (insert-before-markers-and-inherit 515 (insert-and-inherit (setq erc-timestamp-last-inserted string))
513 (setq erc-timestamp-last-inserted string))
514 (dolist (p erc-stamp--inherited-props) 516 (dolist (p erc-stamp--inherited-props)
515 (when-let ((v (get-text-property (point) p))) 517 (when-let ((v (get-text-property (point) p)))
516 (put-text-property (point-min) (point) p v))) 518 (put-text-property (point-min) (point) p v)))
diff --git a/test/lisp/erc/erc-scenarios-stamp.el b/test/lisp/erc/erc-scenarios-stamp.el
new file mode 100644
index 00000000000..d6b5d868ce5
--- /dev/null
+++ b/test/lisp/erc/erc-scenarios-stamp.el
@@ -0,0 +1,90 @@
1;;; erc-scenarios-stamp.el --- Misc `erc-stamp' scenarios -*- lexical-binding: t -*-
2
3;; Copyright (C) 2023 Free Software Foundation, Inc.
4
5;; This file is part of GNU Emacs.
6
7;; GNU Emacs is free software: you can redistribute it and/or modify
8;; it under the terms of the GNU General Public License as published by
9;; the Free Software Foundation, either version 3 of the License, or
10;; (at your option) any later version.
11
12;; GNU Emacs is distributed in the hope that it will be useful,
13;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;; GNU General Public License for more details.
16
17;; You should have received a copy of the GNU General Public License
18;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
19
20;;; Code:
21
22(require 'ert-x)
23(eval-and-compile
24 (let ((load-path (cons (ert-resource-directory) load-path)))
25 (require 'erc-scenarios-common)))
26
27(require 'erc-stamp)
28
29(defvar erc-scenarios-stamp--user-marker nil)
30
31(defun erc-scenarios-stamp--on-post-modify ()
32 (when-let (((erc--check-msg-prop 'erc-cmd 4)))
33 (set-marker erc-scenarios-stamp--user-marker (point-max))
34 (ert-info ("User marker correctly placed at `erc-insert-marker'")
35 (should (= ?\n (char-before erc-scenarios-stamp--user-marker)))
36 (should (= erc-scenarios-stamp--user-marker erc-insert-marker))
37 (save-excursion
38 (goto-char erc-scenarios-stamp--user-marker)
39 ;; The raw message ends in " Iabefhkloqv". However,
40 ;; `erc-server-004' only prints up to the 5th parameter.
41 (should (looking-back "CEIMRUabefhiklmnoqstuv\n"))))))
42
43(ert-deftest erc-scenarios-stamp--left/display-margin-mode ()
44
45 (erc-scenarios-common-with-cleanup
46 ((erc-scenarios-common-dialog "base/reconnect")
47 (dumb-server (erc-d-run "localhost" t 'unexpected-disconnect))
48 (port (process-contact dumb-server :service))
49 (erc-scenarios-stamp--user-marker (make-marker))
50 (erc-stamp--current-time 704591940)
51 (erc-stamp--tz t)
52 (erc-server-flood-penalty 0.1)
53 (erc-timestamp-only-if-changed-flag nil)
54 (erc-insert-timestamp-function #'erc-insert-timestamp-left)
55 (erc-modules (cons 'fill-wrap erc-modules))
56 (erc-timestamp-only-if-changed-flag nil)
57 (expect (erc-d-t-make-expecter)))
58
59 (ert-info ("Connect")
60 (with-current-buffer (erc :server "127.0.0.1"
61 :port port
62 :full-name "tester"
63 :nick "tester")
64
65 (add-hook 'erc-insert-post-hook #'erc-scenarios-stamp--on-post-modify
66 nil t)
67 (funcall expect 5 "This server is in debug mode")
68
69 (ert-info ("Stamps appear in left margin and are invisible")
70 (should (eq 'erc-timestamp (field-at-pos (pos-bol))))
71 (should (= (pos-bol) (field-beginning (pos-bol))))
72 (should (eq 'msg (get-text-property (pos-bol) 'erc-msg)))
73 (should (eq 'NOTICE (get-text-property (pos-bol) 'erc-cmd)))
74 (should (= ?- (char-after (field-end (pos-bol)))))
75 (should (equal (get-text-property (1+ (field-end (pos-bol)))
76 'erc-speaker)
77 "irc.foonet.org"))
78 (should (pcase (get-text-property (pos-bol) 'display)
79 (`((margin left-margin) ,s)
80 (eq 'timestamp (get-text-property 0 'invisible s))))))
81
82 ;; We set a third-party marker at the end of 004's message (on
83 ;; then "\n"), post-insertion.
84 (ert-info ("User markers untouched by subsequent message left stamp")
85 (save-excursion
86 (goto-char erc-scenarios-stamp--user-marker)
87 (should (looking-back "CEIMRUabefhiklmnoqstuv\n"))
88 (should (looking-at (rx "[")))))))))
89
90;;; erc-scenarios-stamp.el ends here