Modifying a gedit syntax highlighting file
- by Oscar Saleta Reig
I am trying to change a highlighting file from Gedit. I have modified the file /usr/share/gtksourceview-3.0/language-specs/fortran.lang because I want to change the cases in which the editor takes a statement as a comment. The problem I have is that when I choose the new highlighting scheme nothing highlights, it just remains as plain text.
The file fortran.lang was opened with su permissions and I just copy-pasted everything into a new Gedit file and later saved it as fortran_enhanced.lang in the same folder. The changes I've done to the original file are these:
Original fortran.lang file:
<language id="fortran" _name="Fortran 95" version="2.0" _section="Sources">
<metadata>
<property name="mimetypes">text/x-fortran</property>
<property name="globs">*.f;*.f90;*.f95;*.for</property>
<property name="line-comment-start">!</property>
</metadata>
<styles>
<style id="comment" _name="Comment" map-to="def:comment"/>
<style id="floating-point" _name="Floating Point" map-to="def:floating-point"/>
<style id="keyword" _name="Keyword" map-to="def:keyword"/>
<style id="intrinsic" _name="Intrinsic function" map-to="def:builtin"/>
<style id="boz-literal" _name="BOZ Literal" map-to="def:base-n-integer"/>
<style id="decimal" _name="Decimal" map-to="def:decimal"/>
<style id="type" _name="Data Type" map-to="def:type"/>
</styles>
<default-regex-options case-sensitive="false"/>
<definitions>
<!-- Note: contains an hack to avoid considering ^COMMON a comment -->
<context id="line-comment" style-ref="comment" end-at-line-end="true" class="comment" class-disabled="no-spell-check">
<start>!|(^[Cc](\b|[^OoAaYy]))</start>
<include>
<context ref="def:escape"/>
<context ref="def:in-line-comment"/>
</include>
</context>
(...)
Modified fortran_enhanced.lang file:
<!-- Note: changed language id and name -->
<language id="fortran_enhanced" _name="Fortran 95 2.0" version="2.0" _section="Sources">
<metadata>
<property name="mimetypes">text/x-fortran</property>
<!-- Note: removed *.f and *.for from file extensions -->
<property name="globs">*.f90;*.f95;</property>
<property name="line-comment-start">!</property>
</metadata>
<styles>
<style id="comment" _name="Comment" map-to="def:comment"/>
<style id="floating-point" _name="Floating Point" map-to="def:floating-point"/>
<style id="keyword" _name="Keyword" map-to="def:keyword"/>
<style id="intrinsic" _name="Intrinsic function" map-to="def:builtin"/>
<style id="boz-literal" _name="BOZ Literal" map-to="def:base-n-integer"/>
<style id="decimal" _name="Decimal" map-to="def:decimal"/>
<style id="type" _name="Data Type" map-to="def:type"/>
</styles>
<default-regex-options case-sensitive="false"/>
<definitions>
<!-- Note: I want comments only beginning with !, not C -->
<context id="line-comment" style-ref="comment" end-at-line-end="true" class="comment" class-disabled="no-spell-check">
<start>!</start>
<include>
<context ref="def:escape"/>
<context ref="def:in-line-comment"/>
</include>
</context>
(...)
I have read this question [ Custom gedit Syntax Highlighting for Dummies? ] and I tried to make the new fortran_enhanced.lang file readable with
$ cd /usr/share/gtksourceview-3.0/language-specs
$ sudo chmod 0644 fortran_enhanced.lang
but it doesn't seem that made some difference.
I have to say that I have never done a thing like this before and I don't even understand most of the language file, so I am open to every criticism, as I have been guided purely by intuition.
Thank you in advanced!