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

(mini.indentscope) Add option for a prefix symbol #161

Closed
wants to merge 5 commits into from

Conversation

mivort
Copy link

@mivort mivort commented Nov 15, 2022

This small change adds an ability to use a user-defined symbol for a prefix instead of only a hard-coded space character. The idea is to allow the usage of this plugin with a leading space 'listchar' option enabled.

Context

Hi! Thanks a lot for a very cool and minimalistic plugin to provide a nice indent visualization without introducing a performance penalty!

I've been using a listchars vim option for a while to visualize leading tabs and whitespaces, so when I've stared using mini.indentscope plugin, I've noticed that it overwrites existing NonText marks with a blank space:

before

I think the option to provide a user-defined prefix character instead of hard-coded ' ' could be useful to listchars users without introducing a performance penalty. With this patch it's possible to keep the visible whitespaces while getting a highlighted scope under cursor (using the following config):

vim.o.listchars = 'lead:┆'
require('mini.indentscope').setup { prefix = '' }

after

It can also provide users with ability to customize scope visualization with existing MiniIndentscopePrefix highlight.

In any case, thanks again for a great and very useful Neovim plugin!

This small change adds an ability to use a user-defined symbol for a
prefix instead of only a hard-coded space character. The idea is to
allow the usage of this plugin with a leading space 'listchar' option
enabled.
@echasnovski
Copy link
Owner

Hi! Thanks for the PR!

This is an interesting idea. Seems like related to #125.

Would you mind sharing relevant config parts with which you achieved the second screenshot?

@mivort
Copy link
Author

mivort commented Nov 15, 2022

@echasnovski Sure, here's options I've used:

vim.o.listchars = 'lead:┆'
require('mini.indentscope').setup { prefix = '' }

@echasnovski
Copy link
Owner

Ok, I see now. I personally don't use it, so didn't know you should also set 'list' option.

The two main drawbacks I see with this approach:

  • It doesn't seem to work well with some other 'listchars' values (like tab and leadmultispace).
  • Doesn't really fix the case of using it with 'indent-blankline.nvim'.

Hmm... Maybe allow general string instead of single character would fix it? I'll think about pros and cons of this approach (might be a few days).

@mivort
Copy link
Author

mivort commented Nov 15, 2022

I think I found a way to handle nicely all possible listchars combinations (and indent-blankline.nvim). The idea is to support an '' value, in which case prefix won't be prepended, but rather virt_text_win_col increased to the proper amount. That way prefix will be 'transparent' and will not overwrite any listchars.

Here how it looks with prefix = '' and vim.o.listchars = 'leadmultispace:*-':

leading

I've updated PR and added a remark about empty string value case handling in the documentation. Tested on Neovim 0.8.

@echasnovski
Copy link
Owner

I am a little bit confused right now... Using virt_text_win_col option seems to solve the issue quite nicely even without the new prefix option. I thought maybe it was added in Neovim 0.8, but no, it is present in Neovim 0.6.1. And all tests seem to (virtually) pass...

I'll need to investigate this further. Maybe your PR will indirectly lead to removing some code instead of adding one, which is even better :)

@mivort
Copy link
Author

mivort commented Nov 16, 2022

Without at least some option it will make MiniIndentscopePrefix redundant and it wouldn't be possible to have something like this (e.g. provide a significantly more visually pronounced indent, which is nice):

require('mini.indentscope').setup { symbol = ' ', prefix = ' ' }
vim.cmd [[hi MiniIndentscopeSymbol ctermbg=203 | hi MiniIndentscopePrefix ctermbg=210]]

image

So I think keeping this option may provide a benefit :) (and also allows to keep the old behavior, since the default value is ' ').

@echasnovski
Copy link
Owner

echasnovski commented Nov 16, 2022

Without at least some option it will make MiniIndentscopePrefix redundant and it wouldn't be possible to have something like this (e.g. provide a significantly more visually pronounced indent, which is nice):

True. But the only reason for MiniIndentscopePrefix was to create "invisible" highlight group to mitigate the (what I thought was) necessary approach with prefix. At the moment I am leaning towards deprecating this highlight group, but I'll think it through.

@echasnovski
Copy link
Owner

In the end, I decided to make a breaking change of removing MiniIndentscopePrefix highlight group in favor of always showing single line.

Thanks for making PR and showing virt_text_win_col capabilities!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants