diff --git a/CHANGES.md b/CHANGES.md index b6424015..7632e789 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -44,6 +44,17 @@ All of these were now removed. You can use the re-exported `def` from `Data.Default` instead. + * `XMonad.Hooks.Script` + + `execScriptHook` now has an `X` constraint (was: `MonadIO`), due to changes + in how the xmonad core handles XDG directories. + + * `XMonad.Prompt` + + `historyCompletion` and `historyCompletionP` now both have an `X` + constraint (was: `IO`), due to changes in how the xmonad core handles XDG + directories. + ### New Modules * `XMonad.Util.Hacks` diff --git a/XMonad/Actions/Search.hs b/XMonad/Actions/Search.hs index d410d307..bfbde3e8 100644 --- a/XMonad/Actions/Search.hs +++ b/XMonad/Actions/Search.hs @@ -363,18 +363,16 @@ namedEngine name (SearchEngine _ site) = searchEngineF name site Prompt's result, passes it to a given searchEngine and opens it in a given browser. -} promptSearchBrowser :: XPConfig -> Browser -> SearchEngine -> X () -promptSearchBrowser config browser (SearchEngine name site) = - mkXPrompt (Search name) config (historyCompletionP ("Search [" `isPrefixOf`)) $ search browser site +promptSearchBrowser config browser (SearchEngine name site) = do + hc <- historyCompletionP ("Search [" `isPrefixOf`) + mkXPrompt (Search name) config hc $ search browser site {- | Like 'promptSearchBrowser', but only suggest previous searches for the given 'SearchEngine' in the prompt. -} promptSearchBrowser' :: XPConfig -> Browser -> SearchEngine -> X () -promptSearchBrowser' config browser (SearchEngine name site) = - mkXPrompt - (Search name) - config - (historyCompletionP (searchName `isPrefixOf`)) - $ search browser site +promptSearchBrowser' config browser (SearchEngine name site) = do + hc <- historyCompletionP (searchName `isPrefixOf`) + mkXPrompt (Search name) config hc $ search browser site where searchName = showXPrompt (Search name) diff --git a/XMonad/Hooks/Script.hs b/XMonad/Hooks/Script.hs index b298920f..6c3371c6 100644 --- a/XMonad/Hooks/Script.hs +++ b/XMonad/Hooks/Script.hs @@ -44,7 +44,7 @@ import XMonad -- @~\/.xmonad\/hooks startup@ will also. -- | Execute a named script hook -execScriptHook :: MonadIO m => String -> m () +execScriptHook :: String -> X () execScriptHook hook = do xmonadDir <- getXMonadDir let script = xmonadDir ++ "/hooks " diff --git a/XMonad/Prompt.hs b/XMonad/Prompt.hs index 3f4303a7..3d283ce9 100644 --- a/XMonad/Prompt.hs +++ b/XMonad/Prompt.hs @@ -543,7 +543,8 @@ mkXPromptImplementation historyKey conf om = do XConf { display = d, theRoot = rw } <- ask s <- gets $ screenRect . W.screenDetail . W.current . windowset numlock <- gets X.numberlockMask - hist <- io readHistory + cachedir <- getXMonadCacheDir + hist <- io $ readHistory cachedir fs <- initXMF (font conf) st' <- io $ bracket @@ -562,7 +563,7 @@ mkXPromptImplementation historyKey conf om = do releaseXMF fs when (successful st') $ do let prune = take (historySize conf) - io $ writeHistory $ + io $ writeHistory cachedir $ M.insertWith (\xs ys -> prune . historyFilter conf $ xs ++ ys) historyKey @@ -1560,21 +1561,21 @@ type History = M.Map String [String] emptyHistory :: History emptyHistory = M.empty -getHistoryFile :: IO FilePath -getHistoryFile = fmap (++ "/prompt-history") getXMonadCacheDir +getHistoryFile :: FilePath -> FilePath +getHistoryFile cachedir = cachedir ++ "/prompt-history" -readHistory :: IO History -readHistory = readHist `E.catch` \(SomeException _) -> return emptyHistory +readHistory :: FilePath -> IO History +readHistory cachedir = readHist `E.catch` \(SomeException _) -> return emptyHistory where readHist = do - path <- getHistoryFile + let path = getHistoryFile cachedir xs <- bracket (openFile path ReadMode) hClose hGetLine readIO xs -writeHistory :: History -> IO () -writeHistory hist = do - path <- getHistoryFile - let filtered = M.filter (not . null) hist +writeHistory :: FilePath -> History -> IO () +writeHistory cachedir hist = do + let path = getHistoryFile cachedir + filtered = M.filter (not . null) hist writeFile path (show filtered) `E.catch` \(SomeException e) -> hPutStrLn stderr ("error writing history: "++show e) setFileMode path mode @@ -1667,14 +1668,17 @@ breakAtSpace s -- | 'historyCompletion' provides a canned completion function much like -- 'getShellCompl'; you pass it to mkXPrompt, and it will make completions work -- from the query history stored in the XMonad cache directory. -historyCompletion :: ComplFunction +historyCompletion :: X ComplFunction historyCompletion = historyCompletionP (const True) -- | Like 'historyCompletion' but only uses history data from Prompts whose -- name satisfies the given predicate. -historyCompletionP :: (String -> Bool) -> ComplFunction -historyCompletionP p x = fmap (toComplList . M.filterWithKey (const . p)) readHistory - where toComplList = deleteConsecutive . filter (isInfixOf x) . M.foldr (++) [] +historyCompletionP :: (String -> Bool) -> X ComplFunction +historyCompletionP p = do + cd <- getXMonadCacheDir + pure $ \x -> + let toComplList = deleteConsecutive . filter (isInfixOf x) . M.foldr (++) [] + in toComplList . M.filterWithKey (const . p) <$> readHistory cd -- | Sort a list and remove duplicates. Like 'deleteAllDuplicates', but trades off -- laziness and stability for efficiency.