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: Wed, 8 Aug 2018 16:12:36 +0200 Message-ID: <537ef32f-fd1f-a83d-d09c-365850f6e1a9@imag.fr> References: <9fecb36d-cd58-0a70-ac84-ddaa8edb5030@imag.fr> <87sh3sxke5.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------39E1FC5C3002D921C573DAED" X-Trace: blaine.gmane.org 1533737473 29549 195.159.176.226 (8 Aug 2018 14:11:13 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 8 Aug 2018 14:11: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 Wed Aug 08 16:11: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 1fnPB2-0007VZ-SW for geb-bug-gnu-emacs@m.gmane.org; Wed, 08 Aug 2018 16:11:05 +0200 Original-Received: from localhost ([::1]:44007 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fnPD9-0001ql-ER for geb-bug-gnu-emacs@m.gmane.org; Wed, 08 Aug 2018 10:13:15 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36187) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fnPD0-0001qF-OC for bug-gnu-emacs@gnu.org; Wed, 08 Aug 2018 10:13:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fnPCw-00071o-L1 for bug-gnu-emacs@gnu.org; Wed, 08 Aug 2018 10:13:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:40151) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fnPCw-00071b-Cq for bug-gnu-emacs@gnu.org; Wed, 08 Aug 2018 10:13:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fnPCw-00024Z-75 for bug-gnu-emacs@gnu.org; Wed, 08 Aug 2018 10:13: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: Wed, 08 Aug 2018 14:13:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 32365 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 32365-submit@debbugs.gnu.org id=B32365.15337375647933 (code B ref 32365); Wed, 08 Aug 2018 14:13:02 +0000 Original-Received: (at 32365) by debbugs.gnu.org; 8 Aug 2018 14:12:44 +0000 Original-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 Original-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 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 DBE98A04E4 for <32365@debbugs.gnu.org>; Wed, 8 Aug 2018 16:12:36 +0200 (CEST) Original-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) 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 A4EE8125EB6 for <32365@debbugs.gnu.org>; Wed, 8 Aug 2018 16:12:36 +0200 (CEST) In-Reply-To: <87sh3sxke5.fsf@gmail.com> Content-Language: fr X-Greylist: Whitelist-UGA SMTP Authentifie (mounieg@univ-grenoble-alpes.fr) via submission-587 ACL (112) 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:149352 Archived-At: 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--