From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Amin Bandali Newsgroups: gmane.emacs.bugs Subject: bug#51082: [PATCH] erc-prompt: support substitution patterns "%target" and "%network" Date: Fri, 08 Oct 2021 20:53:27 -0400 Message-ID: <871r4vc92w.fsf__27186.1041824863$1633740855$gmane$org@gnu.org> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21816"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.60 (gnu/linux) Cc: emacs-erc@gnu.org, 51082@debbugs.gnu.org To: Stefan Kangas Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Oct 09 02:54:09 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mZ0cq-0005S9-T9 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 09 Oct 2021 02:54:08 +0200 Original-Received: from localhost ([::1]:58292 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mZ0cp-0000VO-JI for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 08 Oct 2021 20:54:07 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:53724) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZ0ck-0000VF-1Y for bug-gnu-emacs@gnu.org; Fri, 08 Oct 2021 20:54:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:40586) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mZ0cj-0003gq-Qd for bug-gnu-emacs@gnu.org; Fri, 08 Oct 2021 20:54:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mZ0cj-00056N-Nh for bug-gnu-emacs@gnu.org; Fri, 08 Oct 2021 20:54:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Amin Bandali Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 09 Oct 2021 00:54:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51082 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 51082-submit@debbugs.gnu.org id=B51082.163374081719578 (code B ref 51082); Sat, 09 Oct 2021 00:54:01 +0000 Original-Received: (at 51082) by debbugs.gnu.org; 9 Oct 2021 00:53:37 +0000 Original-Received: from localhost ([127.0.0.1]:52132 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mZ0cL-00055h-Ej for submit@debbugs.gnu.org; Fri, 08 Oct 2021 20:53:37 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:51796) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mZ0cI-00055T-Fh for 51082@debbugs.gnu.org; Fri, 08 Oct 2021 20:53:35 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:37852) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mZ0cD-0003fJ-2h; Fri, 08 Oct 2021 20:53:29 -0400 Original-Received: from [2607:fea8:3fdf:f2d9:96c:eb1a:a939:2482] (port=41464 helo=langa) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZ0cC-0004da-Qh; Fri, 08 Oct 2021 20:53:28 -0400 In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:216743 Archived-At: Hi Stefan, Thanks for the patch. :) Please see my comments below. Stefan Kangas writes: > Severity: wishlist > > The attached patch adds substitution patterns "%target" and "%network" > so you can do stuff like > > (setq erc-prompt "[%target]") > (setq erc-prompt "[%target@%network]") > > to get prompts that looks like this: > > [#erc] > [#erc@Libera.Chat] >From a cursory look at Rcirc, it looks like they too support something like this, though with shorter names -- which might be nice to have along with the longer names -- and two other options: the user's nick, and the server. I think these all would potentially be nice to have, in addition to the two you've added in your patch. How do you feel about adding those as well? Maybe something like: %m or %modes: channel modes (do we want to support user modes too?) %n or %nick: current nick %N or %network: network name %s or %server: server name/address %t or %target: target Other ones I'd find useful would be %o, %v, etc., corresponding to the 'op' or 'voice' status of the user and so on (see `erc-format-@nick'). Also, for v2 please add an accompanying etc/ERC-NEWS entry for the change. > From d6ac0356afa366276f1a0be26b81cf2d4b076b8d Mon Sep 17 00:00:00 2001 > From: Stefan Kangas > Date: Thu, 7 Oct 2021 14:26:36 +0200 > Subject: [PATCH] Support two substitution patterns in erc-prompt > > * lisp/erc/erc.el (erc-prompt--subsitutions): New function to > support substitution patters "%target" and "%network". > (erc-prompt) : Use the above new function. > (erc-prompt) : Document the new substitution patterns. > --- > lisp/erc/erc.el | 31 +++++++++++++++++++++++++++++-- > 1 file changed, 29 insertions(+), 2 deletions(-) > > diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el > index 308812f0eb..aa5002c2ea 100644 > --- a/lisp/erc/erc.el > +++ b/lisp/erc/erc.el > @@ -640,17 +640,44 @@ erc-string-no-properties > newstring)) > > (defcustom erc-prompt "ERC>" > - "Prompt used by ERC. Trailing whitespace is not required." > + "Prompt used by ERC. Trailing whitespace is not required. > + > +You can also use these substitution patterns: > + \"%target\" - channel, user, or server > + \"%network\" - IRC network" > :group 'erc-display > :type '(choice string function)) > > +(defun erc-prompt--subsitutions (prompt) > + "Make \"%target\" substitutions in PROMPT. Per (info "(elisp) Coding Conventions") I believe the name may better be `erc--prompt-substitutions'? Also, since this function supports substitutions other than "%target", the first sentence of the doc string should be reworded to reflect that, or instead be more generic and enumerate them in subsequent lines rather than the first line. > +See also the variable `erc-prompt'." > + (while (string-match (rx "%" (or "target" > + "network" > + ;; "modes" > + )) > + prompt) > + (setq prompt > + (replace-match > + (pcase (match-string 0 prompt) > + ("%target" (or (erc-format-target) > + (erc-format-target-and/or-server) > + "ERC")) > + ("%network" (and (fboundp 'erc-network-name) (erc-network-name))) > + ;; TODO: Maybe have one variable for the prompt in the > + ;; server window and one for channels and queries? > + ;;("%modes" (erc-format-channel-modes)) Why leave "%modes" commented out? Would using `erc-format-channel-modes' not work here? > + (_ "")) > + nil nil prompt 0))) > + prompt) > + > (defun erc-prompt () > "Return the input prompt as a string. > > See also the variable `erc-prompt'." > (let ((prompt (if (functionp erc-prompt) > (funcall erc-prompt) > - erc-prompt))) > + (erc-prompt--subsitutions erc-prompt)))) > (if (> (length prompt) 0) > (concat prompt " ") > prompt))) Thanks, amin -- https://bndl.org