(unless (eq end erc-insert-marker)
(set-marker end nil)))
+(defvar erc--insert-line-function nil
+ "When non-nil, an alterntive to `insert' for inserting messages.")
+
(defvar erc--insert-marker nil
"Internal override for `erc-insert-marker'.")
(save-restriction
(widen)
(goto-char insert-position)
- (insert string)
+ (if erc--insert-line-function
+ (funcall erc--insert-line-function string)
+ (insert string))
(erc--assert-input-bounds)
;; run insertion hook, with point at restored location
(save-restriction
(not (eq 'erc-timestamp (field-at-pos (point))))))
(should (erc--get-inserted-msg-prop 'erc-cmd)))))))
+;; This user-owned hook member places a marker on the first message in
+;; a buffer. Inserting a date stamp in front of it shouldn't move the
+;; marker.
+(defun erc-scenarios-stamp--on-insert-modify ()
+ (unless (marker-position erc-scenarios-stamp--user-marker)
+ (set-marker erc-scenarios-stamp--user-marker (point-min))
+ (save-excursion
+ (goto-char erc-scenarios-stamp--user-marker)
+ (should (looking-at "Opening"))))
+
+ ;; Sometime after the first message ("Opening connection.."), assert
+ ;; that the marker we just placed hasn't moved.
+ (when (erc--check-msg-prop 'erc-cmd 2)
+ (save-restriction
+ (widen)
+ (ert-info ("Date stamp preserves opening user marker")
+ (goto-char erc-scenarios-stamp--user-marker)
+ (should-not (eq 'erc-timestamp (field-at-pos (point))))
+ (should (looking-at "Opening"))
+ (should (eq 'unknown (get-text-property (point) 'erc-msg))))))
+
+ ;; On 003 ("*** This server was created on"), clear state to force a
+ ;; new date stamp on the next message.
+ (when (erc--check-msg-prop 'erc-cmd 3)
+ (setq erc-timestamp-last-inserted-left nil)
+ (set-marker erc-scenarios-stamp--user-marker erc-insert-marker)))
+
+(ert-deftest erc-scenarios-stamp--date-mode/left-and-right ()
+
+ (should (eq erc-insert-timestamp-function
+ #'erc-insert-timestamp-left-and-right))
+
+ (erc-scenarios-common-with-cleanup
+ ((erc-scenarios-common-dialog "base/reconnect")
+ (dumb-server (erc-d-run "localhost" t 'unexpected-disconnect))
+ (port (process-contact dumb-server :service))
+ (erc-scenarios-stamp--user-marker (make-marker))
+ (erc-server-flood-penalty 0.1)
+ (erc-modules (if (zerop (random 2))
+ (cons 'fill-wrap erc-modules)
+ erc-modules))
+ (expect (erc-d-t-make-expecter))
+ (erc-mode-hook
+ (cons (lambda ()
+ (add-hook 'erc-insert-modify-hook
+ #'erc-scenarios-stamp--on-insert-modify -99 t))
+ erc-mode-hook)))
+
+ (ert-info ("Connect")
+ (with-current-buffer (erc :server "127.0.0.1"
+ :port port
+ :full-name "tester"
+ :nick "tester")
+
+ (funcall expect 5 "Welcome to the foonet")
+ (funcall expect 5 "*** AWAYLEN=390")
+
+ (ert-info ("Date stamp preserves other user marker")
+ (goto-char erc-scenarios-stamp--user-marker)
+ (should-not (eq 'erc-timestamp (field-at-pos (point))))
+ (should (looking-at (rx "*** irc.foonet.org oragono")))
+ (should (eq 's004 (get-text-property (point) 'erc-msg))))
+
+ (funcall expect 5 "This server is in debug mode")))))
+
;;; erc-scenarios-stamp.el ends here