molok / vim-smartusline

Vim plugin that changes the color of the statusbar of the focused window according with the current mode (normal/insert/replace)
34 stars 1 forks source link

Support for expression status lines, starting with "%!" #5

Closed blueyed closed 12 years ago

blueyed commented 12 years ago

I am using an expression in my statusline config, which looks as follows:

set statusline=%!MyStatusLine('Enter')

I think smartusline should evaluate this expression and then do its search-and-replace on the result.

I have tried the following code in the SmartusLineWin function, but did not get it to work properly:

if curr_stl[0:1] == "%!"
    let curr_stl = eval(curr_stl[2:-1])
endif

The issue appears to be that any "%{}" parts (returned from the function) need to be evaluated, too. (from ":h 'stl'": The result can contain %{} items that will be evaluated too.)

However, in my case, I would like to highlight the result of the following expression: "%{ShortenFilename(fnamemodify(bufname("%"), ":~"), 20)}"

Therefore smartusline would have to handle highlighting not only in the end (when everything is evaluated), but look for a matching g:smartusline_string_to_highlight after each "eval()".

I for myself will just stay with the non-plugin approach for now - feel free to close this as "won't fix" if you consider it to be too much hassle.

molok commented 12 years ago

I pushed an experimental branch called eval-expression, could you test it? It might work!

molok commented 12 years ago

I'm not sure if I should evaluate %{} items or not

molok commented 12 years ago

Note for myself: I could have a g:smartusline_deep_eval true/false shallow: evaluate %!{} only deep: evaluate %{} too

blueyed commented 12 years ago

Using the parser you currently are evaluating deeply, aren't you? So it won't work for me currently, because the "%{ShortenFilename(fnamemodify(bufname("%"), ":~"), 20)}" would get evaluated and nothing would be there to get matched.

I guess that you need to evaluate deeply though, because Vim only evaluates %{} itself when the whole setting started with "%!".

What's missing now appears to be looking for a g:smartusline_string_to_highlight match after each eval() in the parser and then applying the markers accordingly.

molok commented 12 years ago

Yeah, I realized that after I commited the change. I'll probably implement shallow evaluation when I have a little bit of free time.

molok commented 12 years ago

With 0194aaf8d789494159257897bb77f8ccce4cf107 shallow evaluation (e.g. %!MyStatusLine()) is now on by default, and there is a new smartusline_deep_eval option to do deep evaluation (%{} items returned by %!MyStatusLine())