From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Helmut Eller Newsgroups: gmane.emacs.bugs Subject: bug#64725: 30.0.50; set-face-foreground shows background colors Date: Thu, 20 Jul 2023 16:34:34 +0200 Message-ID: References: <83351k5aw5.fsf@gnu.org> <83lefb50lu.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="9201"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 64725@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jul 20 16:35:31 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qMUkc-00025M-15 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 20 Jul 2023 16:35:30 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qMUkJ-0006w3-4a; Thu, 20 Jul 2023 10:35:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qMUkC-0006sS-29 for bug-gnu-emacs@gnu.org; Thu, 20 Jul 2023 10:35:05 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qMUkA-0001zb-V8 for bug-gnu-emacs@gnu.org; Thu, 20 Jul 2023 10:35:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qMUkA-0003vn-G7 for bug-gnu-emacs@gnu.org; Thu, 20 Jul 2023 10:35:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Helmut Eller Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 20 Jul 2023 14:35:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 64725 X-GNU-PR-Package: emacs Original-Received: via spool by 64725-submit@debbugs.gnu.org id=B64725.168986368515085 (code B ref 64725); Thu, 20 Jul 2023 14:35:02 +0000 Original-Received: (at 64725) by debbugs.gnu.org; 20 Jul 2023 14:34:45 +0000 Original-Received: from localhost ([127.0.0.1]:59441 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qMUjs-0003vE-KM for submit@debbugs.gnu.org; Thu, 20 Jul 2023 10:34:45 -0400 Original-Received: from mail-lj1-x230.google.com ([2a00:1450:4864:20::230]:53728) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qMUjq-0003v0-8X for 64725@debbugs.gnu.org; Thu, 20 Jul 2023 10:34:44 -0400 Original-Received: by mail-lj1-x230.google.com with SMTP id 38308e7fff4ca-2b9540031acso12568601fa.3 for <64725@debbugs.gnu.org>; Thu, 20 Jul 2023 07:34:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689863676; x=1690468476; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=dRU9qqCk+AhCIxe+hVEKjDT9ieLioI8A42A5wEdcYyY=; b=Dr5KS2ZYWlLXD0PPWeh+aoPTK3YoRq9N87uTxp5h9W55KcWr/1PyTXxUxz0OZG8bKk Ba784/KbBib+2BdaJotdrXJYgX7sGpG/wLyVE/Gwn5k8pMcFH5SA1iOyAR7Qs8z580Sz oqH4L5k9xvSPR13+P9fv1PFlz4xOJMAo3R+1WlV/+2sq61W0LmRINs3VnytGtfSsQeLc uVYEYW5yMGwDH2KgqDXGUn6CsBsxA6tj0z1OIvCuEzAKzN/0AN7X/UF5cLq/d0HuETmS dUKc0ZVRRSBytZMwYoWPpeydAvMkkWegjiOH3c0wxZdiqujjLjBb8CfsLUAyEfXhSwXj CGIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689863676; x=1690468476; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=dRU9qqCk+AhCIxe+hVEKjDT9ieLioI8A42A5wEdcYyY=; b=CXHsh7E34wcKBUqUzOxQt1OJ9Rvvj5y6WJUihvBMAyEzkTj9y8FYF0voRxrNz10Fnz VkuEB9sm0XxaTFc8P46YYXvH/sqPCEfZ8whkiPfyjP5uVVubbKJQCTxZLmaTI7K4dQfc av1xeBVYmDSRDu+1ix10aJf9VWhIf5sYAGzzkZTG4eWslUgspVe7Y/SA+c9QGp9Z1rQI 0T+9IX9nVLE+FczqwVlxLr+9BFHnoIz5+PADI6PMu/GOzT6CLy/cyEm2ZUtc0I5RR4tH 8YHDQtzkAmZH7jFgBDdZT5qaKlcWz8PgLwJUZPajznEPqQnZ9ks6vDjxGOAoaCHynJMy /O+g== X-Gm-Message-State: ABy/qLYEgomaXj4kwxJC1g5CUF66b4gq72MfuNeLFh2sKlcocL3DvH59 ZcrZ3U2VRVnRCsC5ARMLUWYSDuESeLg= X-Google-Smtp-Source: APBJJlF5ETni1XYNTyOQ86zW3i0i1E7XA7N6PvyXNuxe5AuDv23A8iLIDvpdVEd+xm9vtoELyjuFHw== X-Received: by 2002:ac2:4db7:0:b0:4fd:d9e0:4d79 with SMTP id h23-20020ac24db7000000b004fdd9e04d79mr1837786lfe.6.1689863675645; Thu, 20 Jul 2023 07:34:35 -0700 (PDT) Original-Received: from caladan ([212.46.176.29]) by smtp.gmail.com with ESMTPSA id l14-20020a1c790e000000b003fc3b03caa4sm4383085wme.0.2023.07.20.07.34.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jul 2023 07:34:34 -0700 (PDT) In-Reply-To: <83lefb50lu.fsf@gnu.org> (Eli Zaretskii's message of "Wed, 19 Jul 2023 19:26:21 +0300") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:265602 Archived-At: --=-=-= Content-Type: text/plain On Wed, Jul 19 2023, Eli Zaretskii wrote: > That's exactly what I meant: when you customize the foreground color > of a face, show the candidates as text in that color on the background > of the face's background color, and when you customize the background > of a face, show the candidates as background with the text in the > foreground color of the face. IOW, show the face with its both colors > as it will look if this candidate is chosen. OK. Here is a patch that should do this: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Improve-the-interactive-use-of-set-face-foreground.patch >From 69159b5ca0123692373a014ed19e01547c12449e Mon Sep 17 00:00:00 2001 From: Helmut Eller Date: Thu, 20 Jul 2023 16:27:34 +0200 Subject: [PATCH] Improve the interactive use of set-face-foreground When displaying the completion candidates, show how the face would look with the new foreground. * lisp/faces.el (faces--string-with-color): New helper. Factored out from defined-colors-with-face-attributes. (defined-colors-with-face-attributes): Use it. (read-color): Add optional argument FACE and pass it to faces--string-with-color. (read-face-attribute): Call read-color with more appropriate foreground and face arguments. * doc/lispref/minibuf.texi (High-Level Completion): Describe the intention behind the arguments FOREGROUND and FACE of read-color. --- doc/lispref/minibuf.texi | 8 ++++- lisp/faces.el | 64 +++++++++++++++++++++++++--------------- 2 files changed, 48 insertions(+), 24 deletions(-) diff --git a/doc/lispref/minibuf.texi b/doc/lispref/minibuf.texi index a861b8e910b..12ea7b12386 100644 --- a/doc/lispref/minibuf.texi +++ b/doc/lispref/minibuf.texi @@ -1515,7 +1515,8 @@ High-Level Completion @code{commandp}. @end defun -@deffn Command read-color &optional prompt convert allow-empty display +@deffn Command read-color &optional prompt convert allow-empty @ + display foreground face This function reads a string that is a color specification, either the color's name or an RGB hex value such as @code{#RRRGGGBBB}. It prompts with @var{prompt} (default: @code{"Color (name or #RGB triplet):"}) @@ -1535,6 +1536,11 @@ High-Level Completion Interactively, or when @var{display} is non-@code{nil}, the return value is also displayed in the echo area. + +The optional arguments FOREGROUND and FACE control the appearence of +the completion candidates. The candidates are displayed like FACE but +with different colors. If FOREGROUND is non-@code{nil} the foreground +varies, otherwise the background. @end deffn See also the functions @code{read-coding-system} and diff --git a/lisp/faces.el b/lisp/faces.el index 44d64c743ba..4f51a031156 100644 --- a/lisp/faces.el +++ b/lisp/faces.el @@ -1340,10 +1340,11 @@ read-face-attribute (format "%s" old-value)))) (setq new-value (if (memq attribute '(:foreground :background)) - (let ((color - (read-color - (format-prompt "%s for face `%s'" - default attribute-name face)))) + (let* ((prompt (format-prompt + "%s for face `%s'" + default attribute-name face)) + (fg (eq attribute ':foreground)) + (color (read-color prompt nil nil nil fg face))) (if (equal (string-trim color) "") default color)) @@ -1870,15 +1871,26 @@ defined-colors-with-face-attributes strings with text properties, that make the color names render with the color they represent as background color (if FOREGROUND is nil; otherwise use the foreground color)." - (mapcar - (lambda (color-name) - (let ((color (copy-sequence color-name))) - (propertize color 'face - (if foreground - (list :foreground color) - (list :foreground (readable-foreground-color color-name) - :background color))))) - (defined-colors frame))) + (mapcar (lambda (color-name) + (faces--string-with-color color-name color-name foreground)) + (defined-colors frame))) + +(defun faces--string-with-color (string color &optional foreground face) + "Return a copy of STRING with face attributes for COLOR. +Set the :background or :foreground attribute to COLOR, depending +on the argument FOREGROUND. + +The optional FACE argument controls the values for other +attributes." + (let* ((defaults (if face (list face) '())) + (colors (cond (foreground + (list :foreground color)) + (face + (list :background color)) + (t + (list :foreground (readable-foreground-color color) + :background color))))) + (propertize string 'face (cons colors defaults)))) (defun readable-foreground-color (color) "Return a readable foreground color for background COLOR. @@ -1987,7 +1999,7 @@ display-grayscale-p (> (tty-color-gray-shades display) 2))) (defun read-color (&optional prompt convert-to-RGB allow-empty-name msg - foreground) + foreground face) "Read a color name or RGB triplet. Completion is available for color names, but not for RGB triplets. @@ -2016,17 +2028,23 @@ read-color Interactively, or with optional arg MSG non-nil, print the 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." +Interactively, displays a list of colored completions. If +optional argument FOREGROUND is non-nil, shows them as +foregrounds, otherwise as backgrounds. The optional argument +FACE controls the default appearance." (interactive "i\np\ni\np") ; Always convert to RGB interactively. (let* ((completion-ignore-case t) - (colors (append '("foreground at point" "background at point") - (if allow-empty-name '("")) - (if (display-color-p) - (defined-colors-with-face-attributes - nil foreground) - (defined-colors)))) + (color-alist + `(("foreground at point" . ,(foreground-color-at-point)) + ("background at point" . ,(background-color-at-point)) + ,@(if allow-empty-name '(("" . unspecified))) + ,@(mapcar (lambda (c) (cons c c)) (defined-colors)))) + (colors (mapcar (lambda (pair) + (let* ((name (car pair)) + (color (cdr pair))) + (faces--string-with-color name color + foreground face))) + color-alist)) (color (completing-read (or prompt "Color (name or #RGB triplet): ") ;; Completing function for reading colors, accepting -- 2.39.2 --=-=-=--