local present, _ = pcall(require, "impatient")
require "option"
require "mapping"

local install_path = vim.fn.stdpath "data" .. "/site/pack/packer/opt/packer.nvim"
if not present or vim.fn.empty(vim.fn.glob(install_path)) > 0 then
	vim.fn.system { "git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", install_path }
	vim.api.nvim_set_hl(0, "NormalFloat", { bg = "#131313" })
	vim.api.nvim_create_user_command("TSUpdate", "", {})
	vim.api.nvim_command "packadd packer.nvim"
	require "plugins"
	require("packer").sync()
end

vim.cmd [[
function! SynStack()
  if !exists("*synstack")
    return
  endif
  echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
endfunc
]]
-- Usage -> :lua=extAtCursor()
function extAtCursor()
	local namespaces = vim.api.nvim_get_namespaces()
	local i = vim.fn.line('.')
	local j = vim.fn.col('.')
	local hl_groups = {}
	for _, ns_id in pairs(namespaces) do
		local extmarks = vim.api.nvim_buf_get_extmarks(0, ns_id, 
			{ i - 1, j - 1 }, { i, j }, { details = 1 })
		for _, extmark in pairs(extmarks) do
			hl_groups[#hl_groups + 1] = extmark[4].hl_group
		end
	end
	return hl_groups
end