-
Notifications
You must be signed in to change notification settings - Fork 203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add :next and :previous commands for vim keymap #1075
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
module Yi.Keymap.Vim.Ex.Commands.BufferCycle (parse) where | ||
|
||
import Control.Applicative (Alternative ((<|>))) | ||
import Control.Monad | ||
import Data.List | ||
import qualified Data.Attoparsec.Text as P | ||
import Lens.Micro.Platform | ||
import Yi.Editor | ||
import Yi.Keymap (Action (EditorA)) | ||
import Yi.Window | ||
import Yi.Keymap.Vim.Common (EventString) | ||
import qualified Yi.Keymap.Vim.Ex.Commands.Common as Common | ||
import Yi.Keymap.Vim.Ex.Types (ExCommand (cmdAction, cmdShow)) | ||
|
||
parse :: EventString -> Maybe ExCommand | ||
parse = Common.parse $ do | ||
void (P.char 'b') <|> return () | ||
direction <- (fmap (const False) $ P.string "prev" <|> P.string "previous") <|> fmap (const True) (P.string "next") | ||
return $ Common.pureExCommand { | ||
cmdShow = if direction then "next" else "previous", | ||
cmdAction = EditorA $ currentWindowA %= \window -> let | ||
cl = bufkey window : bufAccessList window | ||
cl' = if direction | ||
then last cl : init cl | ||
else tail cl ++ [head cl] | ||
in forceSpine cl' `seq` window { bufkey = head cl', bufAccessList = tail cl' } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain how this would cause a memory leak without Edit: I think I see it, the reference to the old Edit 2: Are you sure this works? I tried this: main = do
print $ iterate f [1..100] !! 1000000
where
f x = forceSpine r `seq` r
where
r = tail x ++ [head x]
forceSpine = go
where
go [] = ()
go (_:xs) = go xs And that still has the leak. Edit 3: Even this still has the leak: import Data.List
main = do
print $ foldl' (\xs _ -> f xs) [1..100] (replicate 1000000 ())
where
f x = forceSpine r `seq` r
where
r = tail x ++ [head x]
forceSpine = go
where
go [] = ()
go (_:xs) = go xs Edit 4: This fixes it: main = do
print $ iterate f [1..100] !! 1000000
where
f x = forceSpine r `seq` r
where
r = tail x ++ [head x]
forceSpine = go
where
go [] = ()
go (x:xs) = x `seq` go xs |
||
} | ||
|
||
{-# INLINE forceSpine #-} | ||
forceSpine :: [a] -> () | ||
forceSpine = go where | ||
go [] = () | ||
go (_:r) = go r |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P.string "prev" <|> P.string "previous"
is redundant, because the "prev" parser also matches "previous". Maybe this behavior should be changed, because now "prevsomething" is also accepted.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be solved by using the
endOfInput
parserThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opened #1085 to track this issue for all parsers.