Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Support for filetype-specific styling options #251

Closed
Doodler8888 opened this issue Mar 15, 2024 · 9 comments
Closed

Support for filetype-specific styling options #251

Doodler8888 opened this issue Mar 15, 2024 · 9 comments

Comments

@Doodler8888
Copy link

Describe the solution you'd like

Currently 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 context

No response

@mvllow
Copy link
Member

mvllow commented Mar 15, 2024

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.

@Doodler8888
Copy link
Author

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')':

vim.api.nvim_create_autocmd("BufEnter", {
  callback = function()
    local bold = false
    local italic = false
    local filetypes = {"norg", "markdown"}
    if vim.tbl_contains(filetypes, vim.bo.filetype) then
      bold = true
      italic = true
    end
    require("rose-pine").setup({
      styles = { bold = bold, italic = italic },
    })
    vim.cmd('colorscheme rose-pine')
  end,
})

@mvllow
Copy link
Member

mvllow commented Mar 16, 2024

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.

@Doodler8888
Copy link
Author

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.

@Doodler8888
Copy link
Author

I've tried to set norg type manually, it doesn't help.

@mvllow
Copy link
Member

mvllow commented Mar 16, 2024

Are you able to provide some highlight groups from a Neorg file? For example, if you would want _some text_ to be italic could you do :Inspect over _some text_?

Personally, I disable italic via styles.italic = false but re-enable it for comments via highlight_groups = { Comment = { italic = true } } so if they have their own highlight groups you could override them as such.

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.

@Doodler8888
Copy link
Author

Running ':Inspect' on italic character gives this:

Treesitter

  • @spell.norg links to @spell norg
  • @neorg.markup.italic.norg links to @markup.italic norg
  • @neorg.markup.italic.norg links to @markup.italic norg

@mvllow
Copy link
Member

mvllow commented Mar 17, 2024

In that case, you should be able do:

require('rose-pine').setup({
  highlight_groups = {
    ['@neorg.markup.italic.norg'] = { italic = true }
  }
})

@Doodler8888
Copy link
Author

Yep, it looks like it actually works, big thanks!

@rose-pine rose-pine locked and limited conversation to collaborators Mar 17, 2024
@mvllow mvllow converted this issue into discussion #253 Mar 17, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

2 participants