all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Glenn Morris <rgm@gnu.org>
To: Juri Linkov <juri@linkov.net>
Cc: 33799@debbugs.gnu.org
Subject: bug#33799: 27.0.50; set-foreground-color completion shows background colors
Date: Wed, 19 Dec 2018 13:51:59 -0500	[thread overview]
Message-ID: <5aftutcptc.fsf@fencepost.gnu.org> (raw)
In-Reply-To: <875zvqz8om.fsf@mail.linkov.net> (Juri Linkov's message of "Wed,  19 Dec 2018 02:01:13 +0200")

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





  reply	other threads:[~2018-12-19 18:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

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

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

  git send-email \
    --in-reply-to=5aftutcptc.fsf@fencepost.gnu.org \
    --to=rgm@gnu.org \
    --cc=33799@debbugs.gnu.org \
    --cc=juri@linkov.net \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.