1
1
[ ![ License GPL 3] [ badge-license ]] ( http://www.gnu.org/licenses/gpl-3.0.txt )
2
2
[ ![ Build Status] ( https://github.com/elixir-editors/emacs-elixir/actions/workflows/ci.yml/badge.svg )] ( https://github.com/elixir-editors/emacs-elixir/actions )
3
+ [ ![ NonGNU ELPA] ( https://elpa.nongnu.org/nongnu/elixir-mode.svg )] ( https://elpa.nongnu.org/nongnu/elixir-mode.html )
3
4
[ ![ MELPA Stable] ( http://stable.melpa.org/packages/elixir-mode-badge.svg )] ( http://stable.melpa.org/#/elixir-mode )
4
5
[ ![ MELPA] ( http://melpa.org/packages/elixir-mode-badge.svg )] ( http://melpa.org/#/elixir-mode )
5
6
7
+ > ** WARNING**
8
+ > There is a built-in Elixir mode with tree-sitter support from Emacs 30+ that can also be used with Emacs 29
9
+ > This repository is for an older elixir-mode built with SMIE (Simple Minded Indentation Engine) which is not
10
+ > as advanced as tree-sitter for a language like Elixir.
11
+
6
12
# Elixir Mode
7
13
8
14
Provides font-locking, indentation and navigation support for the
9
15
[ Elixir programming language.] ( http://elixir-lang.org/ )
10
16
11
- - [ Installation] ( #installation )
12
- - [ Via package.el] ( #via-packageel )
13
- - [ Via el-get] ( #via-el-get )
14
- - [ Manual] ( #manual )
15
- - [ Usage] ( #usage )
16
- - [ Interactive Commands] ( #interactive-commands )
17
- - [ Configuration] ( #configuration )
18
- - [ Keymapping] ( #keymapping )
19
- - [ Notes] ( #notes )
20
- - [ Elixir Tooling Integration] ( #elixir-tooling-integration )
21
- - [ Elixir Format] ( #elixir-format )
22
- - [ Treesitter Support] ( #treesitter-support )
23
- - [ History] ( #history )
24
- - [ Contributing] ( #contributing )
25
- - [ License] ( #license )
26
-
27
17
## Installation
28
18
19
+ ` elixir-mode ` is available on [ NON-GNU ELPA] ( https://elpa.nongnu.org/ ) ,
20
+ [ MELPA STABLE] ( https://stable.melpa.org/ ) and [ MELPA] ( https://melpa.org/ ) .
21
+
29
22
### Via package.el
30
23
31
24
` package.el ` is the built-in package manager in Emacs.
32
25
33
- ` elixir-mode ` is available on the two major community maintained repositories -
34
- [ MELPA STABLE] ( https://stable.melpa.org/ ) and [ MELPA] ( https://melpa.org/ ) .
35
-
36
26
You can install ` elixir-mode ` with the following command:
37
27
38
28
<kbd >M-x package-install [ RET] elixir-mode [ RET] </kbd >
@@ -52,20 +42,20 @@ If the installation doesn't work try refreshing the package list:
52
42
Keep in mind that MELPA packages are built automatically from
53
43
the ` master ` branch, meaning bugs might creep in there from time to
54
44
time. Never-the-less, installing from MELPA is the recommended way of
55
- obtaining ` Elixir-Mode ` , as the ` master ` branch is normally quite stable and
56
- "stable" (tagged) builds are released somewhat infrequently.
45
+ obtaining ` Elixir-Mode ` .
57
46
58
- With the most recent builds of Emacs, you can pin ` Elixir-Mode ` to always
59
- use MELPA Stable by adding this to your Emacs initialization:
47
+ MELPA Stable contains packages released from our tags.
60
48
61
- ### Manual
49
+ ### Via use-package
62
50
63
- You can install ` Elixir-Mode ` manually by placing ` Elixir-Mode ` on your ` load-path ` and
64
- ` require ` ing it. Many people favour the folder ` ~/.emacs.d/vendor ` .
51
+ Since Emacs 29, ` use-package ` is a built-in feature. For versions prior to 29
52
+ one can also install it from MELPA (and MELPA Stable) .
65
53
66
- ``` el
67
- (add-to-list 'load-path "~/.emacs.d/vendor")
68
- (require 'elixir-mode)
54
+ To install elixir-mode using ` use-package ` one can:
55
+
56
+ ``` elisp
57
+ (use-package elixir-mode
58
+ :ensure t)
69
59
```
70
60
71
61
## Usage
@@ -141,20 +131,17 @@ This package is tested only with a single version of OTP and 3 versions of Elixi
141
131
142
132
## Elixir Tooling Integration
143
133
144
- If you looking for elixir tooling integration for Emacs, check: [ alchemist.el] ( https://github.com/tonini/alchemist.el )
145
-
146
134
You can use [ web-mode.el] ( http://web-mode.org ) to edit elixir templates (eex files).
147
135
148
136
[ mix.el] ( https://github.com/ayrat555/mix.el ) provides a minor mode for integration with Mix, a build tool that ships with Elixir.
149
137
138
+ [ exunit.el] ( https://github.com/ananthakumaran/exunit.el ) provides ` ExUnit ` integration.
150
139
151
140
## Elixir Format
152
141
153
- ``` elisp
154
- M-x elixir-format
155
- ```
142
+ This mode can call mix for formatting code. When inside an elixir buffer, just type ` M-x elixir-format ` .
156
143
157
- ### Add elixir-mode hook to run elixir format on file save
144
+ To automate that, you can add this command to the ` before- save` hook.
158
145
159
146
``` elisp
160
147
;; Create a buffer-local hook to run elixir-format on save, only when we enable elixir-mode.
@@ -180,25 +167,99 @@ or you set `elixir-format-arguments` in a hook like this:
180
167
```
181
168
182
169
In this example we use [ Projectile] ( https://github.com/bbatsov/projectile ) to determine if we are in a project and then set ` elixir-format-arguments ` accordingly.
170
+
183
171
Please note that this code snippet may cause unhappiness if there is no ` .formatter.exs ` file available.
184
172
185
- ## Treesitter Support
173
+ ## Tips & Tricks
174
+
175
+ ### Prettify symbols
176
+
177
+ Emacs supports [ font ligatures] ( https://en.wikipedia.org/wiki/Ligature_(writing) ) . For enabling it for Elixir
178
+ you can add it to your configuration:
186
179
187
- There is a work-in-progress mode that uses Tree-Sitter instead of SMIE. If you are on Emacs 29.x you can try it out [ wkirschbaum/elixir-ts-mode] ( https://github.com/wkirschbaum/elixir-ts-mode ) .
180
+ ``` elisp
181
+ (add-hook
182
+ 'elixir-mode-hook
183
+ (lambda ()
184
+ (push '(">=" . ?\u2265) prettify-symbols-alist)
185
+ (push '("<=" . ?\u2264) prettify-symbols-alist)
186
+ (push '("!=" . ?\u2260) prettify-symbols-alist)
187
+ (push '("==" . ?\u2A75) prettify-symbols-alist)
188
+ (push '("=~" . ?\u2245) prettify-symbols-alist)
189
+ (push '("<-" . ?\u2190) prettify-symbols-alist)
190
+ (push '("->" . ?\u2192) prettify-symbols-alist)
191
+ (push '("<-" . ?\u2190) prettify-symbols-alist)
192
+ (push '("|>" . ?\u25B7) prettify-symbols-alist)))
193
+
194
+ ;; Or if you use use-packge
195
+
196
+ (use-package elixir-mode
197
+ :hook (elixir-mode . (lambda ()
198
+ (push '(">=" . ?\u2265) prettify-symbols-alist)
199
+ (push '("<=" . ?\u2264) prettify-symbols-alist)
200
+ (push '("!=" . ?\u2260) prettify-symbols-alist)
201
+ (push '("==" . ?\u2A75) prettify-symbols-alist)
202
+ (push '("=~" . ?\u2245) prettify-symbols-alist)
203
+ (push '("<-" . ?\u2190) prettify-symbols-alist)
204
+ (push '("->" . ?\u2192) prettify-symbols-alist)
205
+ (push '("<-" . ?\u2190) prettify-symbols-alist)
206
+ (push '("|>" . ?\u25B7) prettify-symbols-alist))))
207
+ ```
208
+
209
+ ### Formatting
210
+
211
+ If you have issues with the formatter provided by this package, you can try
212
+ using the format function of language servers. Elixir-ls supports this.
213
+
214
+ One way to configure this with ` eglot ` and ` use-package ` would be:
215
+
216
+ ``` elisp
217
+ (use-package elixir-mode
218
+ :hook (elixir-mode . eglot-ensure)
219
+ (before-save . eglot-format))
220
+ ```
221
+
222
+ ### Syntax highlighting for LiveView (and similar techniques for other syntaxes)
223
+
224
+ When you need different major modes in the SAME buffer, Emacs do not provide a standard way.
225
+ There is an external package that can help here by adding more than one major mode called ` poly-mode ` .
226
+
227
+ A possible configuration would be:
228
+
229
+ ``` elisp
230
+ ;; Assumes web-mode and elixir-mode are already set up
231
+ ;;
232
+ (use-package polymode
233
+ :mode ("\.ex$" . poly-elixir-web-mode)
234
+ :config
235
+ (define-hostmode poly-elixir-hostmode :mode 'elixir-mode)
236
+ (define-innermode poly-liveview-expr-elixir-innermode
237
+ :mode 'web-mode
238
+ :head-matcher (rx line-start (* space) "~H" (= 3 (char "\"'")) line-end)
239
+ :tail-matcher (rx line-start (* space) (= 3 (char "\"'")) line-end)
240
+ :head-mode 'host
241
+ :tail-mode 'host
242
+ :allow-nested nil
243
+ :keep-in-mode 'host
244
+ :fallback-mode 'host)
245
+ (define-polymode poly-elixir-web-mode
246
+ :hostmode 'poly-elixir-hostmode
247
+ :innermodes '(poly-liveview-expr-elixir-innermode))
248
+ )
249
+ (setq web-mode-engines-alist '(("elixir" . "\\.ex\\'")))
250
+ ```
188
251
189
252
## History
190
253
191
- This mode is based on the
192
- [ Emacs mode by secondplanet] ( https://github.com/secondplanet/elixir-mode ) .
254
+ This mode is based on the [ Emacs mode by secondplanet] ( https://github.com/secondplanet/elixir-mode ) .
193
255
194
256
## Contributing
195
257
196
258
Please read [ CONTRIBUTING.md] ( https://github.com/elixir-editors/emacs-elixir/blob/master/CONTRIBUTING.md ) for guidelines on how to contribute to this project.
197
259
198
260
## License
199
261
200
- Copyright © 2011-2017 Samuel Tonini, Matt DeBoard, Andreas Fuchs, secondplanet and
201
- [ contributors] ( https://github.com/elixir-editors/emacs-elixir/contributors ) .
262
+ Copyright © 2011-2017 Samuel Tonini, Matt DeBoard, Andreas Fuchs, secondplanet and [ contributors] ( https://github.com/elixir-editors/emacs-elixir/contributors ) .
202
263
203
264
Distributed under the GNU General Public License, version 3
204
265
0 commit comments