Board index FlightGear Development Nasal

Nasal syntax highlighting for Geany

Nasal is the scripting language of FlightGear.

Nasal syntax highlighting for Geany

Postby Bjoern » Tue Jan 28, 2020 1:17 am

This is rudimentary filetype file for syntax highlighting in Geany, a lightweight, multiplatform editor and IDE based on Scintilla and my favourite tool of the trade.
It's based on Geany's default C# filetype and is not perfect, as much of the highlighting depends on Geany's lexer definitions, which are unfortunately hard-coded.

I had to work around the visual code folding rules which would start a fold by detecting an "if" (or similar), regardless of the line being commented out or not*, by defining a fake multiline comment rule. So in order to not make commented out code blocks containing an "if" (or similar) fold, wrap it in "#(" and "#)".


Installation:

1) Find Geany's user configuration directory (OS dependant): https://www.geany.org/manual/current/#c ... file-paths

2) In "[user dir]/filedefs", create an empty text file. Paste this code below into that file and save it.

Code: Select all
# For complete documentation of this file, please see Geany's main documentation
[styling=C]

[keywords]
# all items must be in one line
primary=abstract as base bool break byte case catch char checked class const continue decimal default delegate do double else enum event explicit extern false finally fixed float for foreach goto if implicit in int interface internal is lock long namespace new null object operator out override params private protected public readonly ref return sbyte sealed short sizeof stackalloc static string struct switch this throw true try typeof uint ulong unchecked unsafe ushort using virtual void volatile while
secondary=add alias ascending async await descending dynamic from get global group into join let orderby partial remove select set value var where yield
# these are some doxygen keywords (incomplete)
docComment=attention author brief bug class code date def enum example exception file fn namespace note param remarks return see since struct throw todo typedef var version warning union
# keywords: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/

[lexer_properties]

[settings]
lexer_filetype=C

# default extension used when saving files
extension=nas

# MIME type
#mime_type=text/x-csharp

# the following characters are these which a "word" can contains, see documentation
#wordchars=_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789

# single comments, like # in this file
comment_single=#
# multiline comments
comment_open=#(
comment_close=#)

# set to false if a comment character/string should start at column 0 of a line, true uses any
# indentation of the line, e.g. setting to true causes the following on pressing CTRL+d
   #command_example();
# setting to false would generate this
#   command_example();
# This setting works only for single line comments
comment_use_indent=true

# context action command (please see Geany's main documentation for details)
context_action_cmd=

[indentation]
width=3
# 0 is spaces, 1 is tabs, 2 is tab & spaces
type=1


3) Rename the text file to "filetypes.Nasal.conf". The file name is case sensitive, i.e. "Nasal" must start with a capital "N"!

4) Replace the content of "~/.config/geany/filetype_extensions.conf" with the one below.
All I did was add an entry for Nasal to the default list of filetypes in the "[Extensions]" section and add Nasal to the "Script=" line in the "[Groups]" section.
Note that this file has a higher priority than the default one in "/usr/share/geany" and is by default deactivated, with all filetypes commented out.
(Folder paths will differ on Windows and OSX.)

Code: Select all
# Filetype extension configuration file for Geany
# Insert as many items as you want, separate them with a ";".
# See Geany's main documentation for details.
[Extensions]
Abaqus=*.inp;
Abc=*.abc;*.abp;
ActionScript=*.as;
Ada=*.adb;*.ads;
Arduino=*.ino;*.pde;
Asciidoc=*.asciidoc;*.adoc;
ASM=*.asm;*.asm51;*.a51;*.s;*.S;*.sx;
Batch=*.bat;*.cmd;*.nt;
CAML=*.ml;*.mli;
C=*.c;*.xpm;
C++=*.cpp;*.cxx;*.c++;*.cc;*.h;*.hpp;*.hxx;*.h++;*.hh;*.C;*.H;
Clojure=*.clj;*.cljs;*.cljc;
CUDA=*.cu;*.cuh;*.h;
C#=*.cs;
CMake=CMakeLists.txt;*.cmake;*.ctest;
COBOL=*.cob;*.cpy;*.cbl;*.cobol;
CoffeeScript=*.coffee;Cakefile;*.Cakefile;*.coffee.erb;*.iced;*.iced.erb;
Conf=*.conf;*.ini;config;*rc;*.cfg;*.desktop;*.properties;
CSS=*.css;
Cython=*.pyx;*.pxd;*.pxi;
D=*.d;*.di;
Diff=*.diff;*.patch;*.rej;
Docbook=*.docbook;
Erlang=*.erl;*.hrl;
F77=*.f;*.for;*.ftn;*.f77;*.F;*.FOR;*.FTN;*.fpp;*.FPP;
Ferite=*.fe;
Forth=*.fs;*.fth;
Fortran=*.f90;*.f95;*.f03;*.f08;*.F90;*.F95;*.F03;*.F08;
FreeBasic=*.bas;*.bi;*.vbs;
Genie=*.gs;
GLSL=*.glsl;*.frag;*.vert;
Go=*.go;
Graphviz=*.gv;*.dot;
Groovy=*.groovy;*.gradle;
Haskell=*.hs;*.lhs;*.hs-boot;*.lhs-boot;
Haxe=*.hx;
HTML=*.htm;*.html;*.shtml;*.hta;*.htd;*.htt;*.cfm;*.tpl;
Java=*.java;*.jsp;
Javascript=*.js;
JSON=*.json;
Kotlin=*.kt;*.kts;
LaTeX=*.tex;*.sty;*.idx;*.ltx;*.latex;*.aux;*.bib;
Lisp=*.lisp;
Lua=*.lua;
Make=*.mak;*.mk;GNUmakefile;makefile;Makefile;makefile.*;Makefile.*;
Markdown=*.mdml;*.markdown;*.md;*.mkd;*.mkdn;*.mdwn;*.mdown;*.mdtxt;*.mdtext;
Matlab/Octave=*.m;
Nasal=*.nas
Nim=*.nim;
NSIS=*.nsi;*.nsh;
Objective-C=*.m;*.mm;*.h;
Pascal=*.pas;*.pp;*.inc;*.dpr;*.dpk;
Perl=*.pl;*.perl;*.pm;*.agi;*.pod;
PHP=*.php;*.php3;*.php4;*.php5;*.phtml;
Po=*.po;*.pot;
Python=*.py;*.pyw;SConstruct;SConscript;wscript;
PowerShell=*.ps1;*.psm1;
reStructuredText=*.rest;*.reST;*.rst;
R=*.R;*.r;
Rust=*.rs;
Ruby=*.rb;*.rhtml;*.ruby;*.gemspec;Gemfile;rakefile;Rakefile;
Scala=*.scala;*.scl;
Sh=*.sh;configure;configure.in;configure.in.in;configure.ac;*.ksh;*.mksh;*.zsh;*.ash;*.bash;.bashrc;bash.bashrc;.bash_*;bash_*;*.m4;PKGBUILD;*profile;
SQL=*.sql;
Swift=*.swift;
Tcl=*.tcl;*.tk;*.wish;*.exp;
Txt2tags=*.t2t;
TypeScript=*.ts;
Vala=*.vala;*.vapi;
Verilog=*.v;
VHDL=*.vhd;*.vhdl;
XML=*.xml;*.sgml;*.xsl;*.xslt;*.xsd;*.xhtml;*.xul;*.dtd;*.xtpl;*.mml;*.mathml;
YAML=*.yaml;*.yml;
Zephir=*.zep;
None=*;

# Note: restarting is required after editing groups
[Groups]
Programming=Arduino;Clojure;CUDA;Cython;Genie;Groovy;Kotlin;Nim;Scala;Swift;
Script=Graphviz;TypeScript;Nasal
Markup=
Misc=JSON;
None=


Save the modified file

5) That should be it. The next time you open up a Nasal file in Geany, you should see some (more or less) pleasant coloring. ;)



If you want to customize or improve "filetypes.Nasal.conf" further, read Geany's documentation about fileytpe definition files: https://www.geany.org/manual/current/#f ... tion-files



* Does Nasal suport multiline comments in the first place?
Bjoern
 
Posts: 484
Joined: Fri Jan 06, 2012 11:00 pm
Location: TXL (RIP)
Version: Next
OS: ArchLinux

Re: Nasal syntax highlighting for Geany

Postby Hooray » Tue Jan 28, 2020 5:46 pm

It'd be a good idea to add your contribution to the wiki, see: http://wiki.flightgear.org/Howto:Syntax ... _for_Nasal
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: Nasal syntax highlighting for Geany

Postby Bjoern » Tue Jan 28, 2020 6:20 pm

Done. :)
Bjoern
 
Posts: 484
Joined: Fri Jan 06, 2012 11:00 pm
Location: TXL (RIP)
Version: Next
OS: ArchLinux

Re: Nasal syntax highlighting for Geany

Postby Hooray » Tue Jan 28, 2020 6:32 pm

Another easy way to get involved in the wiki is mentioning such new additions in the newsletter, especially if you have screen shots or youtube videos that can be added. You can usually copy the relevant portion of text from the new/updated article and then link to the actual article from the newsletter.

Also, should you decide to contribute your joystick script to the wiki in the form of a new tutorial, that could not just be added to the tutorial section/navbar but also to the newsletter
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: Nasal syntax highlighting for Geany

Postby Bjoern » Tue Jan 28, 2020 10:02 pm

I don't think that a Nasal script or syntax highlighter is enough of an eyecatcher to warrant a mention in a newsletter. Whenever I read the newsletter in the past couple of years, I was looking for more...mundane things such as new feature in aircraft x, a newly developed aircraft y and new feature additions or significant improvements to the core simulator. You know, the more general things.

An addition to the wiki is, of course, another thing for the sake of presenting information.
Bjoern
 
Posts: 484
Joined: Fri Jan 06, 2012 11:00 pm
Location: TXL (RIP)
Version: Next
OS: ArchLinux

Re: Nasal syntax highlighting for Geany

Postby Hooray » Tue Jan 28, 2020 10:15 pm

When I suggested doing that, I didn't expect that you had only added a single sentence to the wiki linking back to the forum - as a matter of fact, if you look at the remaining wiki article, you will see that it grew organically, often also by copying forum postings over to the wiki and editing them as needed - and once you take a look at the newsletter history, you will also see that a number of people did in fact mention their contributions there. Again, it's obviously your call - but you probably wouldn't have created the Geany style had someone else mentioned his own Geany style in the newsletter, would you ? So, there's that, too.
Like you say, it's a tiny and trivial thing to do - but that's how the wiki article started out, too.

Finally, if you are hoping for this to evolve/grow over time, the wiki is obviously a better place than a forum posting, that only you can edit/contribute to.

The newsletter is a community-effort, so what might be of zero interest to you, might be of interest to others - and vice versa.
Aggregating news/events and new contributions in the newsletter is an easy way to get involved, many people consider their contributions marginal, but still the newsletter needs active contributors, too - and many people seem somewhat shy to add their own work to it, even though that's exactly what it was meant for originally. So, I wouldn't underestimate your contributions.
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: Nasal syntax highlighting for Geany

Postby Bjoern » Wed Jan 29, 2020 7:57 pm

Hooray wrote in Tue Jan 28, 2020 10:15 pm:When I suggested doing that, I didn't expect that you had only added a single sentence to the wiki linking back to the forum - as a matter of fact, if you look at the remaining wiki article, you will see that it grew organically, often also by copying forum postings over to the wiki and editing them as needed - and once you take a look at the newsletter history, you will also see that a number of people did in fact mention their contributions there.


I beg to differ. An overview article about syntax highlighters for various editors is not the place to copy+paste a complete forum posting as it just adds the clutter that I find so irritating about other articles.
A separate article maybe, but then again, you'd have to add articles containing the code for all the other syntax highlighters for other editors as well so the single article about Geany doesn't look like the odd thing out between other, more focused articles.

If you think that having the complete first post in the Wiki is more helpful, just post it there. I won't mind.

Again, it's obviously your call - but you probably wouldn't have created the Geany style had someone else mentioned his own Geany style in the newsletter, would you ? So, there's that, too.
Like you say, it's a tiny and trivial thing to do - but that's how the wiki article started out, too.


My decision stands. The newsletter is not the place to announce something as a meager highlighter. If there's a requirement for things to put in there, there's a lot more important development going on. RGATC, Shuttle, compositor, OSM2City world build, etc.
If I was to develop something with a larger potential impact, it would be something different.

Finally, if you are hoping for this to evolve/grow over time, the wiki is obviously a better place than a forum posting, that only you can edit/contribute to.


This subject is open to everybody and individual posts can be linked to in the wiki, so I don't see a problem if somebody posts an improved script here and amends the section in the wiki.

The newsletter is a community-effort, so what might be of zero interest to you, might be of interest to others - and vice versa.
Aggregating news/events and new contributions in the newsletter is an easy way to get involved, many people consider their contributions marginal, but still the newsletter needs active contributors, too - and many people seem somewhat shy to add their own work to it, even though that's exactly what it was meant for originally. So, I wouldn't underestimate your contributions.


Again: Mind the scope. A new Nasal tutorial or overhaul of the Wiki section would definitely be worth a mention, a bit of a code example isn't.
Bjoern
 
Posts: 484
Joined: Fri Jan 06, 2012 11:00 pm
Location: TXL (RIP)
Version: Next
OS: ArchLinux


Return to Nasal

Who is online

Users browsing this forum: No registered users and 2 guests