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

"Failed to run config for headlines.nvim", and unable to see any highlight using default config #57

Open
hopezh opened this issue Jun 29, 2023 · 3 comments

Comments

@hopezh
Copy link

hopezh commented Jun 29, 2023

I got the following error after installing headlines.nvim:

Failed to run `config` for headlines.nvim

...9cf3b/share/nvim/runtime/lua/vim/treesitter/language.lua:99: no parser for 'norg' language, see :help treesitter-parsers

# stacktrace:
  - /opt/homebrew/Cellar/neovim/HEAD-e59cf3b/share/nvim/runtime/lua/vim/treesitter/language.lua:99 _in_ **add**
  - /opt/homebrew/Cellar/neovim/HEAD-e59cf3b/share/nvim/runtime/lua/vim/treesitter/query.lua:252 _in_ **parse**
  - lua/plugins/headlines.lua:84 _in_ **config**
  - lua/config/lazy.lua:17
  - init.lua:2

I'm unable to get any highlight for a simple test.md file:

Screenshot 2023-06-30 at 12 26 52 AM

I'm using lazy.nvim to install headlines.nvim. My config file headlines.lua is the default one, and it's put in the lua/plugins folder of a lazynvim installation:

return {
    "lukas-reineke/headlines.nvim",

    dependencies = {
        "nvim-treesitter/nvim-treesitter",
    },

    -- config = true,

    config = function()
        vim.cmd([[highlight Headline1 guibg=#1e2718]])
        vim.cmd([[highlight Headline2 guibg=#21262d]])
        vim.cmd([[highlight CodeBlock guibg=#1c1c1c]])
        vim.cmd([[highlight Dash guibg=#D19A66 gui=bold]])

        require("headlines").setup({
            markdown = {
                query = vim.treesitter.query.parse(
                    "markdown",
                    [[
                        (atx_heading [
                            (atx_h1_marker)
                            (atx_h2_marker)
                            (atx_h3_marker)
                            (atx_h4_marker)
                            (atx_h5_marker)
                            (atx_h6_marker)
                        ] @headline)

                        (thematic_break) @dash

                        (fenced_code_block) @codeblock

                        (block_quote_marker) @quote
                        (block_quote (paragraph (inline (block_continuation) @quote)))
                    ]]
                ),
                headline_highlights = { "Headline1", "Headline2" },
                codeblock_highlight = "CodeBlock",
                dash_highlight = "Dash",
                dash_string = "-",
                quote_highlight = "Quote",
                quote_string = "┃",
                fat_headlines = true,
                fat_headline_upper_string = "▃",
                fat_headline_lower_string = "🬂",
            },

            rmd = {
                query = vim.treesitter.query.parse(
                    "markdown",
                    [[
                        (atx_heading [
                            (atx_h1_marker)
                            (atx_h2_marker)
                            (atx_h3_marker)
                            (atx_h4_marker)
                            (atx_h5_marker)
                            (atx_h6_marker)
                        ] @headline)

                        (thematic_break) @dash

                        (fenced_code_block) @codeblock

                        (block_quote_marker) @quote
                        (block_quote (paragraph (inline (block_continuation) @quote)))
                    ]]
                ),
                treesitter_language = "markdown",
                headline_highlights = { "Headline" },
                codeblock_highlight = "CodeBlock",
                dash_highlight = "Dash",
                dash_string = "-",
                quote_highlight = "Quote",
                quote_string = "┃",
                fat_headlines = true,
                fat_headline_upper_string = "▃",
                fat_headline_lower_string = "🬂",
            },

            norg = {
                query = vim.treesitter.query.parse(
                    "norg",
                    [[
                        [
                            (heading1_prefix)
                            (heading2_prefix)
                            (heading3_prefix)
                            (heading4_prefix)
                            (heading5_prefix)
                            (heading6_prefix)
                        ] @headline

                        (weak_paragraph_delimiter) @dash
                        (strong_paragraph_delimiter) @doubledash

                        ((ranged_tag
                            name: (tag_name) @_name
                            (#eq? @_name "code")
                        ) @codeblock (#offset! @codeblock 0 0 1 0))

                        (quote1_prefix) @quote
                    ]]
                ),
                headline_highlights = { "Headline" },
                codeblock_highlight = "CodeBlock",
                dash_highlight = "Dash",
                dash_string = "-",
                doubledash_highlight = "DoubleDash",
                doubledash_string = "=",
                quote_highlight = "Quote",
                quote_string = "┃",
                fat_headlines = true,
                fat_headline_upper_string = "▃",
                fat_headline_lower_string = "🬂",
            },

            org = {
                query = vim.treesitter.query.parse(
                    "org",
                    [[
                        (headline (stars) @headline)

                        (
                            (expr) @dash
                            (#match? @dash "^-----+$")
                        )

                        (block
                            name: (expr) @_name
                            (#eq? @_name "SRC")
                        ) @codeblock

                        (paragraph . (expr) @quote
                            (#eq? @quote ">")
                        )
                    ]]
                ),
                headline_highlights = { "Headline" },
                codeblock_highlight = "CodeBlock",
                dash_highlight = "Dash",
                dash_string = "-",
                quote_highlight = "Quote",
                quote_string = "┃",
                fat_headlines = true,
                fat_headline_upper_string = "▃",
                fat_headline_lower_string = "🬂",
            },
        })
    end,
}
@chrisgrieser
Copy link

no parser for 'norg' language, see :help treesitter-parsers

do you have treesitter and the norg parser installed?

@hopezh
Copy link
Author

hopezh commented Jun 30, 2023

Yes, I solved the norg related issue by installing norg in treesitter. I also have markdown installed in treesitter, as shown below by running :TSModuleInfor in neovim:
image

However, I still can't get the highlight to work, as shown in the config file below, even after I changed the guibg color for all three headers and code block to red (#ff0000). It seems. only Headline3 is affected.
image

Did I specify the colors for headers and code block correctly in the config file?

My modifed lazyvim config with headlines.nvim installed is shown here.

headlines.lua in the lua/plugins folder:

 return {
    "lukas-reineke/headlines.nvim",
    ft = "markdown",
    event = "VeryLazy",
    lazy = false,
    dependencies = {
        "nvim-treesitter/nvim-treesitter",
    },

    config = function()
        require("headlines").setup({
            markdown = {
                query = vim.treesitter.query.parse(
                    "markdown",
                    [[
                        (atx_heading [
                            (atx_h1_marker)
                            (atx_h2_marker)
                            (atx_h3_marker)
                            (atx_h4_marker)
                            (atx_h5_marker)
                            (atx_h6_marker)
                        ] @headline)

                        (thematic_break) @dash

                        (fenced_code_block) @codeblock

                        (block_quote_marker) @quote
                        (block_quote (paragraph (inline (block_continuation) @quote)))
                    ]]
                ),

                headline_highlights = {
                    "Headline1",
                    "Headline2",
                    "Headline3",
                },

                codeblock_highlight = "CodeBlock",
                dash_highlight = "Dash",
                dash_string = "-",
                quote_highlight = "Quote",
                quote_string = "┃",
                fat_headlines = true,
                -- fat_headline_upper_string = "▃",
                -- fat_headline_lower_string = "🬂",
                fat_headline_upper_string = "-",
                fat_headline_lower_string = "",
            },
        })

        vim.cmd([[highlight Headline1 guibg=#ff0000]])
        vim.cmd([[highlight Headline2 guibg=#ff0000]])
        vim.cmd([[highlight Headline3 guibg=#ff0000]])
        vim.cmd([[highlight CodeBlock guibg=#ff0000]])
        vim.cmd([[highlight Dash guibg=#ff0000 gui=bold]])
    end,
}

@hopezh
Copy link
Author

hopezh commented Jun 30, 2023

Ok, allow me to reply to myself.

I think I managed to make headlines.nvim work, and for both .md and .qmd files, as shown in this post .

For normal markdown .md file:
image

For quarto .qmd file:
image

My updated /lua/plugins/headlines.lua config is shown here.

Note that the colors for headlines and code block are defined in the /lua/config/options.lua file, rather than inside the headlines.nvim file.

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

No branches or pull requests

2 participants