julienvincent / nvim-paredit

A Paredit implementation for Neovim, built using Treesitter and written in Lua.
MIT License
176 stars 9 forks source link

Form selection #12

Closed grierson closed 1 year ago

grierson commented 1 year ago

The af and if objects selects forms The aF and iF objects select top-level forms.

Why

Replicate vim-sexp Text Object Selections

Clojure uses multiples types for surrounds ( { [ being able to refer to each with just f/F makes text manipulation within Clojure much easier.

Expected behaviour

Current form

  1. (+ 1 1) (Cursor anywhere within expression)
  2. dif
  3. () deletes everything within form

Top level form

  1. (+ 1 (+ 2 3)) (Cursor within sub form)
  2. diF
  3. () deletes everything within top level form
julienvincent commented 1 year ago

Agreed this will be useful to have, and should be straight forward to add. Will get around to it when I have a moment :)

Olical commented 1 year ago

Just a note that I don't think there's a way to select root elements / forms still. So there's no vaF to select a whole defn from anywhere inside the form for example. If I'm right in that assumption maybe I can add it soon.

Olical commented 1 year ago

You'll have to ignore the Fennel and custom macros for exporting values from the Lua module, but here's what I use in Conjure to select the root form in tree sitter across multiple languages.

https://github.com/Olical/conjure/blob/58c46d1f4999679659a5918284b574c266a7ac83/fnl/conjure/tree-sitter.fnl#L77-L87

So this may be a good template to rip off to get started with.

julienvincent commented 1 year ago

Ah you are right I forgot about the root form selections. Shouldn't be too difficult to add, if you want to take a stab at it go ahead :)

Otherwise I can look into it when I get a moment.

Olical commented 1 year ago

I'm working on this at the moment but a heads up that the tests seem to fail for the slurp/barfing in the Neovim nightly build. I swapped to stable and they run just fine. tests/nvim-paredit/barf_spec.lua was the only failing file for me on Arch Linux, I see errors like:

Fail    ||  barfing barfing backwards should barf different form types quoted list  
            ./tests/nvim-paredit/utils.lua:34: Expected objects to be the same.
            Passed in:
            (table: 0x7f4118fe6c08) {
              [1] = 1
             *[2] = 0 }
            Expected:
            (table: 0x7f41193c6810) {
              [1] = 1
             *[2] = 2 }

            stack traceback:
                ./tests/nvim-paredit/utils.lua:34: in function 'expect'
                ./tests/nvim-paredit/utils.lua:51: in function <./tests/nvim-paredit/utils.lua:40>
julienvincent commented 1 year ago

Yea I noticed this recently too, something changed upstream in nightly that's broken this plugin.

See #32 as well - split tests to allow running against either nightly or stable. Will try get nightly working again in that PR.

julienvincent commented 1 year ago

Ok I actually just disabled nightly for now and merged that PR. Running just test will now use stable.

Olical commented 1 year ago

Nice, rebased my changes on this and opening a PR with my first pass now. I have selections and deletions working, will probably add more tests, may need to add more methods for visual selections too, mostly focussed on deletions so far.

Also you may find this useful: https://github.com/Olical/nfnl/blob/main/.github/workflows/test.yaml

It's my GitHub action tests I use to run Plenary Busted (like you do) in GitHub Actions across multiple Neovim versions. The downside is that it doesn't work locally the same way, I run the tests in whatever Neovim version I have installed locally.

Just thought I'd share in case you liked the way you can just add version numbers to the list.