Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 didn't make any 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!

share|improve this question
    
Down at the bottom of your post you said cd /usr/share/gtksourceview-3.0/language-specs. Is that the actual command you ran? If it is, you just need to move the file to /usr/local/share/gtksourceview-3.0/language-specs. –  evan.bovie Nov 29 '11 at 5:52
    
@emb1995 I have copied the folder gtksourceview-3.0 to /usr/local/share as you suggested (I say copied because the folder was located in /usr/share/ in my computer). Anyway, that did not seem to work for me, I still get plain text when choose the new highlighting file in gedit :( –  Oscar Saleta Reig Dec 1 '11 at 21:19
add comment

1 Answer

up vote 1 down vote accepted

I think I found out what went wrong for you:

Solution

It's good and right, that you changed the id (and _name) in the <language ...> tag. After all it is a new highlighting scheme you create.

However you then have to change also the other place in the file where this id is used. Further down in the language definition (omitted in the quote in the question) you find this:

<context id="fortran" class="no-spell-check">

Apparently, you have to have a context with the same id as you language including/referring all the used context definitions, so that gedit/GtkSourceView uses it when a specific scheme is chosen.

How I found it

I am not at all an expert in this. All my qualification is that I have seen XML files before ;) So I could only make "educated" guesses.

What tipped me off was a warning shown when starting gedit from a terminal window

(gedit:6786): GtkSourceView-WARNING **: Failed to load '/usr/local/share/gtksourceview-3.0/language-specs/frtrn.lang': Missing main language definition (id = "frtrn".)

(I used "frtrn" as id, name and file extension while testing, you should get the same warning with "*fortran_enhanced*")

This made me suspicious enough to search for the original ID in the rest of the file. After trying out the above solution I also found the following line to support my explanation:

[definitions] Here we should define a main context, the one we enter at the beginning of the file: to do so we use the tag, with an id equal to the id of the element [...]

It's from the language definition file tutorial in the GtkSourceView documentation.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.