diff --git a/README.md b/README.md index 1806f76..c8b8b4b 100644 --- a/README.md +++ b/README.md @@ -310,12 +310,18 @@ successfully load subsequent files. ### Configuring Cornelis' Behavior -The max size of the info window can be set via: +The max height and width of the info window can be set via: ```viml let g:cornelis_max_size = 30 ``` +and + +```viml +let g:cornelis_max_width = 40 +``` + If you'd prefer your info window to appear somewhere else, you can set `g:cornelis_split_location` (previously `g:cornelis_split_direction`), e.g. diff --git a/src/Cornelis/Config.hs b/src/Cornelis/Config.hs index 7afabf5..c9aed21 100644 --- a/src/Cornelis/Config.hs +++ b/src/Cornelis/Config.hs @@ -8,13 +8,14 @@ import Data.Maybe (fromMaybe) import qualified Data.Text as T import Neovim import Neovim.API.Text +import Control.Monad ((<=<)) ------------------------------------------------------------------------------ -- | Attempt to get a variable from vim. getVar :: Text -> Neovim env (Maybe Object) getVar v - = catchNeovimException (fmap Just $ vim_get_var v) + = catchNeovimException (Just <$> vim_get_var v) $ const $ pure Nothing @@ -33,6 +34,8 @@ getConfig = CornelisConfig <$> fmap (fromMaybe 31 . (objectToInt =<<)) (getVar "cornelis_max_size") - <*> fmap (fromMaybe Horizontal . (readSplitLocation =<<) . fmap T.unpack . (objectToText =<<)) - (getVarWithAlternatives ["cornelis_split_location", "cornelis_split_direction"]) + <*> fmap (fromMaybe 31 . (objectToInt =<<)) + (getVar "cornelis_max_width") + <*> (fromMaybe Horizontal . (>>= (readSplitLocation . T.unpack <=< objectToText)) <$> + getVarWithAlternatives ["cornelis_split_location", "cornelis_split_direction"]) diff --git a/src/Cornelis/InfoWin.hs b/src/Cornelis/InfoWin.hs index 1490851..2fe5b8d 100644 --- a/src/Cornelis/InfoWin.hs +++ b/src/Cornelis/InfoWin.hs @@ -95,6 +95,7 @@ buildInfoBuffer = do -- Setup things in the buffer void $ buffer_set_var b cornelisWindowVar $ ObjectBool True nvim_buf_set_option b "modifiable" $ ObjectBool False + nvim_buf_set_option b "filetype" $ ObjectString "agdainfo" pure $ InfoBuffer b @@ -103,13 +104,15 @@ buildInfoBuffer = do buildInfoWindow :: InfoBuffer -> Window -> Neovim CornelisEnv Window buildInfoWindow (InfoBuffer split_buf) w = savingCurrentWindow $ do nvim_set_current_win w + max_height <- asks $ T.pack . show . cc_max_height . ce_config + max_width <- asks $ T.pack . show . cc_max_width . ce_config asks (cc_split_location . ce_config) >>= \case - Vertical -> vim_command "vsplit" - Horizontal -> vim_command "split" - OnLeft -> vim_command "topleft vsplit" - OnRight -> vim_command "botright vsplit" - OnTop -> vim_command "topleft split" - OnBottom -> vim_command "botright split" + Vertical -> vim_command $ max_width <> " vsplit" + Horizontal -> vim_command $ max_height <> " split" + OnLeft -> vim_command $ "topleft " <> max_width <> " vsplit" + OnRight -> vim_command $ "botright " <> max_width <> " vsplit" + OnTop -> vim_command $ "topleft " <> max_height <> " split" + OnBottom -> vim_command $ "botright " <> max_height <> " split" split_win <- nvim_get_current_win nvim_win_set_buf split_win split_buf diff --git a/src/Cornelis/Types.hs b/src/Cornelis/Types.hs index 00c6687..7924590 100644 --- a/src/Cornelis/Types.hs +++ b/src/Cornelis/Types.hs @@ -103,6 +103,7 @@ readSplitLocation s = case fmap toLower s of data CornelisConfig = CornelisConfig { cc_max_height :: Int64 + , cc_max_width :: Int64 , cc_split_location :: SplitLocation } deriving (Show, Generic)