-
Notifications
You must be signed in to change notification settings - Fork 722
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
Combine selection subtraction #3504
Comments
Hi @mreppen , thanks for bringing that up. In this topic, @alexherbo2 was talking about a "difference" operator: #2850 . Is the "subtraction" you propose related or another concept? Would you mind sharing a short example of manipulation starting from a buffer with lorem ipsum content? |
Hi @Delapouite, for some reason I had missed that issue despite looking. I had searched for "difference" in the issues, but named it subtract to not confuse with symmetric difference. I would like to point out that along with Here is an example with lorem ipsum, one line per sentence (start with a paragraph, then
In terms of sets, On my implementation:
|
I have given this some though, and for the use cases I have in mind, I think not doing pairwise subtraction is better. It also fits the interpretation of a kakoune selections as sets. |
Did you have a look at how vis handle these distinctions? From what I remember this editor offers pairwise ( |
I had a look at your link and in vis's list of available commands, and my understanding is that it only offers pairwise operators. Without pairwise I could save one or more selections of one part of my buffer like a mask and remove that from any other selection. Such things would not work with pairwise. Most pairwise situations would work also without pairwise, I imagine. The type of case where it would not are when one selections overlaps multiple register selections:
The first minus the second becomes either of
depending on whether it is or is not pairwise. Of course, both pairwise and not could be implemented, but I personally would likely make more use of the latter. |
Another remark on pairwise vs not: As a subtraction can both increase and decrease the number of selections, the behavior would be a bit unintuitive when chaining pairwise combine commands. Non-pairwise combine commands can be chained and I think everyone agrees on what is expected to happen. |
@Delapouite if you would like to try it out, I did a quick implementation of both pairwise and not. The ±1 bug is also fixed. |
@mreppen Why do you prefer subtract to symmetric difference?
I got Having symmetric difference operation I would get: |
@vbauerster The neat thing about subtraction is that you can construct the symmetric difference from it ((A\B)∪(B\A), which could be automated with a mapping). Note that symmetric difference +
If you want to try out other set operators, you could construct them from mappings of subtraction and "add" (set union) for now. |
I don't know if this link is really on topic and can be useful to this discussion, but I remembered it recently: https://blog.jooq.org/2016/07/05/say-no-to-venn-diagrams-when-explaining-joins/ Especially the graphics in the second part of the article that could be more inline with the mental model of selections lists |
Thanks @Delapouite. I agree with that author: joins are indeed a subsets of the Cartesian product. Maybe there is some insight I am missing, but I do not see Cartesian products in buffer selections (or at least none that are not very forced), as implemented in kakoune. The operations I am interested in, and I believe also @vbauerster, are precisely the set operations union (kak append), intersection (not in kak, SQL intersect), and set difference (not in kak, SQL except, subtraction in my wording to avoid confusion with symmetric difference). I see the buffer as a set of characters. Each selection is a ("connected") set. Multiple selections are also a set (but not "connected"). This is the context for interpretation as set operators. With the risk of getting a bit technical, a pairwise operation has the same interpretation. The difference is just that it is more like a batch/map operation on pairs of "connected" sets/selections. I'll mention again that I really prefer the non-pairwise version. With the exception of some special cases, I believe it is more general. |
I would be satisfied with either |
If you think of the buffer as a set of characters, and selections as an arbitrary subset, then these sorts of set operations are very natural and make perfect sense. Kakoune doesn't quite work like that, though: there's a very distinct difference between a selection covering the word "hello" and five selections covering the letters "h", "e", "l", "l" and "o". It's certainly possible to "flatten" Kakoune's selections into "a set of selected characters", then perform a set intersection and then reconstruct the original selections by gluing together adjacent selections, and that will work most of the time, but not always. The current "pairwise" selection operations are, I think, about as flexible as you're going to get while respecting Kakoune's selection model. I'd definitely love to see more "mathematical" selection operations (I've missed them myself) but I don't think it would be appropriate for them to replace the current operations. Perhaps it would be a good experiment to implement these operations with a plugin? |
@Screwtapello I should have been clearer in my interpretation. My idea of what these "set operators" should do, and also my implementation, do indeed distinguish between "hello" and the five separate character selections. I can make more precise descriptions if you want. For now though I will make it less technical:
What I suggest as non-pairwise fits kak's model after making my description more precise (pretty much iteration over all pairs of selections). I think nobody suggests replacing current operators; it is just unfortunate that there is a name overlap for intersection, which is part of why I only did subtraction.
Part of the problem is kak does not allow extending the selection mechanism for register combination (the key bindings), so it can't be done. (a trick I used in https://github.com/mreppen/custom-objects.kak works in this context as well, but it's more of a hack because it fails if more than one plugin wants to extend functionality) |
Take the following as a sidenote. There are other more direct ways to describe the same thing. Maybe @Delapouite was ahead of me, but it appears that the following gets it right. I'll describe intersection, as it is simpler.
In this sense, it is reminiscent of join with the extra map before the filter (maybe SQL joins can do that?). This is not a result of extensive deliberation, and I don't want to bring this technicality into the discussion unless somebody finds it useful; I just wanted to connect to @Delapouite's comment. |
A new
|
Feature
The possibility to subtract one selection from another in
<a-z>
akacombine selections from register
.Usecase
Creating more complex selections. Subtraction is a primitive and becomes very powerful together with the other selection tools.
PR?
I have a proof of concept in https://github.com/mreppen/kakoune/tree/subtract . Please excuse the coding/style, as I am not a C.*-programmer. I would gladly work it into a PR though. Main thing missing for a correctly working version is moving some
BufferCoord
s one step backward/forward.The text was updated successfully, but these errors were encountered: