[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/zig-mode e0bccb1 047/104: add zig-format-buffer command
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/zig-mode e0bccb1 047/104: add zig-format-buffer command |
Date: |
Sun, 29 Aug 2021 11:37:00 -0400 (EDT) |
branch: elpa/zig-mode
commit e0bccb1114be0e03e8a507076e6ad5e9b9f6ee8b
Author: Marcio Giaxa <i@mgxm.me>
Commit: Marcio Giaxa <i@mgxm.me>
add zig-format-buffer command
By default the value of `zig-format-on-save` is set to `t`, meaning
that the code is automatically formatted before saves, to disable it,
you can set it to nil.
Besides that, you can toggle the behavior on certain buffers using
`M-x zig-toggle-format-on-save`.
* adds defcustom:
- zig-format-on-save
- zig-zig-bin
* adds defun:
- zig-toggle-format-on-save
- zig-format-buffer
---
zig-mode.el | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 51 insertions(+), 2 deletions(-)
diff --git a/zig-mode.el b/zig-mode.el
index d0f8500..833eb0e 100644
--- a/zig-mode.el
+++ b/zig-mode.el
@@ -34,6 +34,51 @@
:type 'integer
:group 'zig-mode
:safe #'integerp)
+
+(defcustom zig-format-on-save t
+ "Format buffers before saving using zig fmt."
+ :type 'boolean
+ :safe #'booleanp
+ :group 'zig-mode)
+
+(defcustom zig-zig-bin "zig"
+ "Path to zig executable."
+ :type 'string
+ :safe #'stringp
+ :group 'zig-mode)
+
+;; zig CLI commands
+
+;;;###autoload
+(defun zig-toggle-format-on-save ()
+ "Switch format before save on current buffer."
+ (interactive)
+ (if zig-format-on-save
+ (setq-local zig-format-on-save nil)
+ (setq-local zig-format-on-save t)))
+
+
+;;;###autoload
+(defun zig-format-buffer ()
+ "Format the current buffer using the zig fmt."
+ (interactive)
+ (let ((fmt-buffer-name "*zig-fmt*"))
+ ;; If we have an old *zig-fmt* buffer, we want to kill
+ ;; it and start a new one to show the new errors
+ (when (get-buffer fmt-buffer-name)
+ (kill-buffer fmt-buffer-name))
+ (let ((fmt-buffer (get-buffer-create fmt-buffer-name)))
+ (set-process-sentinel
+ (start-process "zig-fmt"
+ fmt-buffer
+ zig-zig-bin
+ "fmt"
+ (buffer-file-name))
+ (lambda (process _e)
+ (when (> (process-exit-status process) 0)
+ (switch-to-buffer-other-window fmt-buffer)
+ (compilation-mode)))))))
+
(defun zig-re-word (inner)
"Construct a regular expression for the word INNER."
(concat "\\<" inner "\\>"))
@@ -313,9 +358,13 @@
(setq-local imenu-generic-expression zig-imenu-generic-expression)
(setq font-lock-defaults '(zig-font-lock-keywords
nil nil nil nil
- (font-lock-syntactic-face-function
- . zig-mode-syntactic-face-function))))
+ (font-lock-syntactic-face-function .
zig-mode-syntactic-face-function)))
+
+ (add-hook 'before-save-hook 'zig-before-save-hook nil t))
+(defun zig-before-save-hook ()
+ (when zig-format-on-save
+ (zig-format-buffer)))
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.zig\\'" . zig-mode))
- [nongnu] elpa/zig-mode 4f281e4 020/104: Changed repository location, (continued)
- [nongnu] elpa/zig-mode 4f281e4 020/104: Changed repository location, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode c5315ff 026/104: Apply font-lock-doc-face to doc comments (for issue #5), ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode c2deea8 037/104: Merge pull request #14 from mgxm/imenu, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 52e3e20 004/104: README., ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode bc1bed3 009/104: Fix package, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 1d26390 015/104: Merge pull request #3 from purcell/patch-1, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 0ed57d8 014/104: Minor fixes, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode e659a58 024/104: Set comment-start and comment-end (for issue #5) (#7), ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode b773127 027/104: Initial implementation of indent-line-function, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 9c200f4 032/104: Add -y flag to apt-get command in AppVeyor install script, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode e0bccb1 047/104: add zig-format-buffer command,
ELPA Syncer <=
- [nongnu] elpa/zig-mode 2acd88f 049/104: add zig-mode-map with default keybinding, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 0a150f2 054/104: Merge pull request #19 from mgxm/fix_multiline_string, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 64994f1 053/104: Merge pull request #17 from xuchunyang/master, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 9609cc3 055/104: Merge pull request #21 from SerialDev/master, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode fab1924 066/104: fix test regression, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode f9e5c57 065/104: Merge pull request #28 from justjosias/pre-doc-comment, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 2426668 070/104: Remove `this` constant, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode e110c29 073/104: Merge pull request #29 from joachimschmidt557/test-regression, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 6d78a6e 074/104: Fix appveyor.yml, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 9b44e04 075/104: Merge pull request #38 from mdsteele/appveyor, ELPA Syncer, 2021/08/29