Openscad code formatter
Scat depends on Fig for reading the format config files. Fig can be obtained from https://github.com/thespookman/fig
Building Scat will also need flex, which is included by default in many linux distros.
Building Fig will need bison.
Scat uses g++ by default, but can probably be compiled with other C++ compilers, just edit the Makefile if you want. Otherwise, just use the following commands to build:
git clone https://github.com/thespookman/scat.git && cd scad && make all
scat file1 [file2...]
Scat will format each file passed as an argument in place i.e. it will overwrite the original file. It will make formatting decisions based on the contents of a config file, if found.
Scat will look for a config file called .scad-format in the working directory, if it doesn't find one, it will check the parent directory, and so on. This allows the user to specify different formats for different projects, if desired.
If no config file is found, a set of default settings will be used, which result in compactly formatted code, with tabs for indentation.
.scad-format files should be made up key-value pairs, each pair being on its own line, with an equals sign in between the key and value.
Following is a list of valid keys, with their default values:
comma padding = 0the number of spaces after each comma.function padding = 1the number of spaces before each function call, when called in sequence (e.g.translate([1,1,1]) rotate([45,0,0]) cube([1,1,1]);.indent spaces = 4when used withindent type = spaces, sets the size of indents.indent type = tabssets whether to use tabs or spaces for indentation.line after function = 0the number of blank lines to be inserted after each function definition.line after module = 0the number of blank lines to be inserted after each module definition.no new identifiers afterhas no default. If to a number, when functions are called in sequence (e.g.translate([1,1,1]) rotate([45,0,0]) cube([1,1,1]);), functions that start further right than the specified number of columns will be moved to a new line.one function per line = falseif set to true, functions called in sequence will each be on a new line, but indented.operator padding = 0the number of spaces before and after any operator.pad before angular = 0the number of spaces before angular brackets (e.g. inuse <file.scad>)pad before comment = 0when a comment follows code on the same line, the number of spaces in between the end of the code and the//. Has no effect when used withtab before comment = true.pad before brace = 0the number of spaces between the parameter list and opening brace in module definitions etc.pad before bracket = 0the number of spaces between the function identifier and opening bracket of the parameter list in function calls and definitions etc.pad comment start = 0the number of spaces between the//and the first word of comments.pad inside angular = 0the number of spaces either side of the file name inside angular brackets.pad inside bracket = 0the number of spaces either side of the parameter list inside brackets.pad inside square = 0the number of spaces either side of an array inside suqare brackets.tab before comment = falseoverridespad before commentto use a tab instead of spaces.tab width = 4when used withno new identifiers after, sets the number of columns taken by tabs when calculating line length.
Keys and values are case-insensitive, and whitespace (except the spaces inside key strings) is ignored. Any line without an equals will be ignored, so can be used as comments.