Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

quickdudley
Copy link
Contributor

No description provided.

@noughtmare
Copy link
Member

I'm not sure if we want to emulate vim's behavior exactly, but :bprev and :prev and :bnext and :next do different things in vim.

@quickdudley
Copy link
Contributor Author

I suspect what I've ended up doing here is neither.

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")
Copy link
Member

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.

Copy link
Member

@noughtmare noughtmare Jun 7, 2018

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 parser

Copy link
Member

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.

cl' = if direction
then last cl : init cl
else tail cl ++ [head cl]
in forceSpine cl' `seq` window { bufkey = head cl', bufAccessList = tail cl' }
Copy link
Member

@noughtmare noughtmare Jun 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain how this would cause a memory leak without forceSpine? Isn't the entire list stored in memory anyway?

Edit: I think I see it, the reference to the old cl is kept.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants