Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Nicer printing when completing filenames in ex commands.

Earlier:
    :e src/library/Yi/Com<TAB>
    src/library/Yi/Command.hs src/library/Yi/Completion.hs
Now:
    :e src/library/Yi/Com<TAB>
    Command.hs Completion.hs
  • Loading branch information...
commit a6071624620db03ff6c74814dd98050d0c28847d 1 parent 0d64cbd
@ethercrow ethercrow authored
Showing with 29 additions and 9 deletions.
  1. +10 −5 yi/src/library/Yi/Completion.hs
  2. +19 −4 yi/src/library/Yi/Keymap/Vim.hs
View
15 yi/src/library/Yi/Completion.hs
@@ -3,6 +3,7 @@
module Yi.Completion
( completeInList, completeInList'
+ , completeInListCustomShow
, commonPrefix
, prefixMatch, infixMatch
, containsMatch', containsMatch, containsMatchCaseInsensitive
@@ -49,16 +50,20 @@ containsMatchCaseInsensitive = containsMatch' False
-- and a list of possibilites. Matching function should return the
-- part of the string that matches the user string.
completeInList :: String -> (String -> Maybe String) -> [String] -> EditorM String
-completeInList s match l
+completeInList = completeInListCustomShow id
+
+-- | Same as 'completeInList', but maps @showFunction@ on possible matches when printing
+completeInListCustomShow :: (String -> String) -> String -> (String -> Maybe String) ->
+ [String] -> EditorM String
+completeInListCustomShow showFunction s match possibilities
| null filtered = printMsg "No match" >> return s
| prefix /= s = return prefix
| isSingleton filtered = printMsg "Sole completion" >> return s
| prefix `elem` filtered = printMsg ("Complete, but not unique: " ++ show filtered) >> return s
- | otherwise = printMsgs filtered >> return s
+ | otherwise = printMsgs (map showFunction filtered) >> return s
where
- prefix = commonPrefix filtered
- -- filtered = nub $ catMaybes $ fmap match l
- filtered = filterMatches match l
+ prefix = commonPrefix filtered
+ filtered = filterMatches match possibilities
completeInList' :: String -> (String -> Maybe String) -> [String] -> EditorM String
completeInList' s match l
View
23 yi/src/library/Yi/Keymap/Vim.hs
@@ -46,7 +46,7 @@ import Yi.Prelude
import Data.Binary
import Data.Char
-import Data.List (nub, take, words, dropWhile, takeWhile, intersperse, reverse)
+import Data.List (nub, take, words, dropWhile, takeWhile, intersperse, reverse, isSuffixOf)
import Data.Maybe (fromMaybe, isJust)
import Data.Either (either)
import Data.Prototype
@@ -59,7 +59,7 @@ import System.PosixCompat.Files (fileExist)
#else
import System.Posix (fileExist)
#endif
-import System.FilePath (FilePath)
+import System.FilePath (FilePath, takeFileName)
import System.Directory (getCurrentDirectory, setCurrentDirectory)
import Control.Monad.State hiding (mapM_, mapM, sequence)
@@ -78,7 +78,7 @@ import Yi.Regex (seInput, regexEscapeString)
import Yi.Search
import Yi.Style
import Yi.TextCompletion
-import Yi.Completion (containsMatch', mkIsPrefixOf)
+import Yi.Completion (containsMatch', mkIsPrefixOf, prefixMatch, completeInListCustomShow)
import Yi.Tag
import Yi.Window (bufkey)
import Yi.Hoogle (hoogle, hoogleSearch)
@@ -436,6 +436,21 @@ exInfixComplete' caseSensitive compl s' = do
exInfixComplete :: (String -> YiM [String]) -> String -> YiM ()
exInfixComplete = exInfixComplete' True
+exFileNameComplete :: String -> YiM ()
+exFileNameComplete s' = mkCompleteFn (completeInListCustomShow basename)
+ prefixMatch (matchingFileNames Nothing) s >>=
+ withBuffer . insertN . drop (length s)
+ where s = dropWhile isSpace s'
+
+ -- this tries to resemble 'basename' utility:
+ -- basename "foo/bar.baz" = "bar.baz"
+ -- basename "foo/bar/" = "bar"
+ -- but
+ -- System.FilePath.takeBaseName "foo/bar.baz" = "bar"
+ -- System.FilePath.takeFileName "foo/bar/" = ""
+ basename f = takeFileName $ if "/" `isSuffixOf` f then init f
+ else f
+
mkExHistComplete :: (String -> String -> Bool) -> (String -> YiM [String]) -> String -> YiM ()
mkExHistComplete matchFn compl s =
mkWordComplete (return s) compl (withEditor . printMsgs . tail) matchFn >>=
@@ -1290,7 +1305,7 @@ exMode self prompt = do
insertN fn
Nothing -> return ()
- | otherwise = exSimpleComplete (matchingFileNames Nothing) f
+ | otherwise = exFileNameComplete f
b_complete = exSimpleComplete matchingBufferNames
ex_complete ('c':'d':' ':f) = f_complete f
Please sign in to comment.
Something went wrong with that request. Please try again.