[Snek] Using 'black' to format python code in snek

Keith Packard keithp at keithp.com
Tue Feb 18 15:54:01 PST 2020


"Mikhail Gusarov" <dottedmag at dottedmag.net> writes:

> What do you think about using an auto-formatter for C code?

I've been convinced in the past; X.org adopted a coding style that has
mostly stuck.

> The most surprising thing writing C again after couple of years of Go was
> the amount of manual formatting needed to write code.

Some of the formatting can be automated with most editors designed for
code, but there are times when you just want to use custom formatting to
try and make the code clearer.

> I even added a config file for clang-format in snek-ev3, but only managed
> to produce something resembling, but not identical to the code style in
> the rest of the project.

Sorry 'bout that. I haven't seen an C formatter that can reproduce how I
format code. Not that I'm consistent, as you say, it takes a lot of
manual formatting.

I just went and poked around with 'indent', 'astyle', and
'clang-format'; they all seem to have limitations, although clang-format
says it can do what I want, it doesn't manage to actually do that.

I think 'indent' is the best current option; here's the settings I'm
using:

#!/bin/sh

INDENT=`which gnuindent || which gindent || which indent`

if [ -z "${INDENT}" ] ; then
    echo "Could not find indent, sorry..." >&2
    exit 1
fi

TYPES=" -T snek_offset_t
	-T snek_soffset_t
	-T snek_poly_t
	-T snek_id_t
	-T snek_op_t
	-T snek_forward_t
	-T snek_type_t
	-T snek_mem_t
	-T snek_list_type_t
	-T snek_list_t
	-T snek_code_t
	-T snek_range_t
	-T snek_in_t
	-T snek_func_t
	-T snek_name_t
	-T snek_variable_t
	-T snek_frame_t
	-T snek_slice_t
	-T snek_builtin_t
	-T snek_buf_t
	-T snek_token_val_t
	-T snek_parse_ret_t"

$INDENT -linux -psl -par $TYPES -cs -bs -lp -di16 "$@"

-- 
-keith
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <http://keithp.com/pipermail/snek/attachments/20200218/e5d1e695/attachment.sig>


More information about the Snek mailing list