Skip to content

Commit

Permalink
Merge pull request agda#107 from 4e554c4c/infoview_width
Browse files Browse the repository at this point in the history
Allow configuring infoview width
  • Loading branch information
isovector authored Jan 17, 2023
2 parents bbac7fc + cc0d348 commit fa235e4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
9 changes: 6 additions & 3 deletions src/Cornelis/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"])

15 changes: 9 additions & 6 deletions src/Cornelis/InfoWin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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

Expand Down
1 change: 1 addition & 0 deletions src/Cornelis/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit fa235e4

Please sign in to comment.