From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Mauro Aranda Newsgroups: gmane.emacs.bugs Subject: bug#45829: 28.0.50; Some tweaks to the color widget, from wid-edit+.el Date: Tue, 12 Jan 2021 19:23:03 -0300 Message-ID: <5ffe2149.1c69fb81.b9bf6.0d1d@mx.google.com> References: <5ffe1f20.1c69fb81.77469.0e30@mx.google.com> 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="35337"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) To: 45829@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Jan 12 23:24:11 2021 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 1kzS5D-00094W-5i for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 12 Jan 2021 23:24:11 +0100 Original-Received: from localhost ([::1]:54952 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kzS5B-0001AH-QD for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 12 Jan 2021 17:24:09 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58712) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzS54-0001A2-Lt for bug-gnu-emacs@gnu.org; Tue, 12 Jan 2021 17:24:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:50262) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kzS54-00036h-Ej for bug-gnu-emacs@gnu.org; Tue, 12 Jan 2021 17:24:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kzS54-0007Vi-At for bug-gnu-emacs@gnu.org; Tue, 12 Jan 2021 17:24:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Mauro Aranda Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 12 Jan 2021 22:24:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 45829 X-GNU-PR-Package: emacs Original-Received: via spool by 45829-submit@debbugs.gnu.org id=B45829.161049019728816 (code B ref 45829); Tue, 12 Jan 2021 22:24:02 +0000 Original-Received: (at 45829) by debbugs.gnu.org; 12 Jan 2021 22:23:17 +0000 Original-Received: from localhost ([127.0.0.1]:33575 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kzS4K-0007Ud-H3 for submit@debbugs.gnu.org; Tue, 12 Jan 2021 17:23:16 -0500 Original-Received: from mail-qk1-f172.google.com ([209.85.222.172]:34947) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kzS4G-0007UG-SE; Tue, 12 Jan 2021 17:23:14 -0500 Original-Received: by mail-qk1-f172.google.com with SMTP id n142so3455530qkn.2; Tue, 12 Jan 2021 14:23:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:from:to:cc:subject:references:date:in-reply-to :user-agent:mime-version; bh=O1WuzZarvD9eR5d3rB9GG123O7Xkw9OXKhl9yMwPki4=; b=NlAcLMFjFFfR/Y8rCEtAS4LcoiV/y8u5WOiQOZnaj8bFIdsoexgpDwndqHBnuDnVj6 Tjdg2dsql2pgusrzf3htT1swMWdpgi2+YB9zxqbyDvugzXHX/YZxWVfmq+uy6ZUesaum tpnpxrKbHF4nPQW5ZY7nit79dG41HvIDlQaNwB9v3lG3fVVD0oDr531KaAlu0CqDJ/cf rilquVLtiMdaLUQAIIfIylGoxds95D3+D2j34LaC/USzsM9Wr77l4cee68JSxpIktlst /9RvdJMo0w1WHgF6ZGYdnBK68qbwakWX3J3xXbbB3kh9gp8X39iNo6RC3+LRJdhXQnGg gEhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:from:to:cc:subject:references:date :in-reply-to:user-agent:mime-version; bh=O1WuzZarvD9eR5d3rB9GG123O7Xkw9OXKhl9yMwPki4=; b=uXPsZ/AygpU6pIuBYIHNNYmcX0I1ZLBr6HpZ/d8xZxRFSIvhYRe2+G+QJbeXAplxfw u5izcqSaS71R0csK7AXLXhylVoJD7NvAdiJy0Tf5IyBsR9w9Y0d8LE0jOjKoVtpaT92V eSFh0quZeKjJ3e6WTzgST7CATGNy4/7VqtBxGPq0hiQcMroNJXjiRVgH2IpTobs2fc5w a1MVtHZWsmQoTDVm4a8DJCLEKvuzkScXtqTeb9csmKXPYimWfRnLSn/pw04ItG9re7N0 DGPtoA6sze3zmFEPunlVwyKmw5CrPEEOwEEPahjs1YcY67aeonWyumAOGLugZDq8f9u+ BANQ== X-Gm-Message-State: AOAM531KqITC5lelbaQWdhiel+1aZRPOdA1NYAj0dfO1cdCS1ZVCMcuQ Ux2CpX/mXQb6QcR+TQQRfKmeYP7YDNc= X-Google-Smtp-Source: ABdhPJyXXPOzJ/la72Bm+73bB7wCdNYFf/OQQn5QSZfGJ6EvrFdmM5zBMJEb105DIP4ibEV5n+k8Ew== X-Received: by 2002:a37:642:: with SMTP id 63mr1823237qkg.123.1610490187010; Tue, 12 Jan 2021 14:23:07 -0800 (PST) Original-Received: from tbb-desktop ([201.213.132.172]) by smtp.gmail.com with ESMTPSA id c136sm118695qkg.71.2021.01.12.14.23.04 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 12 Jan 2021 14:23:05 -0800 (PST) X-Google-Original-Message-ID: <877dohx0ag.fsf@maurooaranda@gmail.com> In-Reply-To: <5ffe1f20.1c69fb81.77469.0e30@mx.google.com> (Mauro Aranda's message of "Tue, 12 Jan 2021 19:13:50 -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" Xref: news.gmane.io gmane.emacs.bugs:197866 Archived-At: --=-=-= Content-Type: text/plain tags 45829 patch quit (CCing Drew) I attach one patch with the changes, and one patch with a test for the new :match function. Opinions? --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Tweaks-to-the-color-widget-Bug-45829.patch Content-Description: Patch >From 8a3a2f8b92708175c62a3b4efd7eb00228c5011a Mon Sep 17 00:00:00 2001 From: Drew Adams Date: Tue, 12 Jan 2021 19:14:19 -0300 Subject: [PATCH] Tweaks to the color widget (Bug#45829) * lisp/wid-edit.el (widget-color-match, widget-color-validate): New functions. (color): Use the new functions. Base size on longest defined color name. --- lisp/wid-edit.el | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lisp/wid-edit.el b/lisp/wid-edit.el index 8b10d71dcb..19e58f5345 100644 --- a/lisp/wid-edit.el +++ b/lisp/wid-edit.el @@ -4024,17 +4024,18 @@ widget-boolean-prompt-value ;;; The `color' Widget. -;; Fixme: match (define-widget 'color 'editable-field "Choose a color name (with sample)." :format "%{%t%}: %v (%{sample%})\n" :value-create 'widget-color-value-create - :size 10 + :size (1+ (apply #'max (mapcar #'length (defined-colors)))) :tag "Color" :value "black" :completions (or facemenu-color-alist (defined-colors)) :sample-face-get 'widget-color-sample-face-get :notify 'widget-color-notify + :match #'widget-color-match + :validate #'widget-color-validate :action 'widget-color-action) (defun widget-color-value-create (widget) @@ -4083,6 +4084,19 @@ widget-color-notify (overlay-put (widget-get widget :sample-overlay) 'face (widget-apply widget :sample-face-get)) (widget-default-notify widget child event)) + +(defun widget-color-match (_widget value) + "Non-nil if VALUE is a defined color or a RGB hex string." + (and (stringp value) + (or (color-defined-p value) + (string-match-p "^#\\([[:xdigit:]]\\{3\\}\\)\\{1,4\\}$" value)))) + +(defun widget-color-validate (widget) + "Check that WIDGET's value is a valid color." + (let ((value (widget-value widget))) + (unless (widget-color-match widget value) + (widget-put widget :error (format "Invalid color: %S" value)) + widget))) ;;; The Help Echo -- 2.29.2 --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Add-test-for-the-widget-color-match-function-Bug-458.patch Content-Description: Test >From 5d6bc24b3b16307361d6411e1b4f1e3735664125 Mon Sep 17 00:00:00 2001 From: Mauro Aranda Date: Tue, 12 Jan 2021 19:19:21 -0300 Subject: [PATCH] Add test for the widget-color-match function (Bug#45829) * test/lisp/wid-edit-tests.el (widget-test-color-match): New test. --- test/lisp/wid-edit-tests.el | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/lisp/wid-edit-tests.el b/test/lisp/wid-edit-tests.el index 17fdfefce8..c410b8e367 100644 --- a/test/lisp/wid-edit-tests.el +++ b/test/lisp/wid-edit-tests.el @@ -322,4 +322,15 @@ widget-test-widget-move (widget-backward 1) (should (string= "Second" (widget-value (widget-at)))))) +(ert-deftest widget-test-color-match () + "Test that the :match function for the color widget works." + (let* ((widget (widget-convert 'color))) + (should (widget-apply widget :match "red")) + (should (widget-apply widget :match "#fa3")) + (should (widget-apply widget :match "#ff0000")) + (should (widget-apply widget :match "#111222333")) + (should (widget-apply widget :match "#111122223333")) + (should-not (widget-apply widget :match "someundefinedcolorihope")) + (should-not (widget-apply widget :match "#11223")))) + ;;; wid-edit-tests.el ends here -- 2.29.2 --=-=-=--