From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jean Louis Newsgroups: gmane.emacs.help Subject: Re: Need for colorful completing read Date: Sun, 11 Sep 2022 09:26:37 +0300 Message-ID: References: <87sfl5w0rn.fsf@disroot.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="8779"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/+ () (2022-06-11) Cc: Help GNU Emacs To: Akib Azmain Turja Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sun Sep 11 08:33:12 2022 Return-path: Envelope-to: geh-help-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 1oXGWl-00021A-P5 for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 11 Sep 2022 08:33:11 +0200 Original-Received: from localhost ([::1]:36896 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oXGWk-0003QX-1n for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 11 Sep 2022 02:33:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44336) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oXGVk-0003Pm-EW for help-gnu-emacs@gnu.org; Sun, 11 Sep 2022 02:32:10 -0400 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:51995) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oXGVi-0005Te-EQ for help-gnu-emacs@gnu.org; Sun, 11 Sep 2022 02:32:08 -0400 Original-Received: from localhost ([::ffff:197.239.4.199]) (AUTH: PLAIN admin, TLS: TLS1.3,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 00000000000B5AB6.00000000631D80E1.00007E99; Sat, 10 Sep 2022 23:32:01 -0700 Mail-Followup-To: Akib Azmain Turja , Help GNU Emacs Content-Disposition: inline In-Reply-To: <87sfl5w0rn.fsf@disroot.org> Received-SPF: pass client-ip=217.170.207.13; envelope-from=bugs@gnu.support; helo=stw1.rcdrun.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_SBL=0.141, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:139356 Archived-At: * Akib Azmain Turja [2022-09-06 08:11]: > Jean Louis 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/