Support for filetype-specific styling options #253
-
Describe the solution you'd likeCurrently i'm able to set global styling options for bold and italic text. I dont' like them in a code so i turned them off, but i would like to be able to enable them for specific filetypes where it makes more sense like norg or markdown. Additional contextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments
-
I'm not sold on adding this functionality into our theme itself due to the potential cost of autocmds and such but I tried this locally and think you could pull it off: vim.api.nvim_create_autocmd({ "BufEnter" }, {
callback = function()
local italic = false
if vim.bo.filetype == "markdown" then
italic = true
end
require("rose-pine").setup({
styles = { italic = italic },
})
end,
}) You may want to do your own research on autocmds and such as I believe you will want to assign a group to the autocmd to prevent duplication. Hopping between my init.lua and a readme.md successfully toggles italic on and off, however. Hope this helps. |
Beta Was this translation helpful? Give feedback.
-
The solution works well for regular filetypes like Markdown, but the problem is that Norg is a custom filetype provided by the Neorg plugin. Using autocmds doesn't seem to work for Norg buffers. Considering the popularity of the Neorg plugin, maybe there is a reason to add specific support for it, especially since the customization problem with other filetypes is basically resolved at this point, which could potentially lessen the overhead of approaching the problem. But at the same maybe it's something that should be solved from the side of Neorg. P.S I had to slightly modify your code by adding 'vim.cmd('colorscheme rose-pine')':
|
Beta Was this translation helpful? Give feedback.
-
After reading more about Neorg it looks like it should set the filetype but others are having issues (see nvim-neorg/neorg#937). This comment has a fix that may help. |
Beta Was this translation helpful? Give feedback.
-
Nah, i think it's not the same thing, because in case of norg, it's not just about bold and italic rendering, the whole rendering of Neorg breaks because of the autocmd. So i'm willing to think it's not that easy to fix because Neorg's rendering is more complex. |
Beta Was this translation helpful? Give feedback.
-
I've tried to set norg type manually, it doesn't help. |
Beta Was this translation helpful? Give feedback.
-
Are you able to provide some highlight groups from a Neorg file? For example, if you would want Personally, I disable italic via Edit: This probably won't be useful for embedded language highlighting if they provide that but could at least highlight intentionally italic or bold text. |
Beta Was this translation helpful? Give feedback.
-
Running ':Inspect' on italic character gives this: Treesitter
|
Beta Was this translation helpful? Give feedback.
-
In that case, you should be able do: require('rose-pine').setup({
highlight_groups = {
['@neorg.markup.italic.norg'] = { italic = true }
}
}) |
Beta Was this translation helpful? Give feedback.
-
Yep, it looks like it actually works, big thanks! |
Beta Was this translation helpful? Give feedback.
In that case, you should be able do: