all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Jean Louis <bugs@gnu.support>
To: Akib Azmain Turja <akib@disroot.org>
Cc: Help GNU Emacs <help-gnu-emacs@gnu.org>
Subject: Re: Need for colorful completing read
Date: Sun, 11 Sep 2022 09:26:37 +0300	[thread overview]
Message-ID: <Yx1/neZW76NFCk6p@protected.localdomain> (raw)
In-Reply-To: <87sfl5w0rn.fsf@disroot.org>

* Akib Azmain Turja <akib@disroot.org> [2022-09-06 08:11]:
> Jean Louis <bugs@gnu.support> writes:
> 
> > Hello,
> >
> > I would like to make a function similar to `completing-read' for the
> > choice of colors as shown by {M-x list-colors-display RET} so that I
> > can choose or select a color and that I can see the color while
> > selecting it.
> >
> > Is that possible or maybe already exists somewhere?
> 
> It should be possible.  Marginalia shows faces (on *Completion* buffer,
> or Vertico, or Selectrum) when you call describe-face.  So, you should
> also be able to show the colors by show spaces with both background set
> to the color you want to show.  May be you can use Marginalia to do
> this.  See Marginalia README, C-h P marginalia RET (make sure you loaded
> the package list with M-x package-show-package-list).

First I have entered all Emacs colors' names into the PostgreSQL
database by using emacs-libpq module:

(defun x-colors-to-db ()
  (let ((colors (sort x-colors 'string<)))
    (while colors
      (rcd-sql "INSERT INTO emacscolors (emacscolors_name) VALUES ($1)" cf-db (pop colors)))))

More about the module:

emacs-libpq @ Github:
https://github.com/anse1/emacs-libpq

Then I have some settings to find which table columns need to be
replaced with Emacs colors:

(defvar columns-to-read-color '(
				"hyobjectypes_emacsforegroundcolor"
				"hyobjectypes_emacsbackgroundcolor"
				)
  "Columns to read Emacs color.")

Then I have some conditional to recognize if value is asked for
specific column, so that it is replaced with `read-color':

    (let ((new-value (cond ((member column columns-to-choose-contact)
			    (let* ((query (rcd-ask cf-people-prompt))
				   (id (cf-people-search-id query)))
			      id))
			   ((member column columns-to-read-color)
			    (rcd-db-read-color-for-column value))

And then finally the function that verifies that color exists in the
database and choses color in colorful way.

(defun rcd-db-read-color-for-column (&optional value)
  "Return color ID with optional default VALUE."
  (let* ((color-chosen (read-color))
	 (value (if value (rcd-db-get-entry "emacscolors" "emacscolors_name" value cf-db)))
	 (color-chosen (if (seq-empty-p color-chosen) value color-chosen))
	 (color-name (rcd-db-get-entry-where "emacscolors" "emacscolors_name"
					     (format "emacscolors_name = '%s'" color-chosen) cf-db)))
    (if (and color-name
	       (string= color-name color-chosen))
	(let ((color-id (rcd-db-get-entry-where "emacscolors" "emacscolors_id"
						(format "emacscolors_name = '%s'" color-chosen) cf-db)))
	  color-id))))

One can see how it works here on video:
https://gnu.support/images/2022/09/2022-09-11/2022-09-11-09:23:09.ogv


-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



      reply	other threads:[~2022-09-11  6:26 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-05 20:48 Need for colorful completing read Jean Louis
2022-09-05 20:51 ` Lars Ingebrigtsen
2022-09-05 21:07   ` Jean Louis
2022-09-06  4:11     ` Emanuel Berg
2022-09-06 10:02     ` Lars Ingebrigtsen
2022-09-06 10:20       ` Jean Louis
2022-09-06  5:06   ` Akib Azmain Turja
2022-09-06  8:59   ` Philip Kaludercic
2022-09-06 10:03     ` Lars Ingebrigtsen
2022-09-06 10:11       ` Philip Kaludercic
2022-09-06 10:27         ` Lars Ingebrigtsen
2022-09-06 16:50           ` Yuri Khan
2022-09-06 17:38             ` Philip Kaludercic
2022-09-06  5:05 ` Akib Azmain Turja
2022-09-11  6:26   ` Jean Louis [this message]

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=Yx1/neZW76NFCk6p@protected.localdomain \
    --to=bugs@gnu.support \
    --cc=akib@disroot.org \
    --cc=help-gnu-emacs@gnu.org \
    /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.