tpope / vim-fireplace

fireplace.vim: Clojure REPL support
https://www.vim.org/scripts/script.php?script_id=4978
1.74k stars 139 forks source link

Possible faster way to find top level expressions for completion context #391

Open SevereOverfl0w opened 2 years ago

SevereOverfl0w commented 2 years ago

I was talking to @PEZ about my PR (#390) and he mentioned how zmacs solved this problem

A Lisp file contains a sequence of expressions that we call top-level expressions, to distinguish them from their own sUbexpressions. Zmacs assumes that top-level expressions begin with an open parenthesis against the left margin. It does not parse top-level expressions by balancing parentheses, since parentheses do not always balance while programs are being written. The indentation represents the programmer’s conception of program structure, and provides a better guide. So by top-level expression, we mean a section of text delimited by open parentheses at the beginning of two lines.

This would be substantially faster than searchpairpos, and would work in plain vim too. Most users are working with vim-sexp or parinfer.vim so will have their parens balanced 99% of the time.

Not sure if you'd be interested in a PR to this effect.