Removes unused function spawnWithActions and redundant imports in XMonad.Actions.Launcher

This commit is contained in:
c.lopez 2012-12-15 22:37:14 +00:00
parent 205e7133ac
commit cc98355700

View File

@ -18,11 +18,10 @@ module XMonad.Actions.Launcher(
, launcherPrompt
) where
import Data.List (find, findIndex, isPrefixOf, tails)
import qualified Data.Map as M
import Data.Maybe (fromMaybe, isJust)
import System.Directory (doesDirectoryExist)
import XMonad hiding (config)
import Data.List (find, findIndex, isPrefixOf, tails)
import qualified Data.Map as M
import Data.Maybe (isJust)
import XMonad hiding (config)
import XMonad.Prompt
import XMonad.Util.Run
@ -53,8 +52,8 @@ data HoogleMode = HMode FilePath String --path to hoogle and browser
data CalculatorMode = CalcMode
data LauncherConfig = LauncherConfig {
browser :: String
, pathToHoogle :: String
browser :: String
, pathToHoogle :: String
}
type ExtensionActions = M.Map String (String -> X())
@ -109,27 +108,6 @@ hoogleMode pathToHoogleBin browser' = XPT $ HMode pathToHoogleBin browser'
calcMode :: XPMode
calcMode = XPT CalcMode
-- | This function takes a map of extensions and a path file. It uses the map to find the pattern that matches the file path, then the corresponding program (listed in the map) is spawned.
spawnWithActions :: ExtensionActions -> FilePath -> X()
spawnWithActions actions fp = do
isDirectoryPath <- liftIO $ doesDirectoryExist fp
let
takeExtension = \p -> "." ++ (reverse . takeWhile (/= '.') $ reverse p) --it includes the dot
-- Patterns defined by the user
extAction = M.lookup (takeExtension fp) actions
dirAction = if (isDirectoryPath) then M.lookup "/" actions else Nothing -- / represents a directory
anyFileAction = M.lookup ".*" actions -- .* represents any file
action = fromMaybe (spawnNoPatternMessage (takeExtension fp)) $ extAction `orElse1` dirAction `orElse1` anyFileAction
action fp
where
-- | This function is defined in Data.Generics.Aliases (package syb "Scrap your boilerplate"), defined here to avoid dependency
orElse1 :: Maybe a -> Maybe a -> Maybe a
x `orElse1` y = case x of
Just _ -> x
Nothing -> y
spawnNoPatternMessage :: String -> String -> X ()
spawnNoPatternMessage fileExt _ = spawn $ "xmessage No action specified for file extension " ++ fileExt ++ ", add a default action by matching the extension \".*\" in the action map sent to launcherPrompt"
{-
-- ideas for XMonad.Prompt running on mode XPMultipleModes