On Thursday, November 14, 2013 11:01:56 AM UTC-5, Kent Sibilev wrote:
> On Thursday, November 14, 2013 6:24:42 AM UTC-5, Daniel "paradigm" Thau wrote:
> 
> > On Wednesday, November 13, 2013 11:10:39 PM UTC-5, Kent Sibilev wrote:
> 
> > > Maybe i'm missing something, but you don't need to patch Vim in order to 
> > > get this functionality. What you need is kana's textobj pluing:
> 
> > > https://github.com/kana/vim-textobj-user
> 
> > > along with textobj-between
> 
> > > https://github.com/thinca/vim-textobj-between
> 
> > 
> 
> > Yes, there are plenty of ways to make custom text-objects without editing 
> > Vim.  However, everything you've listed require the end-user list the 
> > desired objects ahead of time.  You could loop over the character range in 
> > a plugin or vimrc and make them all, or make an operator-mode mapping to a 
> > function that calls getchar() then tries to either make it on-the-fly or 
> > fall back to existing things, but all of these options get ugly fast.  
> > Adding three lines to normal.c ends up being much quicker and cleaner.
> 
> 
> 
> With textobj-between plugin installed you don't need to loop over and make a 
> mapping for every possible character. The plugin adds a single text object 
> activated by pressing 'f'. So if you want to delete a content between to 
> underscores (_) characters, you press dif_. If you want change text between 
> two dollar sign characters you press cif$, 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.

-- 
-- 
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Raspunde prin e-mail lui