Gleam layer
Table of ContentsClose
1. Description
This layers adds support for Gleam. It relies on the official gleam-ts-mode package and requires Emacs to be compiled with treesit support (built-in with version 29+).
To check that the treesit package is installed, you can run M: (treesit-available-p).
1.1. Features:
- Gleam language server integration
- Formatting (
gleam format) - Execution (
gleam build,gleam run,gleam test)
2. Install
To use this configuration layer, add gleam to the existing dotspacemacs-configuration-layers list in your ~/.spacemacs file.
You also need to install Gleam and make sure the gleam command was properly added to you PATH.
3. Configuration
3.1. LSP
lsp-gleam is the official implementation of the Gleam language server that comes pre-installed with the built-in gleam lsp command.
If the lsp layer was already added to your dotfile, the LSP backend will be enabled by default. To explicitly disable it for the gleam layer, set the following:
(gleam :variables gleam-enable-lsp nil)
If the lsp layer is not already installed, the LSP backend must be explicitely enabled for lsp-mode to start automatically when visiting a gleam file:
(gleam :variables gleam-enable-lsp nil)
When enabled, the gleam-lsp server will be automatically initialized when visiting a gleam file.
More details can be found in the lsp layer configuration section.
3.2. Formatting
gleam-ts-mode provides the gleam-ts-format command (SPC m = =) to format source code in the official Gleam style.
To automatically apply formatting files before saving:
(gleam :variables gleam-format-on-save t)
If the LSP backend is enabled, automatic formatting will use the lsp-format-buffer command (SPC m = b) instead.
3.3. Execution
The platform to target during compilation is set to erlang by default. To select javascript instead:
(gleam :variables gleam-target 'javascript)
The default runtime for the javascript target is nodejs. To select a different runtime:
(gleam :variables gleam-target 'javascript gleam-runtime 'bun)
By default, the spacemacs//gleam-run command (SPC m c c) is set up to execute gleam run inside the project root directory. To run the module associated with the current instead:
(gleam :variables gleam-run-scope 'module)
4. Key bindings
4.1. LSP
Detailed key bindings can be found in the lsp layer key bindings section
4.2. Formatting
| Key binding | Description |
|---|---|
SPC m = = |
Run gleam-format |
SPC m T = |
Toggle gleam-format-on-save in current buffer |
4.3. Execution
| Key binding | Description |
|---|---|
SPC m c b |
Build project (run gleam build) |
SPC m c a |
Run project (run gleam run in project root) |
SPC m c m |
Run module (run gleam run --module <module>) |
SPC m c c |
Run project or module (see gleam-run-scope) |
SPC m t a |
Test project (run gleam test) |