Re: erc-ircfmt.el: Transient-based formatting for Erc (Emacs 29+)

"J.P." <[email protected]> Fri, 15 Mar 2024 14:06:29 -0700
Newsgroups gmane.emacs.erc.general
Message-ID <[email protected]>
Alcor <[email protected]> writes:

> Hello Erc'ers,
>
> attached to this message is a proposal for a transient.el-based
> IRC formatting [1] menu for Erc, allowing interactive formatting of
> selected text regions with IRC formatting codes.

I'll have to try it out. Thanks!

>
> The attached Lisp program `erc-ircfmt.el' adds a new C-c q
> keybinding to the Erc keymap, which is bound to an interactive function `erc-fmt'.
>
> `erc-fmt' provides a transient [2] menu where both text formatting
> (bold, italicized, underlined) styles and foreground/background colors
> can be selected, inserting the corresponding control code(s) at point,
> or enclosing a region with them (if active).
>
> I've been using this code for several months now, and it can be
> considered fairly well-tested. A few screenshots showcasing the
> transient prefixes are also attached. A recent version of Emacs (29+)
> including transient.el is required.
>
> The initial idea behind this was to bring Erc to "feature parity" with
> rcirc. Emacs 29's NEWS mentions the following:
>
>> *** New formatting commands.
>> Most IRC clients (including rcirc) support basic formatting using
>> control codes.  Under the 'C-c C-f' prefix a few commands have been
>> added to insert these automatically.  For example, if a region is
>> active and 'C-c C-f C-b' is invoked, markup is inserted for the region
>> to be highlighted in bold.
>
> Contrary to what the NEWS file claims, Erc does not support the
> aforementioned prefixes/keybinds, and the aim of this extension is to
> rectify this. Unfortunately, C-c C-f is already bound to
> `erc-toggle-flood-control', therefore this code uses C-c q as an
> alternative keybind (Many thanks to Corwin for the recommendation).

I haven't looked into the history of `erc-toggle-flood-control', but I
do know that until recently the codebase suffered from a general
confusion between some related concerns, like multiline prompt input,
accidental yanking/terminal pasting, and actual flooding (overly
frequent outgoing messages). Really, the only use case that comes to
mind for disabling flood control is long multiline prompt submissions
(not necessarily in conjunction with the `draft/multiline' extension).
But with this you'd likely run the risk of servers you don't control
penalizing you. Regardless, if your plan is to add this feature to ERC
and you really want the C-c C-f binding, we could just hijack it. Or you
could shadow it in a minor-mode map by couching the feature in a local
module. But then users would have to add `ircfmt' to `erc-modules' or
enable the module's minor mode before they could use it.

> Comments/feedback are appreciated.

Not sure if this is already supported by your patch, but it might be
nice to optionally restore control chars when copying and yanking an
already inserted message that contains `{fg,bg}:erc-color-faceN' faces.
Actually, long ago, ERC shipped with something attempting to provide
such functionality. But it was removed for reasons unknown (to me).

> If desirable, it might be possible to
> include this code (or something similar) in erc-goodies.el, so Erc can
> provide this functionality OOTB.

If this is to find a home in the ERC tree, you'll need to open a bug
report for it and also ensure it doesn't error when compiling or loading
on Emacs 27. This last part wouldn't be necessary if we were to add
transient.el as a hard ELPA dependency, but I'm not sure we're ready to
make that decision anytime soon.