regex - 找出 Emacs 中哪个正则表达式导致了特定的面孔

标签 regex emacs syntax-highlighting emacs-faces font-lock

我试图找出哪个正则表达式导致connect在此cperl-mode缓冲区中突出显示。 describe-face 告诉我这是一个font-lock-type-face。在查看了 font-lock-keywords-alistfont-lock-keywords 后,我不明白这个突出显示是从哪里来的。彩色括号是由rainbow-delimiters-mode创建的。

Syntax highlighted code

是否有一个函数可以检查哪个正则表达式匹配,以便连接用这张脸突出显示?

最佳答案

我有一个本地字体锁定黑客来在缓冲区中记录所使用的规则。下面的补丁可能会做到这一点。应用它(并重新加载 font-lock.el)后,您可以检查(使用 C-u C-x =)缓冲区位置上的 font-lock-debug 属性您想了解其字体。

=== 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)

关于regex - 找出 Emacs 中哪个正则表达式导致了特定的面孔,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14647135/

相关文章:

regex - TSQL 也允许匹配来自字符串的右方括号

regex - 我没有得到正则表达式

php - 将字符串分解为字段

Emacs:如何读取我的键绑定(bind)?

emacs - Lisp 社区 - 优质教程/资源

python - 将代码转换为语法突出显示的 html

java - MySQL 中的 REGEXP 返回不需要的值

vim - 我想改变文本在任何文本编辑器中的内部表示方式

xml - SyntaxHighlighter 不格式化 xml 文本

jquery - 适用于 HTML5 的语法荧光笔?