@@ -8535,18 +8535,19 @@ find_cmdline_var(char_u *src, int *usedlen)
85358535/*
85368536 * Evaluate cmdline variables.
85378537 *
8538- * change '%' to curbuf->b_ffname
8539- * '#' to curwin->w_alt_fnum
8540- * '<cword>' to word under the cursor
8541- * '<cWORD>' to WORD under the cursor
8542- * '<cexpr>' to C-expression under the cursor
8543- * '<cfile>' to path name under the cursor
8544- * '<sfile>' to sourced file name
8545- * '<stack>' to call stack
8546- * '<slnum>' to sourced file line number
8547- * '<afile>' to file name for autocommand
8548- * '<abuf>' to buffer number for autocommand
8549- * '<amatch>' to matching name for autocommand
8538+ * change "%" to curbuf->b_ffname
8539+ * "#" to curwin->w_alt_fnum
8540+ * "%%" to curwin->w_alt_fnum in Vim9 script
8541+ * "<cword>" to word under the cursor
8542+ * "<cWORD>" to WORD under the cursor
8543+ * "<cexpr>" to C-expression under the cursor
8544+ * "<cfile>" to path name under the cursor
8545+ * "<sfile>" to sourced file name
8546+ * "<stack>" to call stack
8547+ * "<slnum>" to sourced file line number
8548+ * "<afile>" to file name for autocommand
8549+ * "<abuf>" to buffer number for autocommand
8550+ * "<amatch>" to matching name for autocommand
85508551 *
85518552 * When an error is detected, "errormsg" is set to a non-NULL pointer (may be
85528553 * "" for error without a message) and NULL is returned.
@@ -8627,47 +8628,57 @@ eval_vars(
86278628 */
86288629 else
86298630 {
8631+ int off = 0 ;
8632+
86308633 switch (spec_idx )
86318634 {
8632- case SPEC_PERC : // '%': current file
8633- if (curbuf -> b_fname == NULL )
8634- {
8635- result = (char_u * )"" ;
8636- valid = 0 ; // Must have ":p:h" to be valid
8637- }
8638- else
8635+ case SPEC_PERC :
8636+ if (!in_vim9script () || src [1 ] != '%' )
86398637 {
8640- result = curbuf -> b_fname ;
8641- tilde_file = STRCMP (result , "~" ) == 0 ;
8638+ // '%': current file
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 ;
86428650 }
8643- break ;
8651+ // "%%" alternate file
8652+ off = 1 ;
8653+ // FALLTHROUGH
86448654
86458655 case SPEC_HASH : // '#' or "#99": alternate file
8646- if (src [1 ] == '#' ) // "##": the argument list
8656+ if (off == 0 ? src [1 ] == '#' : src [ 2 ] == '%' )
86478657 {
8658+ // "##" or "%%%": the argument list
86488659 result = arg_all ();
86498660 resultbuf = result ;
8650- * usedlen = 2 ;
8661+ * usedlen = off + 2 ;
86518662 if (escaped != NULL )
86528663 * escaped = TRUE;
86538664 skip_mod = TRUE;
86548665 break ;
86558666 }
8656- s = src + 1 ;
8667+ s = src + off + 1 ;
86578668 if (* s == '<' ) // "#<99" uses v:oldfiles
86588669 ++ s ;
86598670 i = (int )getdigits (& s );
8660- if (s == src + 2 && src [1 ] == '-' )
8671+ if (s == src + off + 2 && src [off + 1 ] == '-' )
86618672 // just a minus sign, don't skip over it
86628673 s -- ;
86638674 * usedlen = (int )(s - src ); // length of what we expand
86648675
8665- if (src [1 ] == '<' && i != 0 )
8676+ if (src [off + 1 ] == '<' && i != 0 )
86668677 {
8667- if (* usedlen < 2 )
8678+ if (* usedlen < off + 2 )
86688679 {
86698680 // Should we give an error message for #<text?
8670- * usedlen = 1 ;
8681+ * usedlen = off + 1 ;
86718682 return NULL ;
86728683 }
86738684#ifdef FEAT_EVAL
@@ -8685,8 +8696,8 @@ eval_vars(
86858696 }
86868697 else
86878698 {
8688- if (i == 0 && src [1 ] == '<' && * usedlen > 1 )
8689- * usedlen = 1 ;
8699+ if (i == 0 && src [off + 1 ] == '<' && * usedlen > off + 1 )
8700+ * usedlen = off + 1 ;
86908701 buf = buflist_findnr (i );
86918702 if (buf == NULL )
86928703 {
0 commit comments