[xmonad] How to disable history in XMonad.Actions.Search.

Gwern Branwen gwern0 at gmail.com
Sun Sep 20 13:56:36 EDT 2009


On Sun, Sep 20, 2009 at 11:42 AM, Mike Sampson <mike at sambodata.com> wrote:
> Gwern,
>
> On Mon, Sep 21, 2009 at 12:10 AM, Gwern Branwen <gwern0 at gmail.com> wrote:
>
>>
>> Code tip: you could also write '\_ -> []', or just 'const []'.
>
> Yes, my Haskell leaves a lot to be desired. :) I went with const []. Thanks.
>
>>
>>
>> If you look in Search, you'll see:
>>
>> {- | Like 'search', but for use with the output from a Prompt; it
>> grabs the
>>   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 historyCompletion $ search browser site
>>
>> That is, 'config' is not asked for the history completion function nor
>> is any filter ran upon it; rather, it uses the canned
>> historyCompletion function from XMonad.Prompt.
>
> Ahh. I did browse this file but missed the finer details of that function.
>
>> It's possible to grab the historyFilter from the XPConfig that
>> promptSearchBrowser has access to; if you could test out my attached
>> patch?
>
> Applied. This seems to be working perfectly. When the above
> historyFilter is used, the history file is still created but contains
> an empty list. Perfect.
>
> Your assistance is much appreciated. Once again the xmonad mailing
> list comes through for me.
>
> Many thanks,
>
> Mike

This patch isn't perfect, though. I reflected on it and realized that
it doesn't make sense to have invokers of mkXPrompt do the filtering
themselves, when mkXPrompt has access to the XPConfig and the
Completion functions - one could just write the filtering once, in
mkXPrompt, and not every caller.

But when I went to add it, I saw that mkXPrompt wraps
mkXPromptWithReturn, and the latter calls 'historyFilter conf'! Which
mystifies me. I'm now not sure why my patch worked or what to do next:

mkXPromptWithReturn ∷  XPrompt p ⇒  p →  XPConfig →  ComplFunction →
(String →  X a)  →  X (Maybe a)
mkXPromptWithReturn t conf compl action = do
  c ←  ask
  let d = display c
      rw = theRoot c
  s ←  gets $ screenRect · W.screenDetail · W.current · windowset
  hist ←  liftIO $ readHistory
  w ←  liftIO $ createWin d rw conf s
  liftIO $ selectInput d w $ exposureMask .|. keyPressMask
  gc ←  liftIO $ createGC d w
  liftIO $ setGraphicsExposures d gc False
  fs ←  initXMF (font conf)
  let hs = fromMaybe [] $ Map.lookup (showXPrompt t) hist
      st = initState d rw w s compl gc fs (XPT t) hs conf
  st' ←  liftIO $ execStateT runXP st

  releaseXMF fs
  liftIO $ freeGC d gc
  if successful st'
    then do
      liftIO $ writeHistory $ Map.insertWith
                                (λxs ys →  take (historySize conf)
                                        · historyFilter conf $ xs ++ ys)
                                (showXPrompt t) [command st'] hist
      Just <$> action (command st')
    else return Nothing

-- 
gwern


More information about the xmonad mailing list