summaryrefslogtreecommitdiffhomepage
path: root/src/blog/nvim-ts/final.lua.gsp
blob: 08ef22048455c8ff76e5f1b9775128705f75004a (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
@span .kw {-local} ts_utils @span .op {-=} @span .fn {-require}(@span .str {-'nvim-treesitter.ts_utils'})

@span .kw {-local} @span .kw {-function} @span .fn {-map}(lhs, rhs)
	vim.keymap.@span .fn {-set}(@span .str {-'n'}, lhs, @span .kw {-function}()
		@span .kw {-local} node @span .op {-=} ts_utils.@span .fn {-get_node_at_cursor}()
		@span .kw {-if} node @span .op {-==} @span .cnst {-nil} @span .kw {-then}
			@span .fn {-error}(@span .str {-'No tree-sitter parser found.'})
		@span .kw {-end}

		@span .kw {-while} node @span .op {-~=} @span .cnst {-nil} @span .op {-and} node:@span .fn {-type}() @span .op {-~=} @span .str {-'operation'} @span .kw {-do}
			node @span .op {-=} node:@span .fn {-parent}()
		@span .kw {-end}

		@span .kw {-if} node @span .op {-~=} @span .cnst {-nil} @span .kw {-then}
			@span .kw {-local} sr, sc, er, ec @span .op {-=} node:@span .fn {-child}(0):@span .fn {-range}()
			vim.api.@span .fn {-nvim_buf_set_text}(@span .str {-0}, sr, sc, er, ec, { rhs \})
		@span .kw {-end}
	@span .kw {-end}, {
		buffer @span .op {-=} @span .cnst {-true},
		noremap @span .op {-=} @span .cnst {-true},
		silent @span .op {-=} @span .cnst {-true},
	\})
@span .kw {-end}

@span .fn {-map}(@span .str {-'p'}, @span .str {-'pick'})
@span .fn {-map}(@span .str {-'r'}, @span .str {-'reword'})
@span .fn {-map}(@span .str {-'s'}, @span .str {-'squash'})
@span .fn {-map}(@span .str {-'f'}, @span .str {-'fixup'})