Evaluate results of %{%expr%} blocks in statusline#8190
Evaluate results of %{%expr%} blocks in statusline#8190shadmansaleh wants to merge 12 commits intovim:masterfrom shadmansaleh:enhance/statusline_evaluation
Conversation
Currently results of %{} blocks gets directly displayed in statusline.
Because of results of %{} blocks can't contain expressions like
%#highlight# or %f etc . This pr changes that .
|
Can someone tell me what's this suppose to mean char_u is just an alias for unsigned char and used all over the codebase . Why is this error occuring ? line 4487 is char_u *block_start = s;where s itself is a pointer to char_u |
|
This is not backwards compatible, if the %{} result contains any percent sign it's likely to be broken. |
How about Though to be honest I don't think there are many use cases where %{} evaluates to string with % . Even in that case the % can just be escaped with another % |
|
@brammool I've moved the functionality to new Edit: |
|
I think that would be an acceptable solution. Let's await anybody else commenting. |
|
@brammool I think I've a better idea then creating a new % item . We could check for a char at start of expr that cann't exist on valid vim expr. I've just pushed an implementation of that . I think valid vimL_expr doesn't contain ':' at begining(I could be wrong though) . So here result of |
|
@brammool I think I've a better idea then creating a new % item . We
could check for a char at start of expr that cann't exist on valid vim
expr. I've just pushed an implementation of that . I think valid
vimL_expr doesn't contain ':' at begining(I could be wrong though) . So
here result of `%{expr}` doesn't get evaluated while result of
`%{:expr}` gets evaluated . This should be backword compatable and
doesn't require a new item . If ':' is valid as first char ofa vimL
expression or you think ':' is confusing please let me know a char that
can be used for this purpose :) . Also let me know what you think of
this idea ...
Both can work. The most relevant difference might be how the end is
found. For %{} is stated that there cannot be a "}" inside the
expression. For %[] that would be a "]", which is much more common.
But perhaps another way can be used to mark the end, since this
construct is new anyway. Using %[expr%] could also work, and "%]" is
very unlikely to appear.
Using %{: expr } is a bit more cryptic. How about %{% expr %} ?
Or even %{% expr %}% to make it symmetric.
…--
hundred-and-one symptoms of being an internet addict:
253. You wait for a slow loading web page before going to the toilet.
/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
|
I think if we are going with %{} structure I think we should leave the end marker as changing it will definatly be a breaking change to anyone using %{} .
I think if we aren't changing the end marker then we can switch to using Edit: |
|
> For %{} is stated that there cannot be a "}" inside the
> expression. For %[] that would be a "]", which is much more common.
I think if we are going with %{} structure we can leave the end marker
ad it is since it always has been '}' and has worked till now . Also
changing the end marker will definatly be a breaking change to anyone
using %{} .
> Using %{: expr } is a bit more cryptic. How about %{% expr %} ?
I think if we aren't changing the end marker then we can switch to
using `%{%expr}` . How about `%{!expr}` . Since there's already a `%!`
evaluating item might be a familiar syntax .
Yes, %{! is better than %{:, since "!" often means "execute".
I do think that using %} for the end might work better. Not allowing a
"}" inside the expression can be a problem, e.g. when using a
dictionary. If we do not change it now it will be set in stone.
…--
Did you hear about the new 3 million dollar West Virginia State Lottery?
The winner gets 3 dollars a year for a million years.
/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
|
|
@brammool I think github doesn't send mails about edits .That's why you got an older version of the comment. To sum it up here's where I'm at.
I think we can finalize %{%expr} for evaluation and %{expr} retains it's regular behavior . I've already made the changes to use '%'. If you agree I think this proposal can be merged to vim . You can review the changes and let me know if you have any problem about the code . |
I do think It would have been better to have |
No, the suggestion is to require the new end marker ( |
@jamessan thanks for clearifiing . Now that makes a lot more sence :) . @brammool I've changed the end marker for So now for |
|
> No, the suggestion is to require the new end marker (%}) when using the new start marker (%{%).
@jamessan thanks for clearifiing . Now that makes a lot more sence :) .
@brammool I've changed the end marker for `%{%` expressions to `%}`
So now for `%{%myfunc()%}` results of `myfunc() will be evaluated .
This is what you asked for right ?
Right, only require %} instead of } when using the new start marker.
I wonder if we can use %{!, since using ! in front of an expression
would result in a boolean, which doesn't make sense to insert into the
status line. So even though it's not invalid, it would never be
actually used.
I just like %{! a bit better than %{%, but both can work.
…--
hundred-and-one symptoms of being an internet addict:
260. Co-workers have to E-mail you about the fire alarm to get
you out of the building.
/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
|
There are lots of boolean pieces of information which can make sense to put in the status line. I wouldn't count on |
I agree. And it would be nice if a ternary could be used here, in which case the first part of the expression would be a bool. Warning: contrived example ahead: |
Codecov Report
@@ Coverage Diff @@
## master #8190 +/- ##
==========================================
- Coverage 89.35% 89.33% -0.02%
==========================================
Files 148 148
Lines 166793 165713 -1080
==========================================
- Hits 149038 148040 -998
+ Misses 17755 17673 -82
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
|
@brammool I think we shouldn't use |
|
@brammool is this ok to merge ? Or something left to be done ? |
|
Please also add a test for infinite recursion, so that it runs into
MAX_STL_EVAL_DEPTH.
Please use formatting like in the other Vim code: { on a separate line,
empty line after declarations.
…--
Bravely bold Sir Robin, rode forth from Camelot,
He was not afraid to die, Oh Brave Sir Robin,
He was not at all afraid to be killed in nasty ways
Brave, brave, brave, brave Sir Robin.
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
|
|
> I do think that using %} for the end might work better. Not allowing a
> "}" inside the expression can be a problem, e.g. when using a
> dictionary. If we do not change it now it will be set in stone.
I do think It would have been better to have `%}` . But it's already on
the stone . Do you really want to make a breaking change about it ? If
you do I don't have problem making it . To be clear we are no longer
introducing a new item. `%[]` was droped now we are changing the
behavior of already existing `%{}` item to extend it's abilities while
remaining 100% backword compatable . Changing the end marker will break
all existing uses of `%{}` item . I'm just asking for confirmation
because I'm really confused about you trying to make incompatable
changes :D .
We can use %} only for %{%, not for the existing %{. That gives the new
form an advantage and doesn't change the existing one.
…--
A KNIGHT rides into shot and hacks him to the ground. He rides off.
We stay for a moment on the glade. A MIDDLE-AGED LADY in a C. & A.
twin-set emerges from the trees and looks in horror at the body of her
HUSBAND.
MRS HISTORIAN: FRANK!
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
|
Thanks for the review. I've added test for inf recursion and fixed formating as you recomanded. I actually don't know what formating rules vim follow , didn't see anything related to formatting in CONTRIBUTING.md |
Problem: Custom statusline cannot contain % items.
Solution: Add "%{% expr %}". (closes vim/vim#8190)
vim/vim@30e3de2
Problem: Custom statusline cannot contain % items.
Solution: Add "%{% expr %}". (closes vim/vim#8190)
vim/vim@30e3de2
Problem: Custom statusline cannot contain % items.
Solution: Add "%{% expr %}". (closes vim/vim#8190)
vim/vim@30e3de2
Problem: Custom statusline cannot contain % items.
Solution: Add "%{% expr %}". (closes vim/vim#8190)
vim/vim@30e3de2
Currently results of %{} blocks gets directly displayed in statusline.
Because of results of %{} blocks cann't contain expressions like
%#highlight# or %f etc . This pr changes that .
The idea is simple it just replaces the %{} block with it's result and continue evaluating.
Without the patch

With the patch

Edit:
The idea has changed. Current plan is to evaluate %{} blocks only when expr starts with a '%' to remain backword compatable. So format will be %{%expr%}