summaryrefslogtreecommitdiff
path: root/Pancake
diff options
context:
space:
mode:
authordefanor <defanor@uberspace.net>2017-12-14 19:21:27 +0300
committerdefanor <defanor@uberspace.net>2017-12-14 19:21:27 +0300
commitb58e342bf414e869bf772fb3a38691fa4a604978 (patch)
treed6b057c6f6252a60a882f5f4703d5b20cfbd0fa0 /Pancake
parente1151532a46a7ce2c59a8bc86088063cb03c4438 (diff)
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.
Diffstat (limited to 'Pancake')
-rw-r--r--Pancake/Command.hs12
1 files changed, 12 insertions, 0 deletions
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"
])