unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#33799: 27.0.50; set-foreground-color completion shows background colors
@ 2018-12-19  0:01 Juri Linkov
  2018-12-19 18:51 ` Glenn Morris
  0 siblings, 1 reply; 7+ messages in thread
From: Juri Linkov @ 2018-12-19  0:01 UTC (permalink / raw)
  To: 33799

0. emacs -Q

1. M-x set-foreground-color RET TAB

shows a completion list of colors with different backgrounds, not
foregrounds as it would be natural to expect, so it is difficult to
decide what foreground color to select by looking at background colors.





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

* bug#33799: 27.0.50; set-foreground-color completion shows background colors
  2018-12-19  0:01 bug#33799: 27.0.50; set-foreground-color completion shows background colors Juri Linkov
@ 2018-12-19 18:51 ` Glenn Morris
  2018-12-19 21:34   ` Juri Linkov
  2021-09-01  9:29   ` Lars Ingebrigtsen
  0 siblings, 2 replies; 7+ messages in thread
From: Glenn Morris @ 2018-12-19 18:51 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 33799

Juri Linkov wrote:

> 0. emacs -Q
>
> 1. M-x set-foreground-color RET TAB
>
> shows a completion list of colors with different backgrounds, not
> foregrounds as it would be natural to expect

Very lightly tested:


--- i/lisp/faces.el
+++ w/lisp/faces.el
@@ -1838,18 +1838,21 @@ defined-colors
     (mapcar 'car (tty-color-alist frame))))
 (defalias 'x-defined-colors 'defined-colors)
 
-(defun defined-colors-with-face-attributes (&optional frame)
+(defun defined-colors-with-face-attributes (&optional frame foreground)
   "Return a list of colors supported for a particular frame.
 See `defined-colors' for arguments and return value. In contrast
 to `define-colors' the elements of the returned list are color
 strings with text properties, that make the color names render
-with the color they represent as background color."
+with the color they represent as background (or foreground if
+optional argument FOREGROUND is no-nil) color. "
   (mapcar
    (lambda (color-name)
-     (let ((foreground (readable-foreground-color color-name))
-	   (color      (copy-sequence color-name)))
-       (propertize color 'face (list :foreground foreground
-				     :background color))))
+     (let ((readable (readable-foreground-color color-name))
+	   (color (copy-sequence color-name)))
+       (propertize color 'face
+		   (if foreground
+		       (list :foreground color)
+		     (list :foreground readable :background color)))))
    (defined-colors frame)))
 
 (defun readable-foreground-color (color)
@@ -1935,7 +1938,8 @@ display-grayscale-p
      (t
       (> (tty-color-gray-shades display) 2)))))
 
-(defun read-color (&optional prompt convert-to-RGB allow-empty-name msg)
+(defun read-color (&optional prompt convert-to-RGB allow-empty-name msg
+			     foreground)
   "Read a color name or RGB triplet.
 Completion is available for color names, but not for RGB triplets.
 
@@ -1962,14 +1966,19 @@ read-color
 to enter an empty color name (the empty string).
 
 Interactively, or with optional arg MSG non-nil, print the
-resulting color name in the echo area."
+resulting color name in the echo area.
+
+Interactively, displays a list of colored completions.  If optional
+argument FOREGROUND is non-nil, shows them as foregrounds, otherwise
+as backgrounds."
   (interactive "i\np\ni\np")    ; Always convert to RGB interactively.
   (let* ((completion-ignore-case t)
 	 (colors (or facemenu-color-alist
 		     (append '("foreground at point" "background at point")
 			     (if allow-empty-name '(""))
                              (if (display-color-p)
-                                 (defined-colors-with-face-attributes)
+                                 (defined-colors-with-face-attributes
+				   nil foreground)
                                (defined-colors)))))
 	 (color (completing-read
 		 (or prompt "Color (name or #RGB triplet): ")
diff --git i/lisp/frame.el w/lisp/frame.el
index 56b8c54..f056b6d 100644
--- i/lisp/frame.el
+++ w/lisp/frame.el
@@ -1335,7 +1335,7 @@ set-foreground-color
   "Set the foreground color of the selected frame to COLOR-NAME.
 When called interactively, prompt for the name of the color to use.
 To get the frame's current foreground color, use `frame-parameters'."
-  (interactive (list (read-color "Foreground color: ")))
+  (interactive (list (read-color "Foreground color: " nil nil nil t)))
   (modify-frame-parameters (selected-frame)
 			   (list (cons 'foreground-color color-name)))
   (or window-system





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

* bug#33799: 27.0.50; set-foreground-color completion shows background colors
  2018-12-19 18:51 ` Glenn Morris
@ 2018-12-19 21:34   ` Juri Linkov
  2018-12-20 17:49     ` Glenn Morris
  2021-09-01  9:29   ` Lars Ingebrigtsen
  1 sibling, 1 reply; 7+ messages in thread
From: Juri Linkov @ 2018-12-19 21:34 UTC (permalink / raw)
  To: Glenn Morris; +Cc: 33799

>> 1. M-x set-foreground-color RET TAB
>>
>> shows a completion list of colors with different backgrounds, not
>> foregrounds as it would be natural to expect
>
> Very lightly tested:
>
>    (mapcar
>     (lambda (color-name)
> -     (let ((foreground (readable-foreground-color color-name))
> -	   (color      (copy-sequence color-name)))
> -       (propertize color 'face (list :foreground foreground
> -				     :background color))))
> +     (let ((readable (readable-foreground-color color-name))
> +	   (color (copy-sequence color-name)))
> +       (propertize color 'face
> +		   (if foreground
> +		       (list :foreground color)
> +		     (list :foreground readable :background color)))))

I don't know if readable background is needed for set-foreground-color
like readable foreground is used for set-background-color.  I think
your change to not use readable background is more correct because
then the user will see how the selected color will fit with the background.
This helps to select a suitable combination of foreground/background
colors.  The same way maybe readable foreground should be removed
from the completions of set-background-color.  This would allow to see
how the current foreground color will look on different backgrounds
in the completion list.





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

* bug#33799: 27.0.50; set-foreground-color completion shows background colors
  2018-12-19 21:34   ` Juri Linkov
@ 2018-12-20 17:49     ` Glenn Morris
  2018-12-20 22:37       ` Juri Linkov
  0 siblings, 1 reply; 7+ messages in thread
From: Glenn Morris @ 2018-12-20 17:49 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 33799

Juri Linkov wrote:

> I don't know if readable background is needed for set-foreground-color
> like readable foreground is used for set-background-color.  I think
> your change to not use readable background is more correct because
> then the user will see how the selected color will fit with the background.
> This helps to select a suitable combination of foreground/background
> colors.  The same way maybe readable foreground should be removed
> from the completions of set-background-color.  This would allow to see
> how the current foreground color will look on different backgrounds
> in the completion list.

I think defined-colors-with-face-attributes probably needs yet another
argument, to control whether the non-varying component (be it foreground
or background) is a fixed value or a changing "readable" one.





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

* bug#33799: 27.0.50; set-foreground-color completion shows background colors
  2018-12-20 17:49     ` Glenn Morris
@ 2018-12-20 22:37       ` Juri Linkov
  0 siblings, 0 replies; 7+ messages in thread
From: Juri Linkov @ 2018-12-20 22:37 UTC (permalink / raw)
  To: Glenn Morris; +Cc: 33799

>> I don't know if readable background is needed for set-foreground-color
>> like readable foreground is used for set-background-color.  I think
>> your change to not use readable background is more correct because
>> then the user will see how the selected color will fit with the background.
>> This helps to select a suitable combination of foreground/background
>> colors.  The same way maybe readable foreground should be removed
>> from the completions of set-background-color.  This would allow to see
>> how the current foreground color will look on different backgrounds
>> in the completion list.
>
> I think defined-colors-with-face-attributes probably needs yet another
> argument, to control whether the non-varying component (be it foreground
> or background) is a fixed value or a changing "readable" one.

Yes, another argument (or maybe rename the new argument `foreground',
but I have no idea for a good name and its values) is needed specially
for set-foreground-color and set-background-color that should leave the
default background/foreground color instead of replacing it with readable.





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

* bug#33799: 27.0.50; set-foreground-color completion shows background colors
  2018-12-19 18:51 ` Glenn Morris
  2018-12-19 21:34   ` Juri Linkov
@ 2021-09-01  9:29   ` Lars Ingebrigtsen
  2021-09-01 14:37     ` bug#33799: [External] : " Drew Adams
  1 sibling, 1 reply; 7+ messages in thread
From: Lars Ingebrigtsen @ 2021-09-01  9:29 UTC (permalink / raw)
  To: Glenn Morris; +Cc: 33799, Juri Linkov

Glenn Morris <rgm@gnu.org> writes:

>> shows a completion list of colors with different backgrounds, not
>> foregrounds as it would be natural to expect
>
> Very lightly tested:
>
> --- i/lisp/faces.el
> +++ w/lisp/faces.el

I respun the patch for the current trunk and tested it, and I think it
looks really good, so I pushed it to Emacs 28 (with some minor changes).

There was then some discussion about whether
defined-colors-with-face-attributes should have a parameter that says
whether to do readable colours for the "other" colour, and that may be a
good idea, but I don't quite see how that'd be exposed to the user, so I
think we can leave that as is (at least for now).  (And see whether
anybody wants any changes here.)

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

* bug#33799: [External] : bug#33799: 27.0.50; set-foreground-color completion shows background colors
  2021-09-01  9:29   ` Lars Ingebrigtsen
@ 2021-09-01 14:37     ` Drew Adams
  0 siblings, 0 replies; 7+ messages in thread
From: Drew Adams @ 2021-09-01 14:37 UTC (permalink / raw)
  To: Lars Ingebrigtsen, Glenn Morris; +Cc: 33799@debbugs.gnu.org, Juri Linkov

See also bug #15427.






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

end of thread, other threads:[~2021-09-01 14:37 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-19  0:01 bug#33799: 27.0.50; set-foreground-color completion shows background colors Juri Linkov
2018-12-19 18:51 ` Glenn Morris
2018-12-19 21:34   ` Juri Linkov
2018-12-20 17:49     ` Glenn Morris
2018-12-20 22:37       ` Juri Linkov
2021-09-01  9:29   ` Lars Ingebrigtsen
2021-09-01 14:37     ` bug#33799: [External] : " Drew Adams

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