Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Following my question from long ago, I am still trying to tweak my fortune handling capabilities. The display in terminal is awesome, just one thing remains - syntax highlighting in Gedit as I add, edit or delete individual fortunes.

My custom fortune files are in this format:

Friend: "Whats a good movie?"
Me: "Snakes on a plane"
Friend: "Whats it about?"
Me: "Horses... horses on a boat..."
@AYYSIAN
%
Me on my wedding: you still like me, right?
@ComedyPosts
%
Mum: Son I'd love to meet your girlfriend...
Me: Me too...
@ComedyTruth
%
Doctor: "Ok, so what's wrong, how are you feeling?"
Me: *Looks at mum waiting for her to explain*
@ChildhoodFact
%
Friend: 75% of people are good at maths...
Me: Mmmmh, I guess then am in the remaining 18%...
@TheFunnyTeens
%
I loved the Titanic. My favorite character was the iceberg
@__GrumpyCat

It's basically a tweet, @name and the % character. Then repeat.

When I open it in Gedit, everything is black.
I'm looking for a way to create a syntax highlighting file that will convert the % to something like blue and the @name to something like magenta. The tweet can remain black.

NOTE:

  1. The fortune files are mime-type text/plain and only the given format really distinguishes them from another plain text file.
  2. Fortune files have no extension.
share|improve this question

1 Answer 1

up vote 4 down vote accepted

Create and open your fortune language file:

sudo /usr/share/gtksourceview-3.0/language-specs/fortune.lang
gksudo gedit /usr/share/gtksourceview-3.0/language-specs/fortune.lang

Paste the following:

<?xml version="1.0" encoding="UTF-8"?>
<language id="fortune" _name="Fortune" version="2.0" _section="Markup">
  <metadata>
    <property name="mimetypes">text/plain</property>
    <property name="globs">*.</property>
  </metadata>

  <styles>
    <style id="at"      _name="@ sign"  map-to="def:constant" />
    <style id="percent" _name="percent sign"  map-to="def:comment" />
  </styles>
  <definitions>
    <context id="fortune">
      <include>
        <context id="at" style-ref="at">
          <start>@</start>
          <end>$</end>
        </context>
        <context id="percent" style-ref="percent">
          <start>%</start>
          <end>$</end>
        </context>
      </include>
    </context>
  </definitions>
</language>

Make sure it is accessible:

sudo chmod 0644 /usr/share/gtksourceview-2.0/language-specs/screenplay.lang

Restart gedit.

Reference - my source answer

share|improve this answer
    
Thanks alot, will try this out. One thing though, fortune files have no extension, the reason for the text/plain mime type. Does that mean <property name="globs">*.fort</property> becomes <property name="globs">*</property>? –  Parto May 28 at 4:39
    
@Parto That would apply it to all files with no extension, but as most are .txt that would be fine. Change it to <property name="globs">*.</property>, and I've updated the answer with this! –  Tim May 28 at 9:13

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.