<commit_before>-----------------------------------------------------------------------------
-- |
-- Module      :  XMonadContrib.RotView
-- Copyright   :  (c) <NAME> <<EMAIL>>
-- License     :  BSD3-style (see LICENSE)
--
-- Maintainer  :  <NAME> <<EMAIL>>
-- Stability   :  unstable
-- Portability :  unportable
--
-- Provides bindings to cycle through non-empty workspaces.
--
-----------------------------------------------------------------------------

module XMonadContrib.RotView (
                              -- * Usage
                              -- $usage
                              rotView
                             ) where

import Control.Monad.State ( gets )
import Data.List ( sortBy )
import Data.Maybe ( listToMaybe, isJust )

import XMonad
import StackSet hiding (filter)
import qualified Operations as O

-- $usage
-- You can use this module with the following in your Config.hs file:
-- 
-- > import XMonadContrib.RotView
--
-- >   , ((modMask .|. shiftMask, xK_Right), rotView True)
-- >   , ((modMask .|. shiftMask, xK_Left), rotView False)

rotView :: Bool -> X ()
rotView b = do
    ws <- gets windowset
    let m = tag . workspace . current $ ws
        sortWs = sortBy (\x y -> compare (tag x) (tag y))
        pivoted = uncurry (flip (++)) . span ((< m) . tag) . sortWs . hidden $ ws
        nextws = listToMaybe . filter (isJust . stack) . (if b then id else reverse) $ pivoted
    whenJust nextws (O.view . tag)<commit_msg>RotView.rotView: use Data.Ord.comparing.<commit_after>-----------------------------------------------------------------------------
-- |
-- Module      :  XMonadContrib.RotView
-- Copyright   :  (c) <NAME> <<EMAIL>>
-- License     :  BSD3-style (see LICENSE)
--
-- Maintainer  :  <NAME> <<EMAIL>>
-- Stability   :  unstable
-- Portability :  unportable
--
-- Provides bindings to cycle through non-empty workspaces.
--
-----------------------------------------------------------------------------

module XMonadContrib.RotView (
                              -- * Usage
                              -- $usage
                              rotView
                             ) where

import Control.Monad.State ( gets )
import Data.List ( sortBy )
import Data.Maybe ( listToMaybe, isJust )
import Data.Ord ( comparing )

import XMonad
import StackSet hiding (filter)
import qualified Operations as O

-- $usage
-- You can use this module with the following in your Config.hs file:
-- 
-- > import XMonadContrib.RotView
--
-- >   , ((modMask .|. shiftMask, xK_Right), rotView True)
-- >   , ((modMask .|. shiftMask, xK_Left), rotView False)

rotView :: Bool -> X ()
rotView b = do
    ws <- gets windowset
    let m = tag . workspace . current $ ws
        sortWs = sortBy (comparing tag)
        pivoted = uncurry (flip (++)) . span ((< m) . tag) . sortWs . hidden $ ws
        nextws = listToMaybe . filter (isJust . stack) . (if b then id else reverse) $ pivoted
    whenJust nextws (O.view . tag)
{'fraction_non_alphanumeric': 0.21768477894026325, 'fraction_numerical': 0.0006749915626054674, 'mean_word_length': 1.4475639966969447, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6660825', 'n_tokens_mistral': 855, 'n_tokens_neox': 825, 'n_words': 251}