Skip to content

Commit 19ed1ff

Browse files
Update markdown, add Tips & Tricks (#505)
* Update markdown, add Tips & Tricks This updates some little but important things here: - Removes hand-written TOC (GitHub makes its own now) - Add NonGNU Elpa - Update installation instructions - Mention elixir-ts-mode (Emacs 29+) - Add Tips & Tricks section * Add trick for multiple syntaxes * Update README.md Co-authored-by: Walter McGinnis <[email protected]> * Update README.md --------- Co-authored-by: Walter McGinnis <[email protected]>
1 parent 8ac787f commit 19ed1ff

File tree

1 file changed

+102
-41
lines changed

1 file changed

+102
-41
lines changed

README.md

+102-41
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,28 @@
11
[![License GPL 3][badge-license]](http://www.gnu.org/licenses/gpl-3.0.txt)
22
[![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)
34
[![MELPA Stable](http://stable.melpa.org/packages/elixir-mode-badge.svg)](http://stable.melpa.org/#/elixir-mode)
45
[![MELPA](http://melpa.org/packages/elixir-mode-badge.svg)](http://melpa.org/#/elixir-mode)
56

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+
612
# Elixir Mode
713

814
Provides font-locking, indentation and navigation support for the
915
[Elixir programming language.](http://elixir-lang.org/)
1016

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-
2717
## Installation
2818

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+
2922
### Via package.el
3023

3124
`package.el` is the built-in package manager in Emacs.
3225

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-
3626
You can install `elixir-mode` with the following command:
3727

3828
<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:
5242
Keep in mind that MELPA packages are built automatically from
5343
the `master` branch, meaning bugs might creep in there from time to
5444
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`.
5746

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.
6048

61-
### Manual
49+
### Via use-package
6250

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).
6553

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)
6959
```
7060

7161
## Usage
@@ -141,20 +131,17 @@ This package is tested only with a single version of OTP and 3 versions of Elixi
141131

142132
## Elixir Tooling Integration
143133

144-
If you looking for elixir tooling integration for Emacs, check: [alchemist.el](https://github.com/tonini/alchemist.el)
145-
146134
You can use [web-mode.el](http://web-mode.org) to edit elixir templates (eex files).
147135

148136
[mix.el](https://github.com/ayrat555/mix.el) provides a minor mode for integration with Mix, a build tool that ships with Elixir.
149137

138+
[exunit.el](https://github.com/ananthakumaran/exunit.el) provides `ExUnit` integration.
150139

151140
## Elixir Format
152141

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`.
156143

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.
158145

159146
``` elisp
160147
;; 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:
180167
```
181168

182169
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+
183171
Please note that this code snippet may cause unhappiness if there is no `.formatter.exs` file available.
184172

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:
186179

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+
```
188251

189252
## History
190253

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).
193255

194256
## Contributing
195257

196258
Please read [CONTRIBUTING.md](https://github.com/elixir-editors/emacs-elixir/blob/master/CONTRIBUTING.md) for guidelines on how to contribute to this project.
197259

198260
## License
199261

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).
202263

203264
Distributed under the GNU General Public License, version 3
204265

0 commit comments

Comments
 (0)