【问题标题】:Fontifying variable references within string literals in Emacs font-lock-mode在 Emacs font-lock-mode 中对字符串文字中的变量引用进行字体化
【发布时间】:2012-03-23 23:15:31
【问题描述】:

当我在 Emacs ruby​​-mode 中键入以下代码时,“#{foo}”的字体颜色与封闭字符串不同。如何在我自己的 Emacs 模式下执行此操作?我试图破译 ruby​​ 模式的源代码,但在合理的时间内无法理解。

"a #{foo} a"

【问题讨论】:

    标签: emacs font-lock


    【解决方案1】:

    终于明白了。答案是字体化规则中的“override”参数应该设置为 t,这意味着给定的 face 将覆盖字符串 face。有关详细信息,请参阅变量“font-lock-keywords”的文档。这是一个例子:

    (define-derived-mode temp-mode fundamental-mode "Temp"
      "Temporary major mode."
      (set (make-local-variable 'font-lock-defaults)
           '((temp-mode-font-lock-keywords) nil nil nil nil)))
    
    (defconst temp-mode-font-lock-keywords
      (list (list "$[A-Za-z0-9]+" 0 font-lock-variable-name-face t)))
    

    【讨论】:

      【解决方案2】:

      搜索 ruby​​-mode.el 设置 font-lock-syntactic-keywords 的位置:

      (setq ruby-font-lock-syntactic-keywords
        '(
          ;; #{ }, #$hoge, #@foo are not comments
          ("\\(#\\)[{$@]" 1 (1 . nil))
      

      这里有一些关于类似font-lock-keywords 变量的文档,您应该使用它来完成相同类型的字体化。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-10-19
        • 2018-11-09
        • 1970-01-01
        • 1970-01-01
        • 2017-01-17
        • 2020-07-10
        • 1970-01-01
        相关资源
        最近更新 更多