Skip to content

Commit 49acc30

Browse files
committed
Rename functions to match Eve
1 parent 10774d8 commit 49acc30

File tree

10 files changed

+44
-45
lines changed

10 files changed

+44
-45
lines changed

docs/Building-An-Extension.md

+14-14
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ main :: IO ()
7070
main = rasa $ do
7171
-- some plugins...
7272
-- Add the new action here!
73-
onInit helloWorld
73+
helloWorld
7474
```
7575

7676
Okay let's try again! `stack build && stack exec rasa` (you may want to alias
@@ -136,26 +136,26 @@ rasa/rasa-example-config/app/Main.hs:28:10: error:
136136
with actual type ‘Keypress -> Action ()’
137137
```
138138

139-
Hrmm, right! Now that we're listening for keypress events we don't want to use
140-
`onInit` anymore, Rasa provides a way to register listeners for different events;
141-
we'll learn how to listen for any arbitrary event later; but for now it's time for
142-
`onKeypress`!
139+
Hrmm, right! Now that we're listening for keypress events we need to set up an
140+
event-listener! Rasa provides a way to register listeners for different events;
141+
we'll learn how to listen for any arbitrary event later; but for now it's time
142+
for `onKeypress`!
143143

144144
```haskell
145145
onKeypress :: (Keypress -> Action ()) -> Action ListenerId
146146
```
147147

148148
So we've got our function from our event type (Keypress), so let's try
149-
registering it using `onKeypress`; we'll do all of this within `onInit` so the
150-
listener is registered when Rasa starts. The onKeypress function
151-
returns a reference to the newly created listener so that we could cancel the
152-
listener using `removeListener` later if we wanted to; but since we don't need
153-
to do that; we'll just ignore it.
149+
registering it using `onKeypress`; The onKeypress function returns a reference
150+
to the newly created listener so that we could cancel the listener using
151+
`removeListener` later if we wanted to; but since we don't need to do that;
152+
we'll just ignore it by using `void` from `Control.Monad`.
154153

155154
```haskell
155+
import Control.Monad
156156
main = rasa $ do
157157
-- other extensions
158-
onInit $ onKeypress helloWorld
158+
void $ onKeypress helloWorld
159159
```
160160

161161
Okay, let's build that and run it, now in a separate terminal we'll run
@@ -213,7 +213,7 @@ import qualified Yi.Rope as Y
213213
main = rasa $ do
214214
-- other extensions
215215
cursors
216-
onInit $ onKeypress copyPasta
216+
void $ onKeypress copyPasta
217217

218218
copyPasta :: Keypress -> Action ()
219219
copyPasta (Keypress 'y' _) = focusDo_ $ rangeDo_ copier
@@ -504,7 +504,7 @@ newBuf (BufAdded bufRef) = bufDo_ bufRef (addCopyListener copyListener)
504504

505505
main = rasa $ do
506506
-- other extensions
507-
onInit . onBufAdded $ newBuf
507+
onBufAdded_ $ newBuf
508508
```
509509

510510
Okay so this works; but there was a bit of boiler-plate to get it going!
@@ -599,7 +599,7 @@ newtype Copied = Copied String
599599
-- We've renamed things so we can export a single 'Action'
600600
-- that the user can embed in their config.
601601
copyPasta :: Action ()
602-
copyPasta = onInit $ onKeypress keyListener
602+
copyPasta = void $ onKeypress keyListener
603603

604604
keyListener :: Keypress -> Action ()
605605
keyListener (Keypress 'y' _) = do

rasa-ext-cursors/src/Rasa/Ext/Cursors.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ import Rasa.Ext.Cursors.Internal.Actions
2727

2828
-- | Registers listeners for the extension. The user should add this to their config.
2929
cursors :: App ()
30-
cursors = onInit . onBufAdded $
30+
cursors = onBufAdded_ $
3131
\(BufAdded bufRef) -> bufDo_ bufRef setStyleProvider

rasa-ext-logger/src/Rasa/Ext/Logger.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Control.Monad.State
1010

1111
logger :: App ()
1212
logger = do
13-
onInit $ liftIO $ writeFile "logs.log" "Event Log\n"
13+
liftIO $ writeFile "logs.log" "Event Log\n"
1414
onEveryRender_ $ return ()
1515
-- ed <- getEditor
1616
-- liftIO $ appendFile "logs.log" (show ed)

rasa-ext-slate/src/Rasa/Ext/Slate.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import Control.Monad.IO.Class
1717
-- > ...
1818
slate :: App ()
1919
slate = do
20-
onInit terminalEvents
20+
terminalEvents
2121
onEveryRender_ renderAll
2222
onExit shutdown
2323

rasa-ext-views/src/Rasa/Ext/Views/Internal/Actions.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ focusedBufs = do
106106
-- | Returns whether the current buffer is focused in at least one view.
107107
isFocused :: BufAction Bool
108108
isFocused = do
109-
inFocus <- liftAction focusedBufs
109+
inFocus <- liftApp focusedBufs
110110
br <- getBufRef
111111
return $ br `elem` inFocus
112112

rasa-ext-vim/src/Rasa/Ext/Vim.hs

+19-19
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ handleKeypress keypress = focusDo_ $ do
8080

8181
-- | Listeners for keypresses that run regardless of current mode.
8282
anyMode :: [Keypress] -> BufAction ()
83-
anyMode [Keypress 'c' [Ctrl]] = liftAction exit
84-
anyMode [KPageDown []] = liftAction $ scrollBy 14 -- Page down
85-
anyMode [KPageUp []] = liftAction $ scrollBy (-14) -- Page up
83+
anyMode [Keypress 'c' [Ctrl]] = liftApp exit
84+
anyMode [KPageDown []] = liftApp $ scrollBy 14 -- Page down
85+
anyMode [KPageUp []] = liftApp $ scrollBy (-14) -- Page up
8686
anyMode [KHome []] = startOfLine
8787
anyMode [KEnd []] = endOfLine
8888
anyMode _ = return ()
@@ -110,22 +110,22 @@ normal [Keypress 'g' [], Keypress 'g' []] = setRanges [Range (Coord 0 0) (Coord
110110
normal [Keypress 's' []] = addHist $ Keypress 's' []
111111
normal [Keypress 's' [], Keypress 'n' []] = toggleLineNumbers
112112

113-
normal [Keypress '+' []] = liftAction nextBuf
114-
normal [Keypress '-' []] = liftAction prevBuf
115-
normal [Keypress 'w' [Ctrl]] = liftAction hSplit
116-
normal [Keypress 'v' [Ctrl]] = liftAction vSplit
117-
normal [Keypress 'o' [Ctrl]] = liftAction closeInactive
118-
normal [Keypress 'r' [Ctrl]] = liftAction rotate
119-
120-
normal [Keypress 'e' [Ctrl]] = liftAction $ scrollBy 1 -- Scroll down
121-
normal [Keypress 'd' [Ctrl]] = liftAction $ scrollBy 7 -- Half-Page down
122-
normal [Keypress 'y' [Ctrl]] = liftAction $ scrollBy (-1) -- Scroll up
123-
normal [Keypress 'u' [Ctrl]] = liftAction $ scrollBy (-7) -- Half-Page up
124-
125-
normal [KLeft []] = liftAction focusViewLeft
126-
normal [KRight []] = liftAction focusViewRight
127-
normal [KUp []] = liftAction focusViewAbove
128-
normal [KDown []] = liftAction focusViewBelow
113+
normal [Keypress '+' []] = liftApp nextBuf
114+
normal [Keypress '-' []] = liftApp prevBuf
115+
normal [Keypress 'w' [Ctrl]] = liftApp hSplit
116+
normal [Keypress 'v' [Ctrl]] = liftApp vSplit
117+
normal [Keypress 'o' [Ctrl]] = liftApp closeInactive
118+
normal [Keypress 'r' [Ctrl]] = liftApp rotate
119+
120+
normal [Keypress 'e' [Ctrl]] = liftApp $ scrollBy 1 -- Scroll down
121+
normal [Keypress 'd' [Ctrl]] = liftApp $ scrollBy 7 -- Half-Page down
122+
normal [Keypress 'y' [Ctrl]] = liftApp $ scrollBy (-1) -- Scroll up
123+
normal [Keypress 'u' [Ctrl]] = liftApp $ scrollBy (-7) -- Half-Page up
124+
125+
normal [KLeft []] = liftApp focusViewLeft
126+
normal [KRight []] = liftApp focusViewRight
127+
normal [KUp []] = liftApp focusViewAbove
128+
normal [KDown []] = liftApp focusViewBelow
129129

130130

131131
normal [Keypress 'G' []] = do

rasa/src/Rasa.hs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Eve
55
import Rasa.Internal.Listeners
66

77
import Control.Monad
8+
import Data.Default
89

910
-- | The main function to run rasa.
1011
--

rasa/src/Rasa/Ext.hs

+2-4
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@
2626
-- >
2727
-- > logger :: Action ()
2828
-- > logger = do
29-
-- > onInit $ liftIO $ writeFile "logs" "==Logs==\n"
30-
-- > -- Listeners should also be registered using 'onInit'.
31-
-- > -- It ensures all listeners are ready before any actions occur.
32-
-- > onInit $ onKeypress logKeypress
29+
-- > liftIO $ writeFile "logs" "==Logs==\n"
30+
-- > onKeypress logKeypress
3331
-- > onExit $ liftIO $ appendFile "logs" "==Done=="
3432
--
3533
-- Check out this tutorial on building extensions, it's also just a great way to learn

rasa/src/Rasa/Internal/BufActions.hs

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ overBufExt :: (Typeable s, Show s, Default s) => (s -> s) -> BufAction ()
9797
overBufExt f = stateLens %= f
9898

9999
-- -- | This lifts up an 'Action' to be run inside a 'BufAction'
100-
-- liftAction :: App r -> BufAction r
101-
-- liftAction action = liftBufAction $ LiftAction action id
100+
-- liftApp :: App r -> BufAction r
101+
-- liftApp action = liftBufAction $ LiftAction action id
102102

103103
-- | Runs function over given range of text
104104
overRange :: CrdRange -> (Y.YiString -> Y.YiString) -> BufAction ()

stack.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ packages:
1818
- ./rasa-ext-vim
1919
- ./rasa-example-config
2020
- ./text-lens
21-
# - ../eve
21+
- ../eve
2222

2323
extra-deps:
24-
- eve-0.1.1
24+
# - eve-0.1.1
2525
- vty-5.14
2626
- recursion-schemes-5.0.1
2727

0 commit comments

Comments
 (0)