keymap :: KeymapSet keymap = portableKeymap ctrl -- | Introduce a keymap that is compatible with both windows and osx, -- by parameterising the event modifier required for commands portableKeymap :: (Event -> Event) -> KeymapSet portableKeymap cmd = modelessKeymapSet $ selfInsertKeymap <|> move <|> select <|> rect <|> other cmd
other cmd = choice [ spec KBS ?>>! deleteSel bdeleteB, spec KDel ?>>! deleteSel (deleteN 1), spec KEnter ?>>! replaceSel "\n", cmd (char 'q') ?>>! askQuitEditor, cmd (char 'f') ?>> isearchKeymap Forward, cmd (char 'x') ?>>! cut, cmd (char 'c') ?>>! copy, cmd (char 'v') ?>>! paste, cmd (spec KIns) ?>>! copy, shift (spec KIns) ?>>! paste, cmd (char 'z') ?>>! undoB, cmd (char 'y') ?>>! redoB, cmd (char 's') ?>>! fwriteE, cmd (char 'o') ?>>! findFile, cmd (char '/') ?>>! withModeB modeToggleCommentSelection, cmd (char ']') ?>>! autoIndentB IncreaseOnly, cmd (char '[') ?>>! autoIndentB DecreaseOnly ]
spawnMinibufferE :: String -> KeymapEndo -> EditorM BufferRef
-- | Menu type Menu = [MenuItem] -- | Menu utem data MenuItem = MenuAction String (MenuContext -> Char -> Keymap) | SubMenu String Menu -- | Menu action context data MenuContext = MenuContext { parentBuffer :: BufferRef }
-- | Fold menu item foldItem :: (String -> (MenuContext -> Char -> Keymap) -> a) -> (String -> [a] -> a) -> MenuItem -> a foldItem mA sM (MenuAction title act) = mA title act foldItem mA sM (SubMenu title sm) = sM title (map (foldItem mA sM) sm) -- | Fold menu foldMenu :: (String -> (MenuContext -> Char -> Keymap) -> a) -> (String -> [a] -> a) -> Menu -> [a] foldMenu mA sM = map (foldItem mA sM)
-- | Action on item action_ :: (YiAction ax, Show x) => String -> a -> MenuItem action_ title act = action title (const act) -- | Action on item with context action :: (YiAction ax, Show x) => String -> (MenuContext -> a) -> MenuItem action title act = MenuAction title act' where act' ctx c = char c ?>>! (do withEditor closeBufferAndWindowE runAction $ makeAction (act ctx))
-- | Start menu action startMenu :: Menu -> EditorM () startMenu m = do -- , ctx <- fmap MenuContext (gets currentBuffer) startMenu' ctx m where -- , (, ) startMenu' ctx = showMenu . foldMenu onItem onSub where showMenu :: [(String, Maybe Keymap)] -> EditorM () -- β , showMenu is = void $ spawnMinibufferE menuItems (const (subMap is)) where menuItems = (intercalate " " (map fst is)) -- β -- + , onItem title act = (title, fmap (act ctx) (menuEvent title)) where -- β -- + , onSub title is = (title, fmap subMenu (menuEvent title)) where -- 'c' subMenu c = char c ?>>! closeBufferAndWindowE >> showMenu is -- Esc, subMap is = choice $ closeMenu : mapMaybe snd is where closeMenu = spec KEsc ?>>! closeBufferAndWindowE
-- | Main menu mainMenu :: Menu mainMenu = [ menu "File" [ action_ "Quit" askQuitEditor, action "Save" (fwriteBufferE . parentBuffer)], menu "Edit" [ action_ "Auto complete" wordComplete, action_ "Completion" completeWordB], menu "Tools" [ menu "Ghci" ghciMenu], menu "View" [ menu "Windows" windowsMenu, menu "Tabs" tabsMenu, menu "Buffers" buffersMenu, menu "Layout" [ action_ "Next" layoutManagersNextE, action_ "Previous" layoutManagersPreviousE]]] -- | Windows menu windowsMenu :: Menu windowsMenu = [ action_ "Next" nextWinE, action_ "Previous" prevWinE, action_ "Split" splitE, action_ "sWap" swapWinWithFirstE, action_ "Close" tryCloseE, action_ "cLose-all-but-this" closeOtherE]
actionB
, actionE
and actionY
. However, they can be replaced by runAction . makeAction
runAction . makeAction
Source: https://habr.com/ru/post/142769/
All Articles