From 401bc01ace91aac6f3423fc8a04fe7a95b67987c Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Mon, 27 Nov 2023 22:53:00 -0800 Subject: [PATCH 09/11] [5.6] Make erc-get-user-mode-prefix more flexible * lisp/erc/erc-speedbar.el (erc-speedbar-insert-user): Use `erc-get-channel-membership-prefix' so that nicks in the nickbar can have prefixes beyond just voice and op. * lisp/erc/erc.el (erc-get-user-mode-prefix, erc-get-channel-membership-prefix): Rename former to latter because "user-mode" suggests the function somehow involves user modes, but it exclusively concerns channel modes. Also, overload the only parameter in order to avoid redundantly looking up `erc-channel-user' object with every predicate call. In the near future, ERC will likely need to offer an alternate version of this function that returns multiple prefixes instead of just one. (erc-format-@nick): Use `channel-data' parameter. (erc-format-my-nick, erc--format-channel-status-prefix): Use new name for function `erc-get-user-mode-prefix'. (Bug#63595) --- etc/ERC-NEWS | 7 +++++++ lisp/erc/erc-speedbar.el | 4 +--- lisp/erc/erc.el | 30 ++++++++++++++++++++---------- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/etc/ERC-NEWS b/etc/ERC-NEWS index 540d9e98751..4fdfe7a9dcb 100644 --- a/etc/ERC-NEWS +++ b/etc/ERC-NEWS @@ -433,6 +433,13 @@ The 'fill' module is now defined by 'define-erc-module'. The same goes for ERC's imenu integration, which has 'imenu' now appearing in the default value of 'erc-modules'. +*** Function 'erc-get-user-mode-prefix' renamed. +This utility has been renamed to 'erc-get-channel-membership-prefix' +to better reflect its role of delivering a formatted "status prefix", +like "+" (for "voice"), and to avoid confusion with user modes, like +"+i" (for "invisible"). Additionally, its lone parameter is now +overloaded to accept an 'erc-channel-user' object as well as a string. + *** Hidden messages contain a preceding rather than trailing newline. ERC has traditionally only offered to hide messages involving fools, but plans are to make hiding more powerful. Anyone depending on the diff --git a/lisp/erc/erc-speedbar.el b/lisp/erc/erc-speedbar.el index 93be7b9f074..90d7376fc0c 100644 --- a/lisp/erc/erc-speedbar.el +++ b/lisp/erc/erc-speedbar.el @@ -319,9 +319,7 @@ erc-speedbar-insert-user (info (erc-server-user-info user)) (login (erc-server-user-login user)) (name (erc-server-user-full-name user)) - (voice (and cuser (erc-channel-user-voice cuser))) - (op (and cuser (erc-channel-user-op cuser))) - (nick-str (concat (if op "@" "") (if voice "+" "") nick)) + (nick-str (concat (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 diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 98621302abd..8e7162fec89 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -5815,21 +5815,31 @@ erc-format-nick See also `erc-format-nick-function'." (when user (erc-server-user-nickname user))) -(defun erc-get-user-mode-prefix (user) +(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. +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 - (cond ((erc-channel-user-owner-p 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-p user) + ((erc-channel-user-admin user) (propertize "&" 'help-echo "admin")) - ((erc-channel-user-op-p user) + ((erc-channel-user-op user) (propertize "@" 'help-echo "operator")) - ((erc-channel-user-halfop-p user) + ((erc-channel-user-halfop user) (propertize "%" 'help-echo "half-op")) - ((erc-channel-user-voice-p user) + ((erc-channel-user-voice user) (propertize "+" 'help-echo "voice")) (t "")))) -(defun erc-format-@nick (&optional user _channel-data) +(defun erc-format-@nick (&optional user channel-data) "Format the nickname of USER showing if USER has a voice, is an operator, half-op, admin or owner. Owners have \"~\", admins have \"&\", operators have \"@\" and users with voice have \"+\" as a @@ -5838,7 +5848,7 @@ erc-format-@nick (when user (let ((nick (erc-server-user-nickname user))) (concat (propertize - (erc-get-user-mode-prefix nick) + (erc-get-channel-membership-prefix channel-data) 'font-lock-face 'erc-nick-prefix-face) nick)))) @@ -5848,7 +5858,7 @@ erc-format-my-nick (let* ((open "<") (close "> ") (nick (erc-current-nick)) - (mode (erc-get-user-mode-prefix nick))) + (mode (erc-get-channel-membership-prefix nick))) (erc--ensure-spkr-prop nick) (concat (propertize open 'font-lock-face 'erc-default-face) @@ -8486,7 +8496,7 @@ erc--format-user-modes (defun erc--format-channel-status-prefix () "Return the current channel membership prefix." (and (erc--target-channel-p erc--target) - (erc-get-user-mode-prefix (erc-current-nick)))) + (erc-get-channel-membership-prefix (erc-current-nick)))) (defun erc--format-modes (&optional no-query-p) "Return a string of channel modes in channels and user modes elsewhere. -- 2.42.0