3

我正在尝试调整 gedit 样式,以便用户定义的函数具有不同的颜色。

我已经搜索了http://library.gnome.org/devel/gtksourceview-2.0/stable/lang-reference.html但我找不到任何东西。

我想<style name="def:function" />可能会这样做,但它似乎在 gedit 中没有效果。

<?xml version="1.0" ?>
<style-scheme id="wombat" name="Wombat" version="1.0">
        <author/>
        <_description>Wombat theme</_description>
        <style background="#2d2d2d" name="current-line"/>
        <style background="#857b6f" bold="true" foreground="#fff000" name="bracket-match"/>
        <style background="#242424" bold="true" foreground="#fff000" name="search-match"/>
        <style background="#656565" name="cursor"/>
        <style background="#242424" foreground="#f6f3e8" name="text"/>
        <style background="#272727" foreground="#857b6f" name="line-numbers"/>
        <style foreground="#363636" italic="true" name="def:comment"/>
        <style foreground="#e5786d" name="def:constant"/>
        <style foreground="#95e454" italic="true" name="def:string"/>
        <style foreground="#cae682" name="def:identifier"/>
        <style foreground="#000000" name="def:function"/>
        <style foreground="#cae682" name="def:type"/>
        <style foreground="#8ac6f2" name="def:statement"/>
        <style foreground="#8ac6f2" name="def:keyword"/>
        <style foreground="#e5786d" name="def:preprocessor"/>
        <style foreground="#e5786d" name="def:number"/>
        <style foreground="#e7f6da" name="def:specials"/>
    </style-scheme>

有什么提示吗?谢谢!

4

2 回答 2

1

您需要编辑语言定义文件以添加新部分。语言定义是python.lang,对我来说是/usr/share/gtksourceview-2.0/language-specs

您首先需要为要创建的样式 ID 添加样式:

<style id="class-name"    _name="Python Class Name"  map-to="def:type"/>

然后,您需要在以下部分向此文件添加新上下文<context-id="python"

<context id="class-name" style-ref="class-name" style-inside="true">
    <start>\%{string-prefix}def\ </start>
    <end>\(</end>
    <include>
        <context ref="python"/>
        <context ref="format"/>
        <context ref="escaped-char"/>
    </include>
</context>

您需要style-inside="true"不将样式应用于我们匹配的defor (。从文档:

style-inside(可选)如果此属性为“true”,则突出显示样式将应用于开始匹配和结束匹配之间的区域;否则将突出显示整个上下文。

保存它,然后重新启动 gedit 并且函数名称的样式应该与错误相同,例如将的文本AttributeError。您可以更改map-to语言文件顶部的行以更改应用于函数名称的样式。

重用现有样式而不是为类名定义新样式的好处是,它将适用于您将来安装的所有 gedit 主题 - 无需更改它们即可添加特定于 python 的函数名称部分。


编辑:如评论中所述,这会破坏“def”的样式。将“类名”部分(我上面的代码)移动到已经存在的“关键字”部分下方,修复了这个问题,因为它将我们的更改移动到层次结构中的较低位置。有机会会更新图片。

前: 在此处输入图像描述

后: 在此处输入图像描述

于 2012-05-30T01:26:47.873 回答
0

如果我理解正确,首先你需要在 *.lang 文件中定义新样式

<style id="function" _name="Functions"/>

然后列出所有需要的功能,比如

<context id="functions" style-ref="function">
    <keyword>abs</keyword>
    <keyword>acos</keyword>
    <keyword>acosh</keyword>
</context>

然后更新文件末尾的块定义,并添加新的上下文

<context ref="functions"/>

它非常重要的正确顺序,上下文定义顺序在所有文件中应该是相同的,一个元素总是一个接一个,不要混淆它们。

最后,您需要在您的样式/*.xml 文件中定义样式格式,在我的情况下是

<style name="php:function" foreground="#0000ee" bold="false"/>

我使用 php 的地方应该是您的语言 ID,与 *.lang 文件中的相同。

于 2011-03-10T13:09:29.773 回答