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

ignore_beginning works differently between ( and " #46

Open
xulongwu4 opened this issue Mar 12, 2023 · 5 comments
Open

ignore_beginning works differently between ( and " #46

xulongwu4 opened this issue Mar 12, 2023 · 5 comments

Comments

@xulongwu4
Copy link

xulongwu4 commented Mar 12, 2023

Hi, I have a question about the ignore_beginning option. The plugin does not seem to work consistently when this option is set to false.

For example, I have the following cpp code snippet.

#include <iostream>

int main() { std::cout << "It is a test " << (1 + 2) << std::endl; }

Now if the cursor is inside the double quotes, pressing TAB will tab out. However, if the curosr is inside the parentheses (for example, right before the + sign), pressing TAB will insert a tab instead of tabbing out.

I would expect tabout works when the cursor is inside a pair of parenthese as well.

My setup (I use lazy.nvim):

{
  "abecodes/tabout.nvim",
  event = { "InsertEnter" },
  opts = {
    ignore_beginning = false,
  },
},
@abecodes
Copy link
Owner

Hi @xulongwu4

ignore_beginning set to false means:
If you are in a node and there is text before the cursor, the content is shifted instead of a tabout happening.

That being said, if turned to true in your case, it will not jump out consistently of said node. Depending on the whitespace either out of the parantheses or up to the bracket.

@xulongwu4
Copy link
Author

xulongwu4 commented Mar 23, 2023

@abecodes Thanks for your reply. In my config, I set ignore_beginning to false. According to your explanation, I would expect that when I press inside the text "It is a test ", a TAB is inserted rather than the cursor is moved out of the quotes. However, the actual effect is that the cursor moves to right after the closing quotes. On the other hand, if I have the cursor in (1 + 2) initially and press TAB, a TAB will be inserted.

@abecodes
Copy link
Owner

Hi @xulongwu4

I am short on time rn, but I am working on a rewrite and I try to tackle this behavior there 😊 I will let you know once it is ready.

Thanks for finding and sharing.

@mikehaertl
Copy link

I want to add what I observed because I think the claim in the issue title is not completely correct (anymore?).

Quoting @xulongwu4 :

In my config, I set ignore_beginning to false. According to your explanation, I would expect that when I press inside the text "It is a test ", a TAB is inserted rather than the cursor is moved out of the quotes. However, the actual effect is that the cursor moves to right after the closing quotes.

I think it depends on where exactly in the string you are:

  • "abc|" -> "abc"|
  • "ab|c" -> "ab c"

In other words: If the next character after the cursor is the closing character of the current "tabout context" it will jump out. Otherwise it will insert a TAB charachter.

I actually find that behaviour useful.

@abecodes Maybe you can confirm that this is always the case?

@abecodes
Copy link
Owner

Hi @mikehaertl,

"Always" is a pretty powerful word here 🤣
It always depends on how treesitter defines the node.

I experienced what you are describing as well. But not consistently.
I can reproduce it in the above example, but not in a quick golang example.

Partly it depends on how treesitter does things and is partly to the plugin being my first experience with treesitter and lua.
I wanted to rewrite it for a while now, but time is an issue (as usual xD).

PRs are always welcome btw 👍

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

No branches or pull requests

3 participants