Skip to content

Commit

Permalink
Add section on editor integration
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Jul 22, 2024
1 parent 1184d2b commit e7229cb
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ that is appreciated by most Go programmers, see for example the following

- [Installation](#installation)
- [Usage](#usage)
- [CLI](#cli)
- [Editor integration](#editor-integration)
- [Checking formatting](#checking-formatting)
- [Formatting specification](#formatting-specification)

Expand All @@ -30,6 +32,8 @@ Pkg.add(url = "https://github.com/fredrikekre/Runic.jl")

## Usage

### CLI

The main interface to Runic is the command line interface (CLI) through the `main` function
invoked with the `-m` flag. See the output of `julia -m Runic --help` for details:

Expand Down Expand Up @@ -97,6 +101,37 @@ OPTIONS
In addition to the CLI there is also the two function `Runic.format_file` and
`Runic.format_string`. See their respective docstrings for details.
### Editor integration
#### Neovim
Runic can be as a formatter in [Neovim](https://neovim.io/) using
[`conform.nvim`](https://github.com/stevearc/conform.nvim). Refer to the `conform.nvim`
repository for installation and setup instructions.
Runic is not (yet) available directly in `conform.nvim` so the following configuration needs
to be passed to the setup function:
```lua
require("conform").setup({
formatters = {
runic = {
command = "julia",
args = {"[email protected]", "-e", "using Runic; exit(Runic.main(ARGS))", "--", "-o", "-", "-"},
},
},
formatters_by_ft = {
julia = {"runic"},
},
})
```
Finally, Runic needs to be installed in the package environment that the command above uses
(`@conform.nvim`). This can be done with the following command:
```sh
julia [email protected] -e 'using Pkg; Pkg.add(url = "https://github.com/fredrikekre/Runic.jl")'
```
## Checking formatting
Expand Down

5 comments on commit e7229cb

@fredrikekre
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @Klafyvel since I believe you use neovim and have tried out Runic 🙂

@Klafyvel
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks nice, I'll have a look. :)

@Klafyvel
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works like a charm almost from the first try! Some observations:

  • Users will probably read conform.nvim documentation, but since you provide a copy and paste configuration for this plugin, maybe just adding the vim.opt.runtimepath:append(vim.fs.joinpath(rocks_config.rocks_path, "lib", "luarocks", "rocks-5.1", "rocks.nvim", "*")) line can be nice, so we have right away the gq command working.
  • On the first run I hit conform.nvim's timeout limit because of precompilation. I don't think it needs to be mitigated, but it can be interesting to mention it,
  • Using a dedicated named environment is smart, I would also mention that in the part of the readme where you discuss having an alias for runic.

@fredrikekre
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Users will probably read [...]

I haven't used rocks, can you point me to something that describes what that command does? FYI, I used lazy.nvim

On the first run [...]

Yea. I don't think it hurts to recommend an increased time out limit since normal runs are quick.

Using a dedicated named environment [...]

Yea good idea, will add this. Maybe it should just be @runic then since it wouldn't be specific to conform.nvim.

@Klafyvel
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't used rocks, can you point me to something that describes what that command does? FYI, I used lazy.nvim

Oops, I copied the wrong line from my config, I meant vim.o.formatexpr = "v:lua.require'conform'.formatexpr()"

Yea. I don't think it hurts to recommend an increased time out limit since normal runs are quick.

Yeah, I essentially did:

    formatters = {
        runic = {
            command = "julia",
            args = {"[email protected]", "-e", "using Runic; exit(Runic.main(ARGS))", "--", "-o", "-", "-"},
            timeout_ms=2000,
        },
    },

Please sign in to comment.