From 8012d2fccf769261e047b34b4d3e60c155462b14 Mon Sep 17 00:00:00 2001 From: Adam Vogt Date: Wed, 21 Apr 2010 20:30:06 +0200 Subject: Prompt: handle case of historySize Ignore-this: e4a74e905677649ddde36385a9ed47a2 darcs-hash:20100421183006-1499c-b6fb3d6eea1e1c519173bf07346c100b2b5557cb.gz --- XMonad/Prompt.hs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'XMonad/Prompt.hs') diff --git a/XMonad/Prompt.hs b/XMonad/Prompt.hs index 951f9ad..53ec2e5 100644 --- a/XMonad/Prompt.hs +++ b/XMonad/Prompt.hs @@ -293,10 +293,11 @@ mkXPromptWithReturn t conf compl action = do io $ freeGC d gc if successful st' then do + let prune = take (historySize conf) io $ writeHistory $ M.insertWith - (\xs ys -> take (historySize conf) - . historyFilter conf $ xs ++ ys) - (showXPrompt t) (historyFilter conf [command st']) + (\xs ys -> prune . historyFilter conf $ xs ++ ys) + (showXPrompt t) + (prune $ historyFilter conf [command st']) hist -- we need to apply historyFilter before as well, since -- otherwise the filter would not be applied if @@ -768,7 +769,9 @@ readHistory = readHist `catch` \(SomeException _) -> return emptyHistory writeHistory :: History -> IO () writeHistory hist = do path <- getHistoryFile - writeFile path (show hist) `catch` \(SomeException _) -> hPutStrLn stderr "error in writing" + let filtered = M.filter (not . null) hist + writeFile path (show filtered) `catch` \(SomeException e) -> + hPutStrLn stderr ("error writing history: "++show e) setFileMode path mode where mode = ownerReadMode .|. ownerWriteMode -- cgit v1.2.3