unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Amin Bandali <bandali@gnu.org>
To: Stefan Kangas <stefan@marxist.se>
Cc: emacs-erc@gnu.org, 51082@debbugs.gnu.org
Subject: bug#51082: [PATCH] erc-prompt: support substitution patterns "%target" and "%network"
Date: Fri, 08 Oct 2021 20:53:27 -0400	[thread overview]
Message-ID: <871r4vc92w.fsf__27186.1041824863$1633740855$gmane$org@gnu.org> (raw)
In-Reply-To: <CADwFkmkXoy-=4MBALshitVO7wDYeDve7SNmB1Mf3N6z6TGaVaw@mail.gmail.com>

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 <stefan@marxist.se>
> 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) <defun>: Use the above new function.
> (erc-prompt) <defcustom>: 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





  reply	other threads:[~2021-10-09  0:53 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-07 13:05 bug#51082: [PATCH] erc-prompt: support substitution patterns "%target" and "%network" Stefan Kangas
2021-10-09  0:53 ` Amin Bandali [this message]
     [not found] ` <871r4vc92w.fsf@gnu.org>
2021-10-09  8:03   ` J.P.
2022-09-10  5:20 ` Lars Ingebrigtsen
2023-11-20 21:17 ` J.P.
     [not found] ` <875y1wi0q2.fsf@neverwas.me>
2023-11-20 21:22   ` J.P.
2023-11-22 19:25   ` J.P.
     [not found]   ` <87pm01d1yy.fsf@neverwas.me>
2023-11-24 22:12     ` J.P.
     [not found]     ` <87plzy2433.fsf@neverwas.me>
2023-12-15  1:18       ` Stefan Kangas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='871r4vc92w.fsf__27186.1041824863$1633740855$gmane$org@gnu.org' \
    --to=bandali@gnu.org \
    --cc=51082@debbugs.gnu.org \
    --cc=emacs-erc@gnu.org \
    --cc=stefan@marxist.se \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).