From 60703980702455c454a4b463598ff9078d1e3850 Mon Sep 17 00:00:00 2001 From: Martin Potier Date: Thu, 3 Aug 2023 09:12:05 +0300 Subject: [PATCH] Remove manual fuzzy matching, and use the dedicated module --- lib/KeyBindings.hs | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/lib/KeyBindings.hs b/lib/KeyBindings.hs index 1a93c3e..34ea4fd 100644 --- a/lib/KeyBindings.hs +++ b/lib/KeyBindings.hs @@ -4,11 +4,12 @@ module KeyBindings ( ) where import Control.Monad (void) +import Data.Foldable (forM_) import Data.List (sort, isSuffixOf) import Data.Maybe (isJust) import Graphics.X11.Types import System.Exit -import Text.EditDistance +-- import Text.EditDistance import XMonad import XMonad.Actions.CopyWindow (kill1,copy) import XMonad.Actions.CycleWS @@ -18,6 +19,7 @@ import XMonad.Layout.ToggleLayouts import XMonad.Operations import XMonad.Prompt import XMonad.Prompt.ConfirmPrompt +import XMonad.Prompt.FuzzyMatch import XMonad.Prompt.Shell import XMonad.Prompt.Workspace (workspacePrompt) import XMonad.Util.EZConfig @@ -107,18 +109,20 @@ promptConfig = def , font = "xft:Iosevka Samae:style=Regular:size=10:charwidth=6.5" , height = 24 , promptBorderWidth = 5 + -- Fuzzysearch by default + , searchPredicate = fuzzyMatch + , sorter = fuzzySort } --- Slightly taken from --- https://mail.haskell.org/pipermail/xmonad/2010-October/010671.html -data FuzzySpawn = FuzzySpawn deriving (Read, Show) -instance XPrompt FuzzySpawn where showXPrompt _ = "RunC: " -fuzzyPrompt config = do - cmds <- io getCommands - let compl s - | null s = [] - | otherwise = let weight c = levenshteinDistance defaultEditCosts s c - in map snd $ take 20 $ sort $ map (\c -> (weight c,c)) cmds - mkXPrompt FuzzySpawn config (return . compl) spawn - --- https://github.com/MasseR/xmonad-masser/blob/master/src/XMonad/Password.hs +-- -- Slightly taken from +-- -- https://mail.haskell.org/pipermail/xmonad/2010-October/010671.html +-- data FuzzySpawn = FuzzySpawn deriving (Read, Show) +-- instance XPrompt FuzzySpawn where showXPrompt _ = "RunC: " +-- fuzzyPrompt config = do +-- cmds <- io getCommands +-- let compl s +-- | null s = [] +-- | otherwise = let weight c = levenshteinDistance defaultEditCosts s c +-- in map snd $ take 20 $ sort $ map (\c -> (weight c,c)) cmds +-- mkXPrompt FuzzySpawn config (return . compl) spawn +--