Re: [vim/vim] ":tab Foo" does not work for user commands (#802)

2016-05-24 Fir de Conversatie Yegappan Lakshmanan
Hi,

On Tue, May 24, 2016 at 7:01 AM, Yegappan Lakshmanan
 wrote:
> Hi Bram,
>
> On Mon, May 23, 2016 at 12:57 PM, Bram Moolenaar  wrote:
>>> >> >
>>> >> > We could make the modifiers available in <> form, so that the user
>>> >> > command can apply them where needed. Possibly just , to pass on
>>> >> > all modifiers.
>>> >>
>>> >> The attached patch adds support for the  user command escape
>>> >> sequence.
>>> >
>>> > Thanks.  It would be nice if the help has an example that shows how the
>>> > modifiers are applied to only one of the commands.  E.g. do something
>>> > else before the "split".
>>> >
>>>
>>> We can use the example quoted by the OP:
>>>
>>>   :command! -nargs=1 Foo  split 
>>>
>>> Now the ":tab Foo bar" command will open the file in a new tab.
>>
>> It would be clearer if there is another command before or after the
>> "split".  E.g.
>>  split  | edit Results
>> So that we see that  only applies to "split", not to "edit".
>>
>
> The above command will always load the file named Results.
> How about this example?
>
> command! -nargs=+ -complete=file MyEdit for f in expand(, 0,
> 1) | exe ' split ' . f | endfor
>
> This command opens one or more files in a new split window. If the
> command modifiers like "vert" or "tab" are specified, then it opens them
> in a vertically split windows or tab pages.
>

And the below example for :

function! SpecialEdit(files, mods)
for f in expand(a:files, 0, 1)
   exe a:mods . ' split ' . f
endfor
endfunction

command! -nargs=+ -complete=file Sedit
 \ call SpecialEdit(, )

- Yegappan

-- 
-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [vim/vim] ":tab Foo" does not work for user commands (#802)

2016-05-24 Fir de Conversatie Yegappan Lakshmanan
Hi Bram,

On Mon, May 23, 2016 at 12:57 PM, Bram Moolenaar  wrote:
>> >> >
>> >> > We could make the modifiers available in <> form, so that the user
>> >> > command can apply them where needed. Possibly just , to pass on
>> >> > all modifiers.
>> >>
>> >> The attached patch adds support for the  user command escape
>> >> sequence.
>> >
>> > Thanks.  It would be nice if the help has an example that shows how the
>> > modifiers are applied to only one of the commands.  E.g. do something
>> > else before the "split".
>> >
>>
>> We can use the example quoted by the OP:
>>
>>   :command! -nargs=1 Foo  split 
>>
>> Now the ":tab Foo bar" command will open the file in a new tab.
>
> It would be clearer if there is another command before or after the
> "split".  E.g.
>  split  | edit Results
> So that we see that  only applies to "split", not to "edit".
>

The above command will always load the file named Results.
How about this example?

command! -nargs=+ -complete=file MyEdit for f in expand(, 0,
1) | exe ' split ' . f | endfor

This command opens one or more files in a new split window. If the
command modifiers like "vert" or "tab" are specified, then it opens them
in a vertically split windows or tab pages.

- Yegappan

-- 
-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [vim/vim] ":tab Foo" does not work for user commands (#802)

2016-05-23 Fir de Conversatie Bram Moolenaar

Yegappan Lakshmanan wrote:

> >> On Fri, May 20, 2016 at 9:17 AM, Bram Moolenaar 
> >> wrote:
> >>
> >> > Justin Keyes wrote:
> >> >
> >> > >
> >> > > ```
> >> > > Doesn't work for :diffsplit, :diffpatch, :execute and :normal.
> >> > > ```
> >> > >
> >> > > But it doesn't mention user commands. It would avoid a lot of redundant
> >> > commands, and add flexibility, if `:tab` supported user commands.
> >> > >
> >> > > Steps to reproduce:
> >> > >
> >> > > ```
> >> > > :command! -nargs=1 Foo split 
> >> > > :tab Foo bar
> >> > > ```
> >> > >
> >> > > - Expected behavior: opens a new buffer named "bar" in a new tab
> >> > > - Actual behavior: opens a new buffer named "bar" in a new split window
> >> >
> >> > OK, but this will cause trouble if the user command has several Ex
> >> > commands, then we don't know where to apply the modifier. E.g. when
> >> > temporarily opening a scratch bufffer.
> >> >
> >> > We could make the modifiers available in <> form, so that the user
> >> > command can apply them where needed. Possibly just , to pass on
> >> > all modifiers.
> >>
> >> The attached patch adds support for the  user command escape
> >> sequence.
> >
> > Thanks.  It would be nice if the help has an example that shows how the
> > modifiers are applied to only one of the commands.  E.g. do something
> > else before the "split".
> >
> 
> We can use the example quoted by the OP:
> 
>   :command! -nargs=1 Foo  split 

It would be clearer if there is another command before or after the
"split".  E.g.
 split  | edit Results
So that we see that  only applies to "split", not to "edit".

> Now the ":tab Foo bar" command will open the file in a new tab.

-- 
Female engineers become irresistible at the age of consent and remain that
way until about thirty minutes after their clinical death.  Longer if it's a
warm day.
(Scott Adams - The Dilbert principle)

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org///
 \\\help me help AIDS victims -- http://ICCF-Holland.org///

-- 
-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [vim/vim] ":tab Foo" does not work for user commands (#802)

2016-05-23 Fir de Conversatie Bram Moolenaar

Yegappan Lakshmanan wrote:

> >> On Sat, May 21, 2016 at 1:12 PM, Yegappan Lakshmanan
> >>  wrote:
> >> > On Fri, May 20, 2016 at 9:17 AM, Bram Moolenaar 
> >> > 
> >> > wrote:
> >> >>
> >> >>
> >> >> Justin Keyes wrote:
> >> >>
> >> >> >
> >> >> > ```
> >> >> > Doesn't work for :diffsplit, :diffpatch, :execute and :normal.
> >> >> > ```
> >> >> >
> >> >> > But it doesn't mention user commands. It would avoid a lot of 
> >> >> > redundant
> >> >> > commands, and add flexibility, if `:tab` supported user commands.
> >> >> >
> >> >> > Steps to reproduce:
> >> >> >
> >> >> > ```
> >> >> > :command! -nargs=1 Foo split 
> >> >> > :tab Foo bar
> >> >> > ```
> >> >> >
> >> >> > - Expected behavior: opens a new buffer named "bar" in a new tab
> >> >> > - Actual behavior: opens a new buffer named "bar" in a new split 
> >> >> > window
> >> >>
> >> >> OK, but this will cause trouble if the user command has several Ex
> >> >> commands, then we don't know where to apply the modifier. E.g. when
> >> >> temporarily opening a scratch bufffer.
> >> >>
> >> >> We could make the modifiers available in <> form, so that the user
> >> >> command can apply them where needed. Possibly just , to pass on
> >> >> all modifiers.
> >> >
> >> >
> >> > The attached patch adds support for the  user command escape
> >> > sequence.
> >>
> >> Updated the patch to also support "".
> >
> > Thanks.  This new piece is missing from the help.  Would be useful to
> > have an example for this as well.
> >
> 
> The help already has the following text that applies to all the escape
> sequences:
> 
> ---
> If the first two characters of an escape sequence are "q-" (for example,
> ) then the value is quoted in such a way as to make it a valid value
> for use in an expression.  This uses the argument as one single value.
> When there is no argument  is an empty string.
> ---
> 
> So I didn't add additional help text for .

The thing is that the more features we add the more difficult it is to
find the help for something related.  Therefore we need to add more
examples and tags.  When adding the new feature you are probably aware
of the related stuff, but someone just looking at the help for 
will have a hard time figuring out the  variant.

This is not specific for your patch, but since you are making these
changes we should try to make it a bit better.

-- 
Engineers are widely recognized as superior marriage material: intelligent,
dependable, employed, honest, and handy around the house.
(Scott Adams - The Dilbert principle)

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org///
 \\\help me help AIDS victims -- http://ICCF-Holland.org///

-- 
-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [vim/vim] ":tab Foo" does not work for user commands (#802)

2016-05-22 Fir de Conversatie Yegappan Lakshmanan
Hi Bram,

On Sun, May 22, 2016 at 12:17 PM, Bram Moolenaar  wrote:
>
> Yegappan Lakshmanan wrote:
>
>> On Sat, May 21, 2016 at 1:12 PM, Yegappan Lakshmanan
>>  wrote:
>> > On Fri, May 20, 2016 at 9:17 AM, Bram Moolenaar 
>> > wrote:
>> >>
>> >>
>> >> Justin Keyes wrote:
>> >>
>> >> >
>> >> > ```
>> >> > Doesn't work for :diffsplit, :diffpatch, :execute and :normal.
>> >> > ```
>> >> >
>> >> > But it doesn't mention user commands. It would avoid a lot of redundant
>> >> > commands, and add flexibility, if `:tab` supported user commands.
>> >> >
>> >> > Steps to reproduce:
>> >> >
>> >> > ```
>> >> > :command! -nargs=1 Foo split 
>> >> > :tab Foo bar
>> >> > ```
>> >> >
>> >> > - Expected behavior: opens a new buffer named "bar" in a new tab
>> >> > - Actual behavior: opens a new buffer named "bar" in a new split window
>> >>
>> >> OK, but this will cause trouble if the user command has several Ex
>> >> commands, then we don't know where to apply the modifier. E.g. when
>> >> temporarily opening a scratch bufffer.
>> >>
>> >> We could make the modifiers available in <> form, so that the user
>> >> command can apply them where needed. Possibly just , to pass on
>> >> all modifiers.
>> >
>> >
>> > The attached patch adds support for the  user command escape
>> > sequence.
>>
>> Updated the patch to also support "".
>
> Thanks.  This new piece is missing from the help.  Would be useful to
> have an example for this as well.
>

The help already has the following text that applies to all the escape
sequences:

---
If the first two characters of an escape sequence are "q-" (for example,
) then the value is quoted in such a way as to make it a valid value
for use in an expression.  This uses the argument as one single value.
When there is no argument  is an empty string.
---

So I didn't add additional help text for .

- Yegappan

-- 
-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [vim/vim] ":tab Foo" does not work for user commands (#802)

2016-05-22 Fir de Conversatie Yegappan Lakshmanan
Hi Bram,

On Sun, May 22, 2016 at 12:17 PM, Bram Moolenaar  wrote:
>
> Yegappan Lakshmanan wrote:
>
>> On Fri, May 20, 2016 at 9:17 AM, Bram Moolenaar 
>> wrote:
>>
>> > Justin Keyes wrote:
>> >
>> > >
>> > > ```
>> > > Doesn't work for :diffsplit, :diffpatch, :execute and :normal.
>> > > ```
>> > >
>> > > But it doesn't mention user commands. It would avoid a lot of redundant
>> > commands, and add flexibility, if `:tab` supported user commands.
>> > >
>> > > Steps to reproduce:
>> > >
>> > > ```
>> > > :command! -nargs=1 Foo split 
>> > > :tab Foo bar
>> > > ```
>> > >
>> > > - Expected behavior: opens a new buffer named "bar" in a new tab
>> > > - Actual behavior: opens a new buffer named "bar" in a new split window
>> >
>> > OK, but this will cause trouble if the user command has several Ex
>> > commands, then we don't know where to apply the modifier. E.g. when
>> > temporarily opening a scratch bufffer.
>> >
>> > We could make the modifiers available in <> form, so that the user
>> > command can apply them where needed. Possibly just , to pass on
>> > all modifiers.
>>
>> The attached patch adds support for the  user command escape
>> sequence.
>
> Thanks.  It would be nice if the help has an example that shows how the
> modifiers are applied to only one of the commands.  E.g. do something
> else before the "split".
>

We can use the example quoted by the OP:

  :command! -nargs=1 Foo  split 

Now the ":tab Foo bar" command will open the file in a new tab.

- Yegappan

-- 
-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [vim/vim] ":tab Foo" does not work for user commands (#802)

2016-05-22 Fir de Conversatie Bram Moolenaar

Yegappan Lakshmanan wrote:

> On Sat, May 21, 2016 at 1:12 PM, Yegappan Lakshmanan
>  wrote:
> > On Fri, May 20, 2016 at 9:17 AM, Bram Moolenaar 
> > wrote:
> >>
> >>
> >> Justin Keyes wrote:
> >>
> >> >
> >> > ```
> >> > Doesn't work for :diffsplit, :diffpatch, :execute and :normal.
> >> > ```
> >> >
> >> > But it doesn't mention user commands. It would avoid a lot of redundant
> >> > commands, and add flexibility, if `:tab` supported user commands.
> >> >
> >> > Steps to reproduce:
> >> >
> >> > ```
> >> > :command! -nargs=1 Foo split 
> >> > :tab Foo bar
> >> > ```
> >> >
> >> > - Expected behavior: opens a new buffer named "bar" in a new tab
> >> > - Actual behavior: opens a new buffer named "bar" in a new split window
> >>
> >> OK, but this will cause trouble if the user command has several Ex
> >> commands, then we don't know where to apply the modifier. E.g. when
> >> temporarily opening a scratch bufffer.
> >>
> >> We could make the modifiers available in <> form, so that the user
> >> command can apply them where needed. Possibly just , to pass on
> >> all modifiers.
> >
> >
> > The attached patch adds support for the  user command escape
> > sequence.
> 
> Updated the patch to also support "".

Thanks.  This new piece is missing from the help.  Would be useful to
have an example for this as well.

-- 
The only way the average employee can speak to an executive is by taking a
second job as a golf caddie.
(Scott Adams - The Dilbert principle)

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org///
 \\\help me help AIDS victims -- http://ICCF-Holland.org///

-- 
-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [vim/vim] ":tab Foo" does not work for user commands (#802)

2016-05-22 Fir de Conversatie Bram Moolenaar

Yegappan Lakshmanan wrote:

> On Fri, May 20, 2016 at 9:17 AM, Bram Moolenaar 
> wrote:
> 
> > Justin Keyes wrote:
> >
> > >
> > > ```
> > > Doesn't work for :diffsplit, :diffpatch, :execute and :normal.
> > > ```
> > >
> > > But it doesn't mention user commands. It would avoid a lot of redundant
> > commands, and add flexibility, if `:tab` supported user commands.
> > >
> > > Steps to reproduce:
> > >
> > > ```
> > > :command! -nargs=1 Foo split 
> > > :tab Foo bar
> > > ```
> > >
> > > - Expected behavior: opens a new buffer named "bar" in a new tab
> > > - Actual behavior: opens a new buffer named "bar" in a new split window
> >
> > OK, but this will cause trouble if the user command has several Ex
> > commands, then we don't know where to apply the modifier. E.g. when
> > temporarily opening a scratch bufffer.
> >
> > We could make the modifiers available in <> form, so that the user
> > command can apply them where needed. Possibly just , to pass on
> > all modifiers.
> 
> The attached patch adds support for the  user command escape
> sequence.

Thanks.  It would be nice if the help has an example that shows how the
modifiers are applied to only one of the commands.  E.g. do something
else before the "split".


-- 
You can test a person's importance in the organization by asking how much RAM
his computer has.  Anybody who knows the answer to that question is not a
decision-maker.
(Scott Adams - The Dilbert principle)

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org///
 \\\help me help AIDS victims -- http://ICCF-Holland.org///

-- 
-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [vim/vim] ":tab Foo" does not work for user commands (#802)

2016-05-21 Fir de Conversatie Yegappan Lakshmanan
Hi,

On Sat, May 21, 2016 at 1:12 PM, Yegappan Lakshmanan
 wrote:
> On Fri, May 20, 2016 at 9:17 AM, Bram Moolenaar 
> wrote:
>>
>>
>> Justin Keyes wrote:
>>
>> >
>> > ```
>> > Doesn't work for :diffsplit, :diffpatch, :execute and :normal.
>> > ```
>> >
>> > But it doesn't mention user commands. It would avoid a lot of redundant
>> > commands, and add flexibility, if `:tab` supported user commands.
>> >
>> > Steps to reproduce:
>> >
>> > ```
>> > :command! -nargs=1 Foo split 
>> > :tab Foo bar
>> > ```
>> >
>> > - Expected behavior: opens a new buffer named "bar" in a new tab
>> > - Actual behavior: opens a new buffer named "bar" in a new split window
>>
>> OK, but this will cause trouble if the user command has several Ex
>> commands, then we don't know where to apply the modifier. E.g. when
>> temporarily opening a scratch bufffer.
>>
>> We could make the modifiers available in <> form, so that the user
>> command can apply them where needed. Possibly just , to pass on
>> all modifiers.
>
>
> The attached patch adds support for the  user command escape
> sequence.
>

Updated the patch to also support "".

- Yegappan

-- 
-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
diff --git a/runtime/doc/map.txt b/runtime/doc/map.txt
index 3fd22f6..360f4da 100644
--- a/runtime/doc/map.txt
+++ b/runtime/doc/map.txt
@@ -1411,6 +1411,13 @@ The valid escape sequences are
  (See the '-bang' attribute) Expands to a ! if the
command was executed with a ! modifier, otherwise
expands to nothing.
+   **
+ The command modifiers, if specified. Otherwise, expands to
+   nothing. Supported modifiers are 'aboveleft', 'belowright',
+   'botright', 'browse', 'confirm', 'hide', 'keepalt',
+   'keepjumps', 'keepmarks', 'keeppatterns', 'lockmarks',
+   'noswapfile', 'silent', 'tab', 'topleft', 'verbose', and
+   'vertical'.
** **
   (See the '-register' attribute) The optional register,
if specified.  Otherwise, expands to nothing.  
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
index e5de379..42ddc4d 100644
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -6412,6 +6412,26 @@ uc_split_args(char_u *arg, size_t *lenp)
 return buf;
 }
 
+static size_t
+add_cmd_modifier(char_u *buf, char *mod_str, int *multi_mods)
+{
+size_t result;
+
+result = STRLEN(mod_str);
+if (*multi_mods)
+   result += 1;
+if (buf != NULL)
+{
+   if (*multi_mods)
+   STRCAT(buf, " ");
+   STRCAT(buf, mod_str);
+}
+
+*multi_mods = 1;
+
+return result;
+}
+
 /*
  * Check for a <> code in a user command.
  * "code" points to the '<'.  "len" the length of the <> (inclusive).
@@ -6435,8 +6455,8 @@ uc_check_code(
 char_u *p = code + 1;
 size_t l = len - 2;
 intquote = 0;
-enum { ct_ARGS, ct_BANG, ct_COUNT, ct_LINE1, ct_LINE2, ct_REGISTER,
-   ct_LT, ct_NONE } type = ct_NONE;
+enum { ct_ARGS, ct_BANG, ct_COUNT, ct_LINE1, ct_LINE2, ct_MODS,
+   ct_REGISTER, ct_LT, ct_NONE } type = ct_NONE;
 
 if ((vim_strchr((char_u *)"qQfF", *p) != NULL) && p[1] == '-')
 {
@@ -6462,6 +6482,8 @@ uc_check_code(
type = ct_LT;
 else if (STRNICMP(p, "reg>", l) == 0 || STRNICMP(p, "register>", l) == 0)
type = ct_REGISTER;
+else if (STRNICMP(p, "mods>", l) == 0)
+   type = ct_MODS;
 
 switch (type)
 {
@@ -6585,6 +6607,112 @@ uc_check_code(
break;
 }
 
+case ct_MODS:
+{
+   int multi_mods = 0;
+
+   result = quote ? 2 : 0;
+   if (buf != NULL)
+   {
+   if (quote)
+   *buf++ = '"';
+   *buf = '\0';
+   }
+
+#ifdef FEAT_WINDOWS
+   /* :aboveleft and :leftabove */
+   if (cmdmod.split & WSP_ABOVE)
+   result += add_cmd_modifier(buf, "aboveleft", _mods);
+
+   /* :belowright and :rightbelow */
+   if (cmdmod.split & WSP_BELOW)
+   result += add_cmd_modifier(buf, "belowright", _mods);
+
+   /* :botright */
+   if (cmdmod.split & WSP_BOT)
+   result += add_cmd_modifier(buf, "botright", _mods);
+#endif
+
+#ifdef FEAT_BROWSE_CMD
+   /* :browse */
+   if (cmdmod.browse)
+   result += add_cmd_modifier(buf, "browse", _mods);
+#endif
+
+#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
+   /* :confirm */
+   if (cmdmod.confirm)
+

Re: [vim/vim] ":tab Foo" does not work for user commands (#802)

2016-05-21 Fir de Conversatie Yegappan Lakshmanan
Hi,

On Fri, May 20, 2016 at 9:17 AM, Bram Moolenaar 
wrote:

>
> Justin Keyes wrote:
>
> >
> > ```
> > Doesn't work for :diffsplit, :diffpatch, :execute and :normal.
> > ```
> >
> > But it doesn't mention user commands. It would avoid a lot of redundant
> commands, and add flexibility, if `:tab` supported user commands.
> >
> > Steps to reproduce:
> >
> > ```
> > :command! -nargs=1 Foo split 
> > :tab Foo bar
> > ```
> >
> > - Expected behavior: opens a new buffer named "bar" in a new tab
> > - Actual behavior: opens a new buffer named "bar" in a new split window
>
> OK, but this will cause trouble if the user command has several Ex
> commands, then we don't know where to apply the modifier. E.g. when
> temporarily opening a scratch bufffer.
>
> We could make the modifiers available in <> form, so that the user
> command can apply them where needed. Possibly just , to pass on
> all modifiers.


The attached patch adds support for the  user command escape
sequence.

- Yegappan

-- 
-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
diff --git a/runtime/doc/map.txt b/runtime/doc/map.txt
index 3fd22f6..360f4da 100644
--- a/runtime/doc/map.txt
+++ b/runtime/doc/map.txt
@@ -1411,6 +1411,13 @@ The valid escape sequences are
  (See the '-bang' attribute) Expands to a ! if the
command was executed with a ! modifier, otherwise
expands to nothing.
+   **
+ The command modifiers, if specified. Otherwise, expands to
+   nothing. Supported modifiers are 'aboveleft', 'belowright',
+   'botright', 'browse', 'confirm', 'hide', 'keepalt',
+   'keepjumps', 'keepmarks', 'keeppatterns', 'lockmarks',
+   'noswapfile', 'silent', 'tab', 'topleft', 'verbose', and
+   'vertical'.
** **
   (See the '-register' attribute) The optional register,
if specified.  Otherwise, expands to nothing.  
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
index e5de379..2a1b6b0 100644
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -6412,6 +6412,26 @@ uc_split_args(char_u *arg, size_t *lenp)
 return buf;
 }
 
+static size_t
+add_cmd_modifier(char_u *buf, char *mod_str, int *multi_mods)
+{
+size_t result;
+
+result = STRLEN(mod_str);
+if (*multi_mods)
+   result += 1;
+if (buf != NULL)
+{
+   if (*multi_mods)
+   STRCAT(buf, " ");
+   STRCAT(buf, mod_str);
+}
+
+*multi_mods = 1;
+
+return result;
+}
+
 /*
  * Check for a <> code in a user command.
  * "code" points to the '<'.  "len" the length of the <> (inclusive).
@@ -6435,8 +6455,8 @@ uc_check_code(
 char_u *p = code + 1;
 size_t l = len - 2;
 intquote = 0;
-enum { ct_ARGS, ct_BANG, ct_COUNT, ct_LINE1, ct_LINE2, ct_REGISTER,
-   ct_LT, ct_NONE } type = ct_NONE;
+enum { ct_ARGS, ct_BANG, ct_COUNT, ct_LINE1, ct_LINE2, ct_MODS,
+   ct_REGISTER, ct_LT, ct_NONE } type = ct_NONE;
 
 if ((vim_strchr((char_u *)"qQfF", *p) != NULL) && p[1] == '-')
 {
@@ -6462,6 +6482,8 @@ uc_check_code(
type = ct_LT;
 else if (STRNICMP(p, "reg>", l) == 0 || STRNICMP(p, "register>", l) == 0)
type = ct_REGISTER;
+else if (STRNICMP(p, "mods>", l) == 0)
+   type = ct_MODS;
 
 switch (type)
 {
@@ -6585,6 +6607,103 @@ uc_check_code(
break;
 }
 
+case ct_MODS:
+{
+   int multi_mods = 0;
+
+   result = 0;
+   if (buf != NULL)
+   *buf = '\0';
+
+#ifdef FEAT_WINDOWS
+   /* :aboveleft and :leftabove */
+   if (cmdmod.split & WSP_ABOVE)
+   result += add_cmd_modifier(buf, "aboveleft", _mods);
+
+   /* :belowright and :rightbelow */
+   if (cmdmod.split & WSP_BELOW)
+   result += add_cmd_modifier(buf, "belowright", _mods);
+
+   /* :botright */
+   if (cmdmod.split & WSP_BOT)
+   result += add_cmd_modifier(buf, "botright", _mods);
+#endif
+
+#ifdef FEAT_BROWSE_CMD
+   /* :browse */
+   if (cmdmod.browse)
+   result += add_cmd_modifier(buf, "browse", _mods);
+#endif
+
+#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
+   /* :confirm */
+   if (cmdmod.confirm)
+   result += add_cmd_modifier(buf, "confirm", _mods);
+#endif
+
+   /* :hide */
+   if (cmdmod.hide)
+   result += add_cmd_modifier(buf, "hide", _mods);
+
+   /* :keepalt */
+   if (cmdmod.keepalt)
+   result +=