To: vim_dev@googlegroups.com Subject: Patch 7.4.1898 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 7.4.1898 Problem: User commands don't support modifiers. Solution: Add the item. (Yegappan Lakshmanan, closes #829) Files: runtime/doc/map.txt, src/ex_docmd.c, src/testdir/Make_all.mak, src/testdir/test_usercommands.vim *** ../vim-7.4.1897/runtime/doc/map.txt 2014-12-08 04:16:26.253702999 +0100 --- runtime/doc/map.txt 2016-06-04 21:41:58.325927489 +0200 *************** *** 1395,1400 **** --- 1411,1437 ---- (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|. + Examples: > + command! -nargs=+ -complete=file MyEdit + \ for f in expand(, 0, 1) | + \ exe ' split ' . f | + \ endfor + + 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(, ) + < ** ** (See the '-register' attribute) The optional register, if specified. Otherwise, expands to nothing. *** ../vim-7.4.1897/src/ex_docmd.c 2016-06-04 20:25:01.177991001 +0200 --- src/ex_docmd.c 2016-06-04 22:05:21.845908182 +0200 *************** *** 6413,6418 **** --- 6413,6438 ---- 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). *************** *** 6436,6443 **** char_u *p = code + 1; size_t l = len - 2; int quote = 0; ! enum { ct_ARGS, ct_BANG, ct_COUNT, ct_LINE1, ct_LINE2, ct_REGISTER, ! ct_LT, ct_NONE } type = ct_NONE; if ((vim_strchr((char_u *)"qQfF", *p) != NULL) && p[1] == '-') { --- 6456,6463 ---- char_u *p = code + 1; size_t l = len - 2; int quote = 0; ! 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] == '-') { *************** *** 6463,6468 **** --- 6483,6490 ---- 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) { *************** *** 6586,6591 **** --- 6608,6697 ---- break; } + case ct_MODS: + { + int multi_mods = 0; + typedef struct { + int *varp; + char *name; + } mod_entry_T; + static mod_entry_T mod_entries[] = { + #ifdef FEAT_BROWSE_CMD + {&cmdmod.browse, "browse"}, + #endif + #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) + {&cmdmod.confirm, "confirm"}, + #endif + {&cmdmod.hide, "hide"}, + {&cmdmod.keepalt, "keepalt"}, + {&cmdmod.keepjumps, "keepjumps"}, + {&cmdmod.keepmarks, "keepmarks"}, + {&cmdmod.keeppatterns, "keeppatterns"}, + {&cmdmod.lockmarks, "lockmarks"}, + {&cmdmod.noswapfile, "noswapfile"}, + {NULL, NULL} + }; + int i; + + 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", &multi_mods); + /* :belowright and :rightbelow */ + if (cmdmod.split & WSP_BELOW) + result += add_cmd_modifier(buf, "belowright", &multi_mods); + /* :botright */ + if (cmdmod.split & WSP_BOT) + result += add_cmd_modifier(buf, "botright", &multi_mods); + #endif + + /* the modifiers that are simple flags */ + for (i = 0; mod_entries[i].varp != NULL; ++i) + if (*mod_entries[i].varp) + result += add_cmd_modifier(buf, mod_entries[i].name, + &multi_mods); + + /* TODO: How to support :noautocmd? */ + #ifdef HAVE_SANDBOX + /* TODO: How to support :sandbox?*/ + #endif + /* :silent */ + if (msg_silent > 0) + result += add_cmd_modifier(buf, + emsg_silent > 0 ? "silent!" : "silent", &multi_mods); + #ifdef FEAT_WINDOWS + /* :tab */ + if (cmdmod.tab > 0) + result += add_cmd_modifier(buf, "tab", &multi_mods); + /* :topleft */ + if (cmdmod.split & WSP_TOP) + result += add_cmd_modifier(buf, "topleft", &multi_mods); + #endif + /* TODO: How to support :unsilent?*/ + /* :verbose */ + if (p_verbose > 0) + result += add_cmd_modifier(buf, "verbose", &multi_mods); + #ifdef FEAT_WINDOWS + /* :vertical */ + if (cmdmod.split & WSP_VERT) + result += add_cmd_modifier(buf, "vertical", &multi_mods); + #endif + if (quote && buf != NULL) + { + buf += result - 2; + *buf = '"'; + } + break; + } + case ct_REGISTER: result = eap->regname ? 1 : 0; if (quote) *** ../vim-7.4.1897/src/testdir/Make_all.mak 2016-04-14 19:48:54.805601567 +0200 --- src/testdir/Make_all.mak 2016-06-04 22:06:45.705907029 +0200 *************** *** 179,184 **** --- 179,185 ---- test_perl.res \ test_quickfix.res \ test_syntax.res \ + test_usercommands.res \ test_viminfo.res \ test_viml.res \ test_visual.res \ *** ../vim-7.4.1897/src/testdir/test_usercommands.vim 2016-06-04 22:07:43.381906235 +0200 --- src/testdir/test_usercommands.vim 2016-06-04 21:38:42.905930177 +0200 *************** *** 0 **** --- 1,48 ---- + " Tests for user defined commands + + " Test for in user defined commands + function Test_cmdmods() + let g:mods = '' + + command! -nargs=* MyCmd let g:mods .= ' ' + + MyCmd + aboveleft MyCmd + belowright MyCmd + botright MyCmd + browse MyCmd + confirm MyCmd + hide MyCmd + keepalt MyCmd + keepjumps MyCmd + keepmarks MyCmd + keeppatterns MyCmd + lockmarks MyCmd + noswapfile MyCmd + silent MyCmd + tab MyCmd + topleft MyCmd + verbose MyCmd + vertical MyCmd + + aboveleft belowright botright browse confirm hide keepalt keepjumps + \ keepmarks keeppatterns lockmarks noswapfile silent tab + \ topleft verbose vertical MyCmd + + call assert_equal(' aboveleft belowright botright browse confirm ' . + \ 'hide keepalt keepjumps keepmarks keeppatterns lockmarks ' . + \ 'noswapfile silent tab topleft verbose vertical aboveleft ' . + \ 'belowright botright browse confirm hide keepalt keepjumps ' . + \ 'keepmarks keeppatterns lockmarks noswapfile silent tab topleft ' . + \ 'verbose vertical ', g:mods) + + let g:mods = '' + command! -nargs=* MyQCmd let g:mods .= ' ' + + vertical MyQCmd + call assert_equal('"vertical" ', g:mods) + + delcommand MyCmd + delcommand MyQCmd + unlet g:mods + endfunction *** ../vim-7.4.1897/src/version.c 2016-06-04 20:25:01.185991001 +0200 --- src/version.c 2016-06-04 22:07:52.189906114 +0200 *************** *** 755,756 **** --- 755,758 ---- { /* Add new patch number below this line */ + /**/ + 1898, /**/ -- hundred-and-one symptoms of being an internet addict: 47. You are so familiar with the WWW that you find the search engines useless. /// Bram Moolenaar -- Bram@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 ///