vim-parinfer icon indicating copy to clipboard operation
vim-parinfer copied to clipboard

Choose the proper form to evaluate

Open tomaskulich opened this issue 8 years ago • 6 comments

searching opening '(' on the first line seems like a decent heuristics for the beginning of the form.

  let topline = search('^(', 'bn') - 1

The bottomline however is searched for badly. Searching for corresponding ')' may not work, because there may not yet be corresponding closing bracket:

  let bottomline = searchpair('(','',')', 'n') + 1

Good idea may be to look for the next opening bracket on the first line (i.e. beginning of the next 'main' form) (or the end of file if not existing). I'm not sure how to implement this in vimscript though.

tomaskulich avatar Dec 13 '16 14:12 tomaskulich

@tomaskulich yep, this is definitely the tricky part thanks for the bump. I think the topline search is adequate as this is what vim-sexp is doing. Maybe a fallback for searchpair() is the next step

bhurlow avatar Dec 13 '16 15:12 bhurlow

Well, if I understand correctly what the plugin is trying to do, then the searchpair approach is IMO conceptually broken; you cannot ask for matching paren, if the paren is yet-to-be inserted - which is very often the case. The searchpair will work correctly only if there is nothing to do (with this kind of parens)

tomaskulich avatar Dec 13 '16 15:12 tomaskulich

@tomaskulich I'm thinking the best thing here might be like you proposed, to count parens until we hit the next opening (

bhurlow avatar Dec 13 '16 15:12 bhurlow

The proposed solution is what atom-parinfer does 👍

shaunlebron avatar Dec 13 '16 15:12 shaunlebron

@shaunlebron good to know thanks!

bhurlow avatar Dec 13 '16 15:12 bhurlow

ok, I did this: https://github.com/bhurlow/vim-parinfer/commit/8c5269b965b405c58b63a0154773c961e1eece8b. Could be few edge cases still left, although this definitely works smoother

bhurlow avatar Dec 13 '16 17:12 bhurlow