From 28705030e0abbfbc3b157b47c23c71bc0a1bb703 Mon Sep 17 00:00:00 2001 From: Benjamin Tan Date: Sat, 20 Mar 2021 15:11:04 +0800 Subject: [PATCH 1/8] Add `:lang zig` module --- docs/modules.org | 1 + init.example.el | 1 + modules/lang/zig/config.el | 34 ++++++++++++++++++++++++++++++++++ modules/lang/zig/doctor.el | 13 +++++++++++++ modules/lang/zig/packages.el | 4 ++++ 5 files changed, 53 insertions(+) create mode 100644 modules/lang/zig/config.el create mode 100644 modules/lang/zig/doctor.el create mode 100644 modules/lang/zig/packages.el diff --git a/docs/modules.org b/docs/modules.org index 5b0834ca9..998c5286b 100644 --- a/docs/modules.org +++ b/docs/modules.org @@ -151,6 +151,7 @@ Modules that bring support for a language or group of languages to Emacs. + terra - TODO + web =+lsp= - HTML and CSS (SCSS/SASS/LESS/Stylus) support. + [[file:../modules/lang/yaml/README.org][yaml]] =+lsp= - TODO ++ [[file:../modules/lang/zig/README.org][zig]] =+lsp= - Zig support. * :os diff --git a/init.example.el b/init.example.el index 0e3cddb28..3d518d354 100644 --- a/init.example.el +++ b/init.example.el @@ -167,6 +167,7 @@ ;;terra ; Earth and Moon in alignment for performance. ;;web ; the tubes ;;yaml ; JSON, but readable + ;;zig ; C, but simpler :email ;;(mu4e +gmail) diff --git a/modules/lang/zig/config.el b/modules/lang/zig/config.el new file mode 100644 index 000000000..bf3008765 --- /dev/null +++ b/modules/lang/zig/config.el @@ -0,0 +1,34 @@ +;;; lang/zig/config.el -*- lexical-binding: t; -*- + +(after! projectile + (pushnew! projectile-project-root-files "build.zig")) + + +;; +;; zig-mode + +(use-package! zig-mode + :mode "\\.zig$" + :hook (zig-mode . rainbow-delimiters-mode) + :config + ;; Disable zig-mode's default format on save behaviour. + (setq zig-format-on-save nil) + (when (featurep! +lsp) + (add-hook 'zig-mode-local-vars-hook #'lsp!))) + +(map! :localleader + (:after zig-mode + :map zig-mode-map + "b" #'zig-compile + "f" #'zig-format-buffer + "r" #'zig-run + "t" #'zig-test-buffer)) + +(when (featurep! :checkers syntax) + (flycheck-define-checker zig + "A zig syntax checker using the zig-fmt interpreter." + :command ("zig" "fmt" (eval (buffer-file-name))) + :error-patterns + ((error line-start (file-name) ":" line ":" column ": error: " (message) line-end)) + :modes zig-mode) + (add-to-list 'flycheck-checkers 'zig)) diff --git a/modules/lang/zig/doctor.el b/modules/lang/zig/doctor.el new file mode 100644 index 000000000..ecbeca1a1 --- /dev/null +++ b/modules/lang/zig/doctor.el @@ -0,0 +1,13 @@ +;; -*- lexical-binding: t; no-byte-compile: t; -*- +;;; lang/zig/doctor.el + +(assert! (or (not (featurep! +lsp)) + (featurep! :tools lsp)) + "This module requires (:tools lsp)") + +(unless (executable-find "zig") + (warn! "Couldn't find zig binary")) + +(when (featurep! +lsp) + (unless (executable-find "zls") + (warn! "Couldn't find zls binary"))) diff --git a/modules/lang/zig/packages.el b/modules/lang/zig/packages.el new file mode 100644 index 000000000..b309a6a34 --- /dev/null +++ b/modules/lang/zig/packages.el @@ -0,0 +1,4 @@ +;; -*- no-byte-compile: t; -*- +;;; lang/zig/packages.el + +(package! zig-mode :pin "6f10653cc17b9c74150ac2f6833eaaaf55488398") From 27c553782abb49a0078db8339f377bce1a7f522f Mon Sep 17 00:00:00 2001 From: Benjamin Tan Date: Sat, 20 Mar 2021 15:40:21 +0800 Subject: [PATCH 2/8] Simplify `map!` call --- modules/lang/zig/config.el | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/modules/lang/zig/config.el b/modules/lang/zig/config.el index bf3008765..ded11fce2 100644 --- a/modules/lang/zig/config.el +++ b/modules/lang/zig/config.el @@ -14,10 +14,8 @@ ;; Disable zig-mode's default format on save behaviour. (setq zig-format-on-save nil) (when (featurep! +lsp) - (add-hook 'zig-mode-local-vars-hook #'lsp!))) - -(map! :localleader - (:after zig-mode + (add-hook 'zig-mode-local-vars-hook #'lsp!)) + (map! :localleader :map zig-mode-map "b" #'zig-compile "f" #'zig-format-buffer From 86ce548e5d8f7dcc8190432ad2733892829d4ffc Mon Sep 17 00:00:00 2001 From: Benjamin Tan Date: Mon, 5 Apr 2021 16:18:30 +0800 Subject: [PATCH 3/8] Update documentation --- modules/lang/zig/README.org | 67 ++++++++++++++++++++++++++++++++++++ modules/tools/lsp/README.org | 1 + 2 files changed, 68 insertions(+) create mode 100644 modules/lang/zig/README.org diff --git a/modules/lang/zig/README.org b/modules/lang/zig/README.org new file mode 100644 index 000000000..327a5eb34 --- /dev/null +++ b/modules/lang/zig/README.org @@ -0,0 +1,67 @@ +#+TITLE: lang/zig +#+DATE: March 18, 2021 +#+SINCE: v2.0.9 +#+STARTUP: inlineimages nofold + +* Table of Contents :TOC_3:noexport: +- [[#description][Description]] + - [[#maintainers][Maintainers]] + - [[#module-flags][Module Flags]] + - [[#plugins][Plugins]] +- [[#prerequisites][Prerequisites]] +- [[#features][Features]] + - [[#lsp-support][LSP support]] + - [[#keybinds][Keybinds]] +- [[#configuration][Configuration]] + - [[#customize-zls-path][Customize zls path]] + +* Description +This module adds [[https://ziglang.org/][Zig]] support, with optional (but recommended) LSP support via +[[https://github.com/zigtools/zls][zls]]. + ++ Syntax highlighting ++ Syntax-checking (~flycheck~) ++ Code completion and LSP integration (~zls~) + +** Maintainers ++ [[https://github.com/bnjmnt4n][@bnjmnt4n]] (Author) + +** Module Flags ++ =+lsp= Enables integration for the zls LSP server. It is highly recommended + you use this. + +** Plugins ++ [[https://github.com/ziglang/zig-mode][zig-mode]] + +* Prerequisites +To get started with Zig, you need the ~zig~ tool. Pre-built binaries for most +systems are available for download from [[https://ziglang.org/download/]] or from +[[https://github.com/ziglang/zig/wiki/Install-Zig-from-a-Package-Manager][system package managers]]. + +zls is a language server for Zig, which provides code completion, + +* Features +** LSP support +This module supports LSP integration. For it to work you'll need: + +1. zls installed. +2. The =:tools lsp= module enabled. Only =lsp-mode= is supported for now. +3. The ~+lsp~ flag on this module enabled. + +** Keybinds +| Binding | Description | +|-------------------+---------------------| +| ~ b~ | ~zig-compile~ | +| ~ f~ | ~zig-format-buffer~ | +| ~ r~ | ~zig-run~ | +| ~ t~ | ~zig-test-buffer~ | + +* Configuration +** Customize zls path +To customize the path of the =zls= executable, modify +~lsp-clients-zls-executable~. + +#+BEGIN_SRC elisp +;; in $DOOMDIR/config.el +(setq lsp-clients-zls-executable "~/path/to/zls") +#+END_SRC diff --git a/modules/tools/lsp/README.org b/modules/tools/lsp/README.org index 923c6aa83..bbd277d8e 100644 --- a/modules/tools/lsp/README.org +++ b/modules/tools/lsp/README.org @@ -56,6 +56,7 @@ As of this writing, this is the state of LSP support in Doom Emacs: | [[../../lang/swift/README.org][:lang swift]] | swift-mode | sourcekit | | [[../../lang/web/README.org][:lang web]] | web-mode, css-mode, scss-mode, sass-mode, less-css-mode | vscode-css-languageserver-bin, vscode-html-languageserver-bin | | [[../../lang/purescript/README.org][:lang purescript]] | purescript-mode | purescript-language-server | +| [[../../lang/zig/README.org][:lang zig]] | zig-mode | zls | ** Module Flags + =+peek= Use =lsp-ui-peek= when looking up definitions and references with From 608510276659f514e063b28c6c7cee1f63f8049d Mon Sep 17 00:00:00 2001 From: Benjamin Tan Date: Mon, 5 Apr 2021 16:19:55 +0800 Subject: [PATCH 4/8] Remove duplicate `:mode` declaration `zig-mode` already adds handles it. --- modules/lang/zig/config.el | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/lang/zig/config.el b/modules/lang/zig/config.el index ded11fce2..d73670fcf 100644 --- a/modules/lang/zig/config.el +++ b/modules/lang/zig/config.el @@ -8,7 +8,6 @@ ;; zig-mode (use-package! zig-mode - :mode "\\.zig$" :hook (zig-mode . rainbow-delimiters-mode) :config ;; Disable zig-mode's default format on save behaviour. From b90751bafbe56565868272fbba59c8b69966cb8b Mon Sep 17 00:00:00 2001 From: Benjamin Tan Date: Mon, 5 Apr 2021 16:49:39 +0800 Subject: [PATCH 5/8] Update variable name in documentation --- modules/lang/zig/README.org | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/lang/zig/README.org b/modules/lang/zig/README.org index 327a5eb34..da69d1b32 100644 --- a/modules/lang/zig/README.org +++ b/modules/lang/zig/README.org @@ -58,10 +58,9 @@ This module supports LSP integration. For it to work you'll need: * Configuration ** Customize zls path -To customize the path of the =zls= executable, modify -~lsp-clients-zls-executable~. +To customize the path of the =zls= executable, modify ~lsp-zig-zls-executable~. #+BEGIN_SRC elisp ;; in $DOOMDIR/config.el -(setq lsp-clients-zls-executable "~/path/to/zls") +(setq lsp-zig-zls-executable "~/path/to/zls") #+END_SRC From 66569e4d8880db0886a77a410914f075125e2901 Mon Sep 17 00:00:00 2001 From: Benjamin Tan Date: Mon, 5 Apr 2021 22:43:33 +0800 Subject: [PATCH 6/8] Shift `(when (featurep! +lsp))` expression outside of `use-package` --- modules/lang/zig/config.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/lang/zig/config.el b/modules/lang/zig/config.el index d73670fcf..f598a5db2 100644 --- a/modules/lang/zig/config.el +++ b/modules/lang/zig/config.el @@ -12,8 +12,6 @@ :config ;; Disable zig-mode's default format on save behaviour. (setq zig-format-on-save nil) - (when (featurep! +lsp) - (add-hook 'zig-mode-local-vars-hook #'lsp!)) (map! :localleader :map zig-mode-map "b" #'zig-compile @@ -21,6 +19,9 @@ "r" #'zig-run "t" #'zig-test-buffer)) +(when (featurep! +lsp) + (add-hook 'zig-mode-local-vars-hook #'lsp!)) + (when (featurep! :checkers syntax) (flycheck-define-checker zig "A zig syntax checker using the zig-fmt interpreter." From 2cecf3bf84657efc02d765e927db7879b47b01a8 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Wed, 14 Apr 2021 13:30:13 -0400 Subject: [PATCH 7/8] Minor refactors --- modules/lang/zig/config.el | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/modules/lang/zig/config.el b/modules/lang/zig/config.el index f598a5db2..733223254 100644 --- a/modules/lang/zig/config.el +++ b/modules/lang/zig/config.el @@ -1,32 +1,32 @@ ;;; lang/zig/config.el -*- lexical-binding: t; -*- (after! projectile - (pushnew! projectile-project-root-files "build.zig")) + (add-to-list 'projectile-project-root-files "build.zig")) ;; -;; zig-mode +;;; Packages (use-package! zig-mode :hook (zig-mode . rainbow-delimiters-mode) :config - ;; Disable zig-mode's default format on save behaviour. - (setq zig-format-on-save nil) + (setq zig-format-on-save (featurep! :editor format +onsave)) + + (when (featurep! +lsp) + (add-hook 'zig-mode-local-vars-hook #'lsp!)) + + (when (featurep! :checkers syntax) + (flycheck-define-checker zig + "A zig syntax checker using the zig-fmt interpreter." + :command ("zig" "fmt" (eval (buffer-file-name))) + :error-patterns + ((error line-start (file-name) ":" line ":" column ": error: " (message) line-end)) + :modes zig-mode) + (add-to-list 'flycheck-checkers 'zig)) + (map! :localleader :map zig-mode-map "b" #'zig-compile "f" #'zig-format-buffer "r" #'zig-run "t" #'zig-test-buffer)) - -(when (featurep! +lsp) - (add-hook 'zig-mode-local-vars-hook #'lsp!)) - -(when (featurep! :checkers syntax) - (flycheck-define-checker zig - "A zig syntax checker using the zig-fmt interpreter." - :command ("zig" "fmt" (eval (buffer-file-name))) - :error-patterns - ((error line-start (file-name) ":" line ":" column ": error: " (message) line-end)) - :modes zig-mode) - (add-to-list 'flycheck-checkers 'zig)) From 41c0b0b5c163a7e71674be3ce7c183f9ba2dc6c0 Mon Sep 17 00:00:00 2001 From: Benjamin Tan Date: Thu, 15 Apr 2021 11:23:16 +0800 Subject: [PATCH 8/8] Bump :lang zig ziglang/zig-mode@6f10653 -> ziglang/zig-mode@2d0eb23 --- modules/lang/zig/packages.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/lang/zig/packages.el b/modules/lang/zig/packages.el index b309a6a34..dd7274664 100644 --- a/modules/lang/zig/packages.el +++ b/modules/lang/zig/packages.el @@ -1,4 +1,4 @@ ;; -*- no-byte-compile: t; -*- ;;; lang/zig/packages.el -(package! zig-mode :pin "6f10653cc17b9c74150ac2f6833eaaaf55488398") +(package! zig-mode :pin "2d0eb23e6b5c12b946f12c23803157605c90f02f")