-
Notifications
You must be signed in to change notification settings - Fork 18
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
Cell highlighting #9
Cell highlighting #9
Conversation
My current approach to this is to add a syntax rule on an autocmd. api.nvim_create_autocmd(
{ "BufEnter", "BufRead", "BufNewFile" },
{ pattern = "*.py", command = [[syn match HYDROGEN /^\s*# %%.*$/]] }
)
I'm not convinced about running a regex against all the file every time text gets inserted, and doing it only on save feels a bit hacky and unconventional on how it behaves. I wonder if one can limit the search to just the visible buffer or have an autocmd that informs of where changes have happened so that the search for the cell marker can be limited to a small portion of the buffer. Edit: No dice with conceal. It will only replace the text for one character. The documentation seems to be clear in that syntax highlighting will never overextend the match. |
Yeah, I completely agree with the computational overhead of the regex check at every text change. I have only been using I do like the full line highlight though, which is why I use the It may not be a big deal, but I was just worried about incorrect highlights after cell markers are deleted or added. A possibility I've considered before would be to keep track of lines of cell markers so that edited lines could be quickly searched. As a procedure:
The benefit here is checking the changes list (which vim already keeps) really narrows down the regex search. However, this would mean having a cell location list for each buffer, which could be a bit hairy to keep track of. Let me know your thoughts and maybe I can try this approach. |
There is also a possible Neovim API approach using |
Okay, I've updated the implementation to highlight the cells when the FileType is set and to only search for cell markers on the lines being edited but there remain a few cases that aren't handled:
I think both can be addressed, but I wanted to give you a view of the updated regex only on edited lines. |
Alternatively, given that you already have some integration for require('mini.hipatterns').setup({
highlighters = {
notebook_cells = {
pattern = function(buf_id)
local buf_ft = vim.bo[buf_id].filetype
if require"notebook-navigator".config.cell_markers[buf_ft] then
local regex_cell_marker = string.gsub("^"..cell_marker, "%%", "%%%%")
return regex_cell_marker
else
return nil
end
end,
group = require"notebook-navigator".config.cell_highlight_group
}
}
}) So there would basically be a The only downside that I've seen so far (for me) is that there isn't an option for highlighting the entire line. But |
Full line highlighting is now possible in |
Sounds good, I don't mind the extra dependency and it can always be made optional if someone really needs it by having a simply highlight rule as fallback. Also, how? I will check how that was implemented. Edit: How? By running on a timer and having a debounce period that will eat the TextChanged events that happen in close succession. |
Glad this made it in! Sorry for some of the extra cruft lying around after changing directions a couple of time (i.e. the unused Thanks again! |
Thanks to you! |
Addresses #8.
A few design notes for discussion:
nil
there won't be any highlighting (saves having two config options)CursorLineNr
because it usually gives vibrant visible text but a more subtle highlighting. Definitely could be another group though