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

Form selection #12

Closed
grierson opened this issue Jul 31, 2023 · 8 comments · Fixed by #21
Closed

Form selection #12

grierson opened this issue Jul 31, 2023 · 8 comments · Fixed by #21
Labels
enhancement New feature or request

Comments

@grierson
Copy link

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.

  • di( -> dif
  • di[ -> dif
  • di{ -> dif

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
Copy link
Owner

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

@armed armed added the enhancement New feature or request label Aug 3, 2023
julienvincent added a commit that referenced this issue Aug 9, 2023
This implements a set of API's for deleting nodes and forms.

+ `delete_form` - Delete the entire form under the cursor
+ `delete_in_form` - Deletes all elements within the form under the cursor
+ `delete_element` - Deletes the element under the cursor

Addresses #12
julienvincent added a commit that referenced this issue Aug 10, 2023
This builds on top of the previous form/element deletions work by
expanding it to work for text object selections.

This allows constructing selections within/around forms and elements
which can be operated on natively by `d`, `c`, `y` and friends.

Closes #12
julienvincent added a commit that referenced this issue Aug 11, 2023
This builds on top of the previous form/element deletions work by
expanding it to work for text object selections.

This allows constructing selections within/around forms and elements
which can be operated on natively by `d`, `c`, `y`, `v` and friends.

Closes #12
@Olical
Copy link
Contributor

Olical commented Sep 18, 2023

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
Copy link
Contributor

Olical commented Sep 18, 2023

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
Copy link
Owner

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
Copy link
Contributor

Olical commented Sep 22, 2023

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
Copy link
Owner

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
Copy link
Owner

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

@Olical
Copy link
Contributor

Olical commented Sep 23, 2023

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.

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

Successfully merging a pull request may close this issue.

4 participants