<commit_before>-----------------------------------------------------------------------------
-- |
-- Module      :  XMonadContrib.SwapWorkspaces
-- Copyright   :  (c) <NAME> <<EMAIL>>
-- License     :  BSD3-style (see LICENSE)
--
-- Maintainer  :  <NAME> <<EMAIL>>
-- Stability   :  unstable
-- Portability :  unportable
--
-- Lets you swap workspace tags, so you can keep related ones next to
-- each other, without having to move individual windows.
--
-- TODO: add quickcheck props for:
--       * double swap invariant (guarantees no 'loss' of workspaces)
--       * non-swapped ws's invariant
--
-----------------------------------------------------------------------------

module XMonadContrib.SwapWorkspaces (
                                     -- * Usage
                                     -- $usage
                                     swapWithCurrent,
                                     swapWorkspaces
                                    ) where

import StackSet

-- $usage
-- Add this import to your Config.hs:
-- > import XMonadContrib.SwapWorkspaces
--
-- Throw this in your keys definition:
-- > ++
-- > [((modMask .|. controlMask, k), windows $ swapWithCurrent i)
-- >     | (i, k) <- zip workspaces [xK_1 ..]]

swapWithCurrent :: Eq i => i -> StackSet i l a s sd -> StackSet i l a s sd
swapWithCurrent t s = swapWorkspaces t (tag $ workspace $ current s) s

-- Stole this from StackSet.renameTag -- extracted the traversal code they have in common as mapWorkspaces
swapWorkspaces :: Eq i => i -> i -> StackSet i l a s sd -> StackSet i l a s sd
swapWorkspaces t1 t2 = mapWorkspaces swap
    where swap w = if      tag w == t1 then w { tag = t2 }
                   else if tag w == t2 then w { tag = t1 }
                   else w

mapWorkspaces :: (Workspace i l a -> Workspace i l a) -> StackSet i l a s sd -> StackSet i l a s sd
mapWorkspaces f s = s { current = updScr $ current s
                      , visible = map updScr $ visible s
                      , hidden  = map f $ hidden s }
    where updScr scr = scr { workspace = f $ workspace scr }<commit_msg>add man page doco<commit_after>-----------------------------------------------------------------------------
-- |
-- Module      :  XMonadContrib.SwapWorkspaces
-- Copyright   :  (c) <NAME> <<EMAIL>>
-- License     :  BSD3-style (see LICENSE)
--
-- Maintainer  :  <NAME> <<EMAIL>>
-- Stability   :  unstable
-- Portability :  unportable
--
-- Lets you swap workspace tags, so you can keep related ones next to
-- each other, without having to move individual windows.
--
-- TODO: add quickcheck props for:
--       * double swap invariant (guarantees no 'loss' of workspaces)
--       * non-swapped ws's invariant
--
-----------------------------------------------------------------------------

module XMonadContrib.SwapWorkspaces (
                                     -- * Usage
                                     -- $usage
                                     swapWithCurrent,
                                     swapWorkspaces
                                    ) where

import StackSet

-- $usage
-- Add this import to your Config.hs:
-- > import XMonadContrib.SwapWorkspaces
--
-- Throw this in your keys definition:
-- > ++
-- > [((modMask .|. controlMask, k), windows $ swapWithCurrent i)
-- >     | (i, k) <- zip workspaces [xK_1 ..]]
--
-- %import XMonadContrib.SwapWorkspaces
-- %keybindlist ++
-- %keybindlist [((modMask .|. controlMask, k), windows $ swapWithCurrent i)
-- %keybindlist     | (i, k) <- zip workspaces [xK_1 ..]]

swapWithCurrent :: Eq i => i -> StackSet i l a s sd -> StackSet i l a s sd
swapWithCurrent t s = swapWorkspaces t (tag $ workspace $ current s) s

-- Stole this from StackSet.renameTag -- extracted the traversal code they have in common as mapWorkspaces
swapWorkspaces :: Eq i => i -> i -> StackSet i l a s sd -> StackSet i l a s sd
swapWorkspaces t1 t2 = mapWorkspaces swap
    where swap w = if      tag w == t1 then w { tag = t2 }
                   else if tag w == t2 then w { tag = t1 }
                   else w

mapWorkspaces :: (Workspace i l a -> Workspace i l a) -> StackSet i l a s sd -> StackSet i l a s sd
mapWorkspaces f s = s { current = updScr $ current s
                      , visible = map updScr $ visible s
                      , hidden  = map f $ hidden s }
    where updScr scr = scr { workspace = f $ workspace scr }
{'fraction_non_alphanumeric': 0.16967344142498286, 'fraction_numerical': 0.0038821648778259877, 'mean_word_length': 1.4565339315759955, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5170151', 'n_tokens_mistral': 1244, 'n_tokens_neox': 1182, 'n_words': 461}