{-# OPTIONS_HADDOCK show-extensions #-}

-- |
-- Module      :  Yi.Boot.Internal
-- License     :  GPL-2
-- Maintainer  :  yi-devel@googlegroups.com
-- Stability   :  experimental
-- Portability :  portable
--
-- Internal use for Yi.Boot

module Yi.Boot.Internal where

import Config.Dyre.Relaunch (relaunchWithBinaryState)
import Control.Monad.Base   (liftBase)
import Control.Monad.State  (get)
import Yi.Keymap            (YiM, withUI)
import Yi.Types             (withEditor)
import Yi.UI.Common         (end)

-- | "reloads" the configuration
--
-- Serializes the editor state and relaunches Yi using the serialized
-- state. The launch of Yi will result in recompilation of the user's
-- custom Yi. This, in effect, "reloads" the configuration.
reload :: YiM ()
reload :: YiM ()
reload = do
  Editor
editor <- EditorM Editor -> YiM Editor
forall (m :: * -> *) a. MonadEditor m => EditorM a -> m a
withEditor EditorM Editor
forall s (m :: * -> *). MonadState s m => m s
get
  (UI Editor -> IO ()) -> YiM ()
forall a. (UI Editor -> IO a) -> YiM a
withUI (UI Editor -> Maybe ExitCode -> IO ()
forall e. UI e -> Maybe ExitCode -> IO ()
`end` Maybe ExitCode
forall a. Maybe a
Nothing)
  IO () -> YiM ()
forall (b :: * -> *) (m :: * -> *) α. MonadBase b m => b α -> m α
liftBase (IO () -> YiM ()) -> IO () -> YiM ()
forall a b. (a -> b) -> a -> b
$ Maybe Editor -> Maybe [String] -> IO ()
forall a. Binary a => a -> Maybe [String] -> IO ()
relaunchWithBinaryState (Editor -> Maybe Editor
forall a. a -> Maybe a
Just Editor
editor) Maybe [String]
forall a. Maybe a
Nothing