summaryrefslogtreecommitdiff
path: root/lisp/hi-lock.el
diff options
context:
space:
mode:
authorGrégory Mounié <Gregory.Mounie@imag.fr>2018-08-03 23:08:10 +0200
committerNoam Postavsky <npostavs@gmail.com>2018-08-14 19:38:21 -0400
commitcc5a23d40bfa7a832f7a6fb7a016557ac1416559 (patch)
tree258ec3f55c167d7d8c6da9635c67ed81d7677777 /lisp/hi-lock.el
parent1164d49ba6a3ce59a2bd404219851d8e27b54611 (diff)
downloademacs-cc5a23d40bfa7a832f7a6fb7a016557ac1416559.tar.gz
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 (Bug#32365). Copyright-paperwork-exempt: yes
Diffstat (limited to 'lisp/hi-lock.el')
-rw-r--r--lisp/hi-lock.el20
1 files changed, 12 insertions, 8 deletions
diff --git a/lisp/hi-lock.el b/lisp/hi-lock.el
index 13ebffb1afc..23820cda587 100644
--- a/lisp/hi-lock.el
+++ b/lisp/hi-lock.el
@@ -429,10 +429,11 @@ highlighting will not update as you type."
;;;###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 @@ highlighting will not update as you type."
(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,11 +688,12 @@ with completion and history."
(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)))
+ (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)
@@ -712,7 +715,8 @@ with completion and history."
(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))