packages feed

yi-core 0.15.0 → 0.16.0

raw patch · 11 files changed

+25/−378 lines, 11 filesdep −text-icudep ~yi-rope

Dependencies removed: text-icu

Dependency ranges changed: yi-rope

Files

src/Yi/Buffer/HighLevel.hs view
@@ -860,11 +860,10 @@                   | otherwise = False  -- | Helper function: revert the buffer contents to its on-disk version-revertB :: YiString -> Maybe R.ConverterName -> UTCTime -> BufferM ()-revertB s cn now = do+revertB :: YiString -> UTCTime -> BufferM ()+revertB s now = do   r <- regionOfB Document   replaceRegionB r s-  encodingConverterNameA .= cn   markSavedB now  -- get lengths of parts covered by block region
src/Yi/Buffer/Misc.hs view
@@ -191,7 +191,6 @@   , increaseFontSize   , indentSettingsB   , fontsizeVariationA-  , encodingConverterNameA   , stickyEolA   , queryBuffer   ) where@@ -361,9 +360,6 @@     ro <-use readOnlyA     modeNm <- gets (withMode0 modeName)     unchanged <- gets isUnchangedBuffer-    enc <- use encodingConverterNameA >>= return . \case-      Nothing -> mempty :: T.Text-      Just cn -> T.pack $ R.unCn cn     let pct           | pos == 0 || s == 0 = " Top"           | pos == s = " Bot"@@ -375,7 +371,7 @@         toT = T.pack . show      nm <- gets $ shortIdentString (length prefix)-    return $ T.concat [ enc, " ", readOnly', changed, " ", nm+    return $ T.concat [ readOnly', changed, " ", nm                       , "     ", hexChar, "  "                       , "L", T.justifyRight 5 ' ' (toT ln)                       , "  "@@ -610,7 +606,6 @@             , updateTransactionInFlight = False             , updateTransactionAccum = mempty             , fontsizeVariation = 0-            , encodingConverterName = Nothing             , updateStream = mempty             } } 
src/Yi/Config/Simple.hs view
@@ -115,7 +115,6 @@  ) where  import           Lens.Micro.Platform (Lens', (%=), (%~), use, lens)-import           Control.Monad.State hiding (modify, get) import qualified Data.Text as T import qualified Data.Sequence as S import           Text.Printf(printf)
src/Yi/Core.hs view
@@ -254,8 +254,8 @@                      then R.readFile fname >>= return . \case                             Left m ->                               (runDummy b (readOnlyA .= True), Just $ msg3 m)-                            Right (newContents, c) ->-                              (runDummy b (revertB newContents (Just c) now), Just msg1)+                            Right newContents ->+                              (runDummy b (revertB newContents now), Just msg1)                      else return (b, Just msg2)                    else nothing          _ -> nothing
src/Yi/Dired.hs view
@@ -237,12 +237,11 @@     fileToNewBuffer :: FilePath -> YiM (Either T.Text BufferRef)     fileToNewBuffer f = io getCurrentTime >>= \n -> io (R.readFile f) >>= \case       Left m -> return $ Left m-      Right (contents, conv) -> do+      Right contents -> do         permissions <- io $ getPermissions f          b <- stringToNewBuffer (FileBuffer f) contents         withGivenBuffer b $ do-          encodingConverterNameA .= Just conv           markSavedB n           unless (writable permissions) (readOnlyA .= True) 
src/Yi/File.hs view
@@ -50,7 +50,7 @@ import           Yi.Editor import           Yi.Keymap              () import           Yi.Monad               (gets)-import qualified Yi.Rope                as R (readFile, writeFile, writeFileUsingText)+import qualified Yi.Rope                as R (readFile, writeFile) import           Yi.String              (showT) import           Yi.Types import           Yi.Utils               (io)@@ -89,11 +89,11 @@       now <- io getCurrentTime       rf <- liftBase $ R.readFile fp >>= \case         Left m -> print ("Can't revert: " <> m) >> return Nothing-        Right (c, cv) -> return $ Just (c, Just cv)+        Right c -> return $ Just c       case rf of        Nothing -> return ()-       Just (s, conv) -> do-         withCurrentBuffer $ revertB s conv now+       Just s -> do+         withCurrentBuffer $ revertB s now          printMsg ("Reverted from " <> showT fp)     Nothing -> printMsg "Can't revert, no file associated with buffer." @@ -142,23 +142,18 @@   nameContents <- withGivenBuffer bufferKey $ do     fl <- gets file     st <- streamB Forward 0-    conv <- use encodingConverterNameA-    return (fl, st, conv)+    return (fl, st)    case nameContents of-    (Just f, contents, conv) -> io (doesDirectoryExist f) >>= \case+    (Just f, contents) -> io (doesDirectoryExist f) >>= \case       True -> printMsg "Can't save over a directory, doing nothing." >> return False       False -> do         hooks <- view preSaveHooks <$> askCfg         mapM_ runAction hooks-        mayErr <- liftBase $ case conv of-          Nothing -> R.writeFileUsingText f contents >> return Nothing-          Just cn -> R.writeFile f contents cn-        case mayErr of-          Just err -> printMsg err >> return False-          Nothing -> io getCurrentTime >>= withGivenBuffer bufferKey . markSavedB-                     >> return True-    (Nothing, _, _) -> printMsg "Buffer not associated with a file" >> return False+        mayErr <- liftBase $ R.writeFile f contents+        io getCurrentTime >>= withGivenBuffer bufferKey . markSavedB+        return True+    (Nothing, _) -> printMsg "Buffer not associated with a file" >> return False  -- | Write current buffer to disk as @f@. The file is also set to @f@. fwriteToE :: T.Text -> YiM Bool
− src/Yi/Main.hs
@@ -1,178 +0,0 @@-{-# LANGUAGE CPP #-}-{-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE GeneralizedNewtypeDeriving #-}-{-# LANGUAGE OverloadedStrings #-}---- | This is the main module of Yi, called with configuration from the user.--- Here we mainly process command line arguments.--module Yi.Main (-                -- * Static main-                main,-                -- * Command line processing-                do_args,-                ConsoleConfig(..),-               ) where--import Control.Monad-import Data.Char-import Data.Monoid-import qualified Data.Text as T-import Data.List (intercalate)-import Data.Version (showVersion)-import Lens.Micro.Platform (view)-import System.Console.GetOpt-import System.Exit-#ifndef HLINT-#include "ghcconfig.h"-#endif--import Yi.Buffer-import Yi.Config-import Yi.Core (startEditor)-import Yi.Debug-import Yi.Editor-import Yi.File-import Yi.Keymap-import Yi.Option (YiOption, OptionError(..), yiCustomOptions)-import Yi.Paths (getConfigDir)-import Paths_yi_core---- | Configuration information which can be set in the command-line, but not--- in the user's configuration file.-data ConsoleConfig =-  ConsoleConfig {-     ghcOptions :: [String],-     selfCheck :: Bool,-     userConfigDir :: IO FilePath-  }--defaultConsoleConfig :: ConsoleConfig-defaultConsoleConfig =-  ConsoleConfig {-                  ghcOptions = [],-                  selfCheck = False,-                  userConfigDir = Yi.Paths.getConfigDir-                }---- ------------------------------------------------------------------------ | Argument parsing. Pretty standard.--data Opts = Help-          | Version-          | LineNo String-          | EditorNm String-          | File String-          | Frontend String-          | ConfigFile String-          | SelfCheck-          | GhcOption String-          | Debug-          | OpenInTabs-          | CustomNoArg YiOption-          | CustomReqArg (String -> YiOption) String-          | CustomOptArg (Maybe String -> YiOption) (Maybe String)---- | List of editors for which we provide an emulation.-editors :: [(String,Config -> Config)]-editors = []--builtinOptions :: [OptDescr Opts]-builtinOptions =-  [ Option []     ["self-check"]  (NoArg  SelfCheck)             "Run self-checks"-  , Option ['f']  ["frontend"]    (ReqArg Frontend   "FRONTEND") frontendHelp-  , Option ['y']  ["config-file"] (ReqArg ConfigFile "PATH")     "Specify a folder containing a configuration yi.hs file"-  , Option ['V']  ["version"]     (NoArg  Version)               "Show version information"-  , Option ['h']  ["help"]        (NoArg  Help)                  "Show this help"-  , Option []     ["debug"]       (NoArg  Debug)                 "Write debug information in a log file"-  , Option ['l']  ["line"]        (ReqArg LineNo     "NUM")      "Start on line number"-  , Option []     ["as"]          (ReqArg EditorNm   "EDITOR")   editorHelp-  , Option []     ["ghc-option"]  (ReqArg GhcOption  "OPTION")   "Specify option to pass to ghc when compiling configuration file"-  , Option [openInTabsShort] [openInTabsLong] (NoArg  OpenInTabs)  "Open files in tabs"-  ] where frontendHelp = "Select frontend"-          editorHelp   = "Start with editor keymap, where editor is one of:\n" ++ (intercalate ", " . fmap fst) editors--convertCustomOption :: OptDescr YiOption -> OptDescr Opts-convertCustomOption (Option short long desc help) = Option short long desc' help-    where desc' = convertCustomArgDesc desc--convertCustomArgDesc :: ArgDescr YiOption -> ArgDescr Opts-convertCustomArgDesc (NoArg o) = NoArg (CustomNoArg o)-convertCustomArgDesc (ReqArg f s) = ReqArg (CustomReqArg f) s-convertCustomArgDesc (OptArg f s) = OptArg (CustomOptArg f) s--customOptions :: Config -> [OptDescr Opts]-customOptions = fmap convertCustomOption . view yiCustomOptions--openInTabsShort :: Char-openInTabsShort = 'p'--openInTabsLong :: String-openInTabsLong = "open-in-tabs"---- | usage string.-usage :: [OptDescr Opts] -> T.Text-usage opts = T.pack $ usageInfo "Usage: yi [option...] [file]" opts--versinfo :: T.Text-versinfo = "yi " <> T.pack (showVersion version)---- | Transform the config with options-do_args :: Bool -> Config -> [String] -> Either OptionError (Config, ConsoleConfig)-do_args ignoreUnknown cfg args = let options = customOptions cfg ++ builtinOptions in-    case getOpt' (ReturnInOrder File) options args of-        (os, [], [], []) -> handle options os-        (os, _, u:us, []) -> if ignoreUnknown-                                    then handle options os-                                    else fail $ "unknown arguments: " ++ intercalate ", " (u:us)-        (_os, _ex, _ey, errs) -> fail (concat errs)-    where-        shouldOpenInTabs = ("--" ++ openInTabsLong) `elem` args-                         || ('-':[openInTabsShort]) `elem` args-        handle options os = foldM (getConfig options shouldOpenInTabs) (cfg, defaultConsoleConfig) (reverse os)---- | Update the default configuration based on a command-line option.-getConfig :: [OptDescr Opts] -> Bool -> (Config, ConsoleConfig) -> Opts -> Either OptionError (Config, ConsoleConfig)-getConfig options shouldOpenInTabs (cfg, cfgcon) opt =-    case opt of-      Frontend _    -> fail "Panic: frontend not found"-      Help          -> Left $ OptionError (usage options) ExitSuccess-      Version       -> Left $ OptionError versinfo ExitSuccess-      Debug         -> return (cfg { debugMode = True }, cfgcon)-      LineNo l      -> case startActions cfg of-                         x : xs -> return (cfg { startActions = x:makeAction (gotoLn (read l)):xs }, cfgcon)-                         []     -> fail "The `-l' option must come after a file argument"--      File filename -> if shouldOpenInTabs && not (null (startActions cfg)) then-                         prependActions [YiA $ openNewFile filename, EditorA newTabE]-                       else-                         prependAction $ openNewFile filename--      EditorNm emul -> case lookup (fmap toLower emul) editors of-             Just modifyCfg -> return (modifyCfg cfg, cfgcon)-             Nothing -> fail $ "Unknown emulation: " ++ show emul-      GhcOption ghcOpt -> return (cfg, cfgcon { ghcOptions = ghcOptions cfgcon ++ [ghcOpt] })-      ConfigFile f -> return (cfg, cfgcon { userConfigDir = return f })-      CustomNoArg o -> do-          cfg' <- o cfg-          return (cfg', cfgcon)-      CustomReqArg f s -> do-          cfg' <- f s cfg-          return (cfg', cfgcon)-      CustomOptArg f s -> do-          cfg' <- f s cfg-          return (cfg', cfgcon)-      _ -> return (cfg, cfgcon)-  where-    prependActions as = return (cfg { startActions = fmap makeAction as ++ startActions cfg }, cfgcon)-    prependAction a = return (cfg { startActions = makeAction a : startActions cfg}, cfgcon)---- ------------------------------------------------------------------------ | Static main. This is the front end to the statically linked--- application, and the real front end, in a sense. 'dynamic_main' calls--- this after setting preferences passed from the boot loader.----main :: (Config, ConsoleConfig) -> Maybe Editor -> IO ()-main (cfg, _cfgcon) state = do-  when (debugMode cfg) $ initDebug ".yi.dbg"-  startEditor cfg state
− src/Yi/Option.hs
@@ -1,125 +0,0 @@-{-# LANGUAGE TemplateHaskell #-}-{-# LANGUAGE GeneralizedNewtypeDeriving #-}-{-# LANGUAGE Rank2Types #-}-{-# OPTIONS_HADDOCK show-extensions #-}---- |--- Module      :  Yi.Option--- License     :  GPL-2--- Maintainer  :  yi-devel@googlegroups.com--- Stability   :  experimental--- Portability :  portable------ Command-line options--module Yi.Option-    (-    -- * Types-      YiOption-    , YiOptionDescr-    , YiOptions-    , OptionError(..)--    -- * Core-    , yiCustomOptions-    , consYiOption-    , consYiOptions--    -- * Argument-less options-    , yiBoolOption-    , yiFlagOption-    , yiActionFlagOption--    -- * Argument-taking options-    , yiStringOption-    , yiStringOption'-    , yiActionOption-    , yiActionOption'-    )-where--import           Data.Default          (Default)-import qualified Data.Text             as T (Text)-import           Data.Typeable         (Typeable)-import           Data.String           (IsString, fromString)-import           Lens.Micro.Platform   (Lens', makeLenses, over, set)-import           System.Exit           (ExitCode)-import           System.Console.GetOpt (OptDescr, ArgDescr(..))-import           Yi.Config.Lens        (configVariable, startActionsA)-import           Yi.Types              (Action, Config, YiConfigVariable)--data OptionError = OptionError T.Text ExitCode---- | An option is a function that attempts to change the configuration of the--- editor at runtime.-type YiOption = Config -> Either OptionError Config--type YiOptionDescr = OptDescr YiOption---- | Custom options that should be accepted. Provided in user configuration.------ The general flow is that the user adds options to his configuration. Options--- are essentially functions describing how to modify the configuration at runtime.--- When an option is called, it gets the current config and may modify it (to encode--- its value)-newtype YiOptions = YiOptions { _yiOptions :: [YiOptionDescr] }-    deriving (Default, Typeable)--instance YiConfigVariable YiOptions--makeLenses ''YiOptions---- | Lens for accessing the list of custom options.------ You can pretty much create whatever types of options you want with this.--- But most cases are taken care of by one of the helper functions in this module.-yiCustomOptions :: Lens' Config [YiOptionDescr]-yiCustomOptions = configVariable . yiOptions---- | Includes an extra option in the configuration. Small wrapper around 'yiCustomOptions'-consYiOption :: YiOptionDescr -> Config -> Config-consYiOption opt = over yiCustomOptions (opt:)---- | Like 'consYiOption' but supports multiple options. Convenient for keymaps which might--- want to install lots of options.-consYiOptions :: [YiOptionDescr] -> Config -> Config-consYiOptions opts = over yiCustomOptions (opts++)---- | An argument which sets some configuration value to 'True'.-yiBoolOption :: Lens' Config Bool -> ArgDescr YiOption-yiBoolOption lens = NoArg $ Right . set lens True---- | An argument which applies a function transforming some inner value of--- the configuration.-yiFlagOption :: Lens' Config a -> (a -> a) -> ArgDescr YiOption-yiFlagOption lens f = NoArg $ Right . over lens f---- | Flag that appends an action to the startup actions.-yiActionFlagOption :: Action -> ArgDescr YiOption-yiActionFlagOption action = NoArg f-    where f config = Right $ over startActionsA (++[action]) config- --- | Sets the value of an option which is any string type (hopefully text...)------ This is not meant to be fully applied. By only passing in the lens you--- will obtain a value suitable for use in OptDescr.-yiStringOption :: IsString a => Lens' Config a -> String -> ArgDescr YiOption-yiStringOption lens desc = ReqArg f desc-    where f string config = Right $ set lens (fromString string) config---- | Just like 'yiStringOption', except it applies a 'Just'. Useful for setting--- string-like values whose default is 'None'.-yiStringOption' :: IsString a => Lens' Config (Maybe a) -> String -> ArgDescr YiOption-yiStringOption' lens desc = ReqArg f desc-    where f string config = Right $ set lens (Just $ fromString string) config---- | Option that appends a parameterized action to the startup actions.-yiActionOption :: IsString a => (a -> Action) -> String -> ArgDescr YiOption-yiActionOption action desc = ReqArg f desc-    where f string config = Right $ over startActionsA (++[action (fromString string)]) config--yiActionOption' :: IsString a => (a -> Either OptionError Action) -> String -> ArgDescr YiOption-yiActionOption' action desc = ReqArg f desc-    where f string config = do-            action' <- action (fromString string)-            return $ over startActionsA (++[action']) config
src/Yi/Rectangle.hs view
@@ -17,41 +17,10 @@ import           Data.List           (sort, transpose) import           Data.Monoid         ((<>)) import qualified Data.Text           as T (Text, concat, justifyLeft, length)-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 import           Yi.String           (lines', mapLines, unlines')--alignRegion :: T.Text -> BufferM ()-alignRegion str = do-  s <- getSelectRegionB >>= unitWiseRegion Line-  modifyRegionB (R.fromText . alignText str . R.toText) s-  where-    regexSplit :: T.Text -> T.Text -> [T.Text]-    regexSplit pattern l = case ICU.find (ICU.regex [] pattern) l of-        Nothing -> error "regexSplit: text does not match"-        Just m  -> drop 1 $ ICU.unfold ICU.group m--    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 regex <$> ls--            columnsWidth :: [Int]-            columnsWidth = fmap (maximum . fmap T.length) $ transpose columns--            columns' :: [[T.Text]]-            columns' = fmap (zipWith (`T.justifyLeft` ' ') columnsWidth) columns--            ls' = T.concat <$> columns'---- | Align each line of the region on the given regex.--- Fails if it is not found in any line.-alignRegionOn :: T.Text -> BufferM ()-alignRegionOn s = alignRegion $ "^(.*)(" <> s <> ")(.*)"  -- | Get the selected region as a rectangle. -- Returns the region extended to lines, plus the start and end columns of the rectangle.
src/Yi/Types.hs view
@@ -58,7 +58,7 @@ import           Yi.Layout                      (AnyLayoutManager) import           Yi.Monad                       (getsAndModify) import           Yi.Process                     (SubprocessId, SubprocessInfo)-import qualified Yi.Rope                        as R (ConverterName, YiString)+import qualified Yi.Rope                        as R (YiString) import           Yi.Style                       (StyleName) import           Yi.Style.Library               (Theme) import           Yi.Syntax                      (ExtHL, Stroke)@@ -230,7 +230,6 @@     , updateTransactionInFlight :: !Bool     , updateTransactionAccum :: !(S.Seq Update)     , fontsizeVariation :: !Int-    , encodingConverterName :: !(Maybe R.ConverterName)       -- ^ How many points (frontend-specific) to change       -- the font by in this buffer     , updateStream :: !(S.Seq Update)@@ -241,16 +240,16 @@  instance Binary Yi.Types.Attributes where     put (Yi.Types.Attributes n b u bd pc pv se pu selectionStyle_-         _proc wm law lst ro ins _dc _pfw isTransacPresent transacAccum fv cn lg') = do+         _proc wm law lst ro ins _dc _pfw isTransacPresent transacAccum fv lg') = do       let putTime (UTCTime x y) = B.put (fromEnum x) >> B.put (fromEnum y)       B.put n >> B.put b >> B.put u >> B.put bd       B.put pc >> B.put pv >> B.put se >> B.put pu >> B.put selectionStyle_ >> B.put wm       B.put law >> putTime lst >> B.put ro >> B.put ins >> B.put _dc-      B.put isTransacPresent >> B.put transacAccum >> B.put fv >> B.put cn >> B.put lg'+      B.put isTransacPresent >> B.put transacAccum >> B.put fv >> B.put lg'     get = Yi.Types.Attributes <$> B.get <*> B.get <*> B.get <*> B.get <*>           B.get <*> B.get <*> B.get <*> B.get <*> B.get <*> pure I.End <*> B.get <*> B.get           <*> getTime <*> B.get <*> B.get <*> B.get-          <*> pure ({- TODO can serialise now -}mempty) <*> B.get <*> B.get <*> B.get <*> B.get <*> B.get+          <*> pure ({- TODO can serialise now -}mempty) <*> B.get <*> B.get <*> B.get <*> B.get       where         getTime = UTCTime <$> (toEnum <$> B.get) <*> (toEnum <$> B.get) 
yi-core.cabal view
@@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack  name:           yi-core-version:        0.15.0+version:        0.16.0 synopsis:       Yi editor core library category:       Yi homepage:       https://github.com/yi-editor/yi#readme@@ -65,14 +65,13 @@     , process-extras >= 0.3.3.8     , split >= 0.2     , text >= 1.1.1.3-    , text-icu >= 0.7     , time >= 1.1     , transformers-base     , unix-compat >= 0.1     , unordered-containers >= 0.1.3     , xdg-basedir >= 0.2.1     , yi-language >= 0.1.1.0-    , yi-rope >= 0.7.0.0 && < 0.9+    , yi-rope >= 0.10   if os(win32)     build-depends:         Win32@@ -125,14 +124,12 @@       Yi.Keymap.Keys       Yi.KillRing       Yi.Layout-      Yi.Main       Yi.MiniBuffer       Yi.Misc       Yi.Mode.Common       Yi.Mode.Compilation       Yi.Mode.Interactive       Yi.Monad-      Yi.Option       Yi.Paths       Yi.PersistentState       Yi.Process@@ -155,12 +152,12 @@       Yi.Window       System.FriendlyPath       Parser.Incremental+      Paths_yi_core   other-modules:       Control.Exc       Data.DelayList       System.CanonicalizePath       Yi.Buffer.Implementation-      Paths_yi_core   default-language: Haskell2010  test-suite tasty@@ -193,14 +190,13 @@     , process-extras >= 0.3.3.8     , split >= 0.2     , text >= 1.1.1.3-    , text-icu >= 0.7     , time >= 1.1     , transformers-base     , unix-compat >= 0.1     , unordered-containers >= 0.1.3     , xdg-basedir >= 0.2.1     , yi-language >= 0.1.1.0-    , yi-rope >= 0.7.0.0 && < 0.9+    , yi-rope >= 0.10     , tasty     , tasty-hunit     , tasty-quickcheck@@ -251,14 +247,13 @@     , process-extras >= 0.3.3.8     , split >= 0.2     , text >= 1.1.1.3-    , text-icu >= 0.7     , time >= 1.1     , transformers-base     , unix-compat >= 0.1     , unordered-containers >= 0.1.3     , xdg-basedir >= 0.2.1     , yi-language >= 0.1.1.0-    , yi-rope >= 0.7.0.0 && < 0.9+    , yi-rope >= 0.10     , yi-core     , criterion     , deepseq