Linux 如何在gedit中设置用户定义函数名的样式?
我正在尝试调整gedit样式,以便用户定义的函数具有不同的颜色 我找遍了,但什么也没找到 我原以为Linux 如何在gedit中设置用户定义函数名的样式?,linux,gtk,syntax-highlighting,gedit,Linux,Gtk,Syntax Highlighting,Gedit,我正在尝试调整gedit样式,以便用户定义的函数具有不同的颜色 我找遍了,但什么也没找到 我原以为可以做到,但在gedit中似乎没有效果 <?xml version="1.0" ?> <style-scheme id="wombat" name="Wombat" version="1.0"> <author/> <_description>Wombat theme</_description>
可以做到,但在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>
袋熊主题
有什么提示吗?谢谢 如果我理解正确,首先需要在*.lang文件中定义新样式
<style id="function" _name="Functions"/>
然后列出所有需要的函数,如
<context id="functions" style-ref="function">
<keyword>abs</keyword>
<keyword>acos</keyword>
<keyword>acosh</keyword>
</context>
防抱死制动系统
acos
阿科什
然后更新文件末尾的块定义,并添加新上下文
<context ref="functions"/>
正确的顺序非常重要,所有文件中的上下文定义顺序都应该相同,一个元素总是一个接一个,不要混淆它们
最后,您需要在styles/*.xml文件中定义style formmat,在我的例子中是这样的
<style name="php:function" foreground="#0000ee" bold="false"/>
我使用php的地方应该是您的语言id,与*.lang文件中相同。您需要编辑语言定义文件以添加新的部分。语言定义是
python.lang
,对我来说是/usr/share/gtksourceview-2.0/language specs
首先需要为要创建的样式id添加样式:
然后,您需要在
No下为此文件添加一个新上下文,您需要在“def”上匹配,因为我相信海报希望def foo(a,b,c):
中的foo
以不同的颜色突出显示。您不能匹配foo
,因为用户可以随意调用函数。你需要一个正则表达式,它可以捕获def
之后和一个开括号(
)之前的任何内容。我不知道该怎么做。我也需要这个正则表达式,因为它有助于更容易地查找文件中的函数。你想要def foo(a,b,c)中的foo
吗:
以不同的颜色突出显示?这是我的理解,也是我所追求的。我刚刚注意到我假设您使用的是Python。我相信您可以为您尝试这样做的任何语言提出类似的规则。但是,您会注意到,这会从'def'关键字中删除突出显示。不太确定如何删除为了解决这个问题,您可能想看看Vim或Sublime Text的语言定义。@jozzas提供的答案对于Gtksourceview 2.0来说是很好的,但请允许我为3.0版省去一个沉重的负担:您创建的定义id也必须列在/usr/share/Gtksourceview-3.0/language-specs/python.lang.Th的最后一节中如上所述,后一部分中的列表顺序很重要。您可以通过指定以下内容从Gedit theme.xml文件调用样式,例如,
<style id="class-name" _name="Python Class Name" map-to="def:type"/>
<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>