yi-fuzzy-open 0.1.0 → 0.1.0.1
raw patch · 3 files changed
+43/−13 lines, 3 filessetup-changedPVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
API changes (from Hackage documentation)
+ Yi.Fuzzy: defaultDepth :: Int
+ Yi.Fuzzy: fuzzyOpenWithDepth :: Int -> YiM ()
Files
- Setup.hs +2/−0
- src/Yi/Fuzzy.hs +36/−12
- yi-fuzzy-open.cabal +5/−1
Setup.hs view
@@ -1,2 +1,4 @@+#!/usr/bin/env runhaskell import Distribution.Simple+main :: IO () main = defaultMain
src/Yi/Fuzzy.hs view
@@ -1,5 +1,6 @@ {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveGeneric #-}+{-# LANGUAGE LambdaCase #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} {-# OPTIONS_HADDOCK show-extensions #-}@@ -14,7 +15,7 @@ -- TODO if need arises: factor out generic part that captures a pattern of -- having an interactive minibuffer and a window that just renders some state. -module Yi.Fuzzy (fuzzyOpen) where+module Yi.Fuzzy (fuzzyOpen, fuzzyOpenWithDepth, defaultDepth) where import Control.Applicative import Control.Monad@@ -32,7 +33,7 @@ import GHC.Generics import System.Directory (doesDirectoryExist, getDirectoryContents) import System.FilePath ((</>))-+import System.IO.Error import Yi import Yi.Completion import Yi.MiniBuffer@@ -40,6 +41,10 @@ import Yi.Types import Yi.Utils () +-- The following import is a hack which silences redundant import+-- warnings on recent (4.8.0.0) base+import Prelude+ -- FuzzyState is stored in minibuffer's dynamic state data FuzzyState = FuzzyState { _fsItems :: !(V.Vector FuzzyItem)@@ -58,15 +63,30 @@ itemToString (BufferItem (MemBuffer x)) = T.unpack x itemToString (BufferItem (FileBuffer x)) = x +-- | The depth 'fuzzyOpen' should traverse by default. Currently+-- __5__.+defaultDepth :: Int+defaultDepth = 5++-- | Fuzzy open the current directory. The depth searched is+-- 'defaultDepth', use fuzzyOpenWithDepth if you want to customise+-- this. fuzzyOpen :: YiM ()-fuzzyOpen = do+fuzzyOpen = fuzzyOpenWithDepth defaultDepth++-- | Fuzzy-opens the directory to the specified depth. The depth needs+-- to be at least @1@ for it to do anything meaningful.+fuzzyOpenWithDepth :: Int -> YiM ()+fuzzyOpenWithDepth d = case () of+ _ | d <= 0 -> printMsg "You need at least depth of 1 for fuzzyOpenWithDepth"+ | otherwise -> do fileList <- fmap (fmap FileItem)- (liftBase (getRecursiveContents "."))+ (liftBase (getRecursiveContents d ".")) bufList <- fmap (fmap (BufferItem . ident . attributes)) (withEditor (gets (M.elems . buffers))) promptRef <- withEditor (spawnMinibufferE "" (const localKeymap)) let initialState =- FuzzyState (V.fromList (fileList <> bufList))+ FuzzyState (fileList <> V.fromList bufList) (Just 0) "" withGivenBuffer promptRef $ do@@ -77,22 +97,26 @@ -- takes about 3 seconds to traverse linux kernel, which is not too outrageous -- TODO: check if it works at all with cyclic links -- TODO: perform in background, limit file count or directory depth-getRecursiveContents :: FilePath -> IO [FilePath]-getRecursiveContents topdir = do- names <- getDirectoryContents topdir+getRecursiveContents :: Int -> FilePath -> IO (V.Vector FilePath)+getRecursiveContents d _ | d <= 0 = return mempty+getRecursiveContents d t = tryIOError (getDirectoryContents t) >>= \case+ Left _ -> return mempty+ Right names -> do let properNames = filter predicate names++ predicate :: FilePath -> Bool predicate fileName = and [ fileName `notElem` [".", "..", ".git", ".svn"] , not (".hi" `isSuffixOf` fileName) , not ("-boot" `isSuffixOf` fileName) ] paths <- forM properNames $ \name -> do- let path = topdir </> name+ let path = t </> name isDirectory <- doesDirectoryExist path if isDirectory- then getRecursiveContents path- else return [path]- return (concat paths)+ then getRecursiveContents (d - 1) path+ else return $ V.singleton path+ return $ mconcat paths localKeymap :: Keymap localKeymap =
yi-fuzzy-open.cabal view
@@ -1,5 +1,5 @@ name: yi-fuzzy-open-version: 0.1.0+version: 0.1.0.1 category: Development, Editor synopsis: Fuzzy open plugin for Yi. description:@@ -35,3 +35,7 @@ , yi-rope ghc-options: -Wall++source-repository head+ type: git+ location: https://github.com/yi-editor/yi-fuzzy-open.git