emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master cc5a23d: Interactive Highlighting: prefix argument


From: Noam Postavsky
Subject: [Emacs-diffs] master cc5a23d: Interactive Highlighting: prefix argument to select subexp
Date: Tue, 14 Aug 2018 19:38:35 -0400 (EDT)

branch: master
commit cc5a23d40bfa7a832f7a6fb7a016557ac1416559
Author: Grégory Mounié <address@hidden>
Commit: Noam Postavsky <address@hidden>

    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
---
 doc/emacs/display.texi |  3 ++-
 etc/NEWS               |  6 ++++++
 lisp/hi-lock.el        | 20 ++++++++++++--------
 3 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/doc/emacs/display.texi b/doc/emacs/display.texi
index 2f5ce80..fe4936d 100644
--- a/doc/emacs/display.texi
+++ b/doc/emacs/display.texi
@@ -975,7 +975,8 @@ the word ``whim'' using the default face (a yellow 
background), type
 @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 address@hidden
diff --git a/etc/NEWS b/etc/NEWS
index 3ae956c..5146e75 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -716,6 +716,12 @@ A symbol 'uuid' can be passed to thing-at-point and it 
returns the
 UUID at point.
 
 
+** Interactive automatic highlighting
+
++++
+*** 'highlight-regexp' can now highlight subexpressions.
+The command accepts a prefix argument to choose the subexpression.
+
 
 * New Modes and Packages in Emacs 27.1
 
diff --git a/lisp/hi-lock.el b/lisp/hi-lock.el
index 13ebffb..23820cd 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))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]