Closed phgz closed 4 months ago
Hi there, one major reason that I've been hesitant to add this is because I don't believe there's a good way to ensure configuration ordering when calling either setup
or buffer_setup
. In particular, which should take precedence between default.filetype_config
and user.global_config
? It's not abundantly clear. Furthermore, all of the functionality in this PR more or less seems like it can already be accomplished via buffer_setup
calls put into after/plugin/filetype.lua
. Recently, I've found myself trending more and more towards reducing the amount of stuff that my plugin does by default, and simply providing an easy-to-use API for the user to configure the plugin themselves.
In the config file, I added a filetypes_extensions
key where the user could provide the module/table to be merged with the defaults (basically a vim.tbl_deep_extend("force", defaults, <user table defining their own filetype config>)
). But sure, if there is an upcoming more flexible API, I'd be glad to use it :)
I see; I think the tricky part of trying to use filetypes_extensions
is that it would somewhat conflict with the existing buffer_setup
function, as I'm not sure how we could guarantee that the configuration functions would be run in the correct order. I'm actually thinking of removing layers of abstractions by replacing the setup
function call with just a vim.g.nvim_surround
(or vim.b.nvim_surround
, and having users just set that variable wherever they see fit. That way the overriding is completely transparent, instead of forcing people to learn the quirks of whatever interface I create.
Sorry, I'll probably just close this PR for now while I figure how else I wish to restructure the plugin.
… surrounds for lua and python ft
Links to https://github.com/kylechui/nvim-surround/issues/238.
This is a pretty much standalone module, extensible by users own filetypes definitions. All the current tests are passing. Some could be added for this module. Also, there is still the documentation that should be updated.
It is basically an opt-in extension, backward compatible. Users specify, in the surrounds mapping, which key they want to assign for each object.
Before going further, I would like a review to see if there are things to adjust.
Thank you!
Note/Edit:
The behaviour of the cursor for "move_cursor=false" is currently "sticky". Adding the "noop" behaviour should be trivial.
The behaviours are the following: adding delimiters puts the user in insert mode on the blank (condition for conditional, clause for loop and name for function). Changing surrounds acts similarly: it removes that parts and put in insert mode. If for a filetype no placeholder is specified, then the cursor is not moved nor put in insert mode.
Here is a demo:
https://asciinema.org/a/ODi9aWaE2b2DB0yGpVdgBIgMe