From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: =?UTF-8?Q?Gr=C3=A9gory_?= =?UTF-8?Q?Mouni=C3=A9?= Newsgroups: gmane.emacs.bugs Subject: bug#32365: Interactive Highlighting: prefix arg as subexp selector Date: Fri, 3 Aug 2018 23:50:47 +0200 Message-ID: <9fecb36d-cd58-0a70-ac84-ddaa8edb5030@imag.fr> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------7AB7ACAD71569A5EEC594391" X-Trace: blaine.gmane.org 1533333013 6555 195.159.176.226 (3 Aug 2018 21:50:13 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 3 Aug 2018 21:50:13 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.0 To: 32365@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Aug 03 23:50:08 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1flhxY-0001Uv-JL for geb-bug-gnu-emacs@m.gmane.org; Fri, 03 Aug 2018 23:50:08 +0200 Original-Received: from localhost ([::1]:53178 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1flhzZ-0005tY-UH for geb-bug-gnu-emacs@m.gmane.org; Fri, 03 Aug 2018 17:52:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41927) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1flhzS-0005tQ-Jr for bug-gnu-emacs@gnu.org; Fri, 03 Aug 2018 17:52:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1flhzO-0001ea-LS for bug-gnu-emacs@gnu.org; Fri, 03 Aug 2018 17:52:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:35232) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1flhzO-0001eQ-F0 for bug-gnu-emacs@gnu.org; Fri, 03 Aug 2018 17:52:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1flhzO-0005kJ-8A for bug-gnu-emacs@gnu.org; Fri, 03 Aug 2018 17:52:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: =?UTF-8?Q?Gr=C3=A9gory_?= =?UTF-8?Q?Mouni=C3=A9?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 03 Aug 2018 21:52:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 32365 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.153333306722011 (code B ref -1); Fri, 03 Aug 2018 21:52:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 3 Aug 2018 21:51:07 +0000 Original-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 Original-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 Original-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 Original-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 Original-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 Original-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 Original-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 Original-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) Original-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) Original-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) 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-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:149248 Archived-At: 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--