comparison src/ex_docmd.c @ 23370:622e90acea5d v8.2.2228

patch 8.2.2228: Vim9: cannot use ":e #" because # starts a comment Commit: https://github.com/vim/vim/commit/4389f9cd00632adc0216d5ead13d859b186bcbf8 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Dec 27 16:55:11 2020 +0100 patch 8.2.2228: Vim9: cannot use ":e #" because # starts a comment Problem: Vim9: cannot use ":e #" because # starts a comment. Solution: Support using %% instead of #.
author Bram Moolenaar <Bram@vim.org>
date Sun, 27 Dec 2020 17:00:04 +0100
parents b3142fc0a414
children 86d155b29dd7
comparison
equal deleted inserted replaced
23369:a547793a18c1 23370:622e90acea5d
8533 } 8533 }
8534 8534
8535 /* 8535 /*
8536 * Evaluate cmdline variables. 8536 * Evaluate cmdline variables.
8537 * 8537 *
8538 * change '%' to curbuf->b_ffname 8538 * change "%" to curbuf->b_ffname
8539 * '#' to curwin->w_alt_fnum 8539 * "#" to curwin->w_alt_fnum
8540 * '<cword>' to word under the cursor 8540 * "%%" to curwin->w_alt_fnum in Vim9 script
8541 * '<cWORD>' to WORD under the cursor 8541 * "<cword>" to word under the cursor
8542 * '<cexpr>' to C-expression under the cursor 8542 * "<cWORD>" to WORD under the cursor
8543 * '<cfile>' to path name under the cursor 8543 * "<cexpr>" to C-expression under the cursor
8544 * '<sfile>' to sourced file name 8544 * "<cfile>" to path name under the cursor
8545 * '<stack>' to call stack 8545 * "<sfile>" to sourced file name
8546 * '<slnum>' to sourced file line number 8546 * "<stack>" to call stack
8547 * '<afile>' to file name for autocommand 8547 * "<slnum>" to sourced file line number
8548 * '<abuf>' to buffer number for autocommand 8548 * "<afile>" to file name for autocommand
8549 * '<amatch>' to matching name for autocommand 8549 * "<abuf>" to buffer number for autocommand
8550 * "<amatch>" to matching name for autocommand
8550 * 8551 *
8551 * When an error is detected, "errormsg" is set to a non-NULL pointer (may be 8552 * When an error is detected, "errormsg" is set to a non-NULL pointer (may be
8552 * "" for error without a message) and NULL is returned. 8553 * "" for error without a message) and NULL is returned.
8553 * Returns an allocated string if a valid match was found. 8554 * Returns an allocated string if a valid match was found.
8554 * Returns NULL if no match was found. "usedlen" then still contains the 8555 * Returns NULL if no match was found. "usedlen" then still contains the
8625 * File name for autocommand 8626 * File name for autocommand
8626 * and following modifiers 8627 * and following modifiers
8627 */ 8628 */
8628 else 8629 else
8629 { 8630 {
8631 int off = 0;
8632
8630 switch (spec_idx) 8633 switch (spec_idx)
8631 { 8634 {
8632 case SPEC_PERC: // '%': current file 8635 case SPEC_PERC:
8633 if (curbuf->b_fname == NULL) 8636 if (!in_vim9script() || src[1] != '%')
8634 { 8637 {
8635 result = (char_u *)""; 8638 // '%': current file
8636 valid = 0; // Must have ":p:h" to be valid 8639 if (curbuf->b_fname == NULL)
8640 {
8641 result = (char_u *)"";
8642 valid = 0; // Must have ":p:h" to be valid
8643 }
8644 else
8645 {
8646 result = curbuf->b_fname;
8647 tilde_file = STRCMP(result, "~") == 0;
8648 }
8649 break;
8637 } 8650 }
8638 else 8651 // "%%" alternate file
8652 off = 1;
8653 // FALLTHROUGH
8654
8655 case SPEC_HASH: // '#' or "#99": alternate file
8656 if (off == 0 ? src[1] == '#' : src[2] == '%')
8639 { 8657 {
8640 result = curbuf->b_fname; 8658 // "##" or "%%%": the argument list
8641 tilde_file = STRCMP(result, "~") == 0;
8642 }
8643 break;
8644
8645 case SPEC_HASH: // '#' or "#99": alternate file
8646 if (src[1] == '#') // "##": the argument list
8647 {
8648 result = arg_all(); 8659 result = arg_all();
8649 resultbuf = result; 8660 resultbuf = result;
8650 *usedlen = 2; 8661 *usedlen = off + 2;
8651 if (escaped != NULL) 8662 if (escaped != NULL)
8652 *escaped = TRUE; 8663 *escaped = TRUE;
8653 skip_mod = TRUE; 8664 skip_mod = TRUE;
8654 break; 8665 break;
8655 } 8666 }
8656 s = src + 1; 8667 s = src + off + 1;
8657 if (*s == '<') // "#<99" uses v:oldfiles 8668 if (*s == '<') // "#<99" uses v:oldfiles
8658 ++s; 8669 ++s;
8659 i = (int)getdigits(&s); 8670 i = (int)getdigits(&s);
8660 if (s == src + 2 && src[1] == '-') 8671 if (s == src + off + 2 && src[off + 1] == '-')
8661 // just a minus sign, don't skip over it 8672 // just a minus sign, don't skip over it
8662 s--; 8673 s--;
8663 *usedlen = (int)(s - src); // length of what we expand 8674 *usedlen = (int)(s - src); // length of what we expand
8664 8675
8665 if (src[1] == '<' && i != 0) 8676 if (src[off + 1] == '<' && i != 0)
8666 { 8677 {
8667 if (*usedlen < 2) 8678 if (*usedlen < off + 2)
8668 { 8679 {
8669 // Should we give an error message for #<text? 8680 // Should we give an error message for #<text?
8670 *usedlen = 1; 8681 *usedlen = off + 1;
8671 return NULL; 8682 return NULL;
8672 } 8683 }
8673 #ifdef FEAT_EVAL 8684 #ifdef FEAT_EVAL
8674 result = list_find_str(get_vim_var_list(VV_OLDFILES), 8685 result = list_find_str(get_vim_var_list(VV_OLDFILES),
8675 (long)i); 8686 (long)i);
8683 return NULL; 8694 return NULL;
8684 #endif 8695 #endif
8685 } 8696 }
8686 else 8697 else
8687 { 8698 {
8688 if (i == 0 && src[1] == '<' && *usedlen > 1) 8699 if (i == 0 && src[off + 1] == '<' && *usedlen > off + 1)
8689 *usedlen = 1; 8700 *usedlen = off + 1;
8690 buf = buflist_findnr(i); 8701 buf = buflist_findnr(i);
8691 if (buf == NULL) 8702 if (buf == NULL)
8692 { 8703 {
8693 *errormsg = _("E194: No alternate file name to substitute for '#'"); 8704 *errormsg = _("E194: No alternate file name to substitute for '#'");
8694 return NULL; 8705 return NULL;