9

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.

1 Answer 1

9

Create and open your fortune language file:

sudo touch /usr/share/gtksourceview-3.0/language-specs/fortune.lang
sudo -i 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

My pronouns are He / Him

4
  • 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, 2014 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, 2014 at 9:13
  • 2
    Massive thanks. I just used this to add Twig syntax highlighting to gedit.
    – TRiG
    Oct 26, 2016 at 15:36
  • @TRiG Glad to have helped!
    – Tim
    Oct 26, 2016 at 18:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .