module Yi.Config.Simple (
ConfigM,
configMain,
Field,
(%=),
get,
modify,
setFrontendPreferences,
setFrontend,
globalBindKeys,
modeBindKeys,
modeBindKeysByName,
addMode,
modifyMode,
modifyModeByName,
evaluator,
ghciEvaluator,
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.Core,
module Yi.Dired,
module Yi.File,
module Yi.Config,
module Yi.Config.Default,
module Yi.Layout,
module Yi.Search,
module Yi.Style,
module Yi.Style.Library,
module Yi.Misc,
module Yi.Mode.Haskell,
#ifdef SCION
module Yi.Scion,
#endif
) where
import Yi.Boot
import Yi.Core hiding(modifyMode, (%=))
import Yi.Config.Default
import Yi.Config.Misc
import Yi.Config.Simple.Types
import Yi.Dired
import Yi.Eval
import Yi.File
import Yi.Layout
import Yi.Search
import Yi.Style
import Yi.Style.Library
import Yi.Misc
import Yi.Mode.Haskell
#ifdef SCION
import Yi.Scion
#endif
import Text.Printf(printf)
import Prelude hiding((.))
import Control.Monad.State hiding (modify, get)
import Yi.Config(Config, UIConfig,
startFrontEndA, configUIA, startActionsA, initialActionsA, defaultKmA,
configInputPreprocessA, modeTableA, debugModeA,
configRegionStyleA, configKillringAccumulateA, bufferUpdateHandlerA,
configVtyEscDelayA, configFontNameA, configFontSizeA, configScrollWheelAmountA,
configScrollStyleA, configCursorStyleA, CursorStyle(..),
configLeftSideScrollBarA, configAutoHideScrollBarA, configAutoHideTabBarA,
configLineWrapA, configWindowFillA, configThemeA, layoutManagersA, configVarsA,
)
import Data.Maybe(mapMaybe)
configMain :: Config -> ConfigM () -> IO ()
configMain c m = yi =<< execStateT (runConfigM m) c
(%=) :: Field a -> a -> ConfigM ()
(%=) = putA
get :: Field a -> ConfigM a
get = getA
modify :: Field a -> (a -> a) -> ConfigM ()
modify = modA
setFrontendPreferences :: [String] -> ConfigM ()
setFrontendPreferences fs =
case mapMaybe (\f -> lookup f availableFrontends) fs of
(f:_) -> startFrontEndA %= f
[] -> return ()
setFrontend :: String -> ConfigM ()
setFrontend f = maybe (return ()) (startFrontEndA %=) (lookup f availableFrontends)
globalBindKeys :: Keymap -> ConfigM ()
globalBindKeys a = modify (topKeymapA . defaultKmA) (||> a)
modeBindKeys :: Mode syntax -> Keymap -> ConfigM ()
modeBindKeys mode keys = ensureModeRegistered "modeBindKeys" (modeName mode) $ modeBindKeysByName (modeName mode) keys
modeBindKeysByName :: String -> Keymap -> ConfigM ()
modeBindKeysByName name k = ensureModeRegistered "modeBindKeysByName" name $ modifyModeByName name (modeKeymapA ^: f)
where
f :: (KeymapSet -> KeymapSet) -> (KeymapSet -> KeymapSet)
f mkm km = topKeymapA ^: (||> k) $ mkm km
addMode :: Mode syntax -> ConfigM ()
addMode m = modify modeTableA (AnyMode m :)
modifyMode :: Mode syntax -> (forall syntax'. Mode syntax' -> Mode syntax') -> ConfigM ()
modifyMode mode f = ensureModeRegistered "modifyMode" (modeName mode) $ modifyModeByName (modeName mode) f
modifyModeByName :: String -> (forall syntax. Mode syntax -> Mode syntax) -> ConfigM ()
modifyModeByName name f = ensureModeRegistered "modifyModeByName" name $ modify 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 :: String -> ConfigM Bool
isModeRegistered name = (Prelude.any (\(AnyMode mode) -> modeName mode == name)) <$> get modeTableA
ensureModeRegistered :: String -> String -> ConfigM () -> ConfigM ()
ensureModeRegistered caller name m = do
isRegistered <- isModeRegistered name
if isRegistered
then m
else warn caller (printf "mode \"%s\" is not registered." name)
fontName :: Field (Maybe String)
fontName = configFontNameA . configUIA
fontSize :: Field (Maybe Int)
fontSize = configFontSizeA . configUIA
scrollWheelAmount :: Field Int
scrollWheelAmount = configScrollWheelAmountA . configUIA
scrollStyle :: Field (Maybe ScrollStyle)
scrollStyle = configScrollStyleA . configUIA
cursorStyle :: Field CursorStyle
cursorStyle = configCursorStyleA . configUIA
data Side = LeftSide | RightSide
scrollBarSide :: Field Side
scrollBarSide = fromBool . configLeftSideScrollBarA . configUIA
where
fromBool :: Accessor Bool Side
fromBool = accessor (\b -> if b then LeftSide else RightSide) (\s _ -> case s of { LeftSide -> True; RightSide -> False })
autoHideScrollBar :: Field Bool
autoHideScrollBar = configAutoHideScrollBarA . configUIA
autoHideTabBar :: Field Bool
autoHideTabBar = configAutoHideTabBarA . configUIA
lineWrap :: Field Bool
lineWrap = configLineWrapA . configUIA
windowFill :: Field Char
windowFill = configWindowFillA . configUIA
theme :: Field Theme
theme = configThemeA . configUIA
layoutManagers :: Field [AnyLayoutManager]
layoutManagers = layoutManagersA
debug :: Field Bool
debug = debugModeA
runOnStartup :: Action -> ConfigM ()
runOnStartup action = runManyOnStartup [action]
runManyOnStartup :: [Action] -> ConfigM ()
runManyOnStartup actions = modify startActions (++actions)
runAfterStartup :: Action -> ConfigM ()
runAfterStartup action = runManyAfterStartup [action]
runManyAfterStartup :: [Action] -> ConfigM ()
runManyAfterStartup actions = modify 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