X.A.Prefix: Add orIfPrefixed

- Generalise signature of withPrefixArgument, in order to accommodate
  this.
This commit is contained in:
Tony Zorman 2023-06-23 08:05:51 +02:00
parent 4bdcab8bf6
commit e02400b1c7
2 changed files with 14 additions and 1 deletions

View File

@ -232,6 +232,11 @@
- The `emacsLikeXPKeymap` and `vimLikeXPKeymap` keymaps now treat
`C-m` the same as `Return`.
* `XMonad.Actions.Prefix`
- Added `orIfPrefixed`, a combinator to decide upon an action based
on whether any prefix argument was given.
### Other changes
## 0.17.1 (September 3, 2022)

View File

@ -29,6 +29,7 @@ module XMonad.Actions.Prefix
, withPrefixArgument
, isPrefixRaw
, isPrefixNumeric
, orIfPrefixed
, ppFormatPrefix
) where
@ -173,7 +174,7 @@ handlePrefixArg events = do
--
-- First, fetch the current prefix, then pass it as argument to the
-- original function. You should use this to "run" your commands.
withPrefixArgument :: (PrefixArgument -> X ()) -> X ()
withPrefixArgument :: (PrefixArgument -> X a) -> X a
withPrefixArgument = (>>=) XS.get
-- | Test if 'PrefixArgument' is 'Raw' or not.
@ -186,6 +187,13 @@ isPrefixNumeric :: PrefixArgument -> Bool
isPrefixNumeric (Numeric _) = True
isPrefixNumeric _ = False
-- | Execute the first action, unless any prefix argument is given,
-- in which case the second action is chosen instead.
--
-- > action1 `orIfPrefixed` action2
orIfPrefixed :: X a -> X a -> X a
orIfPrefixed xa xb = withPrefixArgument $ bool xa xb . isPrefixRaw
-- | Format the prefix using the Emacs convetion for use in a
-- statusbar, like xmobar.
--