From unknown Wed Jun 18 23:11:33 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#32365 <32365@debbugs.gnu.org> To: bug#32365 <32365@debbugs.gnu.org> Subject: Status: Interactive Highlighting: prefix arg as subexp selector Reply-To: bug#32365 <32365@debbugs.gnu.org> Date: Thu, 19 Jun 2025 06:11:33 +0000 retitle 32365 Interactive Highlighting: prefix arg as subexp selector reassign 32365 emacs submitter 32365 Gr=C3=A9gory Mouni=C3=A9 severity 32365 wishlist tag 32365 fixed patch thanks From debbugs-submit-bounces@debbugs.gnu.org Fri Aug 03 17:51:07 2018 Received: (at submit) by debbugs.gnu.org; 3 Aug 2018 21:51:07 +0000 Received: from localhost ([127.0.0.1]:40250 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1flhyU-0005ix-Un for submit@debbugs.gnu.org; Fri, 03 Aug 2018 17:51:07 -0400 Received: from eggs.gnu.org ([208.118.235.92]:50699) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1flhyR-0005iP-UE for submit@debbugs.gnu.org; Fri, 03 Aug 2018 17:51:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1flhyL-0000aM-Fh for submit@debbugs.gnu.org; Fri, 03 Aug 2018 17:50:58 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50 autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:49819) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1flhyL-0000a7-9c for submit@debbugs.gnu.org; Fri, 03 Aug 2018 17:50:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41653) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1flhyJ-0005dn-IS for bug-gnu-emacs@gnu.org; Fri, 03 Aug 2018 17:50:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1flhyF-0000Vg-Jg for bug-gnu-emacs@gnu.org; Fri, 03 Aug 2018 17:50:55 -0400 Received: from zm-mta-out-1.u-ga.fr ([152.77.200.56]:56805) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1flhyF-0000U7-3k for bug-gnu-emacs@gnu.org; Fri, 03 Aug 2018 17:50:51 -0400 Received: from zm-mta-out.u-ga.fr (zm-mta-out.u-ga.fr [152.77.200.58]) by zm-mta-out-1.u-ga.fr (Postfix) with ESMTP id 090F3A0288 for ; Fri, 3 Aug 2018 23:50:49 +0200 (CEST) Received: from smtps.univ-grenoble-alpes.fr (smtps.univ-grenoble-alpes.fr [195.83.24.202]) by zm-mta-out.u-ga.fr (Postfix) with ESMTP id 057F7E008E for ; Fri, 3 Aug 2018 23:50:49 +0200 (CEST) Received: from [192.168.1.17] (mut38-1-82-67-65-81.fbx.proxad.net [82.67.65.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: mounieg@univ-grenoble-alpes.fr) by smtps.univ-grenoble-alpes.fr (Postfix) with ESMTPSA id C3AA460448 for ; Fri, 3 Aug 2018 23:50:48 +0200 (CEST) To: bug-gnu-emacs@gnu.org From: =?UTF-8?Q?Gr=c3=a9gory_Mouni=c3=a9?= Subject: Interactive Highlighting: prefix arg as subexp selector Message-ID: <9fecb36d-cd58-0a70-ac84-ddaa8edb5030@imag.fr> Date: Fri, 3 Aug 2018 23:50:47 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------7AB7ACAD71569A5EEC594391" Content-Language: en-US X-Greylist: Whitelist-UGA SMTP Authentifie (mounieg@univ-grenoble-alpes.fr) via submission-587 ACL (99) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.4 (----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.4 (-----) This is a multi-part message in MIME format. --------------7AB7ACAD71569A5EEC594391 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Dear Maintainers, I propose to use the prefix argument in Interactive Highlighting. (the interactive function highlight-regexp) Without prefix all should stay identical. The numeric argument give the subexpression number of the regexp that=20 is highlighted by font_lock or overlay. This allows to highlight - the 80th char of every line C-u 1 M-s h r and regexp ^.\{79\}\(.\) - the 6th column of a clean CSV file C-u 1 M-s h r and regexp=20 ^\(?:[^,]*,\)\{5\}\([^,]*\), (clean CSV =3D=3D with enough coma as you get multi-line matching with= =20 this regexp) I am not fluent with interactive stuff. I am not sure either how to treat errors. Have a nice day. Gr=C3=A9gory Mouni=C3=A9 PS: Sorry for generating noise with my previous patch (BUG: 32362) --------------7AB7ACAD71569A5EEC594391 Content-Type: text/x-patch; name="0001-Interactive-Highlighting-prefix-argument-to-select-s.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-Interactive-Highlighting-prefix-argument-to-select-s.pa"; filename*1="tch" >From 6b6291ce1974a363080f535b40f06d5772ffa1be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Mouni=C3=A9?= Date: Fri, 3 Aug 2018 23:08:10 +0200 Subject: [PATCH] Interactive Highlighting: prefix argument to select subexp Use prefix-argument to highlight only the corresponding subexpression of the regexp. * lisp/hi-lock.el (hi-lock-face-buffer, hi-lock-set-pattern) Copyright-paperwork-exempt: yes --- lisp/hi-lock.el | 67 ++++++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/lisp/hi-lock.el b/lisp/hi-lock.el index 13ebffb1af..b0b4a19c6c 100644 --- a/lisp/hi-lock.el +++ b/lisp/hi-lock.el @@ -429,7 +429,7 @@ hi-lock-line-face-buffer ;;;###autoload (defalias 'highlight-regexp 'hi-lock-face-buffer) ;;;###autoload -(defun hi-lock-face-buffer (regexp &optional face) +(defun hi-lock-face-buffer (regexp &optional face subexp) "Set face of each match of REGEXP to FACE. Interactively, prompt for REGEXP using `read-regexp', then FACE. Use the global history list for FACE. @@ -441,10 +441,11 @@ hi-lock-face-buffer (list (hi-lock-regexp-okay (read-regexp "Regexp to highlight" 'regexp-history-last)) - (hi-lock-read-face-name))) + (hi-lock-read-face-name) + current-prefix-arg)) (or (facep face) (setq face 'hi-yellow)) (unless hi-lock-mode (hi-lock-mode 1)) - (hi-lock-set-pattern regexp face)) + (hi-lock-set-pattern regexp face subexp)) ;;;###autoload (defalias 'highlight-phrase 'hi-lock-face-phrase-buffer) @@ -686,39 +687,41 @@ hi-lock-read-face-name (add-to-list 'hi-lock-face-defaults face t)) (intern face))) -(defun hi-lock-set-pattern (regexp face) +(defun hi-lock-set-pattern (regexp face &optional arg) "Highlight REGEXP with face FACE." ;; Hashcons the regexp, so it can be passed to remove-overlays later. (setq regexp (hi-lock--hashcons regexp)) - (let ((pattern (list regexp (list 0 (list 'quote face) 'prepend))) - (no-matches t)) - ;; Refuse to highlight a text that is already highlighted. - (if (assoc regexp hi-lock-interactive-patterns) - (add-to-list 'hi-lock--unused-faces (face-name face)) - (push pattern hi-lock-interactive-patterns) - (if (and font-lock-mode (font-lock-specified-p major-mode)) - (progn - (font-lock-add-keywords nil (list pattern) t) - (font-lock-flush)) - (let* ((range-min (- (point) (/ hi-lock-highlight-range 2))) - (range-max (+ (point) (/ hi-lock-highlight-range 2))) - (search-start - (max (point-min) - (- range-min (max 0 (- range-max (point-max)))))) - (search-end - (min (point-max) - (+ range-max (max 0 (- (point-min) range-min)))))) - (save-excursion - (goto-char search-start) - (while (re-search-forward regexp search-end t) - (when no-matches (setq no-matches nil)) - (let ((overlay (make-overlay (match-beginning 0) (match-end 0)))) - (overlay-put overlay 'hi-lock-overlay t) - (overlay-put overlay 'hi-lock-overlay-regexp regexp) + (let* ((subexp (if (null arg) 0 arg)) + (pattern (list regexp (list subexp (list 'quote face) 'prepend))) + (no-matches t)) + ;; Refuse to highlight a text that is already highlighted. + (if (assoc regexp hi-lock-interactive-patterns) + (add-to-list 'hi-lock--unused-faces (face-name face)) + (push pattern hi-lock-interactive-patterns) + (if (and font-lock-mode (font-lock-specified-p major-mode)) + (progn + (font-lock-add-keywords nil (list pattern) t) + (font-lock-flush)) + (let* ((range-min (- (point) (/ hi-lock-highlight-range 2))) + (range-max (+ (point) (/ hi-lock-highlight-range 2))) + (search-start + (max (point-min) + (- range-min (max 0 (- range-max (point-max)))))) + (search-end + (min (point-max) + (+ range-max (max 0 (- (point-min) range-min)))))) + (save-excursion + (goto-char search-start) + (while (re-search-forward regexp search-end t) + (when no-matches (setq no-matches nil)) + (let ((overlay (make-overlay (match-beginning subexp) + (match-end subexp)))) + (overlay-put overlay 'hi-lock-overlay t) + (overlay-put overlay 'hi-lock-orverlay-regexp regexp) (overlay-put overlay 'face face)) - (goto-char (match-end 0))) - (when no-matches - (add-to-list 'hi-lock--unused-faces (face-name face)) + (goto-char (match-end 0))) + (when no-matches + (add-to-list 'hi-lock--unused-faces (face-name face)) (setq hi-lock-interactive-patterns (cdr hi-lock-interactive-patterns))))))))) -- 2.18.0 --------------7AB7ACAD71569A5EEC594391-- From debbugs-submit-bounces@debbugs.gnu.org Sun Aug 05 23:07:56 2018 Received: (at 32365) by debbugs.gnu.org; 6 Aug 2018 03:07:56 +0000 Received: from localhost ([127.0.0.1]:42183 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fmVsC-0001KX-Bx for submit@debbugs.gnu.org; Sun, 05 Aug 2018 23:07:56 -0400 Received: from mail-io0-f176.google.com ([209.85.223.176]:42119) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fmVs9-0001KE-Vi; Sun, 05 Aug 2018 23:07:54 -0400 Received: by mail-io0-f176.google.com with SMTP id n18-v6so252538ioa.9; Sun, 05 Aug 2018 20:07:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-transfer-encoding; bh=4VSxqEKRbmcOJcziOz+A2jrpFtkp/rnYUJ6kiND+PXs=; b=Fe5ynoD23CiLMOqRgEPUopchKl1R6rZgu/QKOgni2I2c6dSlHGCUyA416WbYEwC+Yx 29Zodt9qvyg1iKGNd4+PTrgvWQ1VgG0uCAiRlWxKBtQelyLdZa7xHSGIeBGoNE8Hko/6 l6cso3vrd0Fh14WoZxgNForaG7/dEXiV0xtGllwvHrN0TcjphlslUMKJRSREgu4iPEni MyzESP1Kn1+KpjA29HbFyAM4QoRdj643jCl7zMO0ixgJbWBJrAmiCQhF/I6AfJnHqdaS VwYq3sW/4wuBYTXO2Cnl5NW665QdCCXem7ZZSlwmAYnbuc2juOgZ4EmvHduOz9Hn+9WM rTuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=4VSxqEKRbmcOJcziOz+A2jrpFtkp/rnYUJ6kiND+PXs=; b=K4AxzL4+yt/+xtLbmKUuVwDI+JMaPrb/iA1moxeXx/2C6dXkkeEHBKTguHJ5f/Sfea 24qOZfNeOPqn/InlxaWGgSD9UZePMgz49cIKIJsQ6uJNNzaeZyDUcyagidFtunM4WILY kGxk5p7J2jIHd3u4RdG5N/uTjNX2TZFDtoLCgKsK/EsZZ5wneOwDwkr2reTsVZgy0g/4 DKmOCfEFfzQXaY7mR79Xe8yeb+gH4TAEtarSQ9NmTnNK+hZknZIQKemDu4ZCmBBKBmAA YDuJ/JMSBHPF4e1vnoAFS/DUhJ5RO2TuHvETFjOxU6mWf1wi39vHvn8tb14eu6qGkcpi 6QGw== X-Gm-Message-State: AOUpUlH9SchDWKQTlx1BEepJGtCJaD8fW346aGXg+LUYsAZjoDgdF9tk fbWlUeWkT52eRrWMUyyg0YF6CGGF X-Google-Smtp-Source: AAOMgpdAqVqivp3opz7aGjJf+dVAnwUiqurrAnPv5ozX88HlJzZGdIE9Iv1+WviIkUZ6DHqzPErKFA== X-Received: by 2002:a6b:6503:: with SMTP id z3-v6mr13622299iob.129.1533524868194; Sun, 05 Aug 2018 20:07:48 -0700 (PDT) Received: from zebian (cbl-45-2-119-34.yyz.frontiernetworks.ca. [45.2.119.34]) by smtp.googlemail.com with ESMTPSA id t20-v6sm3190745itb.31.2018.08.05.20.07.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 05 Aug 2018 20:07:47 -0700 (PDT) From: Noam Postavsky To: =?utf-8?Q?Gr=C3=A9gory_Mouni=C3=A9?= Subject: Re: bug#32365: Interactive Highlighting: prefix arg as subexp selector References: <9fecb36d-cd58-0a70-ac84-ddaa8edb5030@imag.fr> Date: Sun, 05 Aug 2018 23:07:46 -0400 In-Reply-To: <9fecb36d-cd58-0a70-ac84-ddaa8edb5030@imag.fr> (=?utf-8?Q?=22?= =?utf-8?Q?Gr=C3=A9gory=09Mouni=C3=A9=22's?= message of "Fri, 3 Aug 2018 23:50:47 +0200") Message-ID: <87sh3sxke5.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 32365 Cc: 32365@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) tags 32365 + patch forcemerge 32362 32365 quit Gr=C3=A9gory Mouni=C3=A9 writes: > PS: Sorry for generating noise with my previous patch (BUG: 32362) No problem, I'll just merge the bugs. Next time, you can respond to your own bug report by sending mail to xxxxx@debbugs.gnu.org, and the new patch would be added to the same thread. >>>From 6b6291ce1974a363080f535b40f06d5772ffa1be Mon Sep 17 00:00:00 2001 > From: =3D?UTF-8?q?Gr=3DC3=3DA9gory=3D20Mouni=3DC3=3DA9?=3D > Date: Fri, 3 Aug 2018 23:08:10 +0200 > Subject: [PATCH] Interactive Highlighting: prefix argument to select sube= xp > > Use prefix-argument to highlight only the corresponding > subexpression of the regexp. > > * lisp/hi-lock.el (hi-lock-face-buffer, hi-lock-set-pattern) The message should go after the ChangeLog entry, as in * lisp/hi-lock.el (hi-lock-face-buffer, hi-lock-set-pattern): Use prefix-argument to highlight only the corresponding subexpression of the regexp. And I think we should have a NEWS entry mentioning the new feature too. > -(defun hi-lock-face-buffer (regexp &optional face) > +(defun hi-lock-face-buffer (regexp &optional face subexp) > "Set face of each match of REGEXP to FACE. > Interactively, prompt for REGEXP using `read-regexp', then FACE. > Use the global history list for FACE. > -(defun hi-lock-set-pattern (regexp face) > +(defun hi-lock-set-pattern (regexp face &optional arg) > "Highlight REGEXP with face FACE." You should mention the new arg in the docstrings. =20=20 > + (let* ((subexp (if (null arg) 0 arg)) This kind of thing is usually expressesd as (or arg 0). Though since `arg' is a bit vague, it might be clearer to rename arg as subexp, and then inside the function do (setq subexp (or subexp 0)) > + (let ((overlay (make-overlay (match-beginning subexp) > + (match-end subexp)))) > + (overlay-put overlay 'hi-lock-overlay t) > + (overlay-put overlay 'hi-lock-orverlay-regexp regexp) ^^^^^^^^ Looks like a typo. From debbugs-submit-bounces@debbugs.gnu.org Wed Aug 08 10:10:52 2018 Received: (at 32365) by debbugs.gnu.org; 8 Aug 2018 14:10:52 +0000 Received: from localhost ([127.0.0.1]:45152 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fnPAq-00020A-3a for submit@debbugs.gnu.org; Wed, 08 Aug 2018 10:10:52 -0400 Received: from zm-mta-out-1.u-ga.fr ([152.77.200.56]:34528) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fnPAn-0001zt-U9 for 32365@debbugs.gnu.org; Wed, 08 Aug 2018 10:10:50 -0400 Received: from zm-mta-out.u-ga.fr (zm-mta-out.u-ga.fr [152.77.200.58]) by zm-mta-out-1.u-ga.fr (Postfix) with ESMTP id 1E52BA00F5 for <32365@debbugs.gnu.org>; Wed, 8 Aug 2018 16:10:44 +0200 (CEST) Received: from smtps.univ-grenoble-alpes.fr (mailhost.u-ga.fr [152.77.1.30]) by zm-mta-out.u-ga.fr (Postfix) with ESMTP id 1AC79E008E for <32365@debbugs.gnu.org>; Wed, 8 Aug 2018 16:10:44 +0200 (CEST) Received: from [192.168.1.17] (mut38-1-82-67-65-81.fbx.proxad.net [82.67.65.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: mounieg@univ-grenoble-alpes.fr) by smtps.univ-grenoble-alpes.fr (Postfix) with ESMTPSA id E5860125EB4 for <32365@debbugs.gnu.org>; Wed, 8 Aug 2018 16:10:43 +0200 (CEST) Subject: Re: bug#32365: Interactive Highlighting: prefix arg as subexp selector To: 32365@debbugs.gnu.org References: <9fecb36d-cd58-0a70-ac84-ddaa8edb5030@imag.fr> <87sh3sxke5.fsf@gmail.com> From: =?UTF-8?Q?Gr=c3=a9gory_Mouni=c3=a9?= Message-ID: <74ac657f-e37c-8435-862d-8437dc880dfa@imag.fr> Date: Wed, 8 Aug 2018 16:10:43 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.0 MIME-Version: 1.0 In-Reply-To: <87sh3sxke5.fsf@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Greylist: Whitelist-UGA SMTP Authentifie (mounieg@univ-grenoble-alpes.fr) via submission-587 ACL (112) X-Spam-Score: 0.7 (/) X-Debbugs-Envelope-To: 32365 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.3 (/) Here the patch for modifying Automatic Interactive Highlighting (hi-lock.el) for adding prefix-argument to highlight-regexp I add a line documenting the option in the corresponding hightlight-regexp documentation in doc/emacs/display.texi and a section in NEWS. Thanks a lot for the feedback and comments. Grégory Mounié From debbugs-submit-bounces@debbugs.gnu.org Wed Aug 08 10:12:44 2018 Received: (at 32365) by debbugs.gnu.org; 8 Aug 2018 14:12:44 +0000 Received: from localhost ([127.0.0.1]:45163 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fnPCe-00023o-29 for submit@debbugs.gnu.org; Wed, 08 Aug 2018 10:12:44 -0400 Received: from zm-mta-out-1.u-ga.fr ([152.77.200.56]:34556) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fnPCc-00023J-7b for 32365@debbugs.gnu.org; Wed, 08 Aug 2018 10:12:42 -0400 Received: from zm-mta-out.u-ga.fr (zm-mta-out.u-ga.fr [152.77.200.58]) by zm-mta-out-1.u-ga.fr (Postfix) with ESMTP id DBE98A04E4 for <32365@debbugs.gnu.org>; Wed, 8 Aug 2018 16:12:36 +0200 (CEST) Received: from smtps.univ-grenoble-alpes.fr (smtps1.u-ga.fr [152.77.1.30]) by zm-mta-out.u-ga.fr (Postfix) with ESMTP id D8283E008E for <32365@debbugs.gnu.org>; Wed, 8 Aug 2018 16:12:36 +0200 (CEST) Received: from [192.168.1.17] (mut38-1-82-67-65-81.fbx.proxad.net [82.67.65.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: mounieg@univ-grenoble-alpes.fr) by smtps.univ-grenoble-alpes.fr (Postfix) with ESMTPSA id A4EE8125EB6 for <32365@debbugs.gnu.org>; Wed, 8 Aug 2018 16:12:36 +0200 (CEST) From: =?UTF-8?Q?Gr=c3=a9gory_Mouni=c3=a9?= Subject: Re: bug#32365: Interactive Highlighting: prefix arg as subexp selector To: 32365@debbugs.gnu.org References: <9fecb36d-cd58-0a70-ac84-ddaa8edb5030@imag.fr> <87sh3sxke5.fsf@gmail.com> Message-ID: <537ef32f-fd1f-a83d-d09c-365850f6e1a9@imag.fr> Date: Wed, 8 Aug 2018 16:12:36 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.0 MIME-Version: 1.0 In-Reply-To: <87sh3sxke5.fsf@gmail.com> Content-Type: multipart/mixed; boundary="------------39E1FC5C3002D921C573DAED" Content-Language: fr X-Greylist: Whitelist-UGA SMTP Authentifie (mounieg@univ-grenoble-alpes.fr) via submission-587 ACL (112) X-Spam-Score: 0.7 (/) X-Debbugs-Envelope-To: 32365 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.3 (/) This is a multi-part message in MIME format. --------------39E1FC5C3002D921C573DAED Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Here the patch for modifying Automatic Interactive Highlighting (hi-lock.el) for adding prefix-argument to highlight-regexp I add a line documenting the option in the corresponding hightlight-regexp documentation in doc/emacs/display.texi and a section in NEWS. Thanks a lot for the feedback and comments. Grégory Mounié PS: it is even better with the patch --------------39E1FC5C3002D921C573DAED Content-Type: text/x-patch; name="0001-Interactive-Highlighting-prefix-argument-to-select-s.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-Interactive-Highlighting-prefix-argument-to-select-s.pa"; filename*1="tch" >From 64c0e757d57854ddc57a6a9e763f6132e6da1d23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Mouni=C3=A9?= Date: Fri, 3 Aug 2018 23:08:10 +0200 Subject: [PATCH] Interactive Highlighting: prefix argument to select subexp * doc/emacs/display.texi (Highlight Interactively): * etc/NEWS: Document the change. * lisp/hi-lock.el (hi-lock-face-buffer, hi-lock-set-pattern): Use the prefix argument to highlight only the corresponding sub-expression of the regexp. Copyright-paperwork-exempt: yes --- doc/emacs/display.texi | 3 ++- etc/NEWS | 5 +++++ lisp/hi-lock.el | 28 ++++++++++++++++------------ 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/doc/emacs/display.texi b/doc/emacs/display.texi index 2f5ce80d60..ec79f71e9b 100644 --- a/doc/emacs/display.texi +++ b/doc/emacs/display.texi @@ -975,7 +975,8 @@ Highlight Interactively @kbd{M-s h r whim @key{RET} @key{RET}}. Any face can be used for highlighting, Hi Lock provides several of its own and these are pre-loaded into a list of default values. While being prompted -for a face use @kbd{M-n} and @kbd{M-p} to cycle through them. +for a face use @kbd{M-n} and @kbd{M-p} to cycle through them. A prefix +argument limits the highlighting to the corresponding subexpression. @vindex hi-lock-auto-select-face Setting the option @code{hi-lock-auto-select-face} to a non-@code{nil} diff --git a/etc/NEWS b/etc/NEWS index 21887f5bfd..07ed8be112 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -687,6 +687,11 @@ to signal the main thread, e.g., when they encounter an error. +++ *** 'thread-join' returns the result of the finished thread now. +** Interactive automatic highlighting + +*** prefix argument for function 'highlight-regexp' +limits the highlighting to the corresponding subexpression + * New Modes and Packages in Emacs 27.1 diff --git a/lisp/hi-lock.el b/lisp/hi-lock.el index 13ebffb1af..2dc4f0f519 100644 --- a/lisp/hi-lock.el +++ b/lisp/hi-lock.el @@ -429,10 +429,11 @@ hi-lock-line-face-buffer ;;;###autoload (defalias 'highlight-regexp 'hi-lock-face-buffer) ;;;###autoload -(defun hi-lock-face-buffer (regexp &optional face) +(defun hi-lock-face-buffer (regexp &optional face subexp) "Set face of each match of REGEXP to FACE. Interactively, prompt for REGEXP using `read-regexp', then FACE. -Use the global history list for FACE. +Use the global history list for FACE. Limit face setting to the +corresponding SUBEXP of REGEXP. Use Font lock mode, if enabled, to highlight REGEXP. Otherwise, use overlays for highlighting. If overlays are used, the @@ -441,10 +442,11 @@ hi-lock-face-buffer (list (hi-lock-regexp-okay (read-regexp "Regexp to highlight" 'regexp-history-last)) - (hi-lock-read-face-name))) + (hi-lock-read-face-name) + current-prefix-arg)) (or (facep face) (setq face 'hi-yellow)) (unless hi-lock-mode (hi-lock-mode 1)) - (hi-lock-set-pattern regexp face)) + (hi-lock-set-pattern regexp face subexp)) ;;;###autoload (defalias 'highlight-phrase 'hi-lock-face-phrase-buffer) @@ -686,20 +688,21 @@ hi-lock-read-face-name (add-to-list 'hi-lock-face-defaults face t)) (intern face))) -(defun hi-lock-set-pattern (regexp face) - "Highlight REGEXP with face FACE." +(defun hi-lock-set-pattern (regexp face &optional subexp) + "Highlight SUBEXP of REGEXP with face FACE." ;; Hashcons the regexp, so it can be passed to remove-overlays later. (setq regexp (hi-lock--hashcons regexp)) - (let ((pattern (list regexp (list 0 (list 'quote face) 'prepend))) - (no-matches t)) + (setq subexp (or subexp 0)) + (let ((pattern (list regexp (list subexp (list 'quote face) 'prepend))) + (no-matches t)) ;; Refuse to highlight a text that is already highlighted. (if (assoc regexp hi-lock-interactive-patterns) (add-to-list 'hi-lock--unused-faces (face-name face)) (push pattern hi-lock-interactive-patterns) (if (and font-lock-mode (font-lock-specified-p major-mode)) - (progn - (font-lock-add-keywords nil (list pattern) t) - (font-lock-flush)) + (progn + (font-lock-add-keywords nil (list pattern) t) + (font-lock-flush)) (let* ((range-min (- (point) (/ hi-lock-highlight-range 2))) (range-max (+ (point) (/ hi-lock-highlight-range 2))) (search-start @@ -712,7 +715,8 @@ hi-lock-set-pattern (goto-char search-start) (while (re-search-forward regexp search-end t) (when no-matches (setq no-matches nil)) - (let ((overlay (make-overlay (match-beginning 0) (match-end 0)))) + (let ((overlay (make-overlay (match-beginning subexp) + (match-end subexp)))) (overlay-put overlay 'hi-lock-overlay t) (overlay-put overlay 'hi-lock-overlay-regexp regexp) (overlay-put overlay 'face face)) -- 2.18.0 --------------39E1FC5C3002D921C573DAED-- From debbugs-submit-bounces@debbugs.gnu.org Tue Aug 14 19:49:29 2018 Received: (at 32365) by debbugs.gnu.org; 14 Aug 2018 23:49:29 +0000 Received: from localhost ([127.0.0.1]:51174 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fpj44-0005YY-Rg for submit@debbugs.gnu.org; Tue, 14 Aug 2018 19:49:29 -0400 Received: from mail-it0-f50.google.com ([209.85.214.50]:51075) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fpj42-0005YF-76; Tue, 14 Aug 2018 19:49:26 -0400 Received: by mail-it0-f50.google.com with SMTP id j81-v6so21030860ite.0; Tue, 14 Aug 2018 16:49:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:in-reply-to:references:user-agent:date :message-id:mime-version:content-transfer-encoding; bh=oICnE4oS+Z4KcXW5XRTfJOYDxBMgNFX7qERCR4ENfo0=; b=TNJhz6UE1y5ineDB1YR41mjBQ6r3zpRDqMw0MwVj705ITA0XtTRLWLzQX3J1ZsygcD qr5m1EYlF0J7gFOnHoV63+IQ1xRKAaOFX/rLC1szXjGEkL6XsBbvxKpZAdVlmspJY8Xd CeLgP9RVt7SlnWX3XuV8BKvgU4JaLMUYmXtKwBNNjLUrzQEKRv3z19s8WZkd9VmpvTxN kh/PBKz1xv1/wq2QdBOXgzv+tgabT338RQyU9cWVxO4gWZQLn6tpHm4x3UUSN8YDrrIO E6E7i+plTJa4ZZOmqm7gAb9028CbQFefVZ64VpOKyVXrGELw7pfnYpJNTck41xOJUaQI wc9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references :user-agent:date:message-id:mime-version:content-transfer-encoding; bh=oICnE4oS+Z4KcXW5XRTfJOYDxBMgNFX7qERCR4ENfo0=; b=VqCJHfToxrzjtZBL3wPwVtPTvrRbthI/wrdy/OiF1+YNJLV7JsEsgzannZ+pnG7gq0 58R3fHwP30wrLQX5sRgGi3oClIB0F2olnPgWDJXIXWhdiIBzfuxRTwefDVKP5G8Az2Ay uPtxydwPWLFHh/L2Ai3ukY8jX0vgr1WdqY4pNGkVIxQUoYw73Zluh0J8zjHvbfg46kTr 3eykdslXCANQQgoFiA6taOWteKFzzuysucI8OUhQ/y9tgf71nEjeW0znFCvDKGqMf1xs UaDhogw47rv/lkct35TqR27zOb10eijDJEplkebfjbWqmJlPnlGDYqANrawNSDgNv/Tf NBPw== X-Gm-Message-State: AOUpUlFUPXyQfl/aVowKG6jy0ZIWacnGg3Z62/FfC5nDeP4w/XJkkUw/ zIsoz7p6gpTFeeV4/EKNw45cn7QE X-Google-Smtp-Source: AA+uWPzPJ+4ZRB7C2ONQG0PnBRTib+ip+w9+aE8kZwmz4kAqn9pGMJcpuwyts8LWLtly0FCUVVFN/A== X-Received: by 2002:a02:bb04:: with SMTP id y4-v6mr21289152jan.5.1534290560437; Tue, 14 Aug 2018 16:49:20 -0700 (PDT) Received: from zebian (cbl-45-2-119-34.yyz.frontiernetworks.ca. [45.2.119.34]) by smtp.googlemail.com with ESMTPSA id 1-v6sm261418ity.38.2018.08.14.16.49.18 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 Aug 2018 16:49:19 -0700 (PDT) From: Noam Postavsky To: =?utf-8?Q?Gr=C3=A9gory_Mouni=C3=A9?= Subject: Re: bug#32365: Interactive Highlighting: prefix arg as subexp selector In-Reply-To: <537ef32f-fd1f-a83d-d09c-365850f6e1a9@imag.fr> (=?utf-8?Q?=22?= =?utf-8?Q?Gr=C3=A9gory=09Mouni=C3=A9=22's?= message of "Wed, 8 Aug 2018 16:12:36 +0200") References: <9fecb36d-cd58-0a70-ac84-ddaa8edb5030@imag.fr> <87sh3sxke5.fsf@gmail.com> <537ef32f-fd1f-a83d-d09c-365850f6e1a9@imag.fr> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) Date: Tue, 14 Aug 2018 19:49:12 -0400 Message-ID: <87o9e4y0ef.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 32365 Cc: 32365@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) tags 32365 fixed close 32365 27.1 quit Gr=C3=A9gory Mouni=C3=A9 writes: > Here the patch for modifying Automatic Interactive Highlighting > (hi-lock.el) for adding prefix-argument to highlight-regexp > > I add a line documenting the option in the corresponding > hightlight-regexp documentation in doc/emacs/display.texi and a > section in NEWS. Thanks, pushed to master [1: cc5a23d40b]. I fixed a couple of minor things (we use double spacing at end-of-sentence, NEWS entries should first line should be a whole sentence, and some whitespace/indentation issues). [1: cc5a23d40b]: 2018-08-14 19:38:21 -0400 Interactive Highlighting: prefix argument to select subexp https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=3Dcc5a23d40bfa7a83= 2f7a6fb7a016557ac1416559 From unknown Wed Jun 18 23:11:33 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Wed, 12 Sep 2018 11:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator