ribosome: api extensions for nvim-hs

[ library, neovim ] [ Propose Tags ]

Please see the README on GitHub at https://github.com/tek/ribosome


[Skip to Readme]
Versions [RSS] [faq] 0.1.0.0, 0.1.1.0, 0.1.2.0, 0.2.0.0, 0.2.1.0, 0.2.2.0, 0.3.0.0, 0.3.0.1, 0.4.0.0
Dependencies aeson, ansi-terminal, base (==4.*), bytestring, cereal, cereal-conduit, chiasma, composition, composition-extra, conduit, conduit-extra, containers, cornea, data-default, deepseq, directory, either, exceptions, filepath, free, fuzzy, hourglass, hslogger, lens, lifted-async, lifted-base, messagepack, monad-control, monad-loops, mtl, nvim-hs, path, path-io, pretty-terminal, prettyprinter, prettyprinter-ansi-terminal, process, relude (>=0.7 && <1.2), resourcet, safe, split, stm, stm-chans, stm-conduit, template-haskell, text, th-abstraction, time, transformers, transformers-base, typed-process, unix, unliftio, unliftio-core, utf8-string [details]
License BSD-2-Clause-Patent
Copyright 2021 Torsten Schmits
Author Torsten Schmits
Maintainer tek@tryp.io
Category Neovim
Home page https://github.com/tek/ribosome#readme
Bug tracker https://github.com/tek/ribosome/issues
Source repo head: git clone https://github.com/tek/ribosome
Uploaded by tek at 2021-05-08T21:34:36Z
Distributions NixOS:0.4.0.0
Downloads 2962 total (20 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs uploaded by user [build log]
All reported builds failed as of 2021-05-08 [all 3 reports]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees

Candidates


Readme for ribosome-0.4.0.0

[back to package description]

About

ribosome is an extension framework for nvim-hs, a Haskell library that provides a Neovim plugin engine.

ribosome's structure is similar to that of vanilla nvim-hs plugins and is intended to provide a more comfortable API on top of it.

Basic Plugin

ribosome comes with a companion plugin manager, chromatin, but you can start plugins regularly with jobstart().

First, add ribosome to your myplugin.cabal's dependencies.

Your project should have an executable that looks like this:

import Neovim (neovim, plugins, defaultConfig)
import MyPlugin.Plugin (plugin)

main :: IO ()
main =
  neovim defaultConfig {plugins = [plugin]}

In MyPlugin.Plugin, you should write a plugin definition like this:

module MyPlugin.Plugin where

import Data.Default.Class (Default(def))
import Neovim (Neovim, NeovimPlugin, Plugin, wrapPlugin)
import Neovim.Context.Internal (Config(customConfig), asks')
import Ribosome.Api.Echo (echom)
import Ribosome.Control.Monad.Ribo (MonadRibo, NvimE, Ribo)
import Ribosome.Control.Ribosome (Ribosome, newRibosome)
import Ribosome.Error.Report (reportError)
import Ribosome.Internal.IO (retypeNeovim)
import Ribosome.Plugin (RpcDef, autocmd, cmd, riboPlugin, rpcHandler)
import System.Log.Logger (Priority(ERROR), setLevel, updateGlobalLogger)

handleError :: Text -> Ribo () Text ()
handleError err =
  echom err

hello :: NvimE e m => MonadRibo m => m ()
hello ::
  echom "hello"

bufEnter :: NvimE e m => MonadRibo m => m ()
bufEnter ::
  echom "BufEnter"

rpcHandlers :: [[RpcDef (Ribo () Error)]]
rpcHandlers =
  [
    $(rpcHandler (cmd []) 'hello),
    $(rpcHandler (autocmd "BufEnter") 'bufEnter)
  ]

plugin' :: Ribosome () -> Plugin (Ribosome ())
plugin' env =
  riboPlugin "myplugin" env rpcHandlers def handleError def

initialize :: Neovim e (Ribosome Env)
initialize = do
  liftIO $ updateGlobalLogger "Neovim.Plugin" (setLevel ERROR)
  ribo <- newRibosome "myplugin" def
  retypeNeovim (const ribo) (asks' customConfig)

plugin :: Neovim e NeovimPlugin
plugin =
  wrapPlugin . plugin' =<< initialize

Follow the instructions for the bootstrapping vim config in the documentation for chromatin. Now you can execute the command :Hello.

For more inspiration, check out some example projects: proteome, myo, uracil.