From b58e342bf414e869bf772fb3a38691fa4a604978 Mon Sep 17 00:00:00 2001 From: defanor Date: Thu, 14 Dec 2017 19:21:27 +0300 Subject: Add the "set width" command This is mostly needed for embedding, since there doesn't seem to be any practical (let alone portable) standard way to notify pancake of emacs window size changes. In pancake.el, width adjustment is now getting done automatically whenever any other command gets issued. --- Pancake/Command.hs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'Pancake') diff --git a/Pancake/Command.hs b/Pancake/Command.hs index c385dc2..5126146 100644 --- a/Pancake/Command.hs +++ b/Pancake/Command.hs @@ -60,6 +60,7 @@ data Command = Quit | ShowCurrent | Shortcut String String | ReloadConfig + | SetWidth (Maybe Int) deriving (Show, Eq) -- | Parses a user command. @@ -141,6 +142,16 @@ shortcut m = do q <- manyTill anyChar eof pure $ Shortcut u q +-- | A natural numbers parser. +pNat :: Read i => Parser i +pNat = read <$> many1 digit + +-- | 'SetWidth' command parser. +setWidth :: Parser Command +setWidth = string "set width" + *> (SetWidth <$> optionMaybe (spaces *> pNat)) + <* eof + -- | Command parser. command :: Config -> Parser Command command c = @@ -152,5 +163,6 @@ command c = , saveRef (referenceDigits c) "save ref" , saveCurrent "save current" , save "save" + , setWidth "set width" , goTo "follow uri" ]) -- cgit v1.2.3