Yeah, that's what I tried first. Didn't work.
> but I didn't try to see if it works. I have
>
> the impression that it was made by "git diff" or somesuch after
>
> converting the Mercurial repository to git form.
That was my thought as well.
> You might try "hg
>
> qimport" (with the mq extension enabled),
Don't have it and can't install it on the Solaris machine. Does that work if the directory is a zip downloaded from Github instead of a real repository? My workplace blocks all outgoing Hg, Git, and SVN connections.
> and if it doesn't work at
>
> first try, you may want to remove the "index" lines in the patch.
I tried that too, for the patch utility.
Actually I just made it now. Attached for anybody else who needs it.
Here's how, from my home computer which DOES have Vim as an Hg repository:
patch -p1 < autotextobject.diff
hg extdiff -o -Nprc > autotextobject_context.patch
My hope was that we could simply add a disclaimer saying that these are not reserved and any new text object added in the future would take precident over these. My patch includes some wording along those lines in the documentation. If that is not acceptable, but making this a three-character option is, I'll be happy alter it accordingly.
As an alternative to a three-character option, it doesn't look like "I" or "A" do anything in operator-pending (but they do in visual mode). Perhaps would could utilize those for catch-all text-objects (and limit it to only working in operator-pending)?
I disagree that this is a problem. By default, the option introduced by this patch is off, meaning that unreserved text-object characters still do nothing unless the user opts into the behavior by explicitly setting an option.
The documentation for the option explicitly says that it only affects potential objects that are NOT already defined. So basically it is an option that says "do something useful instead of failing if I type something undefined". It also explicitly says that future additions to defined text objects will override this option.
If someone is using this option then they should expect minor changes when new text objects get introduced.
>
> I don't think this can be done properly without adding another
> character, thus making the text selection a three-character operation.
>
Why not? What is the reasoning behind a third character?
Oh, I think I get it now.
I actually think this could work really well.
What about another DEFINED text object, that would work on pairs of
arbitrary characters? Only that one text object would work this way, the
rest would be as they are now.
Then a user could type something like "vam," for "a matched , pair" or
"dim^" for "delete inside matched ^ pair".
If the new text object "im{char}" and "am{char}" were used instead of an
undefined and future incompatible "i{char}" and "a{char}" then you don't
need to worry about future changes breaking scripts or anything like
that. Additionally you can use this feature for alternate behaviors for
currently defined text object characters, for example if you want to
change inside B characters for some reason, or inside >> operators in
C/C++, etc.
My patch (as it is now) has it so you just press "di_" or "di$" - it's a character shorter. It's also much simpler, total-code wise. Without the documentation or setting, it is literally a one line change. Vim has all the structure for this already in place, it just falls back to "flag = FAIL" instead of doing something potentially useful. As Ben said, simply because it can be done in a plugin doesn't mean that the best place for it if it can be done simply in Vim itself.
>
>
>
> Also I don't understand how the aforementioned fallback would work in practice. For example, if I edit an html content <h1>aat....tbb</h1> and my cursor is on one of the dot characters. Is it true that pressing dit would delete only dots characters instead of all tag's content?
No - it would delete the tag's content, just as it does before the patch. The *only* place the patch does anything is with invalid text-objects. With Vim without my patch, if you enter "di$" it doesn't do anything because "$" is not a valid text object specifier. Only in those conditions does my patch do anything.
This may be best illustrated by showing the actual code. Here is Vim's code without my patch:
switch (cap->nchar)
{
case 'w': /* "aw" = a word */
flag = current_word(cap->oap, cap->count1, include, FALSE);
break;
case 'W': /* "aW" = a WORD */
flag = current_word(cap->oap, cap->count1, include, TRUE);
break;
case 'b': /* "ab" = a braces block */
case '(':
case ')':
flag = current_block(cap->oap, cap->count1, include, '(', ')');
break;
case 'B': /* "aB" = a Brackets block */
case '{':
case '}':
flag = current_block(cap->oap, cap->count1, include, '{', '}');
break;
case '[': /* "a[" = a [] block */
case ']':
flag = current_block(cap->oap, cap->count1, include, '[', ']');
break;
case '<': /* "a<" = a <> block */
case '>':
flag = current_block(cap->oap, cap->count1, include, '<', '>');
break;
case 't': /* "at" = a tag block (xml and html) */
flag = current_tagblock(cap->oap, cap->count1, include);
break;
case 'p': /* "ap" = a paragraph */
flag = current_par(cap->oap, cap->count1, include, 'p');
break;
case 's': /* "as" = a sentence */
flag = current_sent(cap->oap, cap->count1, include);
break;
case '"': /* "a"" = a double quoted string */
case '\'': /* "a'" = a single quoted string */
case '`': /* "a`" = a backtick quoted string */
flag = current_quote(cap->oap, cap->count1, include,
cap->nchar);
break;
#if 0 /* TODO */
case 'S': /* "aS" = a section */
case 'f': /* "af" = a filename */
case 'u': /* "au" = a URL */
#endif
default:
flag = FAIL;
break;
}
Vim tries to use the existing text-objects with a function for each type of object, then if an invalid specifier is provided it falls back to "flag = FAIL". All my patch does is wrap that "flag = FAIL" at the end in an if-check against the setting I added and, if the setting is set, do a
flag = current_quote(cap->oap, cap->count1, include, cap->nchar);
i.e.: fall back to treating it like quotes are treated if an object is requested that isn't (yet) defined.
With regards to:
> The problem is that this only works for characters that are not taken
> yet. Thus if we add another text-object type the behavior changes.
> It's like reserving all remaining characters to use for this feature.
I agree with what Ben said. By default this is off so that any unreserved text-object characters don't do anything unless the user opts-in to this. The disclaimer NOTE in the description should ensure that no one depends on this being guarenteed to act the same with future versions of Vim - it's not actually reserving the entire namespace there.
My argument for this patch really boils down to the following:
As Vim acts now, most of the "<operator>[ai]<character>" namespace is completely unused. Reserving it for future use doesn't benefit anyone nearly as much as having it do something sane/useful. A trivially small patch can be used to have do something useful in the unused part of that namespace (without touching the used part at all). A disclaimer - plus the fact it is a default-off setting - can be made (and is, in the patch) so that people do not rely on those keystrokes always acting the same.
I'm not sure I completely follow. I'll try to rephase what I think you're saying:
From what I understand, you're requesting a system to make it easy for end-users to add new text-objects. There are plenty of plugins to do this (you've listed some), but the problem with them is that they re-implement things that Vim already has code for, since Vim does not expose this code in any way a plugin could access.
Am I close?
If so, while I agree that would be a good thing, I don't see how it is necessarily relevant here. The idea behind my patch is that after the defined text-object code - either vim's hardcoded stuff or your new end-user-definable-stuff - there is free namespace. It'd be a separate patch - I don't think this patch necessarily needs to keep your proposed patch in mind.
The only way I could see the two ideas being connected is that maybe another algorithm could be set for the catch-all; however, I can't see how any of the other ones would be used. current_block() requires both bounds be provided, and for the catch-all we're only given one character - what would we use for the other bound? Everything else - current_word(), current_par(), current_sent() - are all hardcoded to only do one thing. The only sane option I see for a generic fall-back is current_quote, which is designed for both bounds being the same.
On Nov 15, 2013 7:49 AM, "Tony Mechelynck" <antoine.m...@gmail.com> wrote:
>
> On 14/11/13 04:00, Ben Fritz wrote:
>>
>> On Wednesday, November 13, 2013 8:27:22 PM UTC-6, Tony Mechelynck wrote:
>
> […]
>
>>> It looks like something that ought to apply with -p1 starting at the top
>>>
>>> of your Vim source directory tree (with the parent of src/ runtime/ etc.
>>>
>>> being the current directory)
>>
>>
>> Yeah, that's what I tried first. Didn't work.
>>
>>> but I didn't try to see if it works. I have
>>>
>>> the impression that it was made by "git diff" or somesuch after
>>>
>>> converting the Mercurial repository to git form.
>>
>>
>> That was my thought as well.
>>
>>> You might try "hg
>>>
>>> qimport" (with the mq extension enabled),
>>
>>
>> Don't have it and can't install it on the Solaris machine. Does that work if the directory is a zip downloaded from Github instead of a real repository? My workplace blocks all outgoing Hg, Git, and SVN connections.
>
>
> A zip downloaded from github will, IIUC, be a git repository and not a Mercurial repository. Git is still "a foreign language" to me and even reading the "git help" manuals doesn't give me any understanding of that software's philosophy, so I cannot help you there. That's also why all the advice I give is based on Mercurial. If someone else here is a git guru, (s)he is more than welcome to speak up.
It will not be a repository at all. Neither git nor mercurial. Github provides repository snapshots. I have never heard of a code hosting that allows downloading archive with repository.
> --
> --
> You received this message from the "vim_dev" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>
> --- You received this message because you are subscribed to the Google Groups "vim_dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+u...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
I can live happily with that. I'll modify the patch and submit a new one accordingly. Two questions, then:
(1) Any objections to dropping the setting for this? With this new version in mind the setting no longer seems beneficial.
(2) Any preferences on what character should be used to utilize it? I'm tempted to go with both "i" and "a" if there are no objections, so that one can do (for example) "dii$" or "caa|".
If you mean my original proposal, while it could certainly be done in script it would be *much* cleaner to do it in vim's source.
If you mean Bram's proposed alteration of my proposal, not only would be easy to do, it's been done; someone else in this thread already pointed this one out: https://github.com/thinca/vim-textobj-between/blob/master/doc/textobj-between.txt
What I had hoped for was a bit different from that and I don't think could be done nnearly as cleanly in script as it could be in vim, but Bram didn't seem as keen on it.
>
> Personally, I love to use a solid text object framework like
>
>
>
> http://www.vim.org/scripts/script.php?script_id=2100
>
>
>
> and choose for myself which special-case text object I need on top of
>
> that. I like that Vim only has a few core text objects and lets me fill
>
> in the rest.
I don't really see how this in any way conflicts with that option.
>
> By the way, "ii" is often used for "inner indent", which selects lines
>
> with the same or greater amount of indentation as the current line:
>
>
>
> http://www.vim.org/scripts/script.php?script_id=2484
>
> http://www.vim.org/scripts/script.php?script_id=3037
>
Good to know, "i" is out then.
I can experiment with adding multi-line to the new im/am object. Perhaps make another function for it instead of piggypacking off the quote funciton. I'll play with having the matching {char} at the beginning and at the end and see if either feels more natural. However, that raises additional questions; there's a number of ways of going about it.
- Should the quote objects also do multiline (after all their currently valid uses), or should they continue to do what they are doing and only have the new m-quote objects do multi-line?
- Should the m objects (including m-quote) seek ahead in the same line the way normal quotes do before checking for multi-line, or should they immediately check multiline and not do the seek-ahead-on-the-same-line thing that the normal quote objects do?
I'm inclined to have normal quote objects do what they've always done, and have the new m objects always go multi-line and not search same-line.
Consider a buffer like so:
foo bar "
baz " qux "
With the cursor on the "z" in baz. The way I am invisioning this, vi" will select the quz and vim" will select the baz. The other im/am objects will similarly just do multi-line and not worry about seeking ahead on the same line.
If there's any disagreement with the way I'm leaning on this I'm more than happy to go about it any other way.
Attached is a patch to have the im/am object support multi-line. I figured you'd probably not want the pre-existing i"/a" object to do multi-line, so instead of continuing to piggyback off of it I made a new function for the im/am object. It does not yet support doing a iv to select a larger range - I can get to that later if this strategy seems acceptable.
I wasn't sure about this idea, but I think it should be fine, and it adds the benefit that you can either do:
vi"
to get the current behavior, or:
vim"
if you want to match multi-line strings!
Review for those who have forgotten and/or don't care to backread:
This patch adds a new text object, "m", which will take one more character as input. That character will be used as bounds to the left and right for the object. For example, "cim$" will change between dollar signs. This supports multi-line objects, so one could do "cim'" which, unlike "ci'", will search across lines; this way users have both.
I've been using it quite happily for the last two months or so, but more eyes and testing would not be a bad idea.
Attached is the patch, in both unified and context format, including a test.
FWIW, I've been compiling and running on Solaris and Windows with this patch applied for a couple months now, and haven't seen any problems. I admit I only use the added feature occasionally, but it's nice to know it's there, and I'm sure it's partially due to habit of not having it available for so long.
Good catch. I can replicate that on my end. Will fix.
I think you just gave me a way to edit bulleted list items in plaintext, using a c-coded text object. I'll need to try it out tomorrow :-)
That is in fact another bug. No idea how that slipped by me. I'll be sure to fix that as well.
I tried updating this patch for 7-4-220 and mostly succeeded, just by applying a couple hundred lines of fuzz, but visual mode is not selecting the full text inside the matched pairs. I don't have time to try to fix it further. I'm attaching the updated patch in case I just did something wrong. I know there have been some visual mode changes outside of this patch between now and the time the patch was created.
Thanks for staying on this! My schedule has hit a huge crunch for the next month or two, and I don't want to rush a fix out myself and risk causing new issues. I'd rather delay fixing this and ensure that when I do the patch is as clean and bug-free as is possible against the code base at that time. When my schedule clears I may also add functionality for adding a v:count to the text object calls, which currently does not work for the new functionality for either of my patches. I might change how my tests work as well in order to have them both be cleaner and more thorough.
I have written a plugin[1] that adds similar functionality. You might want to take a look at the tests[2] that work similar to Vim's test suite.
[1] https://github.com/wellle/targets.vim
[2] https://github.com/wellle/targets.vim/tree/master/test
That patch still applies in 7-4-256, minus a small tweak to the src/testdir/Makefile. I think I characterized the visual mode issue a little better. It appears to only expand the visual selection to the right, it does not move the left side.
Example, with text "I like to eat apples" I can place the cursor on the first "p" of apples and type "vime". This selects from that p up to just before the "e" in apples. If the cursor is on the "t" in "eat" instead, vime will select from the t to the "e" in apples. With the cursor on the "a" in "eat" the full text is selected. Using "vame" is similar, the full text is only selected if I place the cursor on the "e" in "eat". The selection always starts from the cursor location.