2

I want to use an expression (function), which takes two arguments - data and a dictionary - as a statusline.

This is what I'm trying:

let &stl="%{Brick(statusbricks#ReportLinecount('raw'), {
        \   'brick_color': 'LineNr',
        \   'delimiter_position': 'right',
        \   'delimiter_right': '❯'
        \ })}"

Why does this result in the follwing error messages:

E722: Missing comma in Dictionary:
Press ENTER or type command to continue
E116: Invalid arguments for function Brick(statusbricks#ReportLinecount('raw'), {'brick_color': 'LineNr', 'delimiter_position': 'right', 'delimiter_right': '❯'
Press ENTER or type command to continue
E15: Invalid expression:
Brick(statusbricks#ReportLinecount('raw'), {'brick_color': 'LineNr', 'delimiter_position': 'right', 'delimiter_right': '❯'
Press ENTER or type command to continue

If I remove the dictionary in the function call it passes. Even if I use it as a one-liner without any spaces I do get the same errors.

Saucier
  • 4,200
  • 1
  • 25
  • 46
  • 1
    Do you get the same result if you place it all on one line rather than using backslash-escaped line continuation? – Michael Berkowski Aug 03 '15 at 19:28
  • Yes - updated the question based on your comment. – Saucier Aug 03 '15 at 19:32
  • And what if you test with a different delimiter, like `|` or `>`? And any difference if you store the dictionary into a local var which is then passed to the function? The dictionary itself seems to parse correctly, copy/pasting from what you've posted here. – Michael Berkowski Aug 03 '15 at 19:42
  • Even passing an empty dict does not help. But storing it to a variable and then passing the var to the function works. So I'd say `%{}` does not accept "inner" curly braces. Even escaping them does not help. – Saucier Aug 03 '15 at 20:08
  • I don't know what terminology vimscript uses for `%{}` to find its rules in the documentation – Michael Berkowski Aug 03 '15 at 20:18
  • All I found is at `:help stl` – Saucier Aug 03 '15 at 20:21
  • 2
    I see - it isn't part of broader vimscript string interpolation syntax, just statusline. `Evaluate expression between '%{' and '}' and substitute result.`. No rules listed on nesting `{}` but as you've found, it appears not to be legal. – Michael Berkowski Aug 03 '15 at 20:24
  • Yes, looks like I hit either a bug or an undocumented feature. :) – Saucier Aug 03 '15 at 20:53
  • However you can start the option with `%!`. – 1983 Aug 03 '15 at 22:20
  • That is true but there is a significant difference: `%!` expressions get populated globally. That means all statuslines of all buffers get the expression result of the buffer being active. – Saucier Aug 03 '15 at 22:28

1 Answers1

0

To use a dictionary in a 'statusline' expression, a Funcref can be used.

For example, argument sign_getplaced with a dictionary:

let g:Sign_getplaced = function('sign_getplaced', ['', {'group':'*'}])

Then use g:Sign_getplaced in a 'statusline' expression.

Bohr
  • 1,566
  • 1
  • 16
  • 21
  • Although a custom function can also be defined to be used in `'statusline'`. Evaluating a `Funcref` is faster than evaluating a custom function. – Bohr Jan 05 '21 at 02:48