summaryrefslogtreecommitdiffstats
path: root/lua/conf/plugins/treesitter-context.lua
blob: 3306e6b380deac2abd753192b15ad52582b60fc3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
local misc = require("core.misc")
local map = misc.map

local branch = nil
if vim.version().minor == 7 then
  branch = 'compat/0.7'
end

return { 'nvim-treesitter/nvim-treesitter-context',
  disable = vim.version().minor < 7,
  branch = branch,
  requires = 'nvim-treesitter/nvim-treesitter',
  function()
    local treesitter_context = require("treesitter-context")

    treesitter_context.setup {
      enable = true,
      line_numbers = true,
      separator = '─',
    }

    -- mapping to jump to the first closest line of context in buffer
    map("n", "[j", function()
      local lline = vim.api.nvim_win_get_cursor(0)[1];
      local line

      -- go to the first closest line of context and center it
      treesitter_context.go_to_context()
      vim.api.nvim_input('zz')

      -- make sure we actually moved
      line = vim.api.nvim_win_get_cursor(0)[1];
      if line == lline then
        return
      end

      misc.timeout_highlight()
    end)
  end
}