2

I am trying to find out which regexp causes the connect to be highlighted in this cperl-mode buffer. describe-face tells me this is a font-lock-type-face. After having a look at font-lock-keywords-alist and font-lock-keywords I dont't see where this highlight could have come from. The colorful parantheses are created by the rainbow-delimiters-mode.

Syntax highlighted code

Is there a function to check which regexp matched, such that connect is highlighted with this face?

Drew
  • 29,895
  • 7
  • 74
  • 104
Kungi
  • 1,477
  • 1
  • 18
  • 34

3 Answers3

2

I had a local font-lock hack to record in the buffer the rule that was used. The patch below might do it. Once you've applied it (and reloaded font-lock.el), you can check (with C-u C-x =) the font-lock-debug property on the buffer position whose fontification you want to understand.

=== modified file 'lisp/font-lock.el'
--- lisp/font-lock.el   2013-01-11 23:08:55 +0000
+++ lisp/font-lock.el   2013-01-13 15:28:16 +0000
@@ -1563,6 +1611,14 @@

 ;;; Keyword regexp fontification functions.

+(defvar font-lock-debug nil)
+
+(defun font-lock-debug ()
+  (interactive)
+  (set (make-local-variable 'font-lock-debug) t)
+  (make-local-variable 'font-lock-extra-managed-props)
+  (push 'font-lock-debug font-lock-extra-managed-props))
+
 (defsubst font-lock-apply-highlight (highlight)
   "Apply HIGHLIGHT following a match.
 HIGHLIGHT should be of the form MATCH-HIGHLIGHT, see `font-lock-keywords'."
@@ -1577,13 +1633,16 @@
    (when (eq (car-safe val) 'face)
      (add-text-properties start end (cddr val))
      (setq val (cadr val)))
-   (cond
-    ((not (or val (eq override t)))
+   (if (and (not val) (not (eq override t)))
      ;; If `val' is nil, don't do anything.  It is important to do it
      ;; explicitly, because when adding nil via things like
      ;; font-lock-append-text-property, the property is actually
      ;; changed from <face> to (<face>) which is undesirable.  --Stef
-     nil)
+       nil
+     (if font-lock-debug
+         (font-lock-append-text-property start end 'font-lock-debug
+                         (list (cons matcher highlight))))
+     (cond
     ((not override)
      ;; Cannot override existing fontification.
      (or (text-property-not-all start end 'face nil)
@@ -1599,7 +1658,7 @@
      (font-lock-append-text-property start end 'face val))
     ((eq override 'keep)
      ;; Keep existing fontification.
-     (font-lock-fillin-text-property start end 'face val)))))))
+       (font-lock-fillin-text-property start end 'face val))))))))

 (defsubst font-lock-fontify-anchored-keywords (keywords limit)
   "Fontify according to KEYWORDS until LIMIT.
@@ -1621,6 +1680,7 @@
                 (min lead-start (point)))
               limit
               'font-lock-multiline t)))
+    (font-lock-append-text-property (point) limit 'font-lock-debug keywords)
     (save-match-data
       ;; Find an occurrence of `matcher' before `limit'.
       (while (and (< (point) limit)
Stefan
  • 27,908
  • 4
  • 53
  • 82
  • 1
    While keybinding are optional, the functionality your code provides seems missing from Emacs and potentially very useful if not essential. But as a patch it seems tricky to apply unless often-ironically one is already pretty expert with this area of emacs+elisp. So when you can you (1)make this something one with basic emacs skills can load-from else add-to his .emacsrc? (2) Submit it to be added to the emacs distribution? (3) Post back here with URLs to these additions. Thanks! Indeed looks like u put all the great work into this except these last steps which seemingly wd then be easy 4u! :-) – Destiny Architect Jun 09 '14 at 22:57
0

I know of no such function. The regular expressions are compiled to be optimal, why do you need to know?

BTW, displaying font-lock-keyword shows the string nect just besides tinue.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
choroba
  • 231,213
  • 25
  • 204
  • 289
0

Did you try font-lock studio? It works great for me.

Clément
  • 12,299
  • 15
  • 75
  • 115