From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "J.P." Newsgroups: gmane.emacs.bugs Subject: bug#63569: 30.0.50; ERC 5.6: Add automatic nickname highlighting to ERC Date: Thu, 07 Sep 2023 06:31:56 -0700 Message-ID: <87zg1yjeib.fsf__3242.8821710468$1694093605$gmane$org@neverwas.me> References: <87ilcp1za1.fsf@neverwas.me> 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="27684"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: emacs-erc@gnu.org To: 63569@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Sep 07 15:33:18 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 1qeF8H-0006uT-6X for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 07 Sep 2023 15:33:17 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qeF89-00007B-Q8; Thu, 07 Sep 2023 09:33:09 -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 1qeF80-000060-Gm for bug-gnu-emacs@gnu.org; Thu, 07 Sep 2023 09:33: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 1qeF80-0001xB-5G for bug-gnu-emacs@gnu.org; Thu, 07 Sep 2023 09:33:00 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qeF81-00077U-P9 for bug-gnu-emacs@gnu.org; Thu, 07 Sep 2023 09:33:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: "J.P." Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 07 Sep 2023 13:33:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63569 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 63569-submit@debbugs.gnu.org id=B63569.169409353127314 (code B ref 63569); Thu, 07 Sep 2023 13:33:01 +0000 Original-Received: (at 63569) by debbugs.gnu.org; 7 Sep 2023 13:32:11 +0000 Original-Received: from localhost ([127.0.0.1]:38888 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qeF7C-00076T-HR for submit@debbugs.gnu.org; Thu, 07 Sep 2023 09:32:11 -0400 Original-Received: from mail-108-mta111.mxroute.com ([136.175.108.111]:45749) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qeF7A-00076H-F2 for 63569@debbugs.gnu.org; Thu, 07 Sep 2023 09:32:09 -0400 Original-Received: from mail-111-mta2.mxroute.com ([136.175.111.2] filter006.mxroute.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta111.mxroute.com (ZoneMTA) with ESMTPSA id 18a6fd7ab37000d7b6.001 for <63569@debbugs.gnu.org> (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Thu, 07 Sep 2023 13:31:59 +0000 X-Zone-Loop: 5eb8b7272db17da9adf8d53236b3ec1e1c9431c51adf X-Originating-IP: [136.175.111.2] DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=neverwas.me ; s=x; h=Content-Type:MIME-Version:Message-ID:Date:References:In-Reply-To: Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=tEInpdGdRE+Gyhapg9DvMALAlxptY+pOp9Y8t/LSaZA=; b=X2J7gwTqSqz0AYde9gL6lcQcwA kTY4/eHqOM9/zd80tCxeN+7ugueyW7Mube6Cm1K8W60heCms5fxtZlvtkk/7gke+6n1y9f+nhj5mk 5x0UaWmkm2AwtubF5kd+SlL+hc1C5Mwt8lbCWDE0W+RuWyhnIfxiom4JdrlKdH/db2adtZ9sy8MWP vog1EnMNc1sT1SLbnr5xzLnyY9BttBQqsqdPsVvfhYC9t9duSuTLeNik9HuwDGBp9Q08hdyCihBHf AzoaXhgH2EonAEbW/iai3aHGIyat17UzMCndRjjbD7ApDkToCYr8Aq+O8AbOkADOfbmj4oSb7SOWp jI34rHUQ==; In-Reply-To: <87ilcp1za1.fsf@neverwas.me> (J. P.'s message of "Thu, 18 May 2023 07:37:26 -0700") X-Authenticated-Id: masked@neverwas.me 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:269654 Archived-At: --=-=-= Content-Type: text/plain Currently, users on a non-graphical, non 24-bit Emacs who provide their own `erc-nicks-colors' pool must ensure those colors fall within `erc-nicks-contrast-range' and `erc-nicks-saturation-range' (assuming a non-nil `erc-nicks-color-adjustments', the default). Otherwise, their pool is subject to culling without warning on module init, which they may find frustrating even though this behavior is documented. If people believe this to be a grave enough annoyance, we can do something like the attached, which offers a couple alternate pool-prep approaches that "pre-treat" candidates with `erc-nicks-color-adjustments' and coerce them to predefined system palette members, thus effectively culling by way of deduping. If actually doing this, we'd likely have to add a public-facing knob for selecting between various fixed-pool filtering styles, such as: - cull (current) - treat, coerce, and cull - treat and coerce The latter two differ in that the first rechecks if the remapped "defined" value still falls within specified tolerances, and drops it if it doesn't, while the last approach turns a blind eye. IMO, the first is of limited value unless we were to make it try repeatedly to find a satisfactory match. Although these only run on init, folks may find them too sluggish (both are already quadratic). We could instead make them interactive commands (or `custom-set' functions) that users can use to populate `erc-nicks-colors' while configuring. Personally, I'm not affected by the current behavior because I use graphical Emacs or a 24-bit terminal emulator with ERC. However, I'm open to doing this if others think it worthwhile. Thanks. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-POC-Offer-alternate-pool-creation-strategies-in-erc-.patch >From ef97b82a7d38e4a61a54cfb7be7444bc8293261b Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Sun, 3 Sep 2023 16:05:59 -0700 Subject: [PATCH] [POC] Offer alternate pool-creation strategies in erc-nicks (erc-nicks--create-pool-function): New function-valued variable to allow for changing fixed-pool creation strategy. (erc-nicks--create-adjusted-pool, erc-nicks--create-coerced-pool): New functions for filtering user-provided `erc-nicks-color' values. (erc-nicks--init-pool): Call `erc-nicks--create-pool-function'. (erc-nicks-refresh): Provide helpful user error instead of letting `arith-error' propagate due to an empty pool. (Bug#63569) --- lisp/erc/erc-nicks.el | 63 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/lisp/erc/erc-nicks.el b/lisp/erc/erc-nicks.el index a7d0b0769f2..3e5bf2b8d3f 100644 --- a/lisp/erc/erc-nicks.el +++ b/lisp/erc/erc-nicks.el @@ -356,6 +356,64 @@ erc-nicks--reduce erc-nicks-color-adjustments (if (stringp color) (color-name-to-rgb color) color)))) +(defvar erc-nicks--create-pool-function #'erc-nicks--create-adjusted-pool) + +(defun erc-nicks--create-adjusted-pool (adjustments colors) + "Return COLORS that fall within parameters indicated by ADJUSTMENTS. +Apply adjustments before replacing COLORS with the nearest +defined, and then cull those that still don't meet the grade. +Expect to operate on user-provided lists of `erc-nicks-colors' +rather than all those `defined' by the system." + (let* ((seen (make-hash-table :test #'equal)) + (valmax (float (car (color-values "#ffffffffffff")))) + (erc-nicks-color-adjustments adjustments) + addp capp satp pool) + (dolist (adjustment adjustments) + (pcase adjustment + ((or 'erc-nicks-invert 'erc-nicks-add-contrast) (setq addp t)) + ('erc-nicks-cap-contrast (setq capp t)) + ('erc-nicks-ensaturate (setq satp t)))) + (dolist (color colors) + (pcase-let ((`(,quantized ,_ . ,vals) + (tty-color-approximate (color-values + (erc-nicks--reduce color))))) + (if (gethash quantized seen) + (when erc-nicks--colors-rejects + (push color erc-nicks--colors-rejects)) + (let* ((rgb (mapcar (lambda (x) (/ x valmax)) vals)) + (contrast (and (or addp capp) (erc-nicks--get-contrast rgb)))) + (if (or (and addp (< contrast (car erc-nicks-contrast-range))) + (and capp (> contrast (cdr erc-nicks-contrast-range))) + (and-let* ((satp) + (s (cadr (apply #'color-rgb-to-hsl rgb)))) + (or (< s (car erc-nicks-saturation-range)) + (> s (cdr erc-nicks-saturation-range))))) + (when erc-nicks--colors-rejects + (push color erc-nicks--colors-rejects)) + (push quantized pool) + (puthash quantized color seen)))))) + (nreverse pool))) + +(defun erc-nicks--create-coerced-pool (adjustments colors) + "Return COLORS that fall within parameters indicated by ADJUSTMENTS. +Rather than culling, apply adjustments and then dedupe after +first replacing adjusted values with the nearest defined. Unlike +`erc-nicks--create-adjusted-pool', don't recheck after adjusting. +Rather, tolerate values that may fall slightly outside desired +parameters, thus yielding a larger pool." + (let* ((seen (make-hash-table :test #'equal)) + (erc-nicks-color-adjustments adjustments) + pool) + (dolist (color colors) + (let ((quantized (car (tty-color-approximate + (color-values (erc-nicks--reduce color)))))) + (if (gethash quantized seen) + (when erc-nicks--colors-rejects + (push color erc-nicks--colors-rejects)) + (push quantized pool) + (puthash quantized color seen)))) + (nreverse pool))) + (defun erc-nicks--create-pool (adjustments colors) "Return COLORS that fall within parameters indicated by ADJUSTMENTS." (let (addp capp satp pool) @@ -383,7 +441,8 @@ erc-nicks--init-pool (unless (eq erc-nicks-colors 'all) (let* ((colors (or (and (listp erc-nicks-colors) erc-nicks-colors) (defined-colors))) - (pool (erc-nicks--create-pool erc-nicks-color-adjustments colors))) + (pool (funcall erc-nicks--create-pool-function + erc-nicks-color-adjustments colors))) (setq erc-nicks--colors-pool pool erc-nicks--colors-len (length pool))))) @@ -608,6 +667,8 @@ erc-nicks-refresh (unless erc-nicks-mode (user-error "Module `nicks' disabled")) (let ((erc-nicks--colors-rejects (and debug (list t)))) (erc-nicks--init-pool) + (unless erc-nicks--colors-pool + (user-error "Pool empty: all colors rejected")) (dolist (nick (hash-table-keys erc-nicks--face-table)) ;; User-tuned faces do not have an `erc-nicks--key' property. (when-let ((face (gethash nick erc-nicks--face-table)) -- 2.41.0 --=-=-=--