summary refs log tree commit diff
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2022-11-04 16:38:39 +0100
committerRobert Günzler <r@gnzler.io>2022-11-18 18:37:23 +0100
commitd3a25a00bec8492a4c4a194f1bb18ddc50c06234 (patch)
tree380f011113f36b425e9257bc315bc9fbfceff944
parent22c34cb82e591758f07e74e8be7103275669fe0c (diff)
vim: improve gotmpl detection
-rw-r--r--.vim/init.lua22
-rw-r--r--.vim/lua/plugins.lua2
2 files changed, 13 insertions, 11 deletions
diff --git a/.vim/init.lua b/.vim/init.lua
index c10a11c..2d1162a 100644
--- a/.vim/init.lua
+++ b/.vim/init.lua
@@ -312,19 +312,21 @@ require('internal.statusline')
 require('internal.exrc').setup {}
 
 -- TODO: remove eventually
+local is_gotmpl = function(bufnr)
+  for ln = 1, vim.api.nvim_buf_line_count(bufnr), 1 do
+    local line = vim.api.nvim_buf_get_lines(bufnr, ln-1, ln, true)
+    if #line == 0 then break end
+    if line[1]:match('{{.+}}') then
+      return true
+    end
+  end
+  return false
+end
 vim.filetype.add {
   extension = {
     ha = 'hare',
-    html = function(_, bufnr)
-      for ln = 1, vim.api.nvim_buf_line_count(bufnr), 1 do
-        local line = vim.api.nvim_buf_get_lines(bufnr, ln-1, ln, true)
-        if #line == 0 then break end
-        if line[1]:match('{{.+}}') then
-          return 'gotmpl'
-        end
-      end
-      return 'html'
-    end,
+    html = function(_, bufnr) return is_gotmpl(bufnr) and 'gotmpl.html' or 'html' end,
+    yaml = function(_, bufnr) return is_gotmpl(bufnr) and 'gotmpl.yaml' or 'yaml' end,
   },
   filename = {
     ['Caddyfile'] = 'conf',
diff --git a/.vim/lua/plugins.lua b/.vim/lua/plugins.lua
index ad6e80b..48f108e 100644
--- a/.vim/lua/plugins.lua
+++ b/.vim/lua/plugins.lua
@@ -283,7 +283,7 @@ require('packer').startup({function()
           files = {'src/parser.c'},
         },
         filetype = 'gotmpl',
-        used_by = {'gohtmltmpl', 'gotexttmpl', 'gotmpl', 'yaml'},
+        used_by = {'gotmpl.html', 'gotmpl.yaml', 'gotmpl'},
       }
 
       require('nvim-treesitter.configs').setup {