module Yi.Config.Simple (
ConfigM,
configMain,
Field,
setFrontendPreferences,
setFrontend,
globalBindKeys,
modeBindKeys,
modeBindKeysByName,
addMode,
modifyMode,
modifyModeByName,
evaluator,
#ifdef HINT
ghciEvaluator,
#endif
publishedActionsEvaluator,
publishAction,
publishedActions,
fontName,
fontSize,
scrollWheelAmount,
scrollStyle,
ScrollStyle(..),
cursorStyle,
CursorStyle(..),
Side(..),
scrollBarSide,
autoHideScrollBar,
autoHideTabBar,
lineWrap,
windowFill,
theme,
layoutManagers,
debug,
runOnStartup,
runAfterStartup,
startActions,
initialActions,
defaultKm,
inputPreprocess,
modes,
regionStyle,
killringAccumulate,
bufferUpdateHandler,
module Yi.Boot,
module Yi.Buffer,
module Yi.Core,
module Yi.Dired,
module Yi.Editor,
module Yi.File,
module Yi.Config,
module Yi.Config.Default,
module Yi.Keymap,
module Yi.Keymap.Keys,
module Yi.Layout,
module Yi.Search,
module Yi.Style,
module Yi.Style.Library,
module Yi.Misc,
module Yi.Mode.Haskell,
) where
import Control.Applicative
import Control.Lens (Lens', (.=), (%=), (%~), use, lens)
import Control.Monad.State hiding (modify, get)
import Data.Maybe(mapMaybe)
import qualified Data.Text as T
import Text.Printf(printf)
import Yi.Boot
import Yi.Buffer hiding (modifyMode)
import Yi.Config.Default
import Yi.Config.Misc
import Yi.Config.Simple.Types
import Yi.Core
import Yi.Dired
import Yi.Editor
import Yi.Eval
import Yi.File
import Yi.Keymap
import Yi.Keymap.Keys
import Yi.Layout
import Yi.Misc
import Yi.Mode.Haskell
import Yi.Search
import Yi.Style
import Yi.Style.Library
import Yi.Utils
import Yi.Config(Config, UIConfig, startFrontEndA, configUIA,
startActionsA, initialActionsA, defaultKmA,
configInputPreprocessA, modeTableA, debugModeA,
configRegionStyleA, configKillringAccumulateA,
bufferUpdateHandlerA, configFontNameA,
configFontSizeA, configScrollWheelAmountA,
configScrollStyleA, configCursorStyleA,
CursorStyle(..), configLeftSideScrollBarA,
configAutoHideScrollBarA, configAutoHideTabBarA,
configLineWrapA, configWindowFillA, configThemeA,
layoutManagersA, configVarsA,
#ifdef FRONTEND_VTY
configVtyA
#endif
)
configMain :: Config -> ConfigM () -> IO ()
configMain c m = yi =<< execStateT (runConfigM m) c
setFrontendPreferences :: [String] -> ConfigM ()
setFrontendPreferences fs =
case mapMaybe (`lookup` availableFrontends) fs of
(f:_) -> startFrontEndA .= f
[] -> return ()
setFrontend :: String -> ConfigM ()
setFrontend f = case lookup f availableFrontends of
Nothing -> return ()
Just x -> startFrontEndA .= x
globalBindKeys :: Keymap -> ConfigM ()
globalBindKeys a = (defaultKmA . topKeymapA) %= (||> a)
modeBindKeys :: Mode syntax -> Keymap -> ConfigM ()
modeBindKeys mode keys =
ensureModeRegistered "modeBindKeys" (modeName mode) boundKeys
where
boundKeys = modeBindKeysByName (modeName mode) keys
modeBindKeysByName :: T.Text -> Keymap -> ConfigM ()
modeBindKeysByName name k =
ensureModeRegistered "modeBindKeysByName" name modMode
where
f :: (KeymapSet -> KeymapSet) -> KeymapSet -> KeymapSet
f mkm km = topKeymapA %~ (||> k) $ mkm km
modMode = modifyModeByName name (modeKeymapA %~ f)
addMode :: Mode syntax -> ConfigM ()
addMode m = modeTableA %= (AnyMode m :)
modifyMode :: Mode syntax
-> (forall syntax'. Mode syntax' -> Mode syntax')
-> ConfigM ()
modifyMode mode f = ensureModeRegistered "modifyMode" (modeName mode) modMode
where
modMode = modifyModeByName (modeName mode) f
modifyModeByName :: T.Text
-> (forall syntax. Mode syntax -> Mode syntax)
-> ConfigM ()
modifyModeByName name f =
ensureModeRegistered "modifyModeByName" name $ modeTableA %= fmap (onMode g)
where
g :: forall syntax. Mode syntax -> Mode syntax
g m | modeName m == name = f m
| otherwise = m
warn :: String -> String -> ConfigM ()
warn caller msg = io $ putStrLn $ printf "Warning: %s: %s" caller msg
isModeRegistered :: T.Text -> ConfigM Bool
isModeRegistered name =
any (\(AnyMode mode) -> modeName mode == name) <$> use modeTableA
ensureModeRegistered :: String -> T.Text -> ConfigM () -> ConfigM ()
ensureModeRegistered caller name m = do
isRegistered <- isModeRegistered name
if isRegistered
then m
else warn caller (printf "mode \"%s\" is not registered." (T.unpack name))
fontName :: Field (Maybe String)
fontName = configUIA . configFontNameA
fontSize :: Field (Maybe Int)
fontSize = configUIA . configFontSizeA
scrollWheelAmount :: Field Int
scrollWheelAmount = configUIA . configScrollWheelAmountA
scrollStyle :: Field (Maybe ScrollStyle)
scrollStyle = configUIA . configScrollStyleA
cursorStyle :: Field CursorStyle
cursorStyle = configUIA . configCursorStyleA
data Side = LeftSide | RightSide
scrollBarSide :: Field Side
scrollBarSide = configUIA . configLeftSideScrollBarA . fromBool
where
fromBool :: Lens' Bool Side
fromBool = lens (\b -> if b then LeftSide else RightSide)
(\_ s -> case s of { LeftSide -> True; RightSide -> False })
autoHideScrollBar :: Field Bool
autoHideScrollBar = configUIA . configAutoHideScrollBarA
autoHideTabBar :: Field Bool
autoHideTabBar = configUIA . configAutoHideTabBarA
lineWrap :: Field Bool
lineWrap = configUIA . configLineWrapA
windowFill :: Field Char
windowFill = configUIA . configWindowFillA
theme :: Field Theme
theme = configUIA . configThemeA
layoutManagers :: Field [AnyLayoutManager]
layoutManagers = layoutManagersA
debug :: Field Bool
debug = debugModeA
runOnStartup :: Action -> ConfigM ()
runOnStartup action = runManyOnStartup [action]
runManyOnStartup :: [Action] -> ConfigM ()
runManyOnStartup actions = startActions %= (++ actions)
runAfterStartup :: Action -> ConfigM ()
runAfterStartup action = runManyAfterStartup [action]
runManyAfterStartup :: [Action] -> ConfigM ()
runManyAfterStartup actions = initialActions %= (++ actions)
startActions :: Field [Action]
startActions = startActionsA
initialActions :: Field [Action]
initialActions = initialActionsA
defaultKm :: Field KeymapSet
defaultKm = defaultKmA
inputPreprocess :: Field (P Event Event)
inputPreprocess = configInputPreprocessA
modes :: Field [AnyMode]
modes = modeTableA
regionStyle :: Field RegionStyle
regionStyle = configRegionStyleA
killringAccumulate :: Field Bool
killringAccumulate = configKillringAccumulateA
bufferUpdateHandler :: Field [[Update] -> BufferM ()]
bufferUpdateHandler = bufferUpdateHandlerA