Skip to content

Add 'showcmd' statusline item and 'showcmdloc' option#11684

Closed
luukvbaal wants to merge 1 commit intovim:masterfrom
luukvbaal:statusline
Closed

Add 'showcmd' statusline item and 'showcmdloc' option#11684
luukvbaal wants to merge 1 commit intovim:masterfrom
luukvbaal:statusline

Conversation

@luukvbaal
Copy link
Contributor

This statusline item is mostly intended for use with cmdheight == 0 in Neovim. Nevertheless, users have expressed interest in displaying showcmd in their statusline and even tabline.

Just checking if you are open to including this to avoid future naming conflicts of the statusline item. The item name is still up for debate, @justinmk suggested dot. instead.

I assume potential users of this item would set noshowcmd, therefore I decoupled the showcmd routines from p_sc, except for the actual drawing in the cmdline.

I tried adding a non-screendump test to Test_statusline() but only the visual mode test passes. The pending operator test yields an empty statusline. Does the call assert_match() clear the showcmd buffer? That's what it seems like atleast:

  " %S: 'showcmd' content.
  set statusline=%S
  call assert_match('^\s*$', s:get_statusline())
  call feedkeys("\<C-V>l", "xt")
  call assert_match('^1x2\s*$', s:get_statusline())
  call feedkeys("\<Esc>1234", "xt")
  call assert_match('^1234\s*$', s:get_statusline())
  call feedkeys("\<Esc>", "xt")
  " result:
  " RunTheTest[44]..Test_statusline line 130: Pattern '^\\[1234\\]s*$' does not match '\[  occurs 80 times]'

Therefore I grouped them as 2 screendump tests instead. It works as intended in practice.

Redrawing the statusline upon command input caused a test failure in Test_aa_terminal_focus_events(), updated the dump files to reflect the statusline update.

@zeertzjq
Copy link
Member

zeertzjq commented Dec 9, 2022

feedkeys() with x flag needs to cancel pending operator to finish, so it is not possible to stop at op-pending mode after that. I guess it may be possible to check the screen in op-pending mode using timers, but that may make the test confusing.

@codecov
Copy link

codecov bot commented Dec 9, 2022

Codecov Report

Merging #11684 (1d5eacf) into master (98aeb21) will decrease coverage by 0.00%.
The diff coverage is 41.37%.

@@            Coverage Diff             @@
##           master   #11684      +/-   ##
==========================================
- Coverage   81.81%   81.80%   -0.01%     
==========================================
  Files         164      164              
  Lines      190973   191298     +325     
  Branches    43370    43437      +67     
==========================================
+ Hits       156242   156491     +249     
- Misses      22046    22097      +51     
- Partials    12685    12710      +25     
Flag Coverage Δ
huge-clang-none 82.66% <42.85%> (-0.03%) ⬇️
huge-gcc-none 54.56% <13.79%> (-0.01%) ⬇️
huge-gcc-testgui 53.03% <13.79%> (+0.01%) ⬆️
huge-gcc-unittests 0.29% <0.00%> (-0.01%) ⬇️
linux 82.43% <41.37%> (-0.02%) ⬇️
mingw-x64-HUGE 76.23% <38.46%> (+<0.01%) ⬆️
mingw-x86-HUGE 77.02% <38.46%> (+<0.01%) ⬆️
windows 77.87% <38.46%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/buffer.c 87.21% <0.00%> (-0.14%) ⬇️
src/drawscreen.c 80.96% <0.00%> (-0.29%) ⬇️
src/screen.c 80.18% <16.66%> (-0.19%) ⬇️
src/normal.c 90.88% <72.72%> (-0.08%) ⬇️
src/optionstr.c 91.53% <100.00%> (+0.02%) ⬆️
src/vim9type.c 90.26% <0.00%> (-0.76%) ⬇️
src/vim9expr.c 91.41% <0.00%> (-0.67%) ⬇️
src/if_xcmdsrv.c 77.25% <0.00%> (-0.35%) ⬇️
src/userfunc.c 88.96% <0.00%> (-0.19%) ⬇️
src/libvterm/src/screen.c 55.57% <0.00%> (-0.18%) ⬇️
... and 20 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@brammool
Copy link
Contributor

brammool commented Dec 9, 2022

Please first add documentation. Reverse engineering the code to guess what it's supposed to do isn't the right way to add a new feature.
One problem I can spot is that it's redrawing the status lines even when the showcmd item isn't in there.
Also, what happens when 'showcmd' is off is unclear.

@luukvbaal
Copy link
Contributor Author

Please first add documentation.

Right, completely forgot sorry.

One problem I can spot is that it's redrawing the status lines even when the showcmd item isn't in there.

True, should 'statusline' be parsed for this item? Is there precedent for this?

Also, what happens when 'showcmd' is off is unclear.

When 'showcmd' is off, we still fill the showcmd_buf, because the user might have the item in use. If we parse the status/tabline we could set a global and avoid unnecessary work I guess.

@luukvbaal luukvbaal force-pushed the statusline branch 2 times, most recently from a500f6b to 27be343 Compare December 9, 2022 17:38
@luukvbaal
Copy link
Contributor Author

If we parse the status/tabline we could set a global and avoid unnecessary work I guess.

I guess there's no reason not to, latest commit sets a global boolean when the 'showcmd' item is encountered. Status line will only be redrawn when TRUE, so reverted the terminal focus testdump change.

@brammool
Copy link
Contributor

brammool commented Dec 9, 2022 via email

@luukvbaal
Copy link
Contributor Author

Parsing the option only works when when it doesn't start with "!%". I think the only way would be to draw the status line, and set a flag if the "showcmd" value is used.

Yeah I realized, the latest commit does just that.

We could tackle both problems with a 'showcmdwhere' option (better
name?), to tell Vim where the command will be displayed, thus knowing when to update status lines.

Right, let me know if that is a route you want to take to include this feature. I can update accordingly. Do we want to facilitate displaying this item in both the status line and tabline? Or even multiple(status/tab/cmdline) at the same time? In which case I suppose it should be a comma separated string option.

Since the user has to switch 'showcmd' off, setting another option isn't really a problem.

I guess in theory they don't have to but it would make the most sense yeah.

@brammool
Copy link
Contributor

brammool commented Dec 10, 2022 via email

@luukvbaal
Copy link
Contributor Author

Would someone really want it in multiple places? That sounds unusual.
I would not implement that at first, but make the option value in a way
that it's possible in the future.

When you say "status line" it doesn't say where it shows up. Only the
status line for the most bottom-right window? Otherwise it's specified
by the 'statusline' option. But it could also be done when 'statusline'
is empty.

I find it hard to imagine showcmd showing up in the tabline. I suppose
some space would need to be reserved for it. Then the choice is on the
far left or the far right.

Yes showing it in multiple places would be unusual. The way I implemented it currently and what seems to make the most sense to me is to redraw the status line for curwin. Whether it shows up is not our concern I don't think. It would indeed be up to the user to reserve space, if they find the item high enough priority.

With the extra option, probably 'showcmdloc', then 'showcmd' would still
be on. If it is off then it won't show anywhere. That's simple.

'showcmdloc' would now be one word, such as "statusline",
"tablineright", etc. If we ever would want to show it in more than one
place the option can become a comma separated list of these words.

I still have the feeling that very few users are going to use this, thus
consider it low priority.

Very possible, again I only made the PR here to avoid future naming conflicts with Neovim, and get a feel for what item-symbol you would choose. But if we are going to add the feature here we have to add it in a way that makes sense. I think we may not need the 'showcmdloc' option. Since we now pass the option name to build_stl_str_hl(), we can simply set a flag for status/tabline and redraw accordingly in display_showcmd().

@brammool
Copy link
Contributor

brammool commented Dec 10, 2022 via email

@brammool
Copy link
Contributor

brammool commented Dec 10, 2022 via email

@luukvbaal luukvbaal changed the title Add 'showcmd' statusline item Add 'showcmd' statusline item and 'showcmdloc' option Dec 10, 2022
@luukvbaal
Copy link
Contributor Author

When 'statusline' is empty it should still show up. Left of the ruler would be good.

Latest commit adds the 'showcmdloc' option. Will need to figure out how to add this to the default statusline if 'showcmdloc' == "statusline".

@luukvbaal
Copy link
Contributor Author

Will need to figure out how to add this to the default statusline if 'showcmdloc' == "statusline".

Done in the latest commit, as well as for the default tabline. (I don't see it being all that useful in the tabline, I just added it because I came across https://vi.stackexchange.com/questions/16857/showcmd-on-first-line-instead-of-last-line).

I think the attributes for the showcmd text in the default tabline should be attr_nosel without underline. I tried attr_nosel & ~HL_UNDERLINE but that also changed the color. Any way I can use attr_nosel but remove the underline?

@luukvbaal
Copy link
Contributor Author

Any way I can use attr_nosel but remove the underline?

I guess it doesn't make sense to forcefully remove the underline from a highlight group (didn't actually figure out how to do that). This is finished then as far as I'm concerned. Tests for the default status/tabline are still missing. If you are open to including this in it's current form I could add additional tests.

@brammool
Copy link
Contributor

I thought I had already mentioned this: when 'showcmd' is off then the command should not be displayed anywhere.
It is too surprising that with 'noshowcmd' and then 'showcmdloc' set the command shows anyway.

The default value for 'showcmdloc' should be "last". Currently you could replace it with "statusline" or "tabline".
If we ever decide to show it in multiple places, it could be "last,statusline", for example.

Coding style: Please put the opening curly on the next line.

@luukvbaal
Copy link
Contributor Author

I thought I had already mentioned this: when 'showcmd' is off then the command should not be displayed anywhere.
It is too surprising that with 'noshowcmd' and then 'showcmdloc' set the command shows anyway.

The default value for 'showcmdloc' should be "last". Currently you could replace it with "statusline" or "tabline".
If we ever decide to show it in multiple places, it could be "last,statusline", for example.

Coding style: Please put the opening curly on the next line.

Done and additional tests added.

@luukvbaal
Copy link
Contributor Author

Should the tests be in test_normal.vim instead? Existing showcmd test is in there.

@brammool
Copy link
Contributor

brammool commented Dec 14, 2022 via email

@luukvbaal
Copy link
Contributor Author

test_normal.vim is already very big. Perhaps we have enough testing for this feature to justify a new test file? In the past we thought the overhead of starting a new Vim instance would matter, but now it matters more that if a test fails, e.g. there is a memory leak, it is limited in what might cause it. Otherwise, test_statusline.vim would also be related.

Yeah depends on whether you want to group these tests under 'showcmd', in which case a test_showcmd.vim might be warranted. Currently I have placed the showcmdloc=statusline test in test_statusline.vim and the showcmdloc=tabline in tabline.vim, your call.

@luukvbaal
Copy link
Contributor Author

I wonder if adding a builtin showcmd() function, analogous to e.g. mode() and searchcount() will be more useful/idiomatic than adding a statusline item?

@brammool
Copy link
Contributor

brammool commented Dec 15, 2022 via email

@brammool brammool closed this in ba936f6 Dec 15, 2022
luukvbaal added a commit to luukvbaal/neovim that referenced this pull request Dec 16, 2022
Problem:    Cannot display 'showcmd' somewhere else.
Solution:   Add the 'showcmdloc' option. (Luuk van Baal, closes vim/vim#11684)

vim/vim@ba936f6

Co-authored-by: Luuk van Baal <luukvbaal@gmail.com>
luukvbaal added a commit to luukvbaal/neovim that referenced this pull request Dec 16, 2022
Problem:    Cannot display 'showcmd' somewhere else.
Solution:   Add the 'showcmdloc' option. (Luuk van Baal, closes vim/vim#11684)

vim/vim@ba936f6

Co-authored-by: Luuk van Baal <luukvbaal@gmail.com>
luukvbaal added a commit to luukvbaal/neovim that referenced this pull request Dec 16, 2022
Problem:    Cannot display 'showcmd' somewhere else.
Solution:   Add the 'showcmdloc' option. (Luuk van Baal, closes vim/vim#11684)

vim/vim@ba936f6

Co-authored-by: Luuk van Baal <luukvbaal@gmail.com>
zeertzjq pushed a commit to luukvbaal/neovim that referenced this pull request Dec 26, 2022
Problem:    Cannot display 'showcmd' somewhere else.
Solution:   Add the 'showcmdloc' option. (Luuk van Baal, closes vim/vim#11684)

vim/vim@ba936f6

Co-authored-by: Luuk van Baal <luukvbaal@gmail.com>
zeertzjq pushed a commit to luukvbaal/neovim that referenced this pull request Dec 26, 2022
Problem:    Cannot display 'showcmd' somewhere else.
Solution:   Add the 'showcmdloc' option. (Luuk van Baal, closes vim/vim#11684)

vim/vim@ba936f6

Co-authored-by: Luuk van Baal <luukvbaal@gmail.com>
zeertzjq pushed a commit to luukvbaal/neovim that referenced this pull request Dec 26, 2022
Problem:    Cannot display 'showcmd' somewhere else.
Solution:   Add the 'showcmdloc' option. (Luuk van Baal, closes vim/vim#11684)

vim/vim@ba936f6

Co-authored-by: Luuk van Baal <luukvbaal@gmail.com>
zeertzjq pushed a commit to luukvbaal/neovim that referenced this pull request Dec 26, 2022
Problem:    Cannot display 'showcmd' somewhere else.
Solution:   Add the 'showcmdloc' option. (Luuk van Baal, closes vim/vim#11684)

vim/vim@ba936f6

Co-authored-by: Luuk van Baal <luukvbaal@gmail.com>
yesean pushed a commit to yesean/neovim that referenced this pull request Mar 25, 2023
Problem:    Cannot display 'showcmd' somewhere else.
Solution:   Add the 'showcmdloc' option. (Luuk van Baal, closes vim/vim#11684)

vim/vim@ba936f6

Co-authored-by: Luuk van Baal <luukvbaal@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants