【问题标题】:Customizing emacs syntax coloring自定义 emacs 语法着色
【发布时间】:2012-03-26 02:38:54
【问题描述】:

我不知道如何将 emacs 设置为仅使用两种颜色,一种用于 cmets,另一种用于跨所有语言模式的常规代码。 当然,可以将除注释之外的每个块的颜色设置为第二种颜色,但我不确定所有可用的块是什么。

到目前为止,我发现的只是 (setq-default global-font-lock-mode nil) 但这也扼杀了 cmets 的着色。

我想这对于久经考验的 emacs 战士来说一定相当容易。

【问题讨论】:

    标签: emacs syntax highlighting


    【解决方案1】:

    请参阅angry fruit salad wiki 页面以清除字体锁定面。您可以稍微修改代码以免除 cmets。

    如果您确实必须删除所有颜色,则此代码将对除警告和注释之外的所有面孔执行此操作:

    (defun decolorize-font-lock ()
      "remove all colors from font-lock faces except comment and warning"
      (let ((fg (face-attribute 'default :foreground))
            (bg (face-attribute 'default :background)))
        (mapc (lambda (face)
                (when face
                  (set-face-attribute face nil
                                      :foreground fg
                                      :background bg)))
              (mapcar (lambda (f)
                        (if (and (string-match "^font-lock" (symbol-name f))
                                 (not (string-match "-comment\\|-warning" (symbol-name f))))
                            f
                          nil))
                      (face-list)))))
    
    (decolorize-font-lock)
    

    【讨论】:

    • 哇,这成功了!我现在正在修改此代码以消除所有字体粗细差异。我只希望能够从代码中分辨出 cmets。
    • 接受。无法投票,因为这是我的第一个问题,也是我在 stackoverflow 的第一天。
    【解决方案2】:

    color-theme 是一个方便的“框架”,用于以与语言无关的方式定义语法和窗口着色。

    开始使用它就像破解默认主题之一一样简单。其中一个典型的段落是这样的:

     (font-lock-builtin-face ((t (:foreground "#000080"))))
     (font-lock-keyword-face ((t (:bold t :foreground "#000080")))) 
     (font-lock-function-name-face ((t (:foreground "#000080"))))
     (font-lock-variable-name-face ((t (:bold t :foreground "#000080"))))
     (font-lock-string-face ((t (:foreground "#177A12"))))
     (font-lock-comment-face ((t (:italic t :foreground "#716F6F"))))
     (font-lock-constant-face ((t (:italic t :foreground "#660E7A"))))
     (font-lock-doc-string-face ((t (:foreground "DarkOrange"))))
    

    【讨论】:

      猜你喜欢
      • 2011-10-09
      • 1970-01-01
      • 1970-01-01
      • 2012-04-02
      • 1970-01-01
      • 1970-01-01
      • 2012-09-28
      • 2012-10-12
      • 1970-01-01
      相关资源
      最近更新 更多