Skip to content

Instantly share code, notes, and snippets.

@Sciancisco
Last active September 20, 2023 00:04
Show Gist options
  • Save Sciancisco/d1f5f1ea50481633ee1a2d270416543b to your computer and use it in GitHub Desktop.
Save Sciancisco/d1f5f1ea50481633ee1a2d270416543b to your computer and use it in GitHub Desktop.
Gedit groff syntax highlight
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2020 - Sciancisco
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the <organization> nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<language id="groff" name="groff" version="2.0" _section="Markup">
<metadata>
<property name="mimetypes">test/plain</property>
<property name="globs">*.tmac;*.mom;*.ms;*.me;*.mm;*.1;*.2;*.3;*.4;*.5;*.6;*.7;*.8</property>
</metadata>
<styles>
<style id="comment" name="Comment" map-to="def:comment"/>
<style id="escaped-character" name="Escaped Character" map-to="def:special-char"/>
<style id="macro" name="Macro" map-to="def:function"/>
<style id="request" name="Request" map-to="def:builtin"/>
<style id="preprocessor" name="Preprocessor Macro" map-to="def:preprocessor"/>
</styles>
<definitions>
<context id="groff">
<include>
<context id="comment-new" style-ref="comment" class="comment">
<start>\\#</start>
<end>$</end>
</context>
<context id="comment-old" style-ref="comment" class="comment">
<start>\\"</start>
<end>$</end>
</context>
<!-- Here starts the escape sequences mimicking the groff spec. -->
<!-- If one wants to implement the entire spec, have fun: https://web.cecs.pdx.edu/~trent/gnu/groff/groff.html#SEC52 -->
<context id="escape-bracket" style-ref="escaped-character" class="no-spell-check">
<start>\\[[]</start>
<end>[]]</end>
</context>
<context id="escape-bracket-parameter" style-ref="escaped-character" class="no-spell-check">
<start>\\.[[]</start>
<end>[]]</end>
</context>
<context id="escape-parenthesis" style-ref="escaped-character" class="no-spell-check">
<match>\\[(]..</match>
</context>
<context id="escape-parenthesis-parameter" style-ref="escaped-character" class="no-spell-check">
<match>\\.[(]..</match>
</context>
<context id="escape-simple-parameter" style-ref="escaped-character" class="no-spell-check">
<match>\\..</match>
</context>
<context id="escape-simple" style-ref="escaped-character" class="no-spell-check">
<match>\\.</match>
</context>
<!-- Highlight preprocessors -->
<!-- Maybe add preprocessor syntax coloring. -->
<!-- Many preprocessors are missing. -->
<context id="eqn" style-ref="preprocessor" class="no-spell-check">
<!-- Could be nice to add in line highlight with "delim" eqn command -->
<start>^\.EQ(\s|$)</start>
<end>^\.EN</end>
</context>
<context id="pic" style-ref="preprocessor" class="no-spell-check">
<start>^\.PS(\s|$)</start>
<end>^\.PE</end>
</context>
<context id="tbl" style-ref="preprocessor" class="no-spell-check">
<start>^\.TS(\s|$)</start>
<end>^\.TE</end>
</context>
<context id="chem" style-ref="preprocessor" class="no-spell-check">
<start>^\.cstart(\s|$)</start>
<end>^\.cend</end>
</context>
<context id="refer-opt" style-ref="preprocessor" class="no-spell-check">
<start>^\.R1(\s|$)</start>
<end>^\.R2</end>
</context>
<context id="refer-cite" style-ref="preprocessor">
<start>^\.[[]</start>
<end>^\.[]]</end>
</context>
<!-- General macro and request matching -->
<context id="macro" style-ref="macro" class="no-spell-check">
<match>^\.[A-Z0-9_]+</match>
</context>
<context id="request" style-ref="request" class="no-spell-ckeck">
<match>^\.[a-z]+</match>
</context>
</include>
</context>
</definitions>
</language>
@Sciancisco
Copy link
Author

Definition of the groff syntax for GtkSourceView.

This file is to be put in one of:

  • /usr/share/gtksourceview-/language-specs/groff.lang (system wide)
  • ~/.local/share/gtksourceview-/language-specs/groff.lang (user specific)

Once there, an editor using GtkSource View for syntax highlighting (like Gedit or Gnome Builder) should pick it up.

@nerun
Copy link

nerun commented Oct 16, 2022

Very good, thank you! Forked it with few changes.

@Sciancisco i need to talk to you. Is possible to change this license to LGPL 2.1+?

@Sciancisco
Copy link
Author

Oh! Sorry for the ghost...

What is your case for LGPL?

@Sciancisco
Copy link
Author

I just saw it is for a merge request in GtkSourceView!

In this case I accept to the re-licensing, if it is not too late since the merge request is closed.

Kinda feel bad for not reading earlier...

@nerun
Copy link

nerun commented Sep 20, 2023

It's all right, I already gave up anyway. But thanks for responding. Greetings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment