Zift; configurable ZIg FormaTter

Hello.

This is just somethingI am planning to have fun with. I forked a couple of files from the Zig Standard Library to expose configuration options. Only indents for now, but I’d love ideas and contributions.

// zift.zon 
.{
	.indent = .tabs,
	// .indent = .{ .spaces = 4 }, // or any number up to 15.
}

It is currently configurable via a zift.zon file at working directory.

I am yet to wire it up to my editor.

9 Likes

cursed!

:heart_hands:

7 Likes

To set it up in Zed make sure it is in your PATH and add this to settings.json

"languages": {
	// other languages go here.
	"Zig": {
		"formatter": {
			"external": {
				"command": "zift",
				"arguments": ["--stdin"],
			},
		},
	}
},```

Hello.

Since the og posting I added two config options and brought a bunch of bug fixes from upsteam

here is the current default config

// zift.zon
.{
        .indent = .tabs,
        .single_item_whitespace = true,
        .indent_switch_cases = true,
}

Note the last default option is the same behaviour as zig fmt. But now you have the option!

you can also pass --config zigfmt to the cli to just use zig fmt config.

I also added a justfile for a quick install command so you dont have to remember the incantation.

1 Like

a bit off topic

but Zift in arabic, have the following meanings

  1. literal meaning, tar , used in road pavement etc ..
  2. metaphorical meaning, bad, dirty, low quality, ugly etc ..

its funny because it goes against code formatting which is supposed to make code look nice, pretty and not zift :stuck_out_tongue:

maybe you should name it !zift :grinning_face_with_smiling_eyes:

2 Likes

if you open the repo you’ll see a picture of an asphalt road.

1 Like

Do you have a repo on codeberg? Apparently I can’t make ssh work with sourcehut.

unfortunately not. but the ssh is only needed for write access. There is an https option

Oh this is fantastic, thank you! My only current gripe with zig fmt as a blind user is the forcing of four-space indents, because they’re multiple arrow presses. Thanks a ton for letting me use my “cursed” tabs!

1 Like

Yes that’s write access that I needed (in my own fork of course), it just doesn’t want to push there and I gave up. I uploaded my fork on codeberg if you want to check it out (you could merge the commits manually from there if you are interested).

https://codeberg.org/gmbajo/zift

Note that much code is AI-written with some manual edits, so don’t just merge it blindly (if you want to merge something), I did some tests on my own code and it seems ok but I have to test it more.

1 Like

Anyway for the license I think it should remain MIT, it’s derivative work, and could even get in the way for future changes in zig fmt. Not sure what you like about the Mozilla license.