yi-0.18.0/Main.hs0000644000000000000000000000655313306261647011650 0ustar0000000000000000{-# LANGUAGE CPP #-} import Control.Monad.State.Lazy (execStateT) import Data.List (intersperse) import Lens.Micro.Platform ((.=)) import Data.Maybe (fromMaybe) import Data.Monoid ((<>)) import Data.Version (showVersion) import Paths_yi_core (version) import Options.Applicative import Yi hiding (option) import Yi.Config.Simple.Types import Yi.Buffer.Misc (lineMoveRel) import Yi.Config.Default.HaskellMode (configureHaskellMode) import Yi.Config.Default.JavaScriptMode (configureJavaScriptMode) import Yi.Config.Default.MiscModes (configureMiscModes) #ifdef VIM import Yi.Config.Default.Vim (configureVim) #endif #ifdef VTY import Yi.Config.Default.Vty (configureVty) #endif #ifdef EMACS import Yi.Config.Default.Emacs (configureEmacs) #endif #ifdef PANGO import Yi.Config.Default.Pango (configurePango) #endif frontends :: [(String, ConfigM ())] frontends = [ #ifdef PANGO ("pango", configurePango), #endif #ifdef VTY ("vty", configureVty), #endif ("", return ()) ] keymaps :: [(String, ConfigM ())] keymaps = [ #ifdef EMACS ("emacs", configureEmacs), #endif #ifdef VIM ("vim", configureVim), #endif ("", return ()) ] data CommandLineOptions = CommandLineOptions { frontend :: Maybe String , keymap :: Maybe String , startOnLine :: Maybe Int , files :: [String] } commandLineOptions :: Parser (Maybe CommandLineOptions) commandLineOptions = flag' Nothing ( long "version" <> short 'v' <> help "Show the version number") <|> (Just <$> (CommandLineOptions <$> optional (strOption ( long "frontend" <> short 'f' <> metavar "FRONTEND" <> help "The frontend to use (default is pango)")) <*> optional (strOption ( long "keymap" <> short 'k' <> metavar "KEYMAP" <> help "The keymap to use (default is emacs)")) <*> optional (option auto ( long "line" <> short 'l' <> metavar "NUM" <> help "Open the (last) file on line NUM")) <*> many (argument str (metavar "FILES...")) )) main :: IO () main = do mayClo <- execParser opts case mayClo of Nothing -> putStrLn $ "Yi " <> showVersion version Just clo -> do let openFileActions = intersperse (EditorA newTabE) (map (YiA . openNewFile) (files clo)) moveLineAction = YiA $ withCurrentBuffer (lineMoveRel (fromMaybe 0 (startOnLine clo))) cfg <- execStateT (runConfigM (myConfig (frontend clo) (keymap clo) >> (startActionsA .= (openFileActions ++ [moveLineAction])))) defaultConfig startEditor cfg Nothing where opts = info (helper <*> commandLineOptions) ( fullDesc <> progDesc "Edit files" <> header "Yi - a flexible and extensible text editor written in haskell") myConfig :: Maybe String -> Maybe String -> ConfigM () myConfig f k = do -- Lookup f in the frontends list or pick the first element of the frontends list if -- f is nothing or do nothing if f is not found in the frontends list. case f of Nothing -> snd (head frontends) Just f' -> fromMaybe (return ()) (lookup f' frontends) -- Same as above, but then with k and keymaps case k of Nothing -> snd (head keymaps) Just k' -> fromMaybe (return ()) (lookup k' keymaps) configureHaskellMode configureJavaScriptMode configureMiscModes yi-0.18.0/Setup.hs0000644000000000000000000000012613226661437012054 0ustar0000000000000000#!/usr/bin/env runhaskell import Distribution.Simple main :: IO () main = defaultMain yi-0.18.0/yi.cabal0000644000000000000000000000310713326314772012025 0ustar0000000000000000name: yi version: 0.18.0 synopsis: Yi editor category: Yi homepage: https://github.com/yi-editor/yi#readme bug-reports: https://github.com/yi-editor/yi/issues maintainer: Yi developers license: GPL-2 build-type: Simple cabal-version: >= 1.10 source-repository head type: git location: https://github.com/yi-editor/yi flag emacs description: Include the emacs keymap manual: True default: True flag pango description: Include the pango (GUI) frontend, this flag is ignored if compiling with ghc >= 8.2 manual: True default: True flag vim description: Include the vim keymap manual: True default: True flag vty description: Include the vty (CLI) frontend manual: True default: True executable yi main-is: Main.hs hs-source-dirs: ./. ghc-options: -Wall -ferror-spans -threaded -eventlog -rtsopts build-depends: base >= 4.8 && < 5 , microlens-platform >= 0.3.4.0 , mtl >= 2.2.1 , optparse-applicative >= 0.13.0.0 , yi-core >= 0.18 , yi-misc-modes >= 0.18 , yi-mode-haskell >= 0.18 , yi-mode-javascript >= 0.18 , yi-rope >= 0.10 if flag(vty) cpp-options: -DVTY build-depends: yi-frontend-vty >= 0.18 if flag(pango) && impl(ghc < 8.2) cpp-options: -DPANGO build-depends: yi-frontend-pango >= 0.18 if flag(vim) cpp-options: -DVIM build-depends: yi-keymap-vim >= 0.18 if flag(emacs) cpp-options: -DEMACS build-depends: yi-keymap-emacs >= 0.18 default-language: Haskell2010