and help text, and on outgoing messages unless echoed back by
the server (assuming future support)
- - `erc--spkr': a string, the nick of the person speaking
+ - `erc--spkr': a string, the non-case-mapped nick of the speaker as
+ stored in the `nickname' slot of its `erc-server-users' item
- `erc--ctcp': a CTCP command, like `ACTION'
"Template for a CTCP ACTION status message from current client.")
(defun erc--speakerize-nick (nick &optional disp)
- "Propertize NICK with `erc--speaker' if not already present.
-Do so to DISP instead if it's non-nil. In either case, assign
-NICK, sans properties, as the `erc--speaker' value. As a side
-effect, pair the latter string (the same `eq'-able object) with
-the symbol `erc--spkr' in the \"msg prop\" environment for any
-imminent `erc-display-message' invocations. While doing so,
-include any overrides defined in `erc--message-speaker-catalog'."
- (let ((plain-nick (substring-no-properties nick)))
- (erc--ensure-spkr-prop plain-nick (get erc--message-speaker-catalog
- 'erc--msg-prop-overrides))
- (if (text-property-not-all 0 (length (or disp nick))
- 'erc--speaker nil (or disp nick))
- (or disp nick)
- (propertize (or disp nick) 'erc--speaker plain-nick))))
+ "Return propertized NICK with canonical NICK in `erc--speaker'.
+Return propertized DISP instead if given. As a side effect, pair NICK
+with `erc--spkr' in the \"msg prop\" environment for any imminent
+`erc-display-message' invocations, and include any overrides defined in
+`erc--message-speaker-catalog'. Expect NICK (but not necessarily DISP)
+to be absent of any existing text properties."
+ (when-let ((erc-server-process)
+ (cusr (erc-get-server-user nick)))
+ (setq nick (erc-server-user-nickname cusr)))
+ (erc--ensure-spkr-prop nick (get erc--message-speaker-catalog
+ 'erc--msg-prop-overrides))
+ (propertize (or disp nick) 'erc--speaker nick))
(defun erc--determine-speaker-message-format-args
(nick message queryp privmsgp inputp &optional statusmsg prefix disp-nick)
(ert-info ("Server buffer")
(with-current-buffer (get-buffer-create "ServNet")
- (erc-tests-common-prep-for-insertion)
+ (erc-tests-common-make-server-buf "ServNet")
(goto-char erc-insert-marker)
(should (looking-at-p "ServNet 3>"))
(erc-tests-common-init-server-proc "sleep" "1")
(set-process-sentinel erc-server-process #'ignore)
- (setq erc-network 'ServNet
- erc-server-current-nick "tester"
- erc-networks--id (erc-networks--id-create nil)
- erc-server-users (make-hash-table :test 'equal))
- (set-process-query-on-exit-flag erc-server-process nil)
+ (setq erc-server-current-nick "tester")
;; Incoming message redraws prompt
(erc-display-message nil 'notice nil "Welcome")
(should (looking-at-p (rx "*** Welcome")))
(should-not (search-forward (rx (any "3-5") ">") nil t)))))
(ert-info ("Channel buffer")
+ ;; Create buffer manually instead of using `erc--open-target' in
+ ;; order to show prompt before/after network is known.
(with-current-buffer (get-buffer-create "#chan")
(erc-tests-common-prep-for-insertion)
(goto-char erc-insert-marker)
(ert-deftest erc--check-prompt-input-functions ()
(erc-tests-common-with-process-input-spy
(lambda (next)
+ (erc-tests-common-prep-for-insertion)
(ert-info ("Errors when point not in prompt area") ; actually just dings
(insert "/msg #chan hi")
(ert-deftest erc-send-current-line ()
(erc-tests-common-with-process-input-spy
(lambda (next)
- (erc-tests-common-init-server-proc "sleep" "1")
+ (erc-tests-common-make-server-buf (buffer-name))
(should (= 0 erc-last-input-time))
(ert-info ("Simple command")
(ert-with-message-capture messages
(erc-tests-common-with-process-input-spy
(lambda (next)
- (erc-tests-common-init-server-proc "sleep" "300")
+ (erc-tests-common-make-server-buf (buffer-name))
+
(should-not erc-send-whitespace-lines)
(should erc-warn-about-blank-lines)
(ert-deftest erc-send-whitespace-lines ()
(erc-tests-common-with-process-input-spy
(lambda (next)
- (erc-tests-common-init-server-proc "sleep" "1")
+ (erc-tests-common-make-server-buf (buffer-name))
+
(setq-local erc-send-whitespace-lines t)
(ert-info ("Multiline hunk with blank line correctly split")
(erc--determine-speaker-message-format-args nick msg privp msgp
inputp nil pfx))))
+;; This test demonstrates that ERC uses the same string for the
+;; `erc--spkr' and `erc--speaker' text properties, which it gets from
+;; the `nickname' shot of the speaker's server user.
+(ert-deftest erc--speakerize-nick ()
+ (erc-tests-common-make-server-buf)
+ (setq erc-server-current-nick "tester")
+
+ (let ((sentinel "alice"))
+ (with-current-buffer (erc--open-target "#chan")
+ (erc-update-current-channel-member "bob" "bob" t nil nil nil nil nil
+ "example.org" "~u" "bob")
+ (erc-update-current-channel-member "alice" sentinel t nil nil nil nil nil
+ "fsf.org" "~u" "alice"))
+
+ (erc-call-hooks nil (make-erc-response
+ :sender "alice!~u@fsf.org"
+ :command "PRIVMSG"
+ :command-args '("#chan" "one")
+ :contents "one"
+ :unparsed ":alice!~u@fsf.org PRIVMSG #chan :one"))
+ (erc-call-hooks nil (make-erc-response
+ :sender "bob!~u@example.org"
+ :command "PRIVMSG"
+ :command-args '("#chan" "hi")
+ :contents "hi"
+ :unparsed ":bob!~u@example.org PRIVMSG #chan :hi"))
+ (erc-call-hooks nil (make-erc-response
+ :sender "alice!~u@fsf.org"
+ :command "PRIVMSG"
+ :command-args '("#chan" "two")
+ :contents "two"
+ :unparsed ":alice!~u@fsf.org PRIVMSG #chan :two"))
+
+ (with-current-buffer (get-buffer "#chan")
+ (should (eq sentinel
+ (erc-server-user-nickname (erc-get-server-user "alice"))))
+ (goto-char (point-min))
+
+ (should (search-forward "<a" nil t))
+ (should (looking-at "lice> one"))
+ (should (eq (get-text-property (point) 'erc--speaker) sentinel))
+ (should (eq (erc--get-inserted-msg-prop 'erc--spkr) sentinel))
+
+ (should (search-forward "<bob> hi" nil t))
+
+ (should (search-forward "<a" nil t))
+ (should (looking-at "lice> two"))
+ (should (eq (get-text-property (point) 'erc--speaker) sentinel))
+ (should (eq (erc--get-inserted-msg-prop 'erc--spkr) sentinel))
+
+ (when noninteractive (kill-buffer)))))
+
;; This asserts that `erc--determine-speaker-message-format-args'
;; behaves identically to `erc-format-privmessage', the function whose
;; role it basically replaced.