ziglang / zig-mode

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

format code on file save #12

Closed gozes closed 4 years ago

gozes commented 5 years ago

It nice if this mode supported formant on save like the vim plugin dose

cantsin commented 4 years ago

You can do something like this (zig needs to be on your path):

(defun zig-format ()
  "Zig format the buffer."
  (interactive)
  (shell-command (format "zig fmt %s" (buffer-file-name)))
  (revert-buffer :ignore-auto :noconfirm))

(use-package zig-mode
  :defer t
  :mode ("\\.zig\\'" . zig-mode)
  :config (add-hook 'after-save-hook #'zig-format))