Skip to content

Commit 01babd0

Browse files
ivanovs-44e554c4c
authored andcommitted
Implement: Make the rewrite mode modifiable #41
1 parent 1d64bcf commit 01babd0

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

README.md

+14
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ These commands can be used in context of a hole:
6969
Commands with an `<RW>` argument take an optional normalization mode argument,
7070
one of `AsIs`, `Instantiated`, `HeadNormal`, `Simplified` or `Normalised`. When
7171
omitted, defaults to `Normalised`.
72+
This default may be specified in vimrc as `g:cornelis_rewrite_mode`.
7273

7374
Commands with a `<CM>` argument take an optional compute mode argument:
7475

@@ -364,6 +365,19 @@ The following configuration options are available:
364365
- `left`: Opens at the left of the window.
365366
- `right`: Opens at the right of the window.
366367

368+
Set default rewrite mode to use in commands which take an optional
369+
normalization mode argument
370+
371+
```viml
372+
let g:cornelis_rewrite_mode = 'HeadNormal'
373+
```
374+
375+
The following configuration options are available:
376+
- `AsIs`
377+
- `Instantiated`
378+
- `HeadNormal`
379+
- `Simplified`
380+
- `Normalised`
367381

368382
### Aligning Reasoning Justification
369383

src/Cornelis/Config.hs

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
module Cornelis.Config where
44

55
import Cornelis.Types
6+
import Cornelis.Types.Agda (Rewrite(..))
67
import Cornelis.Utils (objectToInt, objectToText)
78
import Data.Maybe (fromMaybe)
89
import qualified Data.Text as T
@@ -38,4 +39,6 @@ getConfig
3839
(getVar "cornelis_max_width")
3940
<*> (fromMaybe Horizontal . (>>= (readSplitLocation . T.unpack <=< objectToText)) <$>
4041
getVarWithAlternatives ["cornelis_split_location", "cornelis_split_direction"])
42+
<*> (fromMaybe HeadNormal . (>>= (readRewrite . T.unpack <=< objectToText)) <$>
43+
(getVar "cornelis_rewrite_mode"))
4144

src/Cornelis/Types.hs

+11-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import Control.Concurrent.Chan.Unagi (InChan)
2626
import Control.Monad.State.Class
2727
import Cornelis.Debug
2828
import Cornelis.Offsets (Pos(..), Interval(..), AgdaIndex, AgdaPos, AgdaInterval, VimIndex, LineNumber, Indexing(..))
29-
import Cornelis.Types.Agda (InteractionId)
29+
import Cornelis.Types.Agda (InteractionId, Rewrite(..))
3030
import Data.Aeson hiding (Error)
3131
import Data.Char (toLower)
3232
import Data.Functor.Identity
@@ -102,11 +102,20 @@ readSplitLocation s = case fmap toLower s of
102102
"bottom" -> Just OnBottom
103103
_ -> Nothing
104104

105+
readRewrite :: String -> Maybe Rewrite
106+
readRewrite s = case fmap toLower s of
107+
"asis" -> Just AsIs
108+
"instantiated" -> Just Instantiated
109+
"headnormal" -> Just HeadNormal
110+
"simplified" -> Just Simplified
111+
"normalised" -> Just Normalised
112+
_ -> Nothing
105113

106114
data CornelisConfig = CornelisConfig
107115
{ cc_max_height :: Int64
108116
, cc_max_width :: Int64
109117
, cc_split_location :: SplitLocation
118+
, cc_rewrite_mode :: Rewrite
110119
}
111120
deriving (Show, Generic)
112121

@@ -115,6 +124,7 @@ data CornelisEnv = CornelisEnv
115124
, ce_stream :: InChan AgdaResp
116125
, ce_namespace :: Int64
117126
, ce_config :: CornelisConfig
127+
118128
}
119129
deriving Generic
120130

src/Plugin.hs

+3-3
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ doRestart _ = do
132132
doAbort :: CommandArguments -> Neovim CornelisEnv ()
133133
doAbort _ = withAgda $ withCurrentBuffer $ getAgda >=> runIOTCM Cmd_abort
134134

135-
normalizationMode :: Neovim env Rewrite
136-
normalizationMode = pure HeadNormal
135+
normalizationMode :: Neovim CornelisEnv Rewrite
136+
normalizationMode = asks (cc_rewrite_mode . ce_config)
137137

138138
computeMode :: Neovim env ComputeMode
139139
computeMode = pure DefaultCompute
@@ -163,7 +163,7 @@ autoOne _ ms = withNormalizationMode ms $ \mode ->
163163
(mkAbsPathRnage fp $ ip_interval' ip)
164164
(T.unpack t)
165165

166-
withNormalizationMode :: Maybe String -> (Rewrite -> Neovim e ()) -> Neovim e ()
166+
withNormalizationMode :: Maybe String -> (Rewrite -> Neovim CornelisEnv ()) -> Neovim CornelisEnv ()
167167
withNormalizationMode Nothing f = normalizationMode >>= f
168168
withNormalizationMode (Just s) f =
169169
case readMaybe s of

0 commit comments

Comments
 (0)