-
-
Notifications
You must be signed in to change notification settings - Fork 63
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
Release v2.0.0 #136
Release v2.0.0 #136
Conversation
* feat!: Easier user configuration. * Breaking change: The translation layer first falls back on any defined defaults, before using `invalid_key_behavior`. * docs: Improve code docs for `config`. * refactor!: Rename `textobject` to `motion`. Breaking Change: The `textobject` key for the `config.get_selection()` function has been renamed to `motion`, to allow for more generalized surrounds. As a result, all existing `textobject` values should have `a` pre-pended to them. * refactor!: Rename the highlight group. Breaking Change: Renames the highlight group from `NvimSurroundHighlightTextObject` to `NvimSurroundHighlight`.
* Remaining issues: Visual block mode.
* Remaining issues: Does not surround the literal visual block.
* feat: Add native Tree-sitter support. * Documents the new feature. * Changes default behavior for `f` to use Tree-sitter nodes by default, falling back on Lua patterns. * Refactors the "nearest selection" heuristic into its own function. * feat: Improve HTML tag/function call patterns. * feat: Sample filetype config for Lua files. * feat: Improve pattern-matching Tree-sitter nodes. * feat!: Add `languages` file with new API. * fix: Naming bug. * refactor: Rename `languages` to `filetype`. * docs: Comment code.
lua/nvim-surround/filetype.lua
Outdated
vim.api.nvim_create_autocmd("FileType", { | ||
pattern = vim.tbl_keys(M.filetype_configurations), | ||
callback = function() | ||
M.filetype_configurations[vim.bo.filetype]() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like there should be a nil-check here in case there is no function for the given filetype :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@smjonas I actually forgot I accounted for this, but there will always exist a function for the given filetype, since the autocommand uses the M.filetype_configurations
table to even choose which files to run on. So this shouldn't be an issue as far as I can tell :) Thanks for checking though!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, you're right, I missed that :D
* feat: Allow custom formatting via `format_lines` key. * fix: Insert surrounds also depend on format key. * refactor!: Rename `format_lines` to `indent_lines`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nvim-surround/lua/nvim-surround/init.lua
Lines 10 to 13 in 28aa65e
---@field add function | |
---@field find function | |
---@field delete function | |
---@field change { target: function, replacement: function? } |
Those lines causing LSP problems as shown below.
Please add string
type to find
, delete
, and target
fields and add string[]
to the add
field since documentation said that those fileds can accept string
type while add
field can take the list of string.
Hmm I didn't realize that LSP would actually tell you about that; the reason why I initially omitted them is because when |
One suggestion for this release: Would you consider falling back to the Example: p = {
add = { "vim.pretty_print(", ")" },
find = "vim%.pretty_print%b()",
delete = "^(vim%.pretty_print%()().-(%))()$",
change = {
target = "^(vim%.pretty_print%()().-(%))()$",
},
}, New: p = {
add = { "vim.pretty_print(", ")" },
find = "vim%.pretty_print%b()",
delete = "^(vim%.pretty_print%()().-(%))()$",
},
Let me know what you think! |
@smjonas Very good point. I suppose change is only different from a literal add/delete pair if it's more complex (e.g. function call, HTML tag), and isn't actually necessary most of the time. I'll add this in at some point; still working on user interface for default filetype-specific surrounds. Design is hard 😅 |
* By default, `change.target` will take on the `delete` key's values, analogous to how `change.replacement` will take on the next surround's `add` key's value.
@smjonas Added in the latest commit, thanks for the great suggestion! |
Awesome, thank you for implementing that so fast! |
If you actually look at the commit it was honestly a really quick fix, just added like 3-4 lines :) |
Oh wait @smjonas an interesting (new) issue cropped up as a result of defaulting to require("nvim-surround").buffer_setup({
surrounds = {
["f"] = {
find = function()
return config.get_selection({ node = "function_call" })
end,
delete = "^([^=%s]+%()().-(%))()$",
},
},
}) then |
I would suggest to only fallback to the local surround's |
Hmm... this behavior might actually be unrelated; will do some more investigating. Edit: It was unrelated. Oops! |
@smjonas I've decided on falling back on globals first, since I don't think it makes sense that tweaking |
Great 🎉 |
@latipun7 There are (unfortunately) still quite a few bugs that need to be ironed out, as well as user config interface decisions that need to be made. This most likely will not appear in a release for a little bit, unless something magical happens and I'm satisfied with the quality of the code. |
Breaking Changes
TODO: In the actual release notes, just link to #77
Some user configuration variables have been renamed to better reflect their actual purpose:
highlight_motion
→highlight
NvimSurroundHighlightTextObject
→NvimSurroundHighlight
textobject
key forrequire("nvim-surround.config").get_selection()
has been replaced by themotion
key. This allows for better compatibility withtargets.vim
and similar plugins that define their own text-objects. All existingtextobject
keys just need to be pre-pended witha
to represent the correct motion, e.g.New Features
:h nvim-surround.config.get_selection()
dsf
to better handle edge cases likesmiley_face(":)")
nvim-surround
indentation can be disabled by setting the new keyindent_lines = false
; see:h nvim-surround.config.indent_lines
Bug Fixes
change.target
key (and subsequently thechange
key) is now optional, and will default todelete
key instead. This is analogous tochange.replacement
andadd
Future Goals
ts
prefix, see Toggle quotes (ts
) #98vim-sandwich
) #135 (if you want this feature, show your support here!)das
/dis
keymaps, still in the works