diff options
author | Thomas Voss <mail@thomasvoss.com> | 2023-11-14 18:10:22 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2023-11-14 18:10:22 +0100 |
commit | ea77956c0224d9f9997d60e91642a4e255750f5b (patch) | |
tree | 7d47222427808b35f9fe07fb5e3249d08fadf109 /src/blog/nvim-ts/final.lua.gsp | |
parent | d31314638a4499ce36def937b61d2069f496eaaa (diff) |
Add a new blog post
Diffstat (limited to 'src/blog/nvim-ts/final.lua.gsp')
-rw-r--r-- | src/blog/nvim-ts/final.lua.gsp | 28 |
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'}) |