-
-
Notifications
You must be signed in to change notification settings - Fork 64
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
feat: Allow users to customize or disable indentation. #109
Comments
I think this is by design? I can't find the issue at the moment but i vaguely remember the discussion. It matches vim-surround at least. Personally, I prefer it to update indentation. |
@NoahTheDuke hmm, well I just tested it and it does not seem to match https://github.com/tpope/vim-surround to me. I mis-indented a line, then deleted some parentheses from it, and the line does not move - just the parens disappear. I'm not sure why this behaviour would be desirable to be honest. I get that having stuff correctly indented is useful, I just don't see why nvim-surround would be involved. With the behaviour built in nvim-surround becomes useless if I am trying to maintain particular indentations for some reason. @kylechui is this a side-effect of something else? @kylechui would you be open to making this behaviour optional or is too complex to maintain both codepaths, do you think? |
A key |
@kylechui sure. I mean IMHO I still don't see the need (I'm kind of curious why this exists at all, personally, I just think it's rather odd!); but glad to hear you're planning on offering an option to turn it off! I'll live with it till then... thanks as always for all your hard work and for your input too @NoahTheDuke. |
The relevant issues are #58, #76; in particular I think it seems reasonable to make the argument either way that having a code formatter makes varying indentation styles (mostly) irrelevant, but I would still like to provide the end-user with as many choices as I can without compromising on code quality. For the record, vim-surround also does line re-indenting based on indentexpr and the = operator, but is much less consistent with it; my goal would be to have new surrounds always appear in the "proper" indentation level, or not re-indent at all if that's preferred. Like I said earlier though, pretty large refactoring is going on to accommodate for pattern-based modifications, so I'll think about this some more (hopefully) in a week or so. Thanks for opening the issue and please let me know of any particular use cases you might have regarding this/any further ideas you want to explore. Thanks! |
@kylechui yeah, that's fair. As I say, I just think that surrounds and indenting are orthogonal issues, so if I had my way, surround wouldn't focus on indenting at all, but I get it's useful for some people. Thanks for highlighting that you plan to allow it to be turned off though. |
For everyone's benefit, I have come up with a hacky monkey-patched way to disable this for now: require("nvim-surround.buffer").format_lines = function(_, _)
-- Do nothing
end (you can put this after your call to Obviously, this is a bit fragile, but if anyone like me is desperate to turn this off I think this'll work until the re-work @kylechui mentions above. |
@andrewferrier Do you mind letting me know what particular use case you have where automatic indentation is undesired? I agree with you that they are orthogonal issues; however, I think that there are a large enough number of people that wanted it to be turned on (IMO probably the majority), such that not having the option would be a pain point for many that are using the plugin. P.S. If your "hack" misses some indentations and can't easily be fixed in post, you can let me know and I can create a temporary branch that goes "into the code" and disables it for you |
@kylechui You ask good questions ;) So some examples why you might not want this:
Basically, my argument is this: nvim-surround doesn't (or shouldn't) have anything to do with indenting. It could organize my Python imports for me too, but it shouldn't, as that's the job of another plugin ;) But I get it, others feel differently. I hope that the easy of me enabling the hack above means it should be relatively easy to continue having a |
And the hack seems fine for now :) Thanks. |
Thanks for the insight, I hadn't considered those cases before. I would think hopefully that your first case is less of an issue (if Tree-sitter doesn't mess with comments), but the other reasons all seem valid. When this gets added as an option, another benefit is that you can leave indentation on for the vast majority of files, and use |
I use LSP to format my file when I save the buffer and I adopted the hack from #109 (comment) and it works as I expect (now I can paste some code, delete the delimiters and save(+auto-format) the file). This removed formatting works well for Clojure editing but it's possible that you probably would need to reformat for Python (but then you would also be reindenting by columns manually because it will preserve columns so... then it's manual). Also if you want to indent your code after the surround changes the parens.. then why don't you provide a lua binding (your plugin has name nvim so lua is fully allowed) to provide my own formatting callback that you would call?
This way you could hook this plugin into whatever you want in your config. And that would also mean that you could extract your formatting into a fully separate plug-in which people would use separately even if they don't use this one. |
Oh wow, that's actually a really good idea, and I suppose people can just use CC: @andrewferrier What are your thoughts on this? I think this matches a lot of the current code philosophy of this project, which seems to be "make everything a function and let the user decide how to handle it" 😆 |
Also one more thing with formatting -- when formatter changes the content using The formatting plugin https://github.com/lukas-reineke/lsp-format.nvim has this issue that even if it's centered around formatting it still doesn't retain marks (the Why didn't they decide to implement mark saving in one plugin and formatting in the other so that all plugins could save marks... weird... Anyway. So far I like your plug-in very much. |
@Invertisment Indeed; I've tried mitigating this issue by using P.S. Thanks for the kind words, I'm trying my best to get as much work done now before school starts up again :) |
I think that's a good idea. As I've said... before... ;)... I don't think nvim-surround should be involved, really, so for me it would then be easy to override this with a simple null function that does nothing. Good solution! Now your only decision is what the default behaviour of that function should be! |
I think that the default should be as-is to maintain parity with |
Ok sorry for the (long) delay; I'm now going to work on this via the |
I just tested it with require("nvim-surround").setup({
format_lines = false,
}) and it seems to work as intended :) |
@Invertisment Do you mind trying it out with the LSP formatter that you said you used? |
It still formats the code when I press My version is This is my whole config:
|
I used the Which branch should I use? There are three branches now. |
Sorry for the confusion. Use custom-indentation, as that is the branch I've delegated to this particular issue. v2.0.0 is a "beta" branch of sorts that I'll be asking people to test prior to a full release. main is the "stable" branch for now. Thinks are kind of a mess right now since I messed up the versioning |
After this issue gets resolved, custom-indentation will get merged into v2.0.0; at some point further in the future v2.0.0 will get merged into main |
I tried and I think |
While it was fine for the time being, I think long-term it makes less sense that way since it makes you dependent on the mechanisms, not the policies for nvim-surround. In any case, glad to know it works well for you; I'll see if I can get a few more things done before asking people to beta test the next release |
Just tested the This is a super-niggly point, but is |
Splitting hairs is good! I would much rather realize this now rather than after I release v2. Hopefully fingers crossed I will be able to make it to a v2.1.0 before v3 haha. In any case, what do you think about |
I'm happy with either I think, it was |
I've renamed everything to |
Merged into |
Re #109 (comment):
And |
@Invertisment Please try updating to the latest commit on |
But I use v2.0.0 right now. Oh it's already deleted... I thought there will be a long release cycle of some sort. Alright 👍 |
Sorry, I've been moving branches back and forth; basically everything is "in beta" except for the versioned tags (of which there is only |
@Invertisment I was experimenting with different branch-naming schemes at first, e.g. keeping a "beta" branch separate from |
I recently made my own small plugin and I basically have a (The plugin is written in Fennel which is a LISP (go to |
Yeah the only problem is that since multiple people are asking for features/bug fixes all at once, I prefer to have 3+ branches open at any given time to work on stuff in parallel (e.g. while waiting for feedback on feature A, I can start on bug fix B). I think now that the README now states that tags are recommended, I will use the |
But will you try to keep Other plugins that I have in my config are upgraded from |
Yes,
If you care about stability over having the "latest and greatest", I suggest you put |
I use |
" Using a tagged release; wildcard allowed (requires git 1.9.2 or above)
Plug 'fatih/vim-go', { 'tag': '*' } ^Source from For further context, I've been trying to get as much as possible done over the summer because I'll need to focus on school soon, so forgive me if the next few weeks are a bit hectic haha. My goal is to have no major new features added during the school year; mostly just bug fixes/minor feature releases. |
I think you procrastinate something 🤔 |
If this is a general question about the plugin or a point of confusion on a feature, please check the wiki before opening a new discussion post.
Checklist
main
branch?:h nvim-surround
to see if there might be any relevant information there?Describe the bug
It appears that a change has happened to nvim-surround which is causing it to re-indent lines when doing something unrelated to indenting (for example, deleting surrounds). I'm not 100% sure if this is intentional or not.
To Reproduce
Buffer, lua filetype, with treesitter enabled (including treesitter indent = true):
Put cursor over
def
. Pressds"
.Expected behavior
Buffer looks like:
Actual behavior
Buffer looks like:
Additional context
I feel pretty strongly this should not be happening, at least by default. In my view,
surround.nvim
should only be adding, modifying or deleting surrounds. Here, what it appears to be doing is re-indenting the line also. In this case, that happens to be correct. But there are many reasons why I might have a line intentionally mis-aligned. I think the keybindings should be doing the minimum to achieve surround's goal only.Not sure if this is a bug or by design?
The text was updated successfully, but these errors were encountered: