unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [Patch] rcirc-color: Allow recoloring nicks
@ 2022-09-28 21:06 Thuna
  2022-09-29 12:14 ` Thuna
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Thuna @ 2022-09-28 21:06 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 353 bytes --]

I think rcirc-color should allow a nick to be "recolored" with the
command `/color nick', instead of signalling an error as it does now.

This is useful, for example, when two similar nicks are assigned the
same color but there's no specific color you want to reassign to either
of them.

I haven't tested the patch, but I can't see why it would fail.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: The patch --]
[-- Type: text/x-patch, Size: 1651 bytes --]

From 8bd21515f31a5e3cfedce623d8ebc9907b82b2a5 Mon Sep 17 00:00:00 2001
From: Thuna <thuna.cing@gmail.com>
Date: Wed, 28 Sep 2022 22:58:00 +0200
Subject: [PATCH] rcirc-color: Select a random color on `/color nick'

* rcirc-color.el: When `/color' is called with a nick but no color,
choose a random color from `rcirc-colors' instead of signalling an
error.
---
 rcirc-color.el | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/rcirc-color.el b/rcirc-color.el
index 872d1d8298..0f6f2adea9 100644
--- a/rcirc-color.el
+++ b/rcirc-color.el
@@ -136,7 +136,9 @@ NICK is the nick for which the new color ist set; if nil, all the
 nicks in `rcirc-color-mapping' are shown with their corresponding
 faces.
 
-COLOR is the color to use as the new foreground-color.
+COLOR is the color to use as the new foreground-color.  If COLOR
+is not supplied, a random color from `rcirc-colors' is used
+instead.
 
 PROCESS and TARGET are the standard arguments for rcirc
 commands."
@@ -151,9 +153,11 @@ commands."
                  rcirc-color-mapping)
         (rcirc-print process (rcirc-nick process) "NOTICE" target
                      (mapconcat 'identity names " ")))
-    (unless color
-      (error "Use what color?"))
-    (puthash nick (cons 'foreground-color color) rcirc-color-mapping)))
+    (puthash nick
+             (cons 'foreground-color
+                   (elt rcirc-colors
+                        (random (length rcirc-colors))))
+             rcirc-color-mapping)))
 
 (advice-add 'rcirc-handler-NICK :before #'rcirc-color--handler-NICK)
 (defun rcirc-color--handler-NICK (_process sender args _text)
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Patch] rcirc-color: Allow recoloring nicks
  2022-09-28 21:06 [Patch] rcirc-color: Allow recoloring nicks Thuna
@ 2022-09-29 12:14 ` Thuna
  2022-09-29 13:30 ` Stefan Kangas
  2022-09-29 15:42 ` Philip Kaludercic
  2 siblings, 0 replies; 5+ messages in thread
From: Thuna @ 2022-09-29 12:14 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 135 bytes --]

> I haven't tested the patch, but I can't see why it would fail.

Alright, it did in fact fail.  Here's the (hopefully) correct patch.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: The *actual* patch --]
[-- Type: text/x-patch, Size: 1691 bytes --]

From 4462df8aa6c0f9986629d5fab7df43e502552ba3 Mon Sep 17 00:00:00 2001
From: Thuna <thuna.cing@gmail.com>
Date: Thu, 29 Sep 2022 14:12:20 +0200
Subject: [PATCH] rcirc-color: Select a random color on `/color nick'

* rcirc-color.el: When `/color' is called with a nick but no color,
choose a random color from `rcirc-colors' instead of signalling an
error.
---
 rcirc-color.el | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/rcirc-color.el b/rcirc-color.el
index 2eff965267..7bcc46c91d 100644
--- a/rcirc-color.el
+++ b/rcirc-color.el
@@ -134,7 +134,9 @@ NICK is the nick for which the new color ist set; if nil, all the
 nicks in `rcirc-color-mapping' are shown with their corresponding
 faces.
 
-COLOR is the color to use as the new foreground-color.
+COLOR is the color to use as the new foreground-color.  If COLOR
+is not supplied, a random color from `rcirc-colors' is used
+instead.
 
 PROCESS and TARGET are the standard arguments for rcirc
 commands."
@@ -149,9 +151,12 @@ commands."
                  rcirc-color-mapping)
         (rcirc-print process (rcirc-nick process) "NOTICE" target
                      (mapconcat 'identity names " ")))
-    (unless color
-      (error "Use what color?"))
-    (puthash nick (cons 'foreground-color color) rcirc-color-mapping)))
+    (puthash nick
+             (cons 'foreground-color
+                   (or color
+                       (elt rcirc-colors
+                            (random (length rcirc-colors)))))
+             rcirc-color-mapping)))
 
 (advice-add 'rcirc-handler-NICK :before #'rcirc-color--handler-NICK)
 (defun rcirc-color--handler-NICK (_process sender args _text)
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Patch] rcirc-color: Allow recoloring nicks
  2022-09-28 21:06 [Patch] rcirc-color: Allow recoloring nicks Thuna
  2022-09-29 12:14 ` Thuna
@ 2022-09-29 13:30 ` Stefan Kangas
  2022-09-29 15:42 ` Philip Kaludercic
  2 siblings, 0 replies; 5+ messages in thread
From: Stefan Kangas @ 2022-09-29 13:30 UTC (permalink / raw)
  To: Thuna, emacs-devel

Thuna <thuna.cing@gmail.com> writes:

> I think rcirc-color should allow a nick to be "recolored" with the
> command `/color nick', instead of signalling an error as it does now.
>
> This is useful, for example, when two similar nicks are assigned the
> same color but there's no specific color you want to reassign to either
> of them.

Thanks for the patch.

> I haven't tested the patch, but I can't see why it would fail.

Not many people will feel confident about installing an untested patch,
so I'd recommend testing it yourself and reporting back.  Please see
"Testing your changes" in CONTRIBUTE.

You could re-send the tested patch to bug-gnu-emacs@gnu.org, which is
where patches should normally go.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Patch] rcirc-color: Allow recoloring nicks
  2022-09-28 21:06 [Patch] rcirc-color: Allow recoloring nicks Thuna
  2022-09-29 12:14 ` Thuna
  2022-09-29 13:30 ` Stefan Kangas
@ 2022-09-29 15:42 ` Philip Kaludercic
  2022-09-29 15:48   ` Philip Kaludercic
  2 siblings, 1 reply; 5+ messages in thread
From: Philip Kaludercic @ 2022-09-29 15:42 UTC (permalink / raw)
  To: Thuna; +Cc: emacs-devel

Thuna <thuna.cing@gmail.com> writes:

> I think rcirc-color should allow a nick to be "recolored" with the
> command `/color nick', instead of signalling an error as it does now.
>
> This is useful, for example, when two similar nicks are assigned the
> same color but there's no specific color you want to reassign to either
> of them.
>
> I haven't tested the patch, but I can't see why it would fail.

It looks about right, but is random really the best we can do?  Would it
not be possible to try and find the most "distant" color to avoid
accidentally assigning similar colors to different names.

On the topic of rcirc-color, I had always assumed it would color all
nicks by default, not when manually selected.  There is /bright in IRC
by default.  It seems like it would be pretty easy to assign a random
color depending on the hash of the nickname.

> From 8bd21515f31a5e3cfedce623d8ebc9907b82b2a5 Mon Sep 17 00:00:00 2001
> From: Thuna <thuna.cing@gmail.com>
> Date: Wed, 28 Sep 2022 22:58:00 +0200
> Subject: [PATCH] rcirc-color: Select a random color on `/color nick'
>
> * rcirc-color.el: When `/color' is called with a nick but no color,
> choose a random color from `rcirc-colors' instead of signalling an
> error.
> ---
>  rcirc-color.el | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/rcirc-color.el b/rcirc-color.el
> index 872d1d8298..0f6f2adea9 100644
> --- a/rcirc-color.el
> +++ b/rcirc-color.el
> @@ -136,7 +136,9 @@ NICK is the nick for which the new color ist set; if nil, all the
>  nicks in `rcirc-color-mapping' are shown with their corresponding
>  faces.
>  
> -COLOR is the color to use as the new foreground-color.
> +COLOR is the color to use as the new foreground-color.  If COLOR
> +is not supplied, a random color from `rcirc-colors' is used
> +instead.
>  
>  PROCESS and TARGET are the standard arguments for rcirc
>  commands."
> @@ -151,9 +153,11 @@ commands."
>                   rcirc-color-mapping)
>          (rcirc-print process (rcirc-nick process) "NOTICE" target
>                       (mapconcat 'identity names " ")))
> -    (unless color
> -      (error "Use what color?"))
> -    (puthash nick (cons 'foreground-color color) rcirc-color-mapping)))
> +    (puthash nick
> +             (cons 'foreground-color
> +                   (elt rcirc-colors
> +                        (random (length rcirc-colors))))
> +             rcirc-color-mapping)))
>  
>  (advice-add 'rcirc-handler-NICK :before #'rcirc-color--handler-NICK)
>  (defun rcirc-color--handler-NICK (_process sender args _text)



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Patch] rcirc-color: Allow recoloring nicks
  2022-09-29 15:42 ` Philip Kaludercic
@ 2022-09-29 15:48   ` Philip Kaludercic
  0 siblings, 0 replies; 5+ messages in thread
From: Philip Kaludercic @ 2022-09-29 15:48 UTC (permalink / raw)
  To: Thuna; +Cc: emacs-devel

Philip Kaludercic <philipk@posteo.net> writes:

> On the topic of rcirc-color, I had always assumed it would color all
> nicks by default, not when manually selected.  There is /bright in IRC
> by default.  It seems like it would be pretty easy to assign a random
> color depending on the hash of the nickname.

Nevermind this, I just noticed that this exactly what rcirc-color does.
Looks like I made a mistake when trying it out the last time.



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-09-29 15:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-28 21:06 [Patch] rcirc-color: Allow recoloring nicks Thuna
2022-09-29 12:14 ` Thuna
2022-09-29 13:30 ` Stefan Kangas
2022-09-29 15:42 ` Philip Kaludercic
2022-09-29 15:48   ` Philip Kaludercic

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