Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move default statusline from C implementation to 'stl' expression #29389

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

yochem
Copy link
Contributor

@yochem yochem commented Jun 18, 2024

Partly fixes: #28809. After this is merged, we can look into implementing a Lua/Vimscript version of a more modern default statusline.

Let me know if/what docs I need to update. The current default is taken from :h 'statusline', where they describe it as Emulate standard status line with 'ruler'. I can change this to Default statusline with 'ruler' set. Should there also be a news entry?

Problem:
- Default C implementation can not be viewed in the form of the
  statusline DSL
- Therefore users can not base their statusline on the default with
  additional tweaks

Solution:
- Removes the C implementation of the default statusline
- Implements the default statusline using the 'statusline' DSL

This will make the default statusline readable as expression, and is
a first step in providing a default Lua/Vimscript implementation.

Reference: neovim#28809
@github-actions github-actions bot added the defaults issues or PRs involving changing the defaults label Jun 18, 2024
@github-actions github-actions bot requested a review from gpanders June 18, 2024 09:17
@dundargoc dundargoc added the statusline tabline, winbar, statuscolumn label Jun 18, 2024
@github-actions github-actions bot requested a review from famiu June 18, 2024 10:00
@famiu
Copy link
Member

famiu commented Jun 18, 2024

I cannot check to make sure as I do not have access to my PC right now, but this does not seem like the correct way of setting the new default to me. This only sets the initial default value instead of a fallback value. E.g. if you did vim.o.statusline = "", I assume it wouldn't use the default statusline anymore, which breaks old behavior. Do correct me if I'm wrong.

A better approach may be to take a statusline string value as a parameter in redraw_custom_statusline. Then you could pass the custom statusline string when it exists, and the default value otherwise.

@yochem
Copy link
Contributor Author

yochem commented Jun 18, 2024

Yes, you're right. I forgot that setting strings option to an empty string usually reverts it to the default value. I'll look into your proposed approach.

@yochem
Copy link
Contributor Author

yochem commented Jun 18, 2024

The easiest way to set the default statusline would be to modify the p_stl or wp->w_p_stl when NUL:

  } else if (*p_stl != NUL || *wp->w_p_stl != NUL) {
    // redraw custom status line
    redraw_custom_statusline(wp);
  } else {
    // default statusline case

    // define default statusline
    char *default_stl = (char*)xmalloc(sizeof("hallo"));
    strcpy(default_stl, "hallo");
    p_stl = default_stl;

    redraw_custom_statusline(wp);
  }

(excuse the probably really bad C code)

But this seems like an antipattern to me:

vim.o.statusline = ""
print(vim.o.statusline)
-- prints "hallo" when built with the C code above

As @famiu suggested, another option would be to modify the functions that draw the stl (win_redr_status, redraw_custom_statusline, win_redr_custom, build_stl_str_hl) to accept a string value for the statusline, which could be set to the default in the else clause above.

The drawback here is that the default statusbar format is then still defined in statusbar.c, and I can imagine it not being ideal if we later want to define the default statusline from Lua/Vimscript.

Also, how would nvim_eval_statusline then be able to evaluate the statusline? Either build_stl_str_hl should know the default value of the statusline, or maybe a function in statusline.c default_stl_str, that returns the default statusline format? nvim_eval_statusline can then call this function to get the default.

@justinmk What do you think would be the right approach here?

@famiu
Copy link
Member

famiu commented Jun 18, 2024

The easiest way to set the default statusline would be to modify the p_stl or wp->w_p_stl when NUL:

  } else if (*p_stl != NUL || *wp->w_p_stl != NUL) {
    // redraw custom status line
    redraw_custom_statusline(wp);
  } else {
    // default statusline case

    // define default statusline
    char *default_stl = (char*)xmalloc(sizeof("hallo"));
    strcpy(default_stl, "hallo");
    p_stl = default_stl;

    redraw_custom_statusline(wp);
  }

(excuse the probably really bad C code)

But this seems like an antipattern to me:

vim.o.statusline = ""
print(vim.o.statusline)
-- prints "hallo" when built with the C code above

As @famiu suggested, another option would be to modify the functions that draw the stl (win_redr_status, redraw_custom_statusline, win_redr_custom, build_stl_str_hl) to accept a string value for the statusline, which could be set to the default in the else clause above.

The drawback here is that the default statusbar format is then still defined in statusbar.c, and I can imagine it not being ideal if we later want to define the default statusline from Lua/Vimscript.

Also, how would nvim_eval_statusline then be able to evaluate the statusline? Either build_stl_str_hl should know the default value of the statusline, or maybe a function in statusline.c default_stl_str, that returns the default statusline format? nvim_eval_statusline can then call this function to get the default.

I don't think we should change option values as a side effect when building the statusline, that sounds like a recipe for disaster.

Instead, we can define a function that returns the default value, and use that in relevant places. This keeps the default value contained to a single place while avoiding any unnecessary hacks

@yochem yochem marked this pull request as draft June 18, 2024 18:50
Problem: No way to pass default format to statusline redrawer.

Solution: This option allows to directly pass a format string to the
function.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defaults issues or PRs involving changing the defaults statusline tabline, winbar, statuscolumn
Projects
None yet
Development

Successfully merging this pull request may close these issues.

statusline: reimplement default, include LSP progress
3 participants