Skip to content

Automation for syntax=on not working #8

@akBeater

Description

@akBeater

Hello,
first of all, thank you for the plugin. It really helps me! :)

I had to make some changes to make it work for me.
I don't have any experience on customizing something like that, so I don't know if this is good code.

The Problem is, as you wrote, that you need syntax=on, but the following didn't worked for me:

if !get(b:, 'jinja_syntax_autocmd_loaded', v:false)
        if luaeval("vim.treesitter.language.get_lang('jinja')") == v:null
                autocmd FileType <buffer> if !empty(&ft) | setlocal syntax=on | endif
        endif
        let b:jinja_syntax_autocmd_loaded = v:true
endif

I handled it the following way in neovim:

  1. First of all, I set all "html" to "html.jinja", because I only write jinja code or html but never django:
vim.filetype.add {
  extension = {
    html = "html.jinja"
  }
}
  1. Secondly I wrote an autocommand to set syntax=on when I open the buffer and it has the filetype "html".
vim.api.nvim_create_autocmd("BufEnter", {
  desc = "set syntax=on on attached buffer",
  group = vim.api.nvim_create_augroup("JinjaSyntaxOn", {clear=true}),
  pattern = "*.html",
  callback = function ()
     vim.opt.syntax = "on"
  end,
})

You could enhance that, if you check for ft=html.jinja and only set it if this is true, but this is simple and works for me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions