xmonad-contrib-0.18.0: Community-maintained extensions for xmonad
Copyright(C) 2015 Norbert Zeh
LicenseGPL
MaintainerNorbert Zeh <norbert.zeh@gmail.com>
Stabilityunstable
Portabilityunportable
Safe HaskellSafe-Inferred
LanguageHaskell2010

XMonad.Prompt.FuzzyMatch

Contents

Description

A module for fuzzy completion matching in prompts akin to emacs ido mode.

Synopsis

Usage

This module offers two aspects of fuzzy matching of completions offered by XMonad.Prompt.

fuzzyMatch can be used as the searchPredicate in the XPConfig. The effect is that any completion that contains the currently typed characters as a subsequence is a valid completion; matching is case insensitive. This means that the sequence of typed characters can be obtained from the completion by deleting an appropriate subset of its characters. Example: "spr" matches "FastSPR" but also "SuccinctParallelTrees" because it's a subsequence of the latter: "S.......P.r..........".

While this type of inclusiveness is helpful most of the time, it sometimes also produces surprising matches. fuzzySort helps sorting matches by relevance, using a simple heuristic for measuring relevance. The matches are sorted primarily by the length of the substring that contains the query characters and secondarily the starting position of the match. So, if the search string is "spr" and the matches are "FastSPR", "FasterSPR", and "SuccinctParallelTrees", then the order is "FastSPR", "FasterSPR", "SuccinctParallelTrees" because both "FastSPR" and "FasterSPR" contain "spr" within a substring of length 3 ("SPR") while the shortest substring of "SuccinctParallelTrees" that matches "spr" is "SuccinctPar", which has length 11. "FastSPR" is ranked before "FasterSPR" because its match starts at position 5 while the match in "FasterSPR" starts at position 7.

To use these functions in an XPrompt, for example, for windowPrompt:

import XMonad.Prompt
import XMonad.Prompt.Window ( windowPrompt )
import XMonad.Prompt.FuzzyMatch

myXPConfig = def { searchPredicate = fuzzyMatch
                 , sorter          = fuzzySort
                 }

then add this to your keys definition:

, ((modm .|. shiftMask, xK_g), windowPrompt myXPConfig Goto allWindows)

For detailed instructions on editing the key bindings, see the tutorial.

fuzzyMatch :: String -> String -> Bool Source #

Returns True if the first argument is a subsequence of the second argument, that is, it can be obtained from the second sequence by deleting elements.

fuzzySort :: String -> [String] -> [String] Source #

Sort the given set of strings by how well they match. Match quality is measured first by the length of the substring containing the match and second by the positions of the matching characters in the string.