ProductPromotion
Logo

Elixir

made by https://0x3d.site

GitHub - dm1try/nvim: write plugins for Neovim using Elixir
write plugins for Neovim using Elixir. Contribute to dm1try/nvim development by creating an account on GitHub.
Visit Site

GitHub - dm1try/nvim: write plugins for Neovim using Elixir

GitHub - dm1try/nvim: write plugins for Neovim using Elixir

Neovim Elixir host Build Status

Implements support for Neovim remote plugins written in Elixir.

Requirements

  • Neovim >= 1.6-dev
  • Elixir >= 1.3

Installation

Install the host archive, we will use it to build the host locally.

mix archive.install https://github.com/dm1try/nvim/releases/download/v0.4.2/nvim.ez

Build and install the host by running nvim.install and providing the path to nvim config(~/.config/nvim by default on linux systems)

mix nvim.install /path/to/nvim/config

Upgrade

Same as the install step but if you have any problem try to remove the host at first:

mix nvim.remove /path/to/nvim/config
mix nvim.install /path/to/nvim/config

Usage

Currently, each time you somehow update remote plugins you should run :UpdateElixirPlugins nvim command.

See :h remote-plugin-manifest for the clarification why the manifest is needed(generally, it saves the neovim startup time if remote plugins are installed).

Plugin Development (Developers only)

                   +--------------------------+
+--------+ MsgPack |              +---------+ |
|        |   RPC   | +------+     |         | |
| Neovim <---------> | Host <-----> Plugins | |
|        |         | +------+     |         | |
+--------+         |              +---------+ |
                   +--------------------------+

Structure

Host supports two types of plugins:

  1. Scripts (an elixir script that usually contains simple logic and does not depend on other libs/does not need the versioning/etc).

  2. Applications (an OTP application that is implemented as part of host umbrella project). You can find more information about umbrella projects here.

Host with plugins lives in rplugin/elixir neovim config directory. Script plugin name must have postfix plugin in his name.

Example my_plugin.exs

Typical files tree for such dir:

~/.config/nvim/rplugin/elixir

├── scripts <~ scripts
├── apps <~ applications AKA "precompiled plugins"
└── mix.exs

Plugin DSL

Events

on_event(better known as autocmd for vim users) defines the callback that triggered by editor when some event happened. Run :h autocmd-events for the list of events.

on_event :vim_enter do
  Logger.info("the editor is ready")
end

Functions

function defines the vim function

function wrong_sum(left, right) do
  left - right
end

use it in the editor :echo WrongSum(1,2)

Commands

command defines the command.

command just_echo do
  NVim.Session.nvim_command("echo 'from remote plugin'")
end

use it in the editor :JustEcho

Only single param can be defined for a command. This param holds an array of strings provided on the command call. Elixir OptionParser is good choice here.

Session

In the latest example we used nvim_command method which is part of Neovim remote API. In the examples below we asume that we import NVim.Session in context of plugin.

State

Each plugin is GenServer. So you can share the state between all actions while the plugin is running:

def init(_args) do
  {:ok, %{move_count: 0}}
end

on_event :cursor_moved do
  state = %{state | move_count: state.move_count + 1}
end

command show_moves_count do
  moves_info = "Current moves: #{state.move_count}"
  nvim_command("echo '#{moves_info}'")
end

NOTE: you cannot assing the state in inner scopes(if/case/with/etc). You should return the value from the scope and then assing it to the state in root scope.

Pre-evaluated values

Any vim value can be pre-evaluated before the action will be triggered:

on_event :cursor_hold_i,
  pre_evaluate: %{
    "expand('cWORD')" => word_under_cursor
  }
do
  if word_under_cursor == "Elixir" do
    something()
  end
end

Basic scripts

"Hello" from plug:

# ~/.config/nvim/rplugin/elixir/scripts/my_plugin.exs
defmodule MyPlug do
  use NVim.Plugin

  command hello_from_plug do
    NVim.Session.nvim_command "echo 'hello'"
  end
end

Debugging scripts.

ElixirHostLog opens the host log. Log severety level can be changed in the host config.

~/.config/nvim/rplugin/elixir/apps/host/config/config.exs is default path on linux

ElixirReloadScript reloads running script.

This works only for the reloading an implementation of already defined command/function/event. This means if you add/remove some definition or change its option(pre_evaluate for example) you should restart the editor.

Articles
to learn more about the elixir concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about Elixir.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory