{- WEI HU: yi-0.4 seems to have changed API a lot. The examples must be adapted accordingly. You have to dive into the source code to figure out the changes. Helpful resources include: Different modes under Yi/Keymap, an incompatible tutorial at http://www.nobugs.org/developer/yi/, the incomplete documentation at http://code.haskell.org/yi/doc/, and a paper at http://www.cse.unsw.edu.au/~dons/papers/yi.pdf -} import Yi import Yi.Keymap.Emacs (keymap, makeKeymap) import qualified Yi.Mode.Shim as Shim import Yi.UI.Common (UIConfig(..)) import Yi.Modes import Data.List (isSuffixOf) import Yi.Prelude import Yi.Mode.Haskell import qualified Data.Map as M import Data.Dynamic import qualified Yi.UI.Vty bestHaskellMode = cleverHaskellMode { modeKeymap = modeKeymap Shim.mode } myModetable :: ReaderT String Maybe AnyMode myModetable = ReaderT $ \fname -> case () of _ | ".hs" `isSuffixOf` fname -> Just $ AnyMode bestHaskellMode _ -> Nothing -- Only published actions can be run from M-x myActions :: M.Map String [Dynamic] myActions = (M.union defaultPublishedActions) $ M.fromList $ [ ("helloW", box helloWorld) ,("commentR", box commentRegionB) ] where box x = [toDyn x] -- The list of keys that you wish to override/add to -- the default emacs keybindings. -- myKeys :: KList -- KList is hidden myKeys = -- @write a@ returns a keymap that just outputs the action @a@. [ ("C-x C-t", write $ helloWorld) ] -- So your keymap will be the emacs keybindings -- 'keymap' with your additional/overriding key -- binding definitions. myKeyMap :: Keymap myKeyMap = keymap <|> makeKeymap myKeys ------------------------ User-defined functions------ ----------------------------------------------------- commentRegionB :: BufferM () commentRegionB = do mark <- getSelectionMarkPointB p <- pointB let region = mkRegion mark p text <- readRegionB region let newText = unlines $ map ("# " ++ ) $ lines text replaceRegionB region newText helloWorld :: BufferM () helloWorld = do insertN "Hello, world!" helloWorld' :: YiM () helloWorld' = do withBuffer $ insertN "Hello, world!" main :: IO () main = yi $ defaultConfig { startFrontEnd = Yi.UI.Vty.start, modeTable = myModetable <|> modeTable defaultConfig, configUI = (configUI defaultConfig) { configFontSize = Just 10 }, defaultKm = myKeyMap, publishedActions = myActions }