summary refs log tree commit diff
path: root/config/init-programming.el
blob: 886725d9bcfde26925d314cde395c766f1a5fb9d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
;;; init-programming.el --- Configure things related to programming -*- lexical-binding: t -*-
;; Author: Franck Cuny <franck@fcuny.net>

;;; 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"))))

;;; 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