emacs-diffs
[Top][All Lists]
Advanced

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

master 163e305: Add possibility to override the default highlighting


From: Tassilo Horn
Subject: master 163e305: Add possibility to override the default highlighting
Date: Mon, 6 Sep 2021 15:52:42 -0400 (EDT)

branch: master
commit 163e3052c8ffd840c41b638dc15a9b1a5922642f
Author: Tassilo Horn <tsdh@gnu.org>
Commit: Tassilo Horn <tsdh@gnu.org>

    Add possibility to override the default highlighting
    
    * lisp/progmodes/bug-reference.el (bug-reference-fontify): Highlight
    99th group if it exists.
    (bug-reference-bug-regexp): Document that regexp group 99 can be used
    to override the default behavior of highlighting the complete match.
    (bug-reference--run-auto-setup): Use run-hook-with-args-until-success
    instead of throw/catch.
---
 lisp/progmodes/bug-reference.el | 29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/lisp/progmodes/bug-reference.el b/lisp/progmodes/bug-reference.el
index c0c9d5e..3354834 100644
--- a/lisp/progmodes/bug-reference.el
+++ b/lisp/progmodes/bug-reference.el
@@ -74,7 +74,20 @@ so that it is considered safe, see 
`enable-local-variables'.")
 (defcustom bug-reference-bug-regexp
   "\\([Bb]ug ?#?\\|[Pp]atch ?#\\|RFE ?#\\|PR 
[a-z+-]+/\\)\\([0-9]+\\(?:#[0-9]+\\)?\\)"
   "Regular expression matching bug references.
-The second subexpression should match the bug reference (usually a number)."
+The second subexpression should match the bug reference (usually
+a number).
+
+The complete expression's matches will be highlighted unless
+there is a 99th subexpression.  In that case, only the matches of
+that will be highlighted.  For example, this can be used to
+define that bug references at the beginning of a line must not be
+matched by using a regexp like
+
+  \"[^\\n]\\\\(?99:\\\\([Bb]ug ?\\\\)\\\\(#[0-9]+\\\\)\\\\)\"
+
+If there wasn't this explicitly numbered group 99, the
+non-newline character before the actual bug reference would be
+highlighted, too."
   :type 'regexp
   :version "24.3")                     ; previously defconst
 
@@ -113,7 +126,13 @@ The second subexpression should match the bug reference 
(usually a number)."
        (when (or (not bug-reference-prog-mode)
                  ;; This tests for both comment and string syntax.
                  (nth 8 (syntax-ppss)))
-         (let ((overlay (make-overlay (match-beginning 0) (match-end 0)
+          ;; We highlight the 99th subexpression if that exists,
+          ;; otherwise the complete match.  See the docstring of
+          ;; `bug-reference-bug-regexp'.
+         (let ((overlay (make-overlay (or (match-beginning 99)
+                                           (match-beginning 0))
+                                       (or (match-end 99)
+                                           (match-end 0))
                                       nil t nil)))
            (overlay-put overlay 'category 'bug-reference)
            ;; Don't put a link if format is undefined
@@ -564,10 +583,8 @@ guesswork is based on these variables:
                  bug-reference-url-format)
       (with-demoted-errors
           "Error during bug-reference auto-setup: %S"
-        (catch 'setup
-          (dolist (f bug-reference-auto-setup-functions)
-            (when (funcall f)
-              (throw 'setup t))))))))
+        (run-hook-with-args-until-success
+         'bug-reference-auto-setup-functions)))))
 
 ;;;###autoload
 (define-minor-mode bug-reference-mode



reply via email to

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