Commit 4939f413 authored by F. Jason Park's avatar F. Jason Park
Browse files

Use advertised PREFIX when formatting nicks in ERC

* lisp/erc/erc-speedbar.el (erc-speedbar-insert-user): Run
`erc-get-channel-membership-prefix' in associated buffer if possible.
* lisp/erc/erc.el (erc-get-channel-membership-prefix): Use known
prefix mappings when determining status chars.
* test/lisp/erc/erc-tests.el (erc--parsed-prefix): Use common helpers
for initializing buffers, and use a more realistic example for PREFIX
value.
(erc--update-channel-modes): Add current buffer to `erc-server-user'
object to maintain essential invariant, even though this doesn't
affect the test's outcome.
(erc-tests--equal-including-properties): Move to `erc-tests-common'
and rename `erc-tests-common-equal-with-props'.
(erc--merge-prop, erc--remove-from-prop-value-list,
erc--remove-from-prop-value-list/many): Use new name for
`erc-tests-common-equal-with-props'.
(erc-get-channel-membership-prefix): New test.
(erc--determine-speaker-message-format-args,
erc--determine-speaker-message-format-args/queries-as-channel,
erc--determine-speaker-message-format-args/queries): Use new name
for `erc-tests-common-equal-with-props'.
* test/lisp/erc/resources/erc-tests-common.el
(erc-tests-common-equal-with-props): New macro, originally
`erc-tests--equal-including-properties' from erc-tests.el.
(erc-tests-common-make-server-buf): Initialize tables and make NAME
argument optional.  (Bug#67677)
parent 2534a473
Pipeline #27693 failed with stage
in 1 minute and 36 seconds
......@@ -319,7 +319,9 @@ a list of four items: the userhost, the GECOS, the current
(info (erc-server-user-info user))
(login (erc-server-user-login user))
(name (erc-server-user-full-name user))
(nick-str (concat (erc-get-channel-membership-prefix cuser) nick))
(nick-str (concat (with-current-buffer (or buffer (current-buffer))
(erc-get-channel-membership-prefix cuser))
nick))
(finger (concat login (when (or login host) "@") host))
(sbtoken (list finger name info (buffer-name buffer))))
(if (or login host name info) ; we want to be expandable
......
......@@ -6130,27 +6130,53 @@ returned name, see `erc-show-speaker-membership-status'."
(define-obsolete-function-alias 'erc-get-user-mode-prefix
#'erc-get-channel-membership-prefix "30.1")
(defun erc-get-channel-membership-prefix (user)
"Return channel membership prefix for USER as a string.
(defun erc-get-channel-membership-prefix (nick-or-cusr)
"Return channel membership prefix for NICK-OR-CUSR as a string.
Ensure returned string has a `help-echo' text property with the
corresponding verbose membership type, like \"voice\", as its
value. Expect USER to be an `erc-channel-user' object or a
string nickname, not necessarily downcased."
(when user
(when (stringp user)
(setq user (and erc-channel-users (cdr (erc-get-channel-user user)))))
(cond ((null user) "")
((erc-channel-user-owner user)
(propertize "~" 'help-echo "owner"))
((erc-channel-user-admin user)
(propertize "&" 'help-echo "admin"))
((erc-channel-user-op user)
(propertize "@" 'help-echo "operator"))
((erc-channel-user-halfop user)
(propertize "%" 'help-echo "half-op"))
((erc-channel-user-voice user)
(propertize "+" 'help-echo "voice"))
(t ""))))
value. Expect NICK-OR-CUSR to be an `erc-channel-user' object or
a string nickname, not necessarily downcased. When called in a
logically connected ERC buffer, use advertised prefix mappings.
For compatibility reasons, don't error when NICK-OR-CUSR is null,
but return nil instead of the empty string. Otherwise, always
return a possibly empty string."
(when nick-or-cusr
(when (stringp nick-or-cusr)
(setq nick-or-cusr (and erc-channel-members
(cdr (erc-get-channel-member nick-or-cusr)))))
(cond
((null nick-or-cusr) "")
;; Special-case most common value.
((zerop (erc-channel-user-status nick-or-cusr)) "")
;; For compatibility, first check whether a parsed prefix exists.
((and-let* ((pfx-obj (erc--parsed-prefix)))
(catch 'done
(pcase-dolist (`(,letter . ,pfx)
(erc--parsed-prefix-alist pfx-obj))
(pcase letter
((and ?q (guard (erc-channel-user-owner nick-or-cusr)))
(throw 'done (propertize (string pfx) 'help-echo "owner")))
((and ?a (guard (erc-channel-user-admin nick-or-cusr)))
(throw 'done (propertize (string pfx) 'help-echo "admin")))
((and ?o (guard (erc-channel-user-op nick-or-cusr)))
(throw 'done (propertize (string pfx) 'help-echo "operator")))
((and ?h (guard (erc-channel-user-halfop nick-or-cusr)))
(throw 'done (propertize (string pfx) 'help-echo "half-op")))
((and ?v (guard (erc-channel-user-voice nick-or-cusr)))
(throw 'done (propertize (string pfx) 'help-echo "voice")))))
"")))
(t
(cond ((erc-channel-user-owner nick-or-cusr)
(propertize "~" 'help-echo "owner"))
((erc-channel-user-admin nick-or-cusr)
(propertize "&" 'help-echo "admin"))
((erc-channel-user-op nick-or-cusr)
(propertize "@" 'help-echo "operator"))
((erc-channel-user-halfop nick-or-cusr)
(propertize "%" 'help-echo "half-op"))
((erc-channel-user-voice nick-or-cusr)
(propertize "+" 'help-echo "voice"))
(t ""))))))
(defun erc-format-@nick (&optional user channel-data)
"Format the nickname of USER showing if USER has a voice, is an
......
This diff is collapsed.
......@@ -40,6 +40,15 @@
(require 'ert-x)
(require 'erc)
(defmacro erc-tests-common-equal-with-props (a b)
"Compare strings A and B for equality including text props.
Use `ert-equal-including-properties' on older Emacsen."
(list (if (< emacs-major-version 29)
'ert-equal-including-properties
'equal-including-properties)
a b))
;; Caller should probably shadow `erc-insert-modify-hook' or populate
;; user tables for erc-button.
;; FIXME explain this comment ^ in more detail or delete.
......@@ -98,14 +107,19 @@ recently passed to the mocked `erc-process-input-line'. Make
(funcall test-fn (lambda () (pop calls)))))
(when noninteractive (kill-buffer))))
(defun erc-tests-common-make-server-buf (name)
(defun erc-tests-common-make-server-buf (&optional name)
"Return a server buffer named NAME, creating it if necessary.
Use NAME for the network and the session server as well."
(unless name
(cl-assert (string-prefix-p " *temp*" (setq name (buffer-name)))))
(with-current-buffer (get-buffer-create name)
(erc-tests-common-prep-for-insertion)
(erc-tests-common-init-server-proc "sleep" "1")
(setq erc-session-server (concat "irc." name ".org")
erc-server-announced-name (concat "west." name ".org")
erc-server-users (make-hash-table :test #'equal)
erc-server-parameters nil
erc--isupport-params (make-hash-table)
erc-session-port 6667
erc-network (intern name)
erc-networks--id (erc-networks--id-create nil))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment