Skip to content

Commit d67b71d

Browse files
committed
Format everything with fourmolu
A consistent defined style for the source files helps getting accustomed to the code base. A configuration for fourmolu has been added and it has been added as a build tool to the nix flake.
1 parent 3a937e6 commit d67b71d

37 files changed

+2184
-2186
lines changed

HLint.hs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
{-# LANGUAGE TemplateHaskell #-}
21
{-# LANGUAGE PackageImports #-}
2+
{-# LANGUAGE TemplateHaskell #-}
3+
34
import "hint" HLint.Default
45
import "hint" HLint.Dollar
56

Setup.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import Distribution.Simple
1+
import Distribution.Simple
22

33
main = defaultMain

example/lib/Fibonacci.hs

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
{-# LANGUAGE TemplateHaskell #-}
2+
23
module Fibonacci (plugin) where
34

4-
import Neovim
55
import Fibonacci.Plugin (fibonacci)
6+
import Neovim
67

78
plugin :: Neovim (StartupConfig NeovimConfig) () NeovimPlugin
8-
plugin = wrapPlugin Plugin
9-
{ exports = [ $(function' 'fibonacci) Sync ]
10-
, statefulExports = []
11-
}
9+
plugin =
10+
wrapPlugin
11+
Plugin
12+
{ exports = [$(function' 'fibonacci) Sync]
13+
, statefulExports = []
14+
}

example/lib/Fibonacci/Plugin.hs

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@ fibonacci :: Int -> Neovim' String
77
fibonacci n = return . show $ fibs !! n
88
where
99
fibs :: [Integer]
10-
fibs = 0:1:scanl1 (+) fibs
11-
10+
fibs = 0 : 1 : scanl1 (+) fibs

example/lib/Random.hs

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE TemplateHaskell #-}
2+
23
module Random (plugin) where
34

45
import Neovim
@@ -7,14 +8,19 @@ import System.Random (newStdGen, randoms)
78

89
plugin :: Neovim (StartupConfig NeovimConfig) () NeovimPlugin
910
plugin = do
10-
g <- liftIO newStdGen -- initialize with a random seed
11+
g <- liftIO newStdGen -- initialize with a random seed
1112
let randomNumbers = randoms g -- an infinite list of random numbers
12-
wrapPlugin Plugin
13-
{ exports = []
14-
, statefulExports =
15-
[ ((), randomNumbers,
16-
[ $(function' 'nextRandom) Sync
17-
, $(function "SetNextRandom" 'setNextRandom) Async
18-
])
19-
]
20-
}
13+
wrapPlugin
14+
Plugin
15+
{ exports = []
16+
, statefulExports =
17+
[
18+
( ()
19+
, randomNumbers
20+
,
21+
[ $(function' 'nextRandom) Sync
22+
, $(function "SetNextRandom" 'setNextRandom) Async
23+
]
24+
)
25+
]
26+
}

example/lib/Random/Plugin.hs

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module Random.Plugin (nextRandom, setNextRandom) where
33
import Neovim
44

55
import System.Random (newStdGen, randoms)
6-
import UnliftIO.STM (TVar, atomically, readTVar, modifyTVar, newTVarIO)
6+
import UnliftIO.STM (TVar, atomically, modifyTVar, newTVarIO, readTVar)
77

88
-- You may want to define a type alias for your plugin, so that if you change
99
-- your environment, you don't have to change all type signatures.
@@ -33,4 +33,3 @@ nextRandom = do
3333
modifyTVar tVarWithRandomNumbers tail
3434

3535
return r
36-

example/nvim.hs

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import Neovim
22

33
import qualified Fibonacci as Fibonacci
4-
import qualified Random as Random
4+
import qualified Random as Random
55

66
main :: IO ()
7-
main = neovim defaultConfig
8-
{ plugins = plugins defaultConfig ++ [ Fibonacci.plugin, Random.plugin ]
9-
}
7+
main =
8+
neovim
9+
defaultConfig
10+
{ plugins = plugins defaultConfig ++ [Fibonacci.plugin, Random.plugin]
11+
}

library/Neovim.hs

+95-71
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,36 @@ module Neovim (
1919
-- $installation
2020

2121
-- * Tutorial
22+
2223
-- ** Motivation
2324
-- $overview
24-
-- ** Combining existing plugins
2525
-- $existingplugins
2626
Neovim,
2727
neovim,
28-
NeovimConfig(..),
28+
NeovimConfig (..),
2929
defaultConfig,
3030
def,
3131

32-
3332
-- ** Creating a plugin
3433
-- $creatingplugins
35-
NeovimPlugin(..),
36-
Plugin(..),
37-
NvimObject(..),
34+
NeovimPlugin (..),
35+
Plugin (..),
36+
NvimObject (..),
3837
(+:),
3938
Dictionary,
40-
Object(..),
39+
Object (..),
4140
wrapPlugin,
4241
function,
4342
function',
4443
command,
4544
command',
4645
autocmd,
47-
Synchronous(..),
48-
CommandOption(..),
49-
RangeSpecification(..),
50-
CommandArguments(..),
51-
AutocmdOptions(..),
46+
Synchronous (..),
47+
CommandOption (..),
48+
RangeSpecification (..),
49+
CommandArguments (..),
50+
AutocmdOptions (..),
5251
addAutocmd,
53-
5452
ask,
5553
asks,
5654

@@ -64,9 +62,10 @@ module Neovim (
6462
err,
6563
errOnInvalidResult,
6664
catchNeovimException,
67-
NeovimException(..),
65+
NeovimException (..),
6866

6967
-- * Unsorted exports
68+
7069
-- This section contains just a bunch of more or less useful functions which
7170
-- were not introduced in any of the previous sections.
7271
liftIO,
@@ -76,62 +75,85 @@ module Neovim (
7675
docFromObject,
7776
Doc,
7877
AnsiStyle,
79-
Pretty(..),
78+
Pretty (..),
8079
putDoc,
8180
exceptionToDoc,
82-
Priority(..),
81+
Priority (..),
8382
module Control.Monad,
8483
module Control.Applicative,
8584
module Data.Monoid,
8685
module Data.Int,
8786
module Data.Word,
87+
) where
88+
89+
import Control.Applicative
90+
import Control.Monad (void)
91+
import Control.Monad.IO.Class (liftIO)
92+
import Data.Default (def)
93+
import Data.Int (Int16, Int32, Int64, Int8)
94+
import Data.MessagePack (Object (..))
95+
import Data.Monoid
96+
import Data.Word (Word, Word16, Word32, Word8)
97+
import Neovim.API.TH (
98+
autocmd,
99+
command,
100+
command',
101+
function,
102+
function',
103+
)
104+
import Neovim.Classes (
105+
AnsiStyle,
106+
Dictionary,
107+
Doc,
108+
NvimObject (..),
109+
Pretty (..),
110+
docFromObject,
111+
docToObject,
112+
(+:),
113+
)
114+
import Neovim.Config (NeovimConfig (..))
115+
import Neovim.Context (
116+
Neovim,
117+
NeovimException (..),
118+
ask,
119+
asks,
120+
err,
121+
errOnInvalidResult,
122+
exceptionToDoc,
123+
)
124+
import Neovim.Exceptions (catchNeovimException)
125+
import Neovim.Main (neovim)
126+
import Neovim.Plugin (addAutocmd)
127+
import Neovim.Plugin.Classes (
128+
AutocmdOptions (..),
129+
CommandArguments (..),
130+
CommandOption (CmdBang, CmdCount, CmdRange, CmdRegister, CmdSync),
131+
RangeSpecification (..),
132+
Synchronous (..),
133+
)
134+
import Neovim.Plugin.Internal (
135+
NeovimPlugin (..),
136+
Plugin (..),
137+
wrapPlugin,
138+
)
139+
import Neovim.RPC.FunctionCall (wait, wait')
140+
import Neovim.Util (unlessM, whenM)
141+
import Prettyprinter.Render.Terminal (putDoc)
142+
import System.Log.Logger (Priority (..))
88143

89-
) where
90-
91-
import Control.Applicative
92-
import Control.Monad (void)
93-
import Control.Monad.IO.Class (liftIO)
94-
import Data.Default (def)
95-
import Data.Int (Int16, Int32, Int64, Int8)
96-
import Data.MessagePack (Object (..))
97-
import Data.Monoid
98-
import Data.Word (Word, Word16, Word32, Word8)
99-
import Neovim.API.TH (autocmd, command, command',
100-
function, function')
101-
import Neovim.Classes (Dictionary, NvimObject (..),
102-
Doc, AnsiStyle, Pretty(..),
103-
docFromObject, docToObject, (+:))
104-
import Neovim.Config (NeovimConfig (..))
105-
import Neovim.Context (Neovim,
106-
NeovimException(..),
107-
exceptionToDoc,
108-
ask, asks, err,
109-
errOnInvalidResult)
110-
import Neovim.Main (neovim)
111-
import Neovim.Exceptions (catchNeovimException)
112-
import Neovim.Plugin (addAutocmd)
113-
import Neovim.Plugin.Classes (AutocmdOptions (..),
114-
CommandArguments (..),
115-
CommandOption (CmdBang, CmdCount, CmdRange, CmdRegister, CmdSync),
116-
RangeSpecification (..),
117-
Synchronous (..))
118-
import Neovim.Plugin.Internal (NeovimPlugin (..), Plugin (..),
119-
wrapPlugin)
120-
import Neovim.RPC.FunctionCall (wait, wait')
121-
import Neovim.Util (unlessM, whenM)
122-
import System.Log.Logger (Priority (..))
123-
import Prettyprinter.Render.Terminal (putDoc)
124144
-- Installation {{{1
145+
125146
{- $installation
126147
127148
Installation instructions are in the README.md file that comes with the source
128149
of this package. It is also on the repositories front page.
129-
130150
-}
151+
131152
-- 1}}}
132153

133154
-- Tutorial {{{1
134155
-- Overview {{{2
156+
135157
{- $overview
136158
An @nvim-hs@ plugin is just a collection of haskell functions that can be
137159
called from neovim.
@@ -146,12 +168,11 @@ writing a plugin.
146168
147169
Since you are reading haddock documentation, you probably want the latter, so
148170
just keep reading. @:-)@
149-
150171
-}
151172

152-
153173
-- 2}}}
154174
-- Combining Existing Plugins {{{2
175+
155176
{- $existingplugins
156177
The easiest way to start is to use the stack template as described in the
157178
@README.md@ of this package. If you initialize it in your neovim configuration
@@ -178,27 +199,27 @@ main file would look something like this:
178199
179200
That's all you have to do! Multiple plugins are simply imported and put in a
180201
list.
181-
182202
-}
183203

184-
-- | Default configuration options for /nvim-hs/. If you want to keep the
185-
-- default plugins enabled, you can define your config like this:
186-
--
187-
-- @
188-
-- main = 'neovim' 'defaultConfig'
189-
-- { plugins = plugins defaultConfig ++ myPlugins
190-
-- }
191-
-- @
192-
--
193-
defaultConfig :: NeovimConfig
194-
defaultConfig = Config
195-
{ plugins = []
196-
, logOptions = Nothing
197-
}
204+
{- | Default configuration options for /nvim-hs/. If you want to keep the
205+
default plugins enabled, you can define your config like this:
198206
207+
@
208+
main = 'neovim' 'defaultConfig'
209+
{ plugins = plugins defaultConfig ++ myPlugins
210+
}
211+
@
212+
-}
213+
defaultConfig :: NeovimConfig
214+
defaultConfig =
215+
Config
216+
{ plugins = []
217+
, logOptions = Nothing
218+
}
199219

200220
-- 2}}}
201221
-- Creating a plugin {{{2
222+
202223
{- $creatingplugins
203224
Creating plugins isn't difficult either. You just have to follow and survive the
204225
compile time errors of seemingly valid code. This may sound scary, but it is not
@@ -318,10 +339,11 @@ mode:
318339
319340
The haddock documentation will now list all the things we have used up until now.
320341
Afterwards, there is a plugin with state which uses the environment.
321-
322342
-}
343+
323344
-- 2}}}
324345
-- Creating a stateful plugin {{{2
346+
325347
{- $statefulplugin
326348
Now that we are a little bit comfortable with the interface provided by /nvim-hs/,
327349
we can start to write a more complicated plugin. Let's create a random number
@@ -436,10 +458,11 @@ You can also cheat and pretend you know the next number:
436458
@
437459
:call SetNextRandom(42)
438460
@
439-
440461
-}
462+
441463
-- 2}}}
442464
-- Calling remote functions {{{2
465+
443466
{- $remote
444467
Calling remote functions is only possible inside a 'Neovim' context. There are
445468
a few patterns of return values for the available functions. Let's start with
@@ -471,6 +494,7 @@ message to neovim which the user immediately notices.
471494
472495
That's pretty much all there is to it.
473496
-}
497+
474498
-- 2}}}
475499
-- 1}}}
476500

0 commit comments

Comments
 (0)