Home Filter manual [0101] [Filt] [Math] [Pwr] Examples Utilities
Go back to:

Searching the Internet for a syntax highlighting file for SPICE netlists/models/libraries/etc I found a certain file that was well below my expectations (I won't say which one). It was for gEdit which is what I was searching for, true, but it didn't "make the cut". I also found out about another one, for Kate. I would have gotten that one if it proved satisfactory, but it didn't, so I made my own. Until then I had no idea what PCRE means or does but, within a week or so, I had a usable configuration that fit my needs. I had sent it to GtkSourceView team, maybe they would incorporate this in their release, but so far it's currently pending. It's not quite what I had in mind, but probably for the better, my original plan involved much more complicated things which, no doubt, would have slowed everything down. It probably looks very childish, programming-wise, but it does the job.
Why? Because working with libraries and subcircuits becomes much easier, spotting variables and functions in large(r) blocks of .params or .funcs isn't a hunt for characters, .model statements are easily recognizable and all of this is done without too many colors that would only put a strain on the eyes. At least, this purpose serves me, may it serve others, as well.
I also made a colour theme to match the colours used by LTspice, to feel more "at home". It's nothing much, really, just the Kate colour theme, modified and adapted. To each his own, I suppose.

Below is a comparative example of how a netlist or a library looks like when opened with a text editor based on GtkSourceView (gEdit, Mousepad, Scribes, that I know of) compared to what LTspice shows. Don't mind the bogus entries, they're for exemplification, only. Also, the colours used are those of the colour theme.
custom syntax highlighting LTspice highlighting
* Example netlist/library (*.net, *.cir, *.sp)
.param x=1/(2*pi) Ron=0.5 Roff=1k Vt=0.5 Vh=-0.1
+ y=2*pi
.func MyFunc(x) {1+x}
V1 1 0 SIN(0 1 1)
R1 1 2 R=MyFunc(time)
L1 2 0 {y}
X1 2 0 SUBCIRCUIT Value={x} ;externally defined
A1 2 0 0 0 0 0 3 0 SCHMITT vt=0 vh=0
S1 0 2 3 0 MySW
.model MySW SW(Ron={Ron} Roff={Roff} Vt={Vt} Vh={Vh})
.subckt SUBCIRCUIT in out
.param Value=1
C1 in out {Value}
.ends SUBCIRCUIT
.tran 10
.backanno
.end
* Example netlist/library (*.net, *.cir, *.sp)
.param x=1/(2*pi) Ron=0.5Roff=1k Vt=0.5 Vh=-0.1
+ y=2*pi
.func MyFunc(x) {1+x}
V1 1 0 SIN(0 1 1)
R1 1 2 R=MyFunc(time)
L1 2 0 {y}
X1 2 0 SUBCIRCUIT Value={x} ;externally defined
A1 2 0 0 0 0 0 3 0 SCHMITT vt=0 vh=0
S1 0 2 3 0 MySW
.model MySW SW(Ron={Ron} Roff={Roff} Vt={Vt} Vh={Vh})
.subckt SUBCIRCUIT in out
.param Value=1
C1 in out {Value}
.ends SUBCIRCUIT
.tran 10
.backanno
.end

The archive, syntax.zip (5852 B) contains the syntax highlighting spice.lang and the colour theme, spice.xml. They are for either versions of GtkSourceView, 2.x or 3.x, but their installment is different.

For GtkSourceView 2.x, spice.lang is placed into
~/.local/share/gtksourceview-2.0/language-specs/spice.lang
and spice.xml into
~/.local/share/gtksourceview-2.0/styles/spice.xml


For GtkSourceView 3.x, spice.lang is placed into
~/.local/share/gtksourceview-3.0/language-specs/spice.lang
and spice.xml into
~/.local/share/gedit/styles/spice.xml

After installing, the files with the extensions *.net, *.cir, *.sp, *.lib, *.sub and *.mod should be automatically recognized and the SPICE highlight mode will be used. The colour theme, if desired, can be selected in the editor's preferences. For example, in gEdit it's in: Edit > Preferences > Fonts&Colours > SPICE.






































































































©Vlad, 2014 - 2015