From e1dcf920d4d6af32db548beebbae146c1de75bce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amy=20de=20Buitl=C3=A9ir?= Date: Tue, 2 Apr 2013 12:01:37 +0100 Subject: [PATCH] Add support for custom key bindings in CUA --- yi-contrib/src/Yi/Config/Users/Amy.hs | 54 +++++++++++++++++++++++++++ yi/src/library/Yi/Keymap/Cua.hs | 19 +++++++++- 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 yi-contrib/src/Yi/Config/Users/Amy.hs diff --git a/yi-contrib/src/Yi/Config/Users/Amy.hs b/yi-contrib/src/Yi/Config/Users/Amy.hs new file mode 100644 index 000000000..81bbd5069 --- /dev/null +++ b/yi-contrib/src/Yi/Config/Users/Amy.hs @@ -0,0 +1,54 @@ +import Yi + +import Prelude () +import Yi.Prelude + +-- Import the desired UI as needed. +-- Some are not complied in, so we import none here. + +-- import Yi.UI.Vty (start) +-- import Yi.UI.Cocoa (start) +-- import Yi.UI.Pango (start) + +import Yi.Keymap.Cua + +myConfig = defaultCuaConfig + +defaultUIConfig = configUI myConfig + +-- Add M-x (which is probably Alt-x on your system) to the default +-- keyset, and have it launch our custom macro. +extendedCuaKeymapSet = customizedCuaKeymapSet $ + choice [ + metaCh 'x' ?>>! helloWorld + ] + +-- A custom macro +helloWorld :: YiM () +helloWorld = withBuffer $ insertN "Hello, world!" + + +main :: IO () +main = yi $ myConfig + { + -- Keymap Configuration + defaultKm = extendedCuaKeymapSet, + + -- UI Configuration + -- Override the default UI as such: + startFrontEnd = startFrontEnd myConfig, + -- Yi.UI.Vty.start -- for Vty + -- (can be overridden at the command line) + -- Options: + configUI = defaultUIConfig + { + configFontSize = Nothing, + -- 'Just 10' for specifying the size. + configTheme = configTheme defaultUIConfig, + -- darkBlueTheme -- Change the color scheme here. + + configWindowFill = ' ' + } + } + + diff --git a/yi/src/library/Yi/Keymap/Cua.hs b/yi/src/library/Yi/Keymap/Cua.hs index 62f3d82dc..78f69d44e 100644 --- a/yi/src/library/Yi/Keymap/Cua.hs +++ b/yi/src/library/Yi/Keymap/Cua.hs @@ -1,6 +1,14 @@ -- Copyright (c) 2008 Jean-Philippe Bernardy -module Yi.Keymap.Cua (keymap, portableKeymap, cut, paste, copy, del) where +module Yi.Keymap.Cua ( + keymap + , portableKeymap + , customizedCuaKeymapSet + , cut + , paste + , copy + , del + ) where import Prelude (length, take, drop) import Yi.Core @@ -10,6 +18,15 @@ import Yi.Misc (adjBlock) import Yi.Rectangle import Yi.String +customizedCuaKeymapSet :: Keymap -> KeymapSet +customizedCuaKeymapSet userKeymap = + modelessKeymapSet $ selfInsertKeymap + <|> move + <|> select + <|> rect + <|> userKeymap + <|> other ctrl + keymap :: KeymapSet keymap = portableKeymap ctrl