From 90a96dee4947b5d67fdd6ca1e32e71a4985fe169 Mon Sep 17 00:00:00 2001 From: slotThe Date: Wed, 17 Nov 2021 19:58:32 +0100 Subject: [PATCH] X.H.ManageHelpers: Flip logic for (^?), (~?), and ($?) This changes how the "is*Of" infix operators are hoisted into the ManageHook context. Instead of `q ~? x` being a lifted version of `isPrefixOf q x` we instead let it be a lift of `isPrefixOf x q`. While this obviously does not matter for symmetric operators like `(==)` and `(/=)`, for `isInfixOf` it is rather essential. The reason for that is that the given `q` on the left side is an atom that can't (shouldn't) be changed (by the user) and we only have control over the right hand side. Otherwise, things like title ~? "foo" would read "only match if `title` is an infix of `foo`" instead of the much more useful "only match if `foo` is an infix of `title`". Fixes: 8b6f17ba6684a126fc1bde8d7275c166b3456d37 --- CHANGES.md | 7 ++++++- XMonad/Hooks/ManageHelpers.hs | 16 ++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 34065612..9a5cadb0 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -25,7 +25,12 @@ * `XMonad.Util.EZConfig` - - Added support for Modifier Keys `KeySym`s for Emacs-like `additionalKeysP` + - Added support for Modifier Keys `KeySym`s for Emacs-like `additionalKeysP`. + + * `XMonad.Hooks.ManageHelpers` + + - Flipped how `(^?)`, `(~?)`, and `($?)` work to more accurately + reflect how one uses these operators. ## 0.17.0 (October 27, 2021) diff --git a/XMonad/Hooks/ManageHelpers.hs b/XMonad/Hooks/ManageHelpers.hs index b2ae327a..3f9dbac3 100644 --- a/XMonad/Hooks/ManageHelpers.hs +++ b/XMonad/Hooks/ManageHelpers.hs @@ -32,9 +32,9 @@ -- > f :: a -> b -> Bool -- > -- > -- a new helper --- > q ***? x = fmap (\a -> f a x) q +-- > q ***? x = fmap (\a -> f a x) q -- or: (\b -> f x b) -- > -- or --- > q ***? x = fmap (`f` x) q +-- > q ***? x = fmap (`f` x) q -- or: (x `f`) -- -- Any existing operator can be "lifted" in the same way: -- @@ -109,17 +109,17 @@ infixr 0 -?>, -->>, -?>> (/=?) :: (Eq a, Functor m) => m a -> a -> m Bool q /=? x = fmap (/= x) q --- | q ^? x. if the result of q 'isPrefixOf' x, return True +-- | q ^? x. if the result of @x `isPrefixOf` q@, return True (^?) :: (Eq a, Functor m) => m [a] -> [a] -> m Bool -q ^? x = fmap (`isPrefixOf` x) q +q ^? x = fmap (x `isPrefixOf`) q --- | q ~? x. if the result of q 'isSuffixOf' x, return True +-- | q ~? x. if the result of @x `isInfixOf` q@, return True (~?) :: (Eq a, Functor m) => m [a] -> [a] -> m Bool -q ~? x = fmap (`isInfixOf` x) q +q ~? x = fmap (x `isInfixOf`) q --- | q $? x. if the result of q 'isSuffixOf' x, return True +-- | q $? x. if the result of @x `isSuffixOf` q@, return True ($?) :: (Eq a, Functor m) => m [a] -> [a] -> m Bool -q $? x = fmap (`isSuffixOf` x) q +q $? x = fmap (x `isSuffixOf`) q -- | q <==? x. if the result of q equals x, return True grouped with q (<==?) :: (Eq a, Functor m) => m a -> a -> m (Match a)