noctuid / things.el

Extensions to thingatpt.el
51 stars 0 forks source link

Smarter Separators #3

Open noctuid opened 5 years ago

noctuid commented 5 years ago

It would be nice to be able select the first and last items in a list with separators. Previously I had them set up to potentially use the bob and eob. This wouldn't let you select the first item in a list that appears after or before any other list in the buffer though.

I've found a relevant issue on the targets.vim repo (wellle/targets.vim#110). One suggestion there is to use the line beginning/end instead (with the downside being that this breaks separators across lines). A follow-up suggestion is to either bound by on lines without the separator or to follow a more complicated line-based boundary.

It seems to me there's no consistent way to decide how to bound a group of separators and it should just be left up to the user to decide. things-define-separator can just allow for an optional bounds function (e.g. line, buffer, etc.) to support more specific cases where necessary.

I think a saner default would probably be the current paragraph (bounded by bob/eob or blank lines) instead of line. This would work for most lists outside of sentences. It would make a pipe | separator for tables smarter since it wouldn't select in between tables but would seek to the next table instead. For other characters, a different boundary might make the most sense by default, so I think it makes sense to just have it configurable per-separator (e.g. bounding by any space characters might make more sense for _; bounding by sentences might make sense for a ; separator intended for prose).

There doesn't seem to be a good way to handle commas in sentences. In some cases it might make more sense to bound by word (or maybe sentence), but there's no way to know the word length of the first item in some comma-separated list in a sentence.

This functionality could probably be used to implement argument things (bound to a pair).

noctuid commented 5 years ago

It also could make sense to restrict separators to the current comment or string or ignore strings/comments for positions not in a string or comment (wellle/targets.vim#111). This could be done with the same method I've used for regexp pairs, but then there are the same performance issues that need to be worked out. This behavior may be "too smart," and it may not be worth the complication. The use cases would likely be handled better by a different text object (e.g. argument text object) as pointed out in the linked issue.