help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Need for colorful completing read


From: Jean Louis
Subject: Re: Need for colorful completing read
Date: Sun, 11 Sep 2022 09:26:37 +0300
User-agent: Mutt/+ () (2022-06-11)

* 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 via email to

[Prev in Thread] Current Thread [Next in Thread]