Working emacs config for zig

Hi Zig enthusiasts and experts,

Does anyone could kindly share working emacs eglot + zls config snippets? And also hints how to tweak it to work greatly?

Thank you very much in advance!

Cheers,

Pawel

I can’t help on eglot, but I installed ziglang/zig-mode: Zig mode for Emacs. - Codeberg.org and the added the snippet below to my init.el to invoke lsp-mode when I edit zig files.

(use-package lsp-mode
  :init
  ;; set prefix for lsp-command-keymap (few alternatives - "C-l", "C-c l")
  (setq lsp-keymap-prefix "C-c l")
  :hook (
         (zig-mode . lsp)
         ;; if you want which-key integration
         (lsp-mode . lsp-enable-which-key-integration))
  :commands lsp)
1 Like

Since emacs 29 eglot is included in its core.
All you have to do is to install zig-mode and start eglot.

  • Run M-x package-install RET zig-mode RET
  • Load a zig file (syntax coloring must be enabled) and then run M-x eglot RET (you must be able to see the argument names in the function calls and the types with gray colors).

Documentation for zls setup for emacs: GNU Emacs - zigtools

1 Like
(use-package zig-mode
  :config
  ;; these are the defaults
  (setq zig-indent-offset 4)
  (setq zig-format-on-save t)
  (setq zig-run-optimization-mode “Debug”)
  :ensure t)

(use-package eglot
  :init
  (setq read-process-output-max (* 1024 1024))
  (add-hook 'zig-mode-hook 'eglot-ensure)
  :config
  (setq eglot-autoshutdown t)
  (setq eglot-ignored-server-capabilities '(:inlayHintProvider))
  :ensure t)
1 Like