-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMain.hs
138 lines (125 loc) · 4.43 KB
/
Main.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -imodules #-}
import Control.Monad.State hiding (state)
import Data.List (intersperse)
import Data.Monoid
import qualified Data.Text as T
import Lens.Micro.Platform
import System.Directory (getCurrentDirectory)
import System.Environment
import Yi hiding (super)
import Yi.Utils (io)
import Yi.Modes (gnuMakeMode)
import qualified Yi.Keymap.Vim as V
import qualified Yi.Keymap.Vim.Common as V
import qualified Yi.Keymap.Vim.Ex.Types as V
import qualified Yi.Keymap.Vim.Ex.Commands.Common as V
import qualified Yi.Keymap.Vim.Utils as V
import qualified Yi.Frontend.Vty as Vty
import FuzzyFile
import Make
import qualified Yi.Snippet as Snippet
import MySnippets
import RainbowMode
import PyflakesMode
main :: IO ()
main = do
files <- getArgs
let actions = intersperse (EditorA newTabE) (map (YiA . openNewFile) files)
startEditor (myConfig actions) Nothing
myConfig :: [Action] -> Config
myConfig actions = defaultConfig
{ modeTable =
fmap
(configureModeline . configureIndent)
(myModes defaultConfig)
, startFrontEnd = Vty.start
, defaultKm = myKeymapSet
, configCheckExternalChangesObsessively = False
, startActions =
(EditorA (do
e <- get
put e { maxStatusHeight = 30 }))
: YiA guessMakePrg
: actions
}
myKeymapSet :: KeymapSet
myKeymapSet = V.mkKeymapSet $ V.defVimConfig `override` \super this ->
let eval = V.pureEval this
in super
{ V.vimBindings = myBindings eval ++ V.vimBindings super
, V.vimExCommandParsers =
exMake : exFlakes : exMakePrgOption : exPwd :
V.vimExCommandParsers super
}
myBindings :: (V.EventString -> EditorM ()) -> [V.VimBinding]
myBindings eval =
let nmap x y = V.mkStringBindingE V.Normal V.Drop (x, y, id)
nmapY x y = V.mkStringBindingY V.Normal (x, y, id)
imapY x y = V.VimBindingY (\evs state -> case V.vsMode state of
V.Insert _ ->
fmap (const (y >> return V.Drop))
(evs `V.matchesString` x)
_ -> V.NoMatch)
defEval = V.pureEval (extractValue V.defVimConfig)
in [ nmap "<BS>" previousTabE
, nmap "<Tab>" nextTabE
, nmap " " (eval ":nohlsearch<CR>")
, nmap ";" (eval ":")
, nmapY "<C-p>" fuzzyFile
, nmap "<M-s>" (withCurrentBuffer deleteTrailingSpaceB)
, nmap "<M-l>" (withCurrentBuffer (transposeB unitWord Forward >> leftB))
, nmap "<M-h>" (withCurrentBuffer (transposeB unitWord Backward))
, nmap "<C-@>" showErrorE
, nmap "<M-d>" debug
, nmapY "s" (jumpToNextErrorInCurrentBufferY Forward)
, nmapY "S" (jumpToNextErrorY Forward)
, nmap ",s" insertErrorMessageE
, imapY "<Tab>"
(withEditor $ do
expanded <- Snippet.expandSnippetE (defEval "<Esc>") mySnippets
when (not expanded) (defEval "<Tab>"))
, nmapY "<Esc>" (flakes >> withEditor (defEval "<Esc>"))
]
configureIndent :: AnyMode -> AnyMode
configureIndent = onMode $ \m ->
if m ^. modeNameA == "Makefile"
then m
else m
{ modeIndentSettings = IndentSettings
{ expandTabs = True
, shiftWidth = 4
, tabSize = 4
}}
configureModeline :: AnyMode -> AnyMode
configureModeline = onMode $ \m -> m {modeModeLine = myModeLine}
where
myModeLine prefix = do
(line, col) <- getLineAndCol
ro <- use readOnlyA
mode <- gets (withMode0 modeName)
unchanged <- gets isUnchangedBuffer
filename <- gets (shortIdentString (length prefix))
errorCount <- errorCountB
return $ T.unwords
[ if ro then "RO" else ""
, if unchanged then "--" else "**"
, filename
, "L", showT line
, "C", showT col
, mode
, if errorCount > 0
then (showT errorCount <> " errors")
else ""
]
myModes :: Config -> [AnyMode]
myModes cfg
= AnyMode gnuMakeMode
: AnyMode pyflakesMode
: AnyMode rainbowParenMode
: modeTable cfg
exPwd :: V.EventString -> Maybe V.ExCommand
exPwd "pwd" = Just (V.impureExCommand{V.cmdAction = YiA (io getCurrentDirectory >>= printMsg . T.pack)})
exPwd _ = Nothing
showT :: Show a => a -> T.Text
showT = T.pack . show