* bug#32365: Interactive Highlighting: prefix arg as subexp selector
@ 2018-08-03 21:50 Grégory Mounié
2018-08-06 3:07 ` Noam Postavsky
0 siblings, 1 reply; 5+ messages in thread
From: Grégory Mounié @ 2018-08-03 21:50 UTC (permalink / raw)
To: 32365
[-- Attachment #1: Type: text/plain, Size: 804 bytes --]
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
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
^\(?:[^,]*,\)\{5\}\([^,]*\),
(clean CSV == with enough coma as you get multi-line matching with
this regexp)
I am not fluent with interactive stuff.
I am not sure either how to treat errors.
Have a nice day.
Grégory Mounié
PS: Sorry for generating noise with my previous patch (BUG: 32362)
[-- Attachment #2: 0001-Interactive-Highlighting-prefix-argument-to-select-s.patch --]
[-- Type: text/x-patch, Size: 5127 bytes --]
From 6b6291ce1974a363080f535b40f06d5772ffa1be Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gr=C3=A9gory=20Mouni=C3=A9?= <Gregory.Mounie@imag.fr>
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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* bug#32365: Interactive Highlighting: prefix arg as subexp selector
2018-08-03 21:50 bug#32365: Interactive Highlighting: prefix arg as subexp selector Grégory Mounié
@ 2018-08-06 3:07 ` Noam Postavsky
2018-08-08 14:10 ` Grégory Mounié
2018-08-08 14:12 ` Grégory Mounié
0 siblings, 2 replies; 5+ messages in thread
From: Noam Postavsky @ 2018-08-06 3:07 UTC (permalink / raw)
To: Grégory Mounié; +Cc: 32365
tags 32365 + patch
forcemerge 32362 32365
quit
Grégory Mounié <Gregory.Mounie@imag.fr> 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: =?UTF-8?q?Gr=C3=A9gory=20Mouni=C3=A9?= <Gregory.Mounie@imag.fr>
> 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)
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.
> + (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.
^ permalink raw reply [flat|nested] 5+ messages in thread
* bug#32365: Interactive Highlighting: prefix arg as subexp selector
2018-08-06 3:07 ` Noam Postavsky
@ 2018-08-08 14:10 ` Grégory Mounié
2018-08-08 14:12 ` Grégory Mounié
1 sibling, 0 replies; 5+ messages in thread
From: Grégory Mounié @ 2018-08-08 14:10 UTC (permalink / raw)
To: 32365
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é
^ permalink raw reply [flat|nested] 5+ messages in thread
* bug#32365: Interactive Highlighting: prefix arg as subexp selector
2018-08-06 3:07 ` Noam Postavsky
2018-08-08 14:10 ` Grégory Mounié
@ 2018-08-08 14:12 ` Grégory Mounié
2018-08-14 23:49 ` Noam Postavsky
1 sibling, 1 reply; 5+ messages in thread
From: Grégory Mounié @ 2018-08-08 14:12 UTC (permalink / raw)
To: 32365
[-- Attachment #1: Type: text/plain, Size: 376 bytes --]
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
[-- Attachment #2: 0001-Interactive-Highlighting-prefix-argument-to-select-s.patch --]
[-- Type: text/x-patch, Size: 5009 bytes --]
From 64c0e757d57854ddc57a6a9e763f6132e6da1d23 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gr=C3=A9gory=20Mouni=C3=A9?= <Gregory.Mounie@imag.fr>
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
+
\f
* 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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* bug#32365: Interactive Highlighting: prefix arg as subexp selector
2018-08-08 14:12 ` Grégory Mounié
@ 2018-08-14 23:49 ` Noam Postavsky
0 siblings, 0 replies; 5+ messages in thread
From: Noam Postavsky @ 2018-08-14 23:49 UTC (permalink / raw)
To: Grégory Mounié; +Cc: 32365
tags 32365 fixed
close 32365 27.1
quit
Grégory Mounié <Gregory.Mounie@imag.fr> 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=cc5a23d40bfa7a832f7a6fb7a016557ac1416559
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-08-14 23:49 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-03 21:50 bug#32365: Interactive Highlighting: prefix arg as subexp selector Grégory Mounié
2018-08-06 3:07 ` Noam Postavsky
2018-08-08 14:10 ` Grégory Mounié
2018-08-08 14:12 ` Grégory Mounié
2018-08-14 23:49 ` Noam Postavsky
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).