summaryrefslogtreecommitdiffhomepage
path: root/src/blog/nvim-ts/final.lua.gsp
diff options
context:
space:
mode:
Diffstat (limited to 'src/blog/nvim-ts/final.lua.gsp')
-rw-r--r--src/blog/nvim-ts/final.lua.gsp28
1 files changed, 28 insertions, 0 deletions
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'})