From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stephen Berman Newsgroups: gmane.emacs.help Subject: Re: Colourising a label prints it twice Date: Sat, 13 Jul 2024 11:05:41 +0200 Message-ID: <871q3xoe56.fsf@gmx.net> References: <9FKix1_o0tnNLD3LMcQjhmz2KX2var0yZf5XFlYEvDDFfYB0AeoC31QwudqoIO7fOYi4ptnzpD8CJmUeDsFrGT4ucd3dDTURevzt4ip2uUE=@protonmail.com> <878qy6fazg.fsf@gmx.net> Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4756"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Heime via Users list for the GNU Emacs text editor To: Heime Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jul 13 11:06:43 2024 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 1sSYiJ-00012N-4Y for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 13 Jul 2024 11:06:43 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSYhW-0000Z9-Ed; Sat, 13 Jul 2024 05:05:54 -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 1sSYhU-0000Yk-8Q for help-gnu-emacs@gnu.org; Sat, 13 Jul 2024 05:05:52 -0400 Original-Received: from mout.gmx.net ([212.227.15.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sSYhO-0002eU-R2 for help-gnu-emacs@gnu.org; Sat, 13 Jul 2024 05:05:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1720861542; x=1721466342; i=stephen.berman@gmx.net; bh=NR/iHMIFVQdJd5CWaZfUUut0TV+PYAZnk/3DiOo2Q9g=; h=X-UI-Sender-Class:From:To:Cc:Subject:In-Reply-To:References:Date: Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=TUVzafVaNU1Ny3W1ztCJbC1pAt/lesonkFs3/wnpYQz4VMLej5kjernprmWMGdUq orBN7TSgDKWMBxNNFkMzuLpqHSJwyjJQqCy20O1ncApTWyZU7FbENxFmduZAwzT9G GzQwx1AaXGR6olyI4yXcEOtU+wFuoEvQ5P2j0EHKwFme1EhPERjBkGaWubl4mgvO/ jH74h1qcsOVf3o4xPrhccmrIax7eVMHaIyKCW/Ddpm8xtRMLbGCxlBp+tghmq48Nk Am1oxuG0njoJnw9mZMyv1jyRGuUG0fm9AJz2RsW1zjV6Rg+de8/7Vujt1LNpACZp9 LkNJYB8r5XsY0FhAcQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Original-Received: from strobelfs ([88.130.49.191]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1M2wGs-1sVs5K0yXU-00CZAH; Sat, 13 Jul 2024 11:05:42 +0200 In-Reply-To: (Heime's message of "Fri, 12 Jul 2024 23:55:49 +0000") X-Provags-ID: V03:K1:u+b1IyXp8HkftulVsd3+9FB+3lfX50ZQhC5quQueHo9jxxOlXGU SCvpIudkMAdhV4BduoyleNjox+VaHh0j790oJncBk9SWjCVBjH8aBttByvXpnyYq1utAMkE DHT4fFDbAt+87qyG6La01c+7zhhpCgjLIiOcBHW9GcQD1qLNP39wGxt1OlOMyfBX6Ch6u0n xlmIe4VpZg+RrDGXRupDg== UI-OutboundReport: notjunk:1;M01:P0:4ipPkqX1554=;zfJ7gp6U1y7LqBu3AcWFy5FApmp IEVB+Q8+EM6s4gdiF3gRDMQQSxdmOcPDStMofOz1aRwIS4Ogje7BhnDtTff6IJIwd/9qPAZHB FfxFZoHIHNKq6btCV+AFhl8TfYy7lg1wIQVaEnNt6jRJKj7WXdu95q2+TQYdhHnSVSMkv/fxU BQQtwkhzVBSfiyPrbqRmmkgnomSseoVtAnp9vVOQJsOuzemvzRnmanphojXakQ7dQ9UvNQqJt N6Gbrw7CB9Am774cdgLbJXiCE8TRJ+4yYeQCEepOBKREBOj1luc+KBuDalT65a87RUmCASxlf We3i+27yLFLl8hvhwfJBPDEhUGNBtoOBkMYCQ0HTIVoxVFO8K1Q4DD4jmrEaQOiOM4nIx0Icj +7/bgOeDWs6xDYgAH5LfKqwEXc4u6BgJMV2EEqyS4r5XcKB/BsDFJBHuIqkKpTuwPLd9Aejp9 oj+KdfHfCQMazw5AWe2sF50z8lavtAuVbyX/AymAZh2ChGgIGOjZVEy3XjBnz2QcvFNk26jRP QB2dkneU/h3XqPMBx5WQo+WiGWEGgNTLcnvXT+rc3LM01N7JxLKYtfvUQsahiNih5S2d8o/q1 4F3pkkckAjNGuGLNJYJYZiOXHh3P4IiXyohoqUZVtBHCxA+YwnF8AeOfIo2HIeMpWJyn+sv3W F4K58j/XMrlojI6VoVSNuuqLRhOWUGhPV11KH/UtSSpGpbO3+7a/DjuQejxMPgfCGr6RMMICz n4hgtVmXFaaTplhNukp1lEshOkShQovOPaFneBaDge/820vxXWQz/a/GnIqM52k0F6eNtUyv Received-SPF: pass client-ip=212.227.15.18; envelope-from=stephen.berman@gmx.net; helo=mout.gmx.net X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:147192 Archived-At: On Fri, 12 Jul 2024 23:55:49 +0000 Heime wrot= e: > On Saturday, July 13th, 2024 at 11:26 AM, Stephen Berman > wrote: > >> On Fri, 12 Jul 2024 23:09:28 +0000 Heime heimeborgia@protonmail.com wro= te: >> >> > I have the following function to colourise the label, but I get OFF >> > printed twice. >> > >> > (defun label-select (label) >> > "Color the part of LABEL after [-]." >> > >> > (if (string-match "\\[\\-\\] \\(.*\\)" label) >> > >> > (let ( (bt (match-string 0 label)) >> > (lb (match-string 1 label)) ) >> > (concat bt (propertize lb 'face '(:foreground "red")))) >> > >> > label)) >> > >> > (insert (format " %s \n" (label-select "[-] OFF "))) >> > (insert (format " %s \n" (label-select "[-] OFF "))) >> > (insert (format " %s \n" (label-select " [-] OFF "))) >> >> >> `bt' is the entire string passed by LABEL, but IIUC it should just be >> the string "[-] ", so put that in a group: >> >> (defun label-select (label) >> "Color the part of LABEL after [-]." >> >> (if (string-match "\\(\\[\\-\\] \\)\\(.*\\)" label) >> >> (let ( (bt (match-string 1 label)) >> (lb (match-string 2 label)) ) >> (concat bt (propertize lb 'face '(:foreground "red")))) >> >> label)) >> >> Steve Berman > > Regarding grouping, I want to replicate the original string with respect > to any whitespaces. Does the grouping outline respect the original whit= espace ? The regexp I used is fairly specific to the examples you gave (though I overlooked that your third example has a space before "[-]"); to allow arbitrary whitespace in the first group before and after "[-]" you can use "\\s-*": (defun label-select (label) "Color the part of LABEL after [-]." (if (string-match "\\(\\s-*\\[\\-\\]\\s-*\\)\\(.*\\)" label) (let ( (bt (match-string 1 label)) (lb (match-string 2 label)) ) (concat bt (propertize lb 'face '(:foreground "red")))) label)) Steve Berman