From ea77956c0224d9f9997d60e91642a4e255750f5b Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Tue, 14 Nov 2023 18:10:22 +0100 Subject: Add a new blog post --- src/blog/nvim-ts/final.lua.gsp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/blog/nvim-ts/final.lua.gsp (limited to 'src/blog/nvim-ts/final.lua.gsp') diff --git a/src/blog/nvim-ts/final.lua.gsp b/src/blog/nvim-ts/final.lua.gsp new file mode 100644 index 0000000..08ef220 --- /dev/null +++ b/src/blog/nvim-ts/final.lua.gsp @@ -0,0 +1,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'}) -- cgit v1.2.3