[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 7db500b50be 09/19: Make erc-get-user-mode-prefix more flexible

From: F. Jason Park
Subject: master 7db500b50be 09/19: Make erc-get-user-mode-prefix more flexible
Date: Sun, 17 Dec 2023 23:21:39 -0500 (EST)

branch: master
commit 7db500b50be5f59ce65785a2cc35a8587e7e6cd1
Author: F. Jason Park <jp@neverwas.me>
Commit: F. Jason Park <jp@neverwas.me>

    Make erc-get-user-mode-prefix more flexible
    * etc/ERC-NEWS: Mention renaming of `erc-get-user-mode-prefix'.
    * 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 those for "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): Actually use the `channel-data' parameter.
    (erc-format-my-nick, erc--format-channel-status-prefix): Use new name
    for function `erc-get-user-mode-prefix'.  (Bug#63595)  (Bug#67677)
 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 3bb302e1dd2..b89c5228e32 100644
--- a/etc/ERC-NEWS
+++ b/etc/ERC-NEWS
@@ -437,6 +437,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 @@ 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))
-        (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 333b762a113..2e078651a52 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -5798,21 +5798,31 @@ NUH, and the current `erc-response' object.")
 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
@@ -5821,7 +5831,7 @@ also `erc-format-nick-function'."
   (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)
@@ -5831,7 +5841,7 @@ also `erc-format-nick-function'."
       (let* ((open "<")
              (close "> ")
              (nick (erc-current-nick))
-             (mode (erc-get-user-mode-prefix nick)))
+             (mode (erc-get-channel-membership-prefix nick)))
          (propertize open 'font-lock-face 'erc-default-face)
          (propertize mode 'font-lock-face 'erc-my-nick-prefix-face)
@@ -8467,7 +8477,7 @@ Currently only used by the option `erc-prompt-format'.")
 (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.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]