【问题标题】:Finding out which regexp caused a specific face in Emacs找出哪个正则表达式导致 Emacs 中的特定面孔
【发布时间】:2013-01-16 19:33:16
【问题描述】:

我试图找出哪个正则表达式导致connect 在此cperl-mode 缓冲区中突出显示。 describe-face 告诉我这是font-lock-type-face。在看了font-lock-keywords-alistfont-lock-keywords 之后,我看不出这个亮点可能来自哪里。五颜六色的花括号是由rainbow-delimiters-mode 创建的。

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

【问题讨论】:

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


    【解决方案1】:

    你试过font-lock studio吗?它对我很有用。

    【讨论】:

      【解决方案2】:

      我知道没有这样的功能。正则表达式被编译为最优,为什么需要知道?

      顺便说一句,显示font-lock-keyword 会在tinue 旁边显示字符串nect

      【讨论】:

        【解决方案3】:

        我有一个本地字体锁定技巧,可以在缓冲区中记录使用的规则。下面的补丁可能会做到这一点。应用它(并重新加载 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)
        

        【讨论】:

        • 虽然键绑定是可选的,但您的代码提供的功能似乎在 Emacs 中缺失,如果不是必需的,它可能非常有用。但作为一个补丁,它似乎很难应用,除非经常具有讽刺意味的是,一个人已经非常熟悉 emacs+elisp 领域。因此,您何时可以 (1) 使具有基本 emacs 技能的东西可以从其他加载项加载到他的 .emacsrc 中? (2) 提交它以添加到 emacs 发行版中? (3) 在此处发回这些添加的 URL。谢谢!确实看起来你把所有伟大的工作都投入了,除了这些看起来很容易 4u 的最后步骤! :-)
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-07-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多