-
Notifications
You must be signed in to change notification settings - Fork 0
/
ontop-elixir.el
225 lines (193 loc) · 7.28 KB
/
ontop-elixir.el
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
223
224
225
;;; ontop-elixir.el --- Elixir configuration -*- lexical-binding: t; -*-
;; This file is part of Emacs ONTOP
;; https://github.com/monkeyjunglejuice/emacs.ontop
;;; Commentary:
;; You can also use this file/configuration independently from Emacs ONTOP
;; Load it from anywhere via `(load-file "/path/to/ontop-elixir.el")'.
;;; Code:
;; ____________________________________________________________________________
;;; USE-PACKAGE
;; <https://github.com/jwiegley/use-package>
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package nil))
(eval-when-compile
(require 'use-package))
;; ____________________________________________________________________________
;;; ELIXIR TREESIT MODE
;; <https://github.com/wkirschbaum/elixir-ts-mode>
(use-package elixir-ts-mode
:ensure t)
;; In order to use Tree Sitter, install the tree-sitter binary with your OS
;; package manager. Then install the language grammar via
;; 'M-x treesit-install-language-grammar'
(use-package treesit
:ensure nil
:config
(add-to-list 'treesit-language-source-alist
'(elixir "https://github.com/elixir-lang/tree-sitter-elixir"))
(add-to-list 'treesit-language-source-alist
'(heex "https://github.com/phoenixframework/tree-sitter-heex")))
;; ____________________________________________________________________________
;;; REPL
(use-package inf-elixir
:ensure t
:custom
(inf-elixir-switch-to-repl-on-send nil)
:config
(defun inf-elixir-recompile ()
"Send `IEx.Helpers.recompile/1' to recompile the current Mix project.
Note this function simply recompiles Elixir modules, without reloading
configuration or restarting applications."
(interactive)
(inf-elixir--send (format "recompile()"))
(if inf-elixir-switch-to-repl-on-send
(goto-char (point-max))))
(defun inf-elixir-observer ()
"Start the Erlang Observer in IEx."
(interactive)
(inf-elixir--send (format ":observer.start()")))
:hook
((elixir-ts-mode heex-ts-mode) . inf-elixir-minor-mode)
:bind
;; Reach the REPL from anywhere via global key binding
(:map ctl-z-x-map
("e" . 'inf-elixir))
(:map elixir-ts-mode-map
("C-c C-z" . inf-elixir-project)
("C-c C-l" . inf-elixir-send-line)
("C-c C-r" . inf-elixir-send-region)
("C-c C-b" . inf-elixir-send-buffer)
("C-c C-c" . inf-elixir-recompile)
("C-c c" . inf-elixir-reload-module)
("C-c C-o" . inf-elixir-observer)))
;; ____________________________________________________________________________
;;; LANGUAGE SERVER
;; <https://github.com/joaotavora/eglot/blob/master/MANUAL.md>
;; Common keybindings are configured in `./ontop-core.el'
;; Elixir-ls language server is used per default in this setup.
;; Here's an Elixir language server comparison:
;; <https://gist.github.com/Nezteb/dc63f1d5ad9d88907dd103da2ca000b1>
;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
;;; ELIXIR-LS
;; <https://github.com/elixir-lsp/elixir-ls>
(use-package eglot
:ensure t
:custom
;; A longer timeout seems required for the first run in a new project
(eglot-connect-timeout 60) ; default: 30
:config
;; Make sure to adapt the path and use the .bat script for Windows
(add-to-list 'eglot-server-programs
'((elixir-ts-mode heex-ts-mode) . ("elixir-ls")))
:hook
;; Start language server automatically
((elixir-ts-mode heex-ts-mode) . eglot-ensure)
;; Tell the language server to format the buffer before saving
((elixir-ts-mode heex-ts-mode) .
(lambda ()
(add-hook 'before-save-hook
#'eglot-format-buffer nil 'local))))
;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
;;; NEXT-LS
;; <https://www.elixir-tools.dev/docs/next-ls/quickstart/>
;; Credo-support is already built in <https://hex.pm/packages/credo>.
;; Add Credo to your project file `mix.exs' and issue the shell command
;; 'mix deps.get'
;; (use-package eglot
;; :ensure t
;; :config
;; ;; Make sure to edit the path appropriately, use the .bat script for Windows
;; (add-to-list 'eglot-server-programs
;; '((elixir-ts-mode heex-ts-mode) .
;; ("nextls" "--stdio=true"
;; :initializationOptions
;; (:experimental (:completions (:enable t))))))
;; :hook
;; ;; Start language server automatically
;; ((elixir-ts-mode heex-ts-mode) . eglot-ensure)
;; ;; Tell the language server to format the buffer before saving
;; ((elixir-ts-mode heex-ts-mode) .
;; (lambda ()
;; (add-hook 'before-save-hook
;; #'eglot-format-buffer nil 'local))))
;; ____________________________________________________________________________
;;; MIX
;; <https://hexdocs.pm/mix/1.12/Mix.html>
(use-package mix
:ensure t
:diminish mix-minor-mode
:hook
((elixir-ts-mode heex-ts-mode) . mix-minor-mode))
;; ____________________________________________________________________________
;;; FLYCHECK CREDO
;; <http://credo-ci.org/>
;; Static analyzer and syntax checker. Must be installed first as a
;; project dependency in `mix.exs' and will be available afterwards:
;;
;; defp deps do
;; [
;; {:credo, "~> 1.7", only: [:dev, :test], runtime: false}
;; ]
;; end
;;
;; Run `mix deps.get' afterwards, and then `mix credo'
;; (use-package flycheck
;; :ensure t
;; :hook
;; (elixir-ts-mode . flycheck-mode))
;; (use-package flycheck-credo
;; :ensure t
;; :custom
;; (flycheck-elixir-credo-strict t)
;; :hook
;; (flycheck-mode . flycheck-credo-setup))
;; ____________________________________________________________________________
;;; EXUNIT
;; <https://github.com/ananthakumaran/exunit.el>
(use-package exunit
:ensure t
:diminish exunit-mode
:custom
(transient-default-level 4)
:hook
(elixir-ts-mode . exunit-mode))
;; ____________________________________________________________________________
;;; ERLANG
;; <https://www.erlang.org/doc/apps/tools/erlang_mode_chapter.html>
(use-package erlang
:ensure t
:defer t)
;; ____________________________________________________________________________
;;; PARENTHESIS DISPLAY
;; Rainbow-delimiters color-coding of nested parens is already enabled
;; for all prog-modes in `ontop-core.el'
(use-package rainbow-delimiters
:ensure t
:hook
(inf-elxir-mode . rainbow-delimiters-mode))
;; Make parens styleable, e.g. more or less prominent
;; <https://github.com/tarsius/paren-face>
;; (use-package paren-face
;; :ensure t
;; :hook
;; ((elixir-ts-mode inf-elixir-mode) . paren-face-mode))
;; ____________________________________________________________________________
;;; ORG-MODE BABEL
;; <https://orgmode.org/worg/org-contrib/babel/index.html>
;; Notebook-like literate programming in Emacs
;; Evaluate Elixir code in Org source code blocks via "C-c C-c"
;; TODO -- not working, package might be outdated
;; <https://github.com/zweifisch/ob-elixir>
;; (use-package ob-elixir
;; :ensure t)
;; (use-package org
;; :ensure nil
;; :hook
;; (org-mode . (lambda ()
;; (org-babel-do-load-languages
;; 'org-babel-load-languages
;; (add-to-list 'org-babel-load-languages '(elixir . t))))))
;; _____________________________________________________________________________
(provide 'ontop-elixir)
;;; ontop-elixir.el ends here