Permalink
Browse files

Bring yi-contrib back into main repo

  • Loading branch information...
1 parent 973fbcc commit 32fb55339e70dbd062267da2eef38597a4d8e4cc @jeffwheeler jeffwheeler committed Mar 21, 2011
View
@@ -0,0 +1,9 @@
+*.hi
+*.hi-boot
+*.o
+*.o-boot
+*.o.cmd
+*.swp
+Yi/Lexer/*.hs
+.yi.*.dbg
+dist/
View
Oops, something went wrong.
@@ -0,0 +1,48 @@
+module Yi.Config.Users.Anders (config) where
+
+import Yi hiding (Block, (.))
+import qualified Yi.Mode.Haskell as H
+import Yi.Hoogle (hoogle)
+import Yi.String (mapLines)
+import Yi.Modes (removeAnnots)
+
+config :: Config
+config = defaultEmacsConfig
+
+-- | Increase the indentation of the selection
+increaseIndent :: BufferM ()
+increaseIndent = do
+ r <- getSelectRegionB
+ r' <- unitWiseRegion Yi.Line r
+ -- extend the region to full lines
+ modifyRegionB (mapLines (' ':)) r'
+ -- prepend each line with a space
+
+main :: IO ()
+main = yi $ config
+ { defaultKm = defaultKm config
+ , startFrontEnd = startFrontEnd config
+ , modeTable =
+ -- My precise mode with my hooks added
+ AnyMode (haskellModeHooks H.preciseMode)
+ -- My no annotations mode with mode hooks
+ : AnyMode (haskellModeHooks noAnnots)
+ : modeTable defaultConfig
+ }
+
+-- | Set my hooks for nice features
+haskellModeHooks mode =
+ mode { modeName = "my " ++ modeName mode
+ , modeKeymap =
+ topKeymapA ^: ((ctrlCh 'c' ?>>
+ choice [ ctrlCh 'l' ?>>! H.ghciLoadBuffer
+ , ctrl (char 'z') ?>>! H.ghciGet
+ , ctrl (char 'h') ?>>! hoogle
+ , ctrlCh 'r' ?>>! H.ghciSend ":r"
+ , ctrlCh 't' ?>>! H.ghciInferType
+ , ctrlCh 'n' ?>>! increaseIndent
+ ])
+ <||) }
+
+-- This is used in order to remove the unicode characters usually used.
+noAnnots = removeAnnots (H.preciseMode {modeName = "preciseNoUnicode"})
@@ -0,0 +1,117 @@
+{-
+
+If Yi is called with parameter "--type", it will insert 500 characters and exit.
+With "--open", it will open a buffer, type, and kill the buffer, 50 times.
+Pango and Vty frontends are supported.
+
+Pango build, test, profile:
+
+ cabal build &&
+ dist/build/yi/yi -fpango time +RTS -hr &&
+ hp2ps -c yi.hp &&
+ evince yi.ps
+
+Vty timing using the "empty-expect" package on Debian:
+
+ empty -f -i in -o out -f dist/build/yi/yi time "$@" &&
+ time cat out >/dev/null
+
+-}
+
+import Yi
+import Yi.Prelude
+import Prelude (take)
+import Yi.Keymap.Emacs (keymap)
+import qualified Yi.UI.Common as Common
+import qualified Yi.UI.Vty as Vty
+import qualified Yi.UI.Pango as Pango
+import Yi.Event (Event(Event),Key(KASCII,KEnter))
+--import Yi.Mode.Latex
+import Yi.Mode.Haskell
+
+import Control.Concurrent (forkIO)
+import System.IO (readFile)
+import System.Environment
+import Data.Char
+import Graphics.UI.Gtk hiding (on, Region, Window, Action, Point, Style)
+import Control.Exception
+import qualified Data.List as L
+nil :: IO a -> IO ()
+nil = (() <$)
+
+type IdleDo = [IO ()] -> IO ()
+idleDoVty :: IdleDo
+idleDoVty = nil . forkIO . sequence_
+
+-- Run in the background enough that the display refereshes
+idleDoPango :: IdleDo
+idleDoPango = foldr idleDo1 (return ())
+idleDo1 :: IO () -> IO () -> IO ()
+idleDo1 a b = nil $ idleAdd (a >> b >> return False) priorityDefaultIdle
+
+main :: IO ()
+main = do
+ args <- getArgs
+ when ("--debug" `elem` args) (initDebug ".yi.dbg")
+ let typing = "--type" `elem` args
+ opening = "--open" `elem` args
+ pango = "-fpango" `elem` args
+ testing = typing || opening
+
+ evs <- if typing then do typingEvs else openingEvs
+
+ let mystart = if pango then Pango.start else Vty.start
+ let idleDo = if pango then idleDoPango else idleDoVty
+ withArgs (if testing then [] else args) . yi $
+ defaultEmacsConfig
+ { defaultKm = keymap
+ , startActions = []
+ , startFrontEnd = (if testing then timeStart idleDo evs else id) mystart
+ , configInputPreprocess = idAutomaton
+ }
+
+timeStart :: IdleDo -> [Event] -> UIBoot -> UIBoot
+timeStart idleDo evs start p1 ch actionCh p4 = do
+ ui <- start p1 ch actionCh p4
+ evaluate (L.length evs)
+ return ui
+ { Common.main = do
+ actionCh . (:[]) . makeAction . withBuffer0 $ setMode Yi.Mode.Haskell.fastMode
+ idleDo (fmap ch evs)
+ Common.main ui
+ }
+
+-- Test sequences
+typingEvs, openingEvs :: IO [Event]
+
+typingEvs = do
+ --text <- take 500 <$> readFile "doc/haskell08/haskell039-bernardy.tex"
+ text <- readFile "src/Yi/Buffer.hs"
+ return (fmap (\x -> Yi.Event.Event (keyFromFile x) []) text ++ quit)
+
+openingEvs = return (times 50 openAndKill ++ quit)
+
+-- Event helpers
+times :: Int -> [a] -> [a]
+times n = concat . replicate n
+
+ckey, key :: Char -> Event
+ckey x = Event (Yi.Event.KASCII x) [MCtrl]
+key x = Event (Yi.Event.KASCII x) []
+
+ret :: Event
+ret = Event KEnter []
+
+quit, openAndKill, open, blah, killmessages, close, confirm :: [Event]
+quit = [ckey 'x', ckey 'c']
+openAndKill = open ++ blah ++ killmessages ++ close ++ confirm
+open = [ckey 'x', ckey 'f', key 'z', ret]
+blah = replicate 20 (key 'x')
+-- clear undo information from the *messages* buffer
+killmessages = [ckey 'x', key 'b', ret, ckey 'x', key 'k', ret]
+close = [ckey 'x', key 'k', ret]
+confirm = [key 'y']
+
+keyFromFile :: Char -> Key
+keyFromFile '\n' = KEnter
+keyFromFile x = KASCII x
@@ -0,0 +1,128 @@
+module Yi.Config.Users.Corey (config) where
+{- An example yi.hs that uses the Vim keymap with these additions:
+ - Always uses the VTY UI by default.
+ - The color style is darkBlueTheme
+ - The insert mode of the Vim keymap has been extended with a few additions
+ I find useful.
+ -}
+import Yi.Prelude
+import Prelude ()
+
+import Yi
+import Yi.Keymap.Vim
+import Yi.Buffer.Indent (indentAsPreviousB)
+import Yi.Keymap.Keys
+import Yi.Misc (adjBlock)
+
+-- import qualified Yi.UI.Vty
+
+import Yi.Style.Library (darkBlueTheme)
+import Data.List (isPrefixOf, reverse, replicate)
+import Control.Monad (replicateM_)
+
+-- Set soft tabs of 4 spaces in width.
+prefIndent :: Mode s -> Mode s
+prefIndent m = m {
+ modeIndentSettings = IndentSettings
+ {
+ expandTabs = True,
+ shiftWidth = 4,
+ tabSize = 4
+ }}
+
+noHaskellAnnots m
+ | modeName m == "haskell" = m { modeGetAnnotations = modeGetAnnotations emptyMode }
+ | otherwise = m
+
+config = defaultConfig
+ {
+ -- Use VTY as the default UI.
+ -- startFrontEnd = Yi.UI.Vty.start,
+ defaultKm = mkKeymap extendedVimKeymap,
+ modeTable = fmap (onMode $ noHaskellAnnots . prefIndent) (modeTable defaultConfig),
+ configUI = (configUI defaultConfig)
+ {
+ configTheme = darkBlueTheme
+ }
+ }
+
+extendedVimKeymap = defKeymap `override` \super self -> super
+ {
+ v_top_level =
+ (deprioritize >> v_top_level super)
+ -- On 'o' in normal mode I always want to use the indent of the previous line.
+ -- TODO: If the line where the newline is to be inserted is inside a
+ -- block comment then the block comment should be "continued"
+ -- TODO: Ends up I'm trying to replicate vim's "autoindent" feature. This
+ -- should be made a function in Yi.
+ <|> (char 'o' ?>> beginIns self $ do
+ moveToEol
+ insertB '\n'
+ indentAsPreviousB
+ )
+ -- On HLX (Haskell Language Extension) I want to go into insert mode such
+ -- that the cursor position is correctly placed to start entering the name
+ -- of an language extension in a LANGUAGE pragma.
+ -- A language pragma will take either the form
+ -- {-# LANGUAGE Foo #-}
+ -- or
+ -- >{-# LANGUAGE Foo #-}
+ -- The form should be chosen based on the current mode.
+ <|> ( pString "HXL" >> startExtesnionNameInsert self ),
+ v_ins_char =
+ (deprioritize >> v_ins_char super)
+ -- On enter I always want to use the indent of previous line
+ -- TODO: If the line where the newline is to be inserted is inside a
+ -- block comment then the block comment should be "continued"
+ -- TODO: Ends up I'm trying to replicate vim's "autoindent" feature. This
+ -- should be made a function in Yi.
+ <|> ( spec KEnter ?>>! do
+ insertB '\n'
+ indentAsPreviousB
+ )
+ -- I want softtabs to be deleted as if they are tabs. So if the
+ -- current col is a multiple of 4 and the previous 4 characters
+ -- are spaces then delete all 4 characters.
+ -- TODO: Incorporate into Yi itself.
+ <|> ( spec KBS ?>>! do
+ c <- curCol
+ line <- readRegionB =<< regionOfPartB Line Backward
+ sw <- indentSettingsB >>= return . shiftWidth
+ let indentStr = replicate sw ' '
+ toDel = if (c `mod` sw) /= 0
+ then 1
+ else if indentStr `isPrefixOf` reverse line
+ then sw
+ else 1
+ adjBlock (-toDel)
+ replicateM_ toDel $ deleteB Character Backward
+ )
+ -- On starting to write a block comment I want the close comment
+ -- text inserted automatically.
+ <|> choice
+ [ pString open_tag >>! do
+ insertN $ open_tag ++ " \n"
+ indentAsPreviousB
+ insertN $ " " ++ close_tag
+ lineUp
+ | (open_tag, close_tag) <-
+ [ ("{-", "-}") -- Haskell block comments
+ , ("/*", "*/") -- C++ block comments
+ ]
+ ]
+ }
+
+
+startExtesnionNameInsert :: ModeMap -> I Event Action ()
+startExtesnionNameInsert self = beginIns self $ do
+ p_current <- pointB
+ m_current <- getMarkB (Just "'")
+ setMarkPointB m_current p_current
+ moveTo $ Point 0
+ insertB '\n'
+ moveTo $ Point 0
+ insertN "{-# LANGUAGE "
+ p <- pointB
+ insertN " #-}"
+ moveTo p
+
Oops, something went wrong.

0 comments on commit 32fb553

Please sign in to comment.