ziglang / zig-mode

Zig mode for Emacs
GNU General Public License v3.0
163 stars 54 forks source link

Use reformatter.el for `zig fmt` #39

Closed joachimschmidt557 closed 1 year ago

joachimschmidt557 commented 3 years ago

https://github.com/purcell/reformatter.el provides an easy interface to provide idiomatic formatting commands. Using this library would make it would be possible to move a lot of the code which deals with zig fmt from this package to reformatter.el. Of course, this means that this mode has one more Elisp package as a dependency.

joachimschmidt557 commented 3 years ago

Issues with current buffer reformatting which would be solved by using reformatter.el:

Due to this, I would suggest that we consider this proposal and weigh the advantages with the disadvantage of having one additional dependency.

GarbageHamburger commented 3 years ago

Most of the programming major modes in Emacs do not seem to have explicit code formatting functionality, but rather, packages such as https://github.com/lassik/emacs-format-all-the-code are used. Coupled with LSP support for formatting via zls, is there a need to have explicit formatting support in zig-mode?

joachimschmidt557 commented 3 years ago

If the zig fmt is not used often by users of zig-mode, we can also consider removing that. But I personally use it all the time and the format on save functionality helps me a lot. zig-mode already supports compiling, running and testing zig source files, so formatting is not very far-fetched.

Seeing zig.vim also having formatting and format on save builtin, I support keeping formatting functionality and moving it to reformatter.el.

GarbageHamburger commented 3 years ago

I see. I will look into adding this myself, I'm also looking into #13 as that significantly improves interop, but I am in no way an expert elisp hacker ^^.

Inc0n commented 2 years ago

I want to add my zig-mode format experience here, given that it's very useful to have hints about my zig code, it doesn't play well with undo-hist, and cause it to prompt buffer-undo-list is not empty. Do you want to recover now? (y or n) every time zig formats on before save hook.

jiacai2050 commented 1 year ago

Hi @joachimschmidt557 I try your forked version, https://github.com/ziglang/zig-mode/pull/51/files

it works amazing, since zls is not very stable now, so I suggest we merge it in master.

PS: I guess no one care one more package, besides its author is purcell, master of elisp.

jiacai2050 commented 1 year ago

I'm a long-time rust-format-buffer user, and there is no such logic in there

Maybe we can follow what rust-mode does, pass stdin to zig fmt, and reinsert via replace-buffer-contents when succeed

joachimschmidt557 commented 1 year ago

See #75: I will merge this PR on the 1st of January 2023.