And i want to suggest not to use ExitSuccess in the example of withLock
you provided in Readme: with default 'mod+q' action xmonad executes xmonad --recompile && xmonad --restart through shell. Thus even if withLock
prevents compile from running second time, xmonad will still restart as many
times as you press 'mod+q'. It may be harmless, but it is useless either. So i
suggest to throw exception instead, then exit code of xmonad --recompile
will be non-zero and xmonad --restart won't be executed by shell. Something
like this (i use cabal build):
{-# LANGUAGE DeriveDataTypeable #-}
import Control.Exception
import System.FilePath ((</>))
import System.Directory (getHomeDirectory, copyFile)
import System.Exit
import XMonad
import qualified XMonad.Util.EntryHelper as EH
-- Redefine withHelper to use cabal for building xmonad and throw an
-- exception, if lock file exists. Then '--recompile' will exit with non-zero
-- code and '--restart' won't run (with default 'mod+q' action). The exception
-- will be evaluated, because it's thrown in compile and postCompile will run
-- afterwards.
withHelper :: IO () -> IO ()
withHelper e = EH.withCustomHelper EH.defaultConfig
{ EH.run = e
, EH.compile = EH.withLock (throw lockAlreadyExists)
. cabalCompile
, EH.postCompile = cabalInstall
}
cabalCompile :: Bool -> IO ExitCode
cabalCompile force = do
let buildCmd = "cabal configure; cabal build"
cmd = (if force then "cabal clean; " else "") ++ buildCmd
uninstallSignalHandlers
r <- EH.compileUsingShell cmd
installSignalHandlers
return r
cabalInstall :: ExitCode -> IO ()
cabalInstall ExitSuccess = do
hd <- getHomeDirectory
xd <- getXMonadDir
copyFile (xd </> "dist/build/xmonad/xmonad") (hd </> "bin/xmonad")
cabalInstall r = EH.defaultPostCompile r
data LockAlreadyExists = LockAlreadyExists FilePath
deriving (Typeable)
-- Default value.
lockAlreadyExists :: LockAlreadyExists
lockAlreadyExists = LockAlreadyExists ""
instance Show LockAlreadyExists where
show (LockAlreadyExists f)
| null f = "Lock file already exists."
| otherwise = "Lock file " ++ f ++ " already exists."
instance Exception LockAlreadyExists where
Hi.
Thanks for good module.
And i want to suggest not to use
ExitSuccess
in the example ofwithLock
you provided in Readme: with default 'mod+q' action xmonad executesxmonad --recompile && xmonad --restart
through shell. Thus even ifwithLock
prevents compile from running second time, xmonad will still restart as many times as you press 'mod+q'. It may be harmless, but it is useless either. So i suggest to throw exception instead, then exit code ofxmonad --recompile
will be non-zero andxmonad --restart
won't be executed by shell. Something like this (i use cabal build):