Skip to content

Commit

Permalink
Remove regex-tdfa, and bump lens version
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddhanathan Shanmugam committed Jul 1, 2015
1 parent 2cfd937 commit 5b86802
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 22 deletions.
12 changes: 7 additions & 5 deletions src/library/Yi/Dired.hs
Expand Up @@ -62,6 +62,7 @@ import qualified Data.Map as M (Map, assocs, delete, empty,
import Data.Maybe (fromMaybe)
import Data.Monoid (mempty, (<>))
import qualified Data.Text as T (Text, pack, unpack)
import qualified Data.Text.ICU as ICU (regex, find, unfold, group, MatchOption(..))
import Data.Time.Clock.POSIX (posixSecondsToUTCTime)
import Data.Typeable (Typeable)
import System.CanonicalizePath (canonicalizePath)
Expand Down Expand Up @@ -103,7 +104,6 @@ import Yi.Keymap.Keys
import Yi.MiniBuffer (noHint, spawnMinibufferE, withMinibuffer, withMinibufferFree)
import Yi.Misc (getFolder, promptFile)
import Yi.Monad (gets)
import Yi.Regex (AllTextSubmatches (..), (=~))
import qualified Yi.Rope as R
import Yi.String (showT)
import Yi.Style
Expand Down Expand Up @@ -258,10 +258,12 @@ editFile filename = do
content <- withGivenBuffer b elemsB

let header = R.take 1024 content
rx = "\\-\\*\\- *([^ ]*) *\\-\\*\\-" :: String
hmode = case R.toString header =~ rx of
AllTextSubmatches [_,m] -> T.pack m
_ -> ""
rx = ICU.regex [] "\\-\\*\\- *([^ ]*) *\\-\\*\\-"
hmode = case ICU.find rx (R.toText header) of
Nothing -> ""
Just m -> case (ICU.unfold ICU.group m) of
[_, n] -> n
_ -> ""
Just mode = find (\(AnyMode m) -> modeName m == hmode) tbl <|>
find (\(AnyMode m) -> modeApplies m f header) tbl <|>
Just (AnyMode emptyMode)
Expand Down
15 changes: 8 additions & 7 deletions src/library/Yi/Modes.hs
Expand Up @@ -21,13 +21,14 @@ module Yi.Modes (TokenBasedMode, fundamentalMode,
gitCommitMode, rubyMode, styleMode
) where

import "regex-tdfa" Text.Regex.TDFA ((=~))

import Control.Applicative ((<$>))
import Control.Lens ((%~), (&), (.~), (^.))
import Data.List (isPrefixOf)
import Data.Maybe (fromMaybe)
import Data.Maybe (fromMaybe, isJust)
import System.FilePath (takeDirectory, takeExtension, takeFileName)
import qualified Data.Text as T (Text)
import qualified Data.Text.ICU as ICU (regex, find, MatchOption(..))

import Yi.Buffer
import qualified Yi.IncrementalParse as IncrParser (scanner)
import Yi.Keymap (YiM)
Expand All @@ -50,7 +51,7 @@ import qualified Yi.Lexer.Srmc as Srmc (lexer)
import qualified Yi.Lexer.SVNCommit as SVNCommit (lexer)
import qualified Yi.Lexer.Whitespace as Whitespace (lexer)
import Yi.MiniBuffer (anyModeByNameM)
import qualified Yi.Rope as R (YiString, toString)
import qualified Yi.Rope as R (YiString, toText)
import Yi.Search (makeSimpleSearch)
import Yi.Style (StyleName)
import Yi.Syntax (ExtHL (ExtHL))
Expand Down Expand Up @@ -233,10 +234,10 @@ anyExtension extensions fileName _contents

-- | When applied to an extensions list and regular expression pattern, creates
-- a 'Mode.modeApplies' function.
extensionOrContentsMatch :: [String] -> String -> FilePath -> R.YiString -> Bool
extensionOrContentsMatch :: [String] -> T.Text -> FilePath -> R.YiString -> Bool
extensionOrContentsMatch extensions pattern fileName contents
= extensionMatches extensions fileName || contentsMatch
where contentsMatch = R.toString contents =~ pattern :: Bool
= extensionMatches extensions fileName || contentsMatch contents
where contentsMatch = isJust . ICU.find (ICU.regex [] pattern) . R.toText

-- | Adds a hook to all matching hooks in a list
hookModes :: (AnyMode -> Bool) -> BufferM () -> [AnyMode] -> [AnyMode]
Expand Down
13 changes: 6 additions & 7 deletions src/library/Yi/Rectangle.hs
Expand Up @@ -13,13 +13,12 @@

module Yi.Rectangle where

import "regex-tdfa" Text.Regex.TDFA ( (=~), AllTextSubmatches(..) )

import Control.Applicative ((<$>))
import Control.Monad (forM_)
import Data.List (sort, transpose)
import Data.Monoid ((<>))
import qualified Data.Text as T (Text, concat, justifyLeft, length, pack, unpack)
import qualified Data.Text.ICU as ICU (regex, find, unfold, group)
import Yi.Buffer
import Yi.Editor (EditorM, getRegE, setRegE, withCurrentBuffer)
import qualified Yi.Rope as R
Expand All @@ -30,17 +29,17 @@ alignRegion str = do
s <- getSelectRegionB >>= unitWiseRegion Line
modifyRegionB (R.fromText . alignText str . R.toText) s
where
regexSplit :: String -> String -> [T.Text]
regexSplit regex l = case l =~ regex of
AllTextSubmatches (_:matches) -> T.pack <$> matches
_ -> error "regexSplit: text does not match"
regexSplit :: T.Text -> T.Text -> [T.Text]
regexSplit r l = case ICU.find (ICU.regex [] r) l of
Just m -> drop 1 $ ICU.unfold ICU.group m
Nothing -> error "regexSplit: text does not match"

alignText :: T.Text -> T.Text -> T.Text
alignText regex text = unlines' ls'
where ls, ls' :: [T.Text]
ls = lines' text
columns :: [[T.Text]]
columns = regexSplit (T.unpack regex) <$> (T.unpack <$> ls)
columns = regexSplit regex <$> ls

columnsWidth :: [Int]
columnsWidth = fmap (maximum . fmap T.length) $ transpose columns
Expand Down
2 changes: 1 addition & 1 deletion src/library/Yi/UI/Pango.hs
Expand Up @@ -23,7 +23,7 @@ module Yi.UI.Pango (start, startGtkHook) where
import Control.Applicative
import Control.Concurrent
import Control.Exception (catch, SomeException)
import Control.Lens hiding (set, Action, from)
import Control.Lens hiding (set, from)
import Control.Monad hiding (forM_, mapM_, forM, mapM)
import Data.Foldable
import Data.IORef
Expand Down
5 changes: 3 additions & 2 deletions yi.cabal
Expand Up @@ -273,7 +273,7 @@ library
bytestring >= 0.9.1 && < 0.11,
dynamic-state >= 0.1.0.5,
data-default,
lens >= 4.4.0.1,
lens >= 4.7,
dlist >=0.4.1,
dyre >=0.8.11,
filepath >= 1.1,
Expand All @@ -283,6 +283,7 @@ library
pointedlist >= 0.5,
regex-base ==0.93.*,
regex-tdfa >= 1.1 && <1.3,
text-icu >= 0.7,
safe >= 0.3.4 && < 0.4,
split >= 0.1 && < 0.3,
template-haskell >= 2.4,
Expand Down Expand Up @@ -391,7 +392,7 @@ Test-Suite test-suite
Vim.TestPureEditorManipulations
build-depends:
base,
lens >= 4.4.0.1,
lens >= 4.7,
semigroups,
tasty,
tasty-hunit,
Expand Down

0 comments on commit 5b86802

Please sign in to comment.