-
Notifications
You must be signed in to change notification settings - Fork 282
Fix trailspace issues #1
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,7 +63,7 @@ function MiniTrailspace.setup(config) | |
| ) | ||
|
|
||
| -- Create highlighting | ||
| vim.api.nvim_exec([[hi link MiniTrailspace Error]], false) | ||
| vim.api.nvim_exec([[hi default link MiniTrailspace Error]], false) | ||
| end | ||
|
|
||
| -- Module config | ||
|
|
@@ -86,21 +86,27 @@ function MiniTrailspace.highlight(check_modifiable) | |
| return | ||
| end | ||
|
|
||
| local win_id = vim.fn.win_getid() | ||
| local win_match = H.window_matches[win_id] | ||
| local win_id = vim.api.nvim_get_current_win() | ||
| if not vim.api.nvim_win_is_valid(win_id) then | ||
| return | ||
| end | ||
|
|
||
| -- Don't add match id on top of existing one | ||
| if win_match == nil then | ||
| if H.window_matches[win_id] == nil then | ||
| H.window_matches[win_id] = vim.fn.matchadd('MiniTrailspace', [[\s\+$]]) | ||
| end | ||
| end | ||
|
|
||
| --- Unhighlight trailing whitespace | ||
| function MiniTrailspace.unhighlight() | ||
| local win_id = vim.fn.win_getid() | ||
| local win_id = vim.api.nvim_get_current_win() | ||
| if not vim.api.nvim_win_is_valid(win_id) then | ||
| return | ||
| end | ||
|
|
||
| local win_match = H.window_matches[win_id] | ||
| if win_match ~= nil then | ||
| vim.fn.matchdelete(win_match) | ||
| pcall(vim.fn.matchdelete, win_match) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This also feels like a valid change. Although if there is a use case when error is given, would you mind sharing it? I would really like to see it. Maybe it is a sign of a bigger problem in design.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, it seems like it might be something a bit more "systemic", however I've never had any leftover matches after adding this (used my own fork for ~1 day now). The error isn't super useful either, it just notes that "no match with ID ... found", seemingly as it doesn't apply to the current Not 100% sure that answers your question, but I can see if I can find a way to reproduce it with a "minimal" configuration. Mine is has a shit-load of plugins, personal libraries, and its all lazy-loaded with Packer so sometimes the issues I see don't tend to show up with "simpler" configurations. Let me know what you'd like to do.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I've had that error when writing module and it really breaks everything. I don't have it anymore, even though I am using Telescope.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Found the culprit on this one; it is a plugin that I have that is just calling Either way at this point though, it doesn't seem like the end of the world to add a |
||
| H.window_matches[win_id] = nil | ||
| end | ||
| end | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels like a valid change. Currently I am having trouble constructing an example where it really matters (and reading help didn't help). I can override
MiniTrailspaceand it works. Could you help me understand (ideally with some reproducible steps) when this can matter?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I set
MiniTrailspacebefore the plugin is loaded (lazy loading, for instance), your declaration here will overwrite whatever I set up. With this in place, it will only be defined if it is not already defined.The key part from the
:h hi-defaultis this line:which means users can define this before
mini.trailspaceis loaded, and the command used here won't overwrite it if they've done so.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that sounds reasonable. I am still having trouble with example. I used this 'init.lua' with only these two plugins installed and it works as expected (trailing whitespace is green):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try linking to another highlight group rather than defining it outright, so:
Either way, I cannot imagine that it (this portion of the PR) will hurt to have.