Cg highlight for Geany

I know that many Panda users, like me, use Geany as their editor of choice. Geany has one drawback, though – it lacks proper syntax highlighting for Cg. Sure, you can use C/C++ highlighting, but that’s far from ideal since it even lacks float2, float4 and so on. I got tired of that, so I wrote a filetypes definition for Cg (couldn’t find any on the Internet, surprisingly).

It highlights the reserved keywords, types, standard library functions and (in a different color) binding semantics.

Disclaimer: This is probably imperfect as it was born out of pure frustration :wink:. I used the official Cg Language Specification and the Cg Standard Library reference, but I’m not sure if there aren’t any typos, stupid mistakes or missed keywords (especially with the horrible syntax Geany uses in the definitions…). If you spot any, let me know or… just fix it and repost :wink:.

Paste the following into a file named filetypes.Cg.conf. The name is case-sensitive (it must match the definition in another file, explained below) and it must contain the “.conf” part despite that most files you have there don’t have it – this is because Geany differs between built in (no .conf) and custom (with .conf) file definitions. Drop the file into ~/.config/geany/filedefs/ or /usr/share/geany/filedefs/. I don’t know where that directory is on Windows, unfortunately:

[styling=C]

[keywords]
# all items must be in one line
primary=asm explicit pixelfragment template asm_fragment extern pixelshader texture auto FALSE private texture1D bool fixed protected texture2D break float public texture3D case for register textureCUBE catch friend reinterpret_cast textureRECT char get return this class goto row_major throw column_major half sampler TRUE compile if sampler_state try const in sampler1D typedef const_cast inline sampler2D typeid continue inout sampler3D typename decl int samplerCUBE samplerRECT uniform default interface shared union delete long short unsigned discard matrix signed using do mutable sizeof vector double namespace static vertexfragment dword new static_cast vertexshader dynamic_cast operator string virtual else out struct void emit packed switch volatile enum pass technique while glstate int1x1 int1x2 int1x3 int1x4 int2x1 int2x2 int2x3 int2x4 int3x1 int3x2 int3x3 int3x4 int4x1 int4x2 int4x3 int4x4 float1x1 float1x2 float1x3 float1x4 float2x1 float2x2 float2x3 float2x4 float3x1 float3x2 float3x3 float3x4 float4x1 float4x2 float4x3 float4x4 double1x1 double1x2 double1x3 double1x4 double2x1 double2x2 double2x3 double2x4 double3x1 double3x2 double3x3 double3x4 double4x1 double4x2 double4x3 double4x4 fixed1x1 fixed1x2 fixed1x3 fixed1x4 fixed2x1 fixed2x2 fixed2x3 fixed2x4 fixed3x1 fixed3x2 fixed3x3 fixed3x4 fixed4x1 fixed4x2 fixed4x3 fixed4x4 half1x1 half1x2 half1x3 half1x4 half2x1 half2x2 half2x3 half2x4 half3x1 half3x2 half3x3 half3x4 half4x1 half4x2 half4x3 half4x4 float2 float3 float4 fixed2 fixed3 fixed4 int2 int3 int4 half2 half3 half4 double2 double3 double4 dot lerp tex1D tex2D tex1Dproj tex2Dproj tex3D tex3Dproj texRECT texCUBE texCUBEproj abs acos all any asin atan atan2 ceil clamp cos cosh cross degrees determinant dot exp exp2 floor fmod frac frexp isfinite isinf isnan ldexp lerp lit log log2 log10 max min modf mul noise pow radians round rsqrt saturate sign sin sincos sinh smoothstep step sqrt tan tanh transpose distance faceforward length normalize reflect refract ddx ddy debug

# TYPE2 TYPE3 TYPE4
# TYPE1x1 TYPE1x2 TYPE1x3 TYPE1x4 TYPE2x1 TYPE2x2 TYPE2x3 TYPE2x4 TYPE3x1 TYPE3x2 TYPE3x3 TYPE3x4 TYPE4x1 TYPE4x2 TYPE4x3 TYPE4x4

secondary=POSITION NORMAL COLOR COLOR0 COLOR1 COL0 COL1 DEPTH TEXUNIT0 TEXUNIT1 TEXUNIT2 TEXUNIT3 TEXUNIT4 TEXUNIT5 TEXUNIT6 TEXUNIT7 TEXUNIT8 TEXUNIT9 TEXUNIT10 TEXUNIT11 TEXUNIT12 TEXUNIT13 TEXUNIT14 TEXUNIT15 TEXCOORD0 TEXCOORD1 TEXCOORD2 TEXCOORD3 TEXCOORD4 TEXCOORD5 TEXCOORD6 TEXCOORD7 TEXCOORD8 TEXCOORD9 TEXCOORD10 TEXCOORD11 TEXCOORD12 TEXCOORD13 TEXCOORD14 TEXCOORD15 BLENDWEIGHT DIFFUSE SPECULAR FOGCOORD ATTR0 ATTR1 ATTR2 ATTR3 ATTR4 ATTR5 ATTR6 ATTR7 ATTR8 ATTR9 ATTR10 ATTR11 ATTR12 ATTR13 ATTR14 ATTR15 PSIZE HPOS PSIZ FOG FOGC BCOL0 BCOL1 TEX0 TEX1 TEX2 TEX3 TEX4 TEX5 TEX6 TEX7 TEX8 TEX9 TEX10 TEX11 TEX12 TEX13 TEX14 TEX15 TESSFACTOR BLENDINDICES TEXCOORD TANGENT BINORMAL CLP0 CLP1 CLP2 CLP3 CLP4 CLP5 WPOS DEPR
# 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

[lexer_properties]
styling.within.preprocessor=1
lexer.cpp.track.preprocessor=0
preprocessor.symbol.$(file.patterns.cpp)=#
preprocessor.start.$(file.patterns.cpp)=if ifdef ifndef
preprocessor.middle.$(file.patterns.cpp)=else elif
preprocessor.end.$(file.patterns.cpp)=endif

[settings]
tag_parser=C
lexer_filetype=C

# default extension used when saving files
extension=sha

# single comments, like # in this file
comment_single=//
# multiline comments
comment_open=/*
comment_close=*/
comment_use_indent=true

[indentation]

[build_settings]

And finally add this to filetype_extensions.conf:

Cg=*.sha;*.cg

Make sure you remove the *.sha or *.cg extension from C or C++, if you added it there (which you probably did, otherwise you would’ve cut yourself by now, I guess :wink: ).

Now restart Geany and you should have nice syntax highlighting for Cg.

If not, make sure the “Cg” part is identical in the filename in filedefs and in the filetype_extensions.conf file and that you don’t have *.sha (or *.cg ) bound to anything else in filetype_extensions.conf.

Thanks for sharing! I was too lazy to make something like this and just used Cg as C++ :slight_smile: Now Geany will be more comfortable, thanks )

Just a bit OT: is it possible to have panda3d autocompletion with Geany?