]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0538: Cannot keep leading whitespace in %{} statusline expr v9.2.0538
authorglepnir <glephunter@gmail.com>
Mon, 25 May 2026 17:30:22 +0000 (17:30 +0000)
committerChristian Brabandt <cb@256bit.org>
Mon, 25 May 2026 17:41:13 +0000 (17:41 +0000)
Problem:  A leading space in the result of a %{} item is sometimes
          stripped, and an all-digit result is converted to a number.
Solution: Add %0{} atom which inserts the expression result verbatim
          (glepnir)

fixes:  #3898
closes: #20315

Signed-off-by: glepnir <glephunter@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/doc/options.txt
runtime/doc/tags
runtime/doc/version9.txt
src/buffer.c
src/testdir/test_statusline.vim
src/version.c

index 6dc518cc758aa152a79057ce850fc285d60c682d..0ef255210b88202ade021771028cef2eaf5a3325 100644 (file)
@@ -8670,7 +8670,8 @@ A jump table for the options with a short description can be found at |Q_op|.
        { NF  Evaluate expression between '%{' and '}' and substitute result.
              Note that there is no '%' before the closing '}'.  The
              expression cannot contain a '}' character, call a function to
-             work around that.  See |stl-%{| below.
+             work around that.  See |stl-%{| below.  Use '%0{' to insert the
+             result verbatim.
        {% -  This is almost same as { except the result of the expression is
              re-evaluated as a statusline format string.  Thus if the
              return value of expr contains % items they will get expanded.
@@ -8797,6 +8798,8 @@ A jump table for the options with a short description can be found at |Q_op|.
        A result of all digits is regarded a number for display purposes.
        Otherwise the result is taken as flag text and applied to the rules
        described above.
+                                                               *stl-%0{*
+       With %0{ neither applies: the result is inserted as a literal string.
 
        Watch out for errors in expressions.  They may render Vim unusable!
        If you are stuck, hold down ':' or 'Q' to get a prompt, then quit and
index 2291864943da29efa0aa89d9046ec13cf0cf5e45..714a9b7dbe062c3261f52164b7c1665ff439439e 100644 (file)
@@ -10562,6 +10562,7 @@ static-tag      tagsrch.txt     /*static-tag*
 status-line    windows.txt     /*status-line*
 statusmsg-variable     eval.txt        /*statusmsg-variable*
 stl-%! options.txt     /*stl-%!*
+stl-%0{        options.txt     /*stl-%0{*
 stl-%@ options.txt     /*stl-%@*
 stl-%[FuncName]        options.txt     /*stl-%[FuncName]*
 stl-%{ options.txt     /*stl-%{*
index 2bea93a32330d03da363596a340166e542ff2311..7c2ace84e76a807eadf8b77e8d7d79d525f405d6 100644 (file)
@@ -52640,6 +52640,8 @@ Other ~
   well.
 - New argument handling for user commands |:command-nargs| using the "-nars=_"
   attribute to handle completion of single arguments with spaces as expected.
+- Support %0{} in 'statusline' to insert the expression result verbatim and
+  not drop leading spaces |stl-%0{|.
 
 Platform specific ~
 -----------------
index a903ab375315dc3bc9ba0e1b59fdaa30043ea7b2..07176fbc434ac80debcda5a6a93a784758f401df 100644 (file)
@@ -5041,7 +5041,8 @@ build_stl_str_hl_local(
 
            if (reevaluate)
                s++;
-           itemisflag = TRUE;
+           // %0{} keeps the result verbatim
+           itemisflag = zeropad ? FALSE : TRUE;
            t = p;
            while ((*s != '}' || (reevaluate && s[-1] != '%'))
                                          && *s != NUL && p + 1 < out + outlen)
@@ -5078,7 +5079,7 @@ build_stl_str_hl_local(
            do_unlet((char_u *)"g:actual_curbuf", TRUE);
            do_unlet((char_u *)"g:actual_curwin", TRUE);
 
-           if (str != NULL && *str != NUL)
+           if (!zeropad && str != NULL && *str != NUL)
            {
                if (*skipdigits(str) == NUL)
                {
index 34aa94e4c518c8c2d6f1f17319b4cc6adabb553c..48c7bb669681f2719dab75de46a36bd16b80728e 100644 (file)
@@ -282,6 +282,16 @@ func Test_statusline()
   call assert_match('^vimLineComment\s*$', s:get_statusline())
   syntax off
 
+  " %0{: result of expression is inserted verbatim
+  set statusline=%{'\ x'}
+  call assert_match('^x\s*$', s:get_statusline())
+  set statusline=%0{'\ x'}
+  call assert_match('^ x\s*$', s:get_statusline())
+  set statusline=%{'000'}
+  call assert_match('^0\s*$', s:get_statusline())
+  set statusline=%0{'000'}
+  call assert_match('^000\s*$', s:get_statusline())
+
   "%{%expr%}: evaluates expressions present in result of expr
   func! Inner_eval()
     return '%n some other text'
index f86259cc9eaf8322385ca4dc0996091164377e40..0707c875de63589bdd4c1795b163a6bdaf326ac0 100644 (file)
@@ -729,6 +729,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    538,
 /**/
     537,
 /**/