To: vim_dev@googlegroups.com Subject: Patch 8.2.2052 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.2052 Problem: Vim9: "edit +4 fname" gives an error. (Naruhiko Nishino) Solution: Allow using a range in the +cmd argument. (closes #7364) Files: src/ex_docmd.c, src/proto/ex_docmd.pro, src/vim.h, src/ex_cmds.c, src/testdir/test_vim9_cmd.vim *** ../vim-8.2.2051/src/ex_docmd.c 2020-11-22 18:15:40.167258395 +0100 --- src/ex_docmd.c 2020-11-25 19:54:08.372091176 +0100 *************** *** 595,600 **** --- 595,611 ---- } /* + * Execute the "+cmd" argument of "edit +cmd fname" and the like. + * This allows for using a range without ":" in Vim9 script. + */ + int + do_cmd_argument(char_u *cmd) + { + return do_cmdline(cmd, NULL, NULL, + DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_KEYTYPED|DOCMD_RANGEOK); + } + + /* * do_cmdline(): execute one Ex command line * * 1. Execute "cmdline" when it is not NULL. *************** *** 989,995 **** * "cmdline_copy" can change, e.g. for '%' and '#' expansion. */ ++recursive; ! next_cmdline = do_one_cmd(&cmdline_copy, flags & DOCMD_VERBOSE, #ifdef FEAT_EVAL &cstack, #endif --- 1000,1006 ---- * "cmdline_copy" can change, e.g. for '%' and '#' expansion. */ ++recursive; ! next_cmdline = do_one_cmd(&cmdline_copy, flags, #ifdef FEAT_EVAL &cstack, #endif *************** *** 1685,1691 **** /* * Execute one Ex command. * ! * If 'sourcing' is TRUE, the command will be included in the error message. * * 1. skip comment lines and leading space * 2. handle command modifiers --- 1696,1703 ---- /* * Execute one Ex command. * ! * If "flags" has DOCMD_VERBOSE, the command will be included in the error ! * message. * * 1. skip comment lines and leading space * 2. handle command modifiers *************** *** 1708,1714 **** static char_u * do_one_cmd( char_u **cmdlinep, ! int sourcing, #ifdef FEAT_EVAL cstack_T *cstack, #endif --- 1720,1726 ---- static char_u * do_one_cmd( char_u **cmdlinep, ! int flags, #ifdef FEAT_EVAL cstack_T *cstack, #endif *************** *** 1731,1736 **** --- 1743,1749 ---- int vim9script = in_vim9script(); int did_set_expr_line = FALSE; #endif + int sourcing = flags & DOCMD_VERBOSE; CLEAR_FIELD(ea); ea.line1 = 1; *************** *** 1794,1800 **** #ifdef FEAT_EVAL // In Vim9 script a colon is required before the range. This may also be // after command modifiers. ! if (vim9script) { may_have_range = FALSE; for (p = ea.cmd; p >= *cmdlinep; --p) --- 1807,1813 ---- #ifdef FEAT_EVAL // In Vim9 script a colon is required before the range. This may also be // after command modifiers. ! if (vim9script && (flags & DOCMD_RANGEOK) == 0) { may_have_range = FALSE; for (p = ea.cmd; p >= *cmdlinep; --p) *************** *** 5009,5015 **** else goto_buffer(eap, DOBUF_FIRST, FORWARD, (int)eap->line2); if (eap->do_ecmd_cmd != NULL) ! do_cmdline_cmd(eap->do_ecmd_cmd); } } --- 5022,5028 ---- else goto_buffer(eap, DOBUF_FIRST, FORWARD, (int)eap->line2); if (eap->do_ecmd_cmd != NULL) ! do_cmd_argument(eap->do_ecmd_cmd); } } *************** *** 5022,5028 **** { goto_buffer(eap, DOBUF_MOD, FORWARD, (int)eap->line2); if (eap->do_ecmd_cmd != NULL) ! do_cmdline_cmd(eap->do_ecmd_cmd); } /* --- 5035,5041 ---- { goto_buffer(eap, DOBUF_MOD, FORWARD, (int)eap->line2); if (eap->do_ecmd_cmd != NULL) ! do_cmd_argument(eap->do_ecmd_cmd); } /* *************** *** 5037,5043 **** goto_buffer(eap, DOBUF_CURRENT, FORWARD, (int)eap->line2); if (eap->do_ecmd_cmd != NULL) ! do_cmdline_cmd(eap->do_ecmd_cmd); } /* --- 5050,5056 ---- goto_buffer(eap, DOBUF_CURRENT, FORWARD, (int)eap->line2); if (eap->do_ecmd_cmd != NULL) ! do_cmd_argument(eap->do_ecmd_cmd); } /* *************** *** 5054,5060 **** goto_buffer(eap, DOBUF_CURRENT, BACKWARD, (int)eap->line2); if (eap->do_ecmd_cmd != NULL) ! do_cmdline_cmd(eap->do_ecmd_cmd); } /* --- 5067,5073 ---- goto_buffer(eap, DOBUF_CURRENT, BACKWARD, (int)eap->line2); if (eap->do_ecmd_cmd != NULL) ! do_cmd_argument(eap->do_ecmd_cmd); } /* *************** *** 5071,5077 **** goto_buffer(eap, DOBUF_FIRST, FORWARD, 0); if (eap->do_ecmd_cmd != NULL) ! do_cmdline_cmd(eap->do_ecmd_cmd); } /* --- 5084,5090 ---- goto_buffer(eap, DOBUF_FIRST, FORWARD, 0); if (eap->do_ecmd_cmd != NULL) ! do_cmd_argument(eap->do_ecmd_cmd); } /* *************** *** 5086,5092 **** goto_buffer(eap, DOBUF_LAST, BACKWARD, 0); if (eap->do_ecmd_cmd != NULL) ! do_cmdline_cmd(eap->do_ecmd_cmd); } /* --- 5099,5105 ---- goto_buffer(eap, DOBUF_LAST, BACKWARD, 0); if (eap->do_ecmd_cmd != NULL) ! do_cmd_argument(eap->do_ecmd_cmd); } /* *************** *** 6680,6686 **** else { if (eap->do_ecmd_cmd != NULL) ! do_cmdline_cmd(eap->do_ecmd_cmd); #ifdef FEAT_TITLE n = curwin->w_arg_idx_invalid; #endif --- 6693,6699 ---- else { if (eap->do_ecmd_cmd != NULL) ! do_cmd_argument(eap->do_ecmd_cmd); #ifdef FEAT_TITLE n = curwin->w_arg_idx_invalid; #endif *** ../vim-8.2.2051/src/proto/ex_docmd.pro 2020-10-24 20:49:37.506683014 +0200 --- src/proto/ex_docmd.pro 2020-11-25 20:08:04.489589839 +0100 *************** *** 1,6 **** --- 1,7 ---- /* ex_docmd.c */ void do_exmode(int improved); int do_cmdline_cmd(char_u *cmd); + int do_cmd_argument(char_u *cmd); int do_cmdline(char_u *cmdline, char_u *(*fgetline)(int, void *, int, getline_opt_T), void *cookie, int flags); int getline_equal(char_u *(*fgetline)(int, void *, int, getline_opt_T), void *cookie, char_u *(*func)(int, void *, int, getline_opt_T)); void *getline_cookie(char_u *(*fgetline)(int, void *, int, getline_opt_T), void *cookie); *** ../vim-8.2.2051/src/vim.h 2020-11-07 18:40:47.132725219 +0100 --- src/vim.h 2020-11-25 19:47:18.977821169 +0100 *************** *** 1043,1048 **** --- 1043,1049 ---- #define DOCMD_KEYTYPED 0x08 // don't reset KeyTyped #define DOCMD_EXCRESET 0x10 // reset exception environment (for debugging) #define DOCMD_KEEPLINE 0x20 // keep typed line for repeating with "." + #define DOCMD_RANGEOK 0240 // can use a range without ":" in Vim9 script // flags for beginline() #define BL_WHITE 1 // cursor on first non-white in the line *** ../vim-8.2.2051/src/ex_cmds.c 2020-11-07 18:40:47.136725212 +0100 --- src/ex_cmds.c 2020-11-25 19:48:32.673500383 +0100 *************** *** 3123,3129 **** #endif if (command != NULL) ! do_cmdline(command, NULL, NULL, DOCMD_VERBOSE); #ifdef FEAT_KEYMAP if (curbuf->b_kmap_state & KEYMAP_INIT) --- 3123,3129 ---- #endif if (command != NULL) ! do_cmdline(command, NULL, NULL, DOCMD_VERBOSE|DOCMD_RANGEOK); #ifdef FEAT_KEYMAP if (curbuf->b_kmap_state & KEYMAP_INIT) *** ../vim-8.2.2051/src/testdir/test_vim9_cmd.vim 2020-11-20 21:06:56.699112617 +0100 --- src/testdir/test_vim9_cmd.vim 2020-11-25 20:02:16.986218781 +0100 *************** *** 648,652 **** --- 648,664 ---- CheckScriptSuccess(lines) enddef + def Test_cmd_argument_without_colon() + new Xfile + setline(1, ['a', 'b', 'c', 'd']) + write + edit +3 % + assert_equal(3, getcurpos()[1]) + edit +/a % + assert_equal(1, getcurpos()[1]) + bwipe + delete('Xfile') + enddef + " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker *** ../vim-8.2.2051/src/version.c 2020-11-25 19:15:15.443211576 +0100 --- src/version.c 2020-11-25 19:46:41.185987846 +0100 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 2052, /**/ -- GUARD #2: It could be carried by an African swallow! GUARD #1: Oh, yeah, an African swallow maybe, but not a European swallow, that's my point. GUARD #2: Oh, yeah, I agree with that... The Quest for the Holy Grail (Monty Python) /// 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 ///