Coder Social home page Coder Social logo

Comments (5)

phmarek avatar phmarek commented on May 24, 2024

Re-indenting 419 lines now gave me

FUNCTION  vlime#ui#CurArgPos()
    Defined: .../vlime/vim/autoload/vlime/ui.vim:1102
Called 1145 times
Total time:  48.109187
 Self time:  48.109187

...
591677             28.625727             let syntax = map(synstack(ln, idx), 'synIDattr(v:val, "name")')

Perhaps a simple per-buffer cache that stores the indentation for each line (or form?) so we don't do O(nĀ²) runs here?

FUNCTIONS SORTED ON TOTAL TIME
count  total (s)   self (s)  function
  399  54.321642   0.074243  vlime#plugin#CalcCurIndent()
  399  54.027148   0.307812  vlime#ui#ParseOuterOperators()
 1145  48.109187             vlime#ui#CurArgPos()
 1145   5.610149   0.124386  vlime#ui#CurOperator()
 1456   5.579339   0.064519  vlime#ui#CurExpr()
 2912   5.461276             vlime#ui#CurExprPos()
  311   0.174020   0.003437  vlime#GetCurrentPackage()
  311   0.170583   0.008193  vlime#ui#GetCurrentPackage()

from vlime.

phmarek avatar phmarek commented on May 24, 2024

Notes:

  • b:changedtick for cache invalidation
  • replace loops by a searchpairpos('(','',')','nrb', CB) with a suitable callback function that stores the start/end positions of all the parens in the file in a dict (referencing the parent parens as well)
  • In the actual CurArgPos() just look at the paren tree and go word-wise backward (B in normal mode), skipping comments

PS: Just found the lua-treesitter reference in the nvim docs... perhaps that might be a future direction. (got https://github.com/nvim-treesitter/nvim-treesitter-refactor resp. https://github.com/nvim-treesitter/playground as links)

from vlime.

theHamsta avatar theHamsta commented on May 24, 2024

Yes, a Lisp parser would be really cool. There is one for clojure that could be adapted for Lisp: https://github.com/sogaiu/tree-sitter-clojure. I always wanted to implement it but never found the time to write the grammar rules and the queries.

Tree-sitter-based paredit is also very cool. It also works for non-lisp languages if the parser gives a sufficiently structure syntax tree.

from vlime.

phmarek avatar phmarek commented on May 24, 2024

Well, treesitter is nvim-only right now, so we'd lose quite a lot of compatibility (and users?).

I guess the caching version to fix the perf issue would be the right way, right now.

from vlime.

theHamsta avatar theHamsta commented on May 24, 2024

And it's only nvim nightly. This is why I was a bit surprised when you cited it. But it would be possible to use it for some functionality if it's available or just have it in nvim-treesitter for additional support for Lisp

from vlime.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.