Logical conditions (e.g., || or &&), #1534
-
Contributing guidelines
Module(s)mini.ai QuestionHi, Is it possible to operate (remove, select, copy) on the logical condition: // cursor positioned on selectedMimes
if (this.form.isDirty() || selectedMimes.length > 0) { } pressing: // after deletion...
if (this.form.isDirty()) { } or maybe it can be done by Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Thanks for kind words! Yes, this should be possible, but to what actual extent depends on the effort. I think the most promising way of doing that would be to use textobjects based on tree-sitter, which requires creating own captures in 'after/queries//textobjects.scm' and use them later in A slightly more straightforward way would be to use Lua patterns and construct a custom textobject according to specification. Even more straightforward (yet limited) approach would be to reuse local ai = require('mini.ai')
ai.setup({
custom_textobjects = {
-- `ax` will remove "||" part, but not "&&"
x = ai.gen_spec.argument({ brackets = { '%b()' }, separator = '%s*||%s*' }),
-- `aX` will remove "&&" part, but not "||"
X = ai.gen_spec.argument({ brackets = { '%b()' }, separator = '%s*&&%s*' }),
},
}) The alternative would be to allow it to also match "|&" and "&|" strings as another "logical operators". As those are rare, I'd consider it a worthy compromise. So the setup is like this: local ai = require('mini.ai')
ai.setup({
custom_textobjects = {
x = ai.gen_spec.argument({ brackets = { '%b()' }, separator = '%s*[|&][|&]%s*' }),
},
}) Notes:
Hope this helps. |
Beta Was this translation helpful? Give feedback.
Thanks for kind words!
Yes, this should be possible, but to what actual extent depends on the effort.
I think the most promising way of doing that would be to use textobjects based on tree-sitter, which requires creating own captures in 'after/queries//textobjects.scm' and use them later in
gen_spec.treesitter()
.A slightly more straightforward way would be to use Lua patterns and construct a custom textobject according to specification.
Even more straightforward (yet limited) approach would be to reuse
gen_spec.argument()
with "||" and "&&" as separators. The problem is that they both can't be used inside single custom textobject (Lua patterns don't allow alteration of strings, only char…