;;; init-programming.el --- Configure things related to programming -*- lexical-binding: t -*- ;; Author: Franck Cuny ;;; Commentary: ;; Configure things related to programming ;;; Code: ;; `elec-pair' is a built-in minor-mode that enables auto-pairing of parens (or ;; similar delimiters). (use-package elec-pair :hook (prog-mode . electric-pair-mode)) (use-package compile :ensure nil :hook (compilation-filter . ansi-color-compilation-filter) :custom (compilation-always-kill t) (compilation-context-lines 10) (compilation-disable-input t) (compilation-scroll-output 'first-error) (compilation-scroll-output t) (compilation-skip-threshold 2) ;; Save all buffers on M-x `compile' (compilation-ask-about-save nil)) (use-package eldoc :diminish :hook ((emacs-lisp-mode) . eldoc-mode) :custom (eldoc-idle-delay 1) (eldoc-documentation-strategy #'eldoc-documentation-default) ;; Don't resize the echo area if the documentation is longer. This is very ;; distracting when combined with Eglot's highlight functionality. (eldoc-echo-area-use-multiline-p nil)) (use-package tree-sitter :ensure t :config (global-tree-sitter-mode)) (use-package tree-sitter-langs :after tree-sitter :ensure t) (use-package direnv :ensure t :custom (direnv-always-show-summary nil) :config (direnv-mode)) (use-package emacs-lisp-mode :bind (:map emacs-lisp-mode-map ("C-c C-r" . eval-region) ("C-c C-d" . eval-defun) ("C-c C-b" . eval-buffer)) :hook ((emacs-lisp-mode . flymake-mode))) (use-package eglot :after yasnippet :bind (:map eglot-mode-map ("C-c l a" . eglot-code-actions) ("C-c l r" . eglot-rename) ("C-c l f" . eglot-format-buffer)) :hook ((go-mode . eglot-ensure) (python-mode . eglot-ensure) (nix-mode . eglot-ensure)) :custom (eglot-send-changes-idle-time 0.1) :config (setq eglot-autoshutdown t ;; Disable logging of events. eglot-events-buffer-size 0) (setq-default eglot-workspace-configuration '(:pylsp (:plugins (:ruff (:enabled t))) :nil (:formatting (:command ["nixfmt"])) :gopls (:usePlaceholders t :staticcheck t :completeUnimported t :matcher "CaseSensitive"))) ;; uses https://github.com/nix-community/nixd for the LSP server instead of rnix (add-to-list 'eglot-server-programs '(nix-mode . ("nil")))) (use-package dape :ensure t :hook ((kill-emacs . dape-breakpoint-save) ; Save breakpoints on quit (dape-compile . kill-buffer) ; Kill compile buffer on build success (dape-display-source . pulse-momentary-highlight-one-line) ; Pulse source line (performance hit) (dape-stopped . dape-info) ; To display info and/or repl buffers on stopped (dape-stopped . dape-repl) (dape-start . (lambda () (save-some-buffers t t)))) ; Save buffers on startup, useful for interpreted languages :config (dape-breakpoint-global-mode) (setq dape-buffer-window-arrangement 'gud) (setq dape-inlay-hints t)) ;;; go related configuration (use-package go-mode :ensure t :defer t :hook ((go-mode . tree-sitter-hl-mode) (go-mode . (lambda () (setq tab-width 4))) (go-mode . (lambda () (add-hook 'before-save-hook 'eglot-format-buffer nil t)))) :bind (:map go-mode-map ("C-c C-c" . compile))) (use-package gotest :ensure t :after go-mode :custom (go-test-verbose t)) ;;; nix related configuration (use-package nix-mode :ensure t :hook ((nix-mode . (lambda () (add-hook 'before-save-hook 'eglot-format-buffer nil t)))) :custom (nix-indent-function 'nix-indent-line)) ;;; justfile (use-package just-mode :ensure t) (use-package justl :ensure t) ;;; python related configuration (use-package python-mode :hook ((python-mode . tree-sitter-hl-mode))) (use-package ruby-mode) ;;; flymake related configuration (use-package flymake :ensure nil :defer t :bind (:prefix "C-c !" :prefix-map flymake-prefix-map ("l" . consult-flymake) ("b" . flymake-show-project-diagnostics) ("n" . flymake-goto-next-error) ("p" . flymake-goto-prev-error)) :hook (prog-mode . flymake-mode) :custom (flymake-start-on-save-buffer t) (flymake-fringe-indicator-position 'left-fringe) (flymake-suppress-zero-counters t) (flymake-proc-compilation-prevents-syntax-check t) (flymake-no-changes-timeout 9999) (elisp-flymake-byte-compile-load-path load-path)) ;;; JSON related modules (use-package json-mode :ensure t :defer t :mode "\\.json\\'") (use-package json-reformat :defer t :ensure t :after json-mode) (use-package jq-mode :defer t :ensure t :mode "\\.jq\\'") ;;; hashicorp related modules (use-package terraform-mode :defer t :ensure t :mode "\.tf\\'") (use-package hcl-mode :defer t :ensure t :mode "\.nomad\\'") ;;; TOML related modules (use-package toml-mode :defer t :ensure t) ;;; YAML related modules (use-package yaml-mode :defer t :ensure t) ;;; docker related modules (use-package docker :defer t :bind ("C-c d" . docker) :ensure t :diminish :init (use-package docker-image :commands docker-images) (use-package docker-volume :commands docker-volumes) (use-package docker-network :commands docker-containers) (use-package docker-compose :commands docker-compose) (use-package docker-container :commands docker-containers :custom (docker-containers-shell-file-name "/bin/bash") (docker-containers-show-all nil))) (use-package docker-compose-mode :defer t :ensure t :mode "docker-compose.*\.yml\\'") (use-package dockerfile-mode :defer t :ensure t :mode "Dockerfile[a-zA-Z.-]*\\'") (use-package protobuf-mode :defer t :ensure t :mode "\\.proto\\'") ;;; css related configuration (use-package css-mode :ensure nil :custom (css-indent-offset 2) (cssm-indent-level 1)) (provide 'init-programming) ;;; init-programming.el ends here