GNU bug report logs - #51082
[PATCH] erc-prompt: support substitution patterns "%target" and "%network"

Previous Next

Package: emacs;

Reported by: Stefan Kangas <stefan <at> marxist.se>

Date: Thu, 7 Oct 2021 13:06:01 UTC

Severity: wishlist

Tags: patch

Done: "J.P." <jp <at> neverwas.me>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 51082 in the body.
You can then email your comments to 51082 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bandali <at> gnu.org, emacs-erc <at> gnu.org, bug-gnu-emacs <at> gnu.org:
bug#51082; Package emacs. (Thu, 07 Oct 2021 13:06:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Stefan Kangas <stefan <at> marxist.se>:
New bug report received and forwarded. Copy sent to bandali <at> gnu.org, emacs-erc <at> gnu.org, bug-gnu-emacs <at> gnu.org. (Thu, 07 Oct 2021 13:06:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefan <at> marxist.se>
To: bug-gnu-emacs <at> gnu.org
Subject: [PATCH] erc-prompt: support substitution patterns "%target" and
 "%network"
Date: Thu, 7 Oct 2021 09:05:02 -0400
[Message part 1 (text/plain, inline)]
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 <at> Libera.Chat]
[0001-Support-two-substitution-patterns-in-erc-prompt.patch (text/x-diff, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#51082; Package emacs. (Sat, 09 Oct 2021 00:54:01 GMT) Full text and rfc822 format available.

Message #8 received at 51082 <at> debbugs.gnu.org (full text, mbox):

From: Amin Bandali <bandali <at> gnu.org>
To: Stefan Kangas <stefan <at> marxist.se>
Cc: emacs-erc <at> gnu.org, 51082 <at> debbugs.gnu.org
Subject: Re: bug#51082: [PATCH] erc-prompt: support substitution patterns
 "%target" and "%network"
Date: Fri, 08 Oct 2021 20:53:27 -0400
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 <at> 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 <at> 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




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#51082; Package emacs. (Sat, 09 Oct 2021 08:04:02 GMT) Full text and rfc822 format available.

Message #11 received at 51082 <at> debbugs.gnu.org (full text, mbox):

From: "J.P." <jp <at> neverwas.me>
To: Amin Bandali <bandali <at> gnu.org>
Cc: emacs-erc <at> gnu.org, Stefan Kangas <stefan <at> marxist.se>, 51082 <at> debbugs.gnu.org
Subject: Re: bug#51082: [PATCH] erc-prompt: support substitution patterns
 "%target" and "%network"
Date: Sat, 09 Oct 2021 01:03:20 -0700
Amin Bandali <bandali <at> gnu.org> writes:

> 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').

This may be my lack of a forebrain talking, but I thought the prompt
only gets updated after sending input.

  (setq erc-prompt (lambda () (format-time-string "[%T.%3N]>")))

IOW, I don't think it's currently driven by response handlers, so it
won't react right away after a nick change or upon receiving a MODE or a
221. The mode line, OTOH, is updated more or less constantly (though
possibly too often). And as far as user modes go, ERC doesn't currently
remember them (AFAIK), a point I rather poorly tried to raise here:

  https://lists.gnu.org/archive/html/emacs-erc/2021-10/msg00012.html

But with Stefan's current changes, none of this really matters (right?)
because target and network are effectively read-only once set (ignoring
a few edge cases).

> Also, for v2 please add an accompanying etc/ERC-NEWS entry for the
> change.

As an aside, one pleasant effect of having our own NEWS file is the
absence of constant merge conflicts on account of etc/NEWS' popularity.
For example, when trying to integrate older #48598 stuff with Olivier's
last services patch (in the months leading up to its installation), I
got annoyed enough by all the repeated manual merging of etc/NEWS that I
ended up replacing his changes to that file with a FIXME/IOU in his
commit message. But I guess the days of resorting to such shenanigans
are over!

>> +(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'?

Fearing similar feedback, I recently mass-renamed my `erc-foo--' stuff
in #48598 to `erc--foo-'. But I was wondering if an exception couldn't
be made for seasoned subprojects like ERC, with its longish primary
library file housing groups of related items sharing longer, more
qualified prefixes (than what's offered by the file/feature). I tried
searching the help list for this a while back but failed to find
anything.

> Why leave "%modes" commented out?  Would using
> `erc-format-channel-modes' not work here?

If we do end up redrawing the prompt more often, which uncommenting this
seems to imply, would it not make sense to also address the occasional
double vision "ERC> ERC>" thing? Just thought I'd mention it in case
anyone already has a patch handy. Otherwise, forget I said anything,
especially if this doesn't ring a bell. We'll just deal with it later,
hopefully after facing down some of ERC's scarier demons.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#51082; Package emacs. (Sat, 10 Sep 2022 05:21:02 GMT) Full text and rfc822 format available.

Message #14 received at 51082 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Stefan Kangas <stefan <at> marxist.se>
Cc: emacs-erc <at> gnu.org, Amin Bandali <bandali <at> gnu.org>, 51082 <at> debbugs.gnu.org
Subject: Re: bug#51082: [PATCH] erc-prompt: support substitution patterns
 "%target" and "%network"
Date: Sat, 10 Sep 2022 07:20:51 +0200
Stefan Kangas <stefan <at> marxist.se> writes:

> The attached patch adds substitution patterns "%target" and "%network"
> so you can do stuff like
>
>     (setq erc-prompt "[%target]")
>     (setq erc-prompt "[%target@%network]")

I think using the normal `format-spec' syntax would be nicer here.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#51082; Package emacs. (Mon, 20 Nov 2023 21:18:01 GMT) Full text and rfc822 format available.

Message #17 received at 51082 <at> debbugs.gnu.org (full text, mbox):

From: "J.P." <jp <at> neverwas.me>
To: 51082 <at> debbugs.gnu.org
Cc: Amin Bandali <bandali <at> gnu.org>, Lars Ingebrigtsen <larsi <at> gnus.org>,
 emacs-erc <at> gnu.org, Stefan Kangas <stefan <at> marxist.se>
Subject: Re: bug#51082: [PATCH] erc-prompt: support substitution patterns
 "%target" and "%network"
Date: Mon, 20 Nov 2023 13:17:09 -0800
[Message part 1 (text/plain, inline)]
Hi people,

I'd like to take this feature over, in case anyone cares. To summarize,
it initially stalled out because an underlying facility to support the
dynamic updating of rich UI elements wasn't available at the time. Most
of it has since been added, and the attached changes (once complete)
should fill in any remaining gaps.

Thus, I've gone ahead and integrated everyone's suggestions, for the
most part, with the only caveat being the feature won't be enabled by
default. Rather, there's an added step involved where a user must first

  (setopt erc-prompt #erc-prompt-format)

before ERC will consider the companion option that contains the actual
template (also called `erc-prompt-format'). Such indirection may be
regrettable from a UX standpoint, but I'd rather hold off on improving
things until we've brought batch processing fully into the fold and have
tuned it to perform respectably with ERC's default configuration.

For anyone unfamiliar, ERC will soon be needing to process incoming
messages in rapid succession all the way to insertion as fast as it can
manage. Like normal messages, these will also influence the state of UI
elements, like the prompt, the mode line, etc. Because such processing
will be foundational to ERC's basic operations going forward, it's
important to prioritize über alles. To that end, I'm hoping we can
revisit this feature again at some later date if folks end up wanting to
expand `erc-prompt' to accommodate format specifiers directly, as
originally envisioned.

Thanks.

[0001-5.6-Don-t-inherit-properties-when-refreshing-ERC-s-p.patch (text/x-patch, attachment)]
[0002-5.6-Use-overlay-instead-of-text-prop-to-hide-ERC-pro.patch (text/x-patch, attachment)]
[0003-5.6-Optionally-align-prompt-to-prefix-in-erc-fill-wr.patch (text/x-patch, attachment)]
[0004-5.6-Optionally-allow-substitution-patterns-in-erc-pr.patch (text/x-patch, attachment)]

Message #18 received at 51082-quiet <at> debbugs.gnu.org (full text, mbox):

From: "J.P." <jp <at> neverwas.me>
To: 51082-quiet <at> debbugs.gnu.org
Subject: Re: bug#51082: [PATCH] erc-prompt: support substitution patterns
 "%target" and "%network"
Date: Mon, 20 Nov 2023 13:19:55 -0800
[Message part 1 (text/plain, inline)]
Screenshot storage:
[erc-prompt-format_demo.webm (video/webm, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#51082; Package emacs. (Mon, 20 Nov 2023 21:24:01 GMT) Full text and rfc822 format available.

Message #21 received at 51082 <at> debbugs.gnu.org (full text, mbox):

From: "J.P." <jp <at> neverwas.me>
To: 51082 <at> debbugs.gnu.org
Cc: Stefan Kangas <stefan <at> marxist.se>, Lars Ingebrigtsen <larsi <at> gnus.org>,
 emacs-erc <at> gnu.org, Amin Bandali <bandali <at> gnu.org>
Subject: Re: bug#51082: [PATCH] erc-prompt: support substitution patterns
 "%target" and "%network"
Date: Mon, 20 Nov 2023 13:22:44 -0800
Screenshot:

https://debbugs.gnu.org/cgi/bugreport.cgi?att=1;msg=18;bug=51082;filename=erc-prompt-format_demo.webm




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#51082; Package emacs. (Wed, 22 Nov 2023 19:27:02 GMT) Full text and rfc822 format available.

Message #24 received at 51082 <at> debbugs.gnu.org (full text, mbox):

From: "J.P." <jp <at> neverwas.me>
To: 51082 <at> debbugs.gnu.org
Cc: Amin Bandali <bandali <at> gnu.org>, Lars Ingebrigtsen <larsi <at> gnus.org>,
 emacs-erc <at> gnu.org, Stefan Kangas <stefan <at> marxist.se>
Subject: Re: bug#51082: [PATCH] erc-prompt: support substitution patterns
 "%target" and "%network"
Date: Wed, 22 Nov 2023 11:25:57 -0800
[Message part 1 (text/plain, inline)]
v2. Simplify `format-spec' helper. Demote `erc-fill-wrap-use-pixels' to
normal variable. Simplify option `erc-prompt-format' and make example
value default. Add substitution for showing channel or user mode based
on context. Add tests.

(Also, make myself primary author of last patch to spare others from
unwanted attribution.) Note that a patch from bug#67220 is also now
included because it's become a dependency.

[0000-v1-v2.diff (text/x-patch, attachment)]
[0001-5.6-Don-t-associate-type-D-channel-modes-with-args-i.patch (text/x-patch, attachment)]
[0002-5.6-Don-t-inherit-properties-when-refreshing-ERC-s-p.patch (text/x-patch, attachment)]
[0003-5.6-Use-overlay-instead-of-text-prop-to-hide-ERC-s-p.patch (text/x-patch, attachment)]
[0004-5.6-Optionally-align-prompt-to-prefix-in-erc-fill-wr.patch (text/x-patch, attachment)]
[0005-5.6-Optionally-allow-substitution-patterns-in-erc-pr.patch (text/x-patch, attachment)]

Reply sent to "J.P." <jp <at> neverwas.me>:
You have taken responsibility. (Fri, 24 Nov 2023 22:14:02 GMT) Full text and rfc822 format available.

Notification sent to Stefan Kangas <stefan <at> marxist.se>:
bug acknowledged by developer. (Fri, 24 Nov 2023 22:14:03 GMT) Full text and rfc822 format available.

Message #29 received at 51082-done <at> debbugs.gnu.org (full text, mbox):

From: "J.P." <jp <at> neverwas.me>
To: 51082-done <at> debbugs.gnu.org
Cc: Amin Bandali <bandali <at> gnu.org>, Lars Ingebrigtsen <larsi <at> gnus.org>,
 emacs-erc <at> gnu.org, Stefan Kangas <stefan <at> marxist.se>
Subject: Re: bug#51082: [PATCH] erc-prompt: support substitution patterns
 "%target" and "%network"
Date: Fri, 24 Nov 2023 14:12:32 -0800
"J.P." <jp <at> neverwas.me> writes:

> v2. Simplify `format-spec' helper. Demote `erc-fill-wrap-use-pixels' to
> normal variable. Simplify option `erc-prompt-format' and make example
> value default. Add substitution for showing channel or user mode based
> on context. Add tests.
>
> (Also, make myself primary author of last patch to spare others from
> unwanted attribution.) Note that a patch from bug#67220 is also now
> included because it's become a dependency.

A version of this has been installed as

  2ed9c9f1b32 * Optionally allow substitution patterns in erc-prompt

Thanks and closing.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#51082; Package emacs. (Fri, 15 Dec 2023 01:19:02 GMT) Full text and rfc822 format available.

Message #32 received at 51082-done <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefankangas <at> gmail.com>
To: "J.P." <jp <at> neverwas.me>, 51082-done <at> debbugs.gnu.org
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>, emacs-erc <at> gnu.org,
 Amin Bandali <bandali <at> gnu.org>
Subject: Re: bug#51082: [PATCH] erc-prompt: support substitution patterns
 "%target" and "%network"
Date: Thu, 14 Dec 2023 17:18:33 -0800
"J.P." <jp <at> neverwas.me> writes:

> A version of this has been installed as
>
>   2ed9c9f1b32 * Optionally allow substitution patterns in erc-prompt
>
> Thanks and closing.

Thanks!




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 12 Jan 2024 12:24:08 GMT) Full text and rfc822 format available.

This bug report was last modified 103 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.