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/index.gsp | 1 + src/blog/nvim-ts/change-command.diff.gsp | 9 ++ src/blog/nvim-ts/final.lua.gsp | 28 ++++ src/blog/nvim-ts/final.webm | Bin 0 -> 207067 bytes src/blog/nvim-ts/get-cursor.diff.gsp | 12 ++ src/blog/nvim-ts/get-parent.diff.gsp | 14 ++ src/blog/nvim-ts/git-log-2.gsp | 11 ++ src/blog/nvim-ts/git-log.gsp | 17 +++ src/blog/nvim-ts/git-rebase-2.gsp | 3 + src/blog/nvim-ts/git-rebase.gsp | 34 +++++ src/blog/nvim-ts/index.gsp | 226 +++++++++++++++++++++++++++++++ src/blog/nvim-ts/skeleton.lua.gsp | 14 ++ src/blog/nvim-ts/ts-tree.scm.gsp | 12 ++ src/fonts/vollkorn-italic.woff2 | Bin 13484 -> 13552 bytes src/fonts/vollkorn-regular.woff2 | Bin 12904 -> 13024 bytes src/style.css | 56 ++++---- 16 files changed, 411 insertions(+), 26 deletions(-) create mode 100644 src/blog/nvim-ts/change-command.diff.gsp create mode 100644 src/blog/nvim-ts/final.lua.gsp create mode 100644 src/blog/nvim-ts/final.webm create mode 100644 src/blog/nvim-ts/get-cursor.diff.gsp create mode 100644 src/blog/nvim-ts/get-parent.diff.gsp create mode 100644 src/blog/nvim-ts/git-log-2.gsp create mode 100644 src/blog/nvim-ts/git-log.gsp create mode 100644 src/blog/nvim-ts/git-rebase-2.gsp create mode 100644 src/blog/nvim-ts/git-rebase.gsp create mode 100644 src/blog/nvim-ts/index.gsp create mode 100644 src/blog/nvim-ts/skeleton.lua.gsp create mode 100644 src/blog/nvim-ts/ts-tree.scm.gsp diff --git a/src/blog/index.gsp b/src/blog/index.gsp index 68b53f8..030ad3e 100644 --- a/src/blog/index.gsp +++ b/src/blog/index.gsp @@ -28,6 +28,7 @@ html lang="en" { p {-Posts:} ul { + m4_article(nvim-ts, {-Hacking with Tree-Sitter on Neovim}) m4_article(gsp, {-Writing an HTML Preprocessor (feat. Tree-Sitter)}) m4_article(fw-ec, {-Patching My Laptop’s Embedded Controller}) } diff --git a/src/blog/nvim-ts/change-command.diff.gsp b/src/blog/nvim-ts/change-command.diff.gsp new file mode 100644 index 0000000..8f1aeeb --- /dev/null +++ b/src/blog/nvim-ts/change-command.diff.gsp @@ -0,0 +1,9 @@ + end + + if node ~= nil then +@span .diff-del {-- -- TODO} +@span .diff-ins {-+ local sr, sc, er, ec = node:child(0):range()} +@span .diff-ins {-+ vim.api.nvim_buf_set_text(0, sr, sc, er, ec, { rhs \})} + end + end, { + buffer = true, 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'}) diff --git a/src/blog/nvim-ts/final.webm b/src/blog/nvim-ts/final.webm new file mode 100644 index 0000000..cbe2c55 Binary files /dev/null and b/src/blog/nvim-ts/final.webm differ diff --git a/src/blog/nvim-ts/get-cursor.diff.gsp b/src/blog/nvim-ts/get-cursor.diff.gsp new file mode 100644 index 0000000..6e8f759 --- /dev/null +++ b/src/blog/nvim-ts/get-cursor.diff.gsp @@ -0,0 +1,12 @@ +@span .diff-ins {-+local ts_utils = require('nvim-treesitter.ts_utils')} +@span .diff-ins {-+} + local function map(lhs, rhs) + vim.keymap.set('n', lhs, function() +@span .diff-del {-- -- TODO} +@span .diff-ins {-+ local node = ts_utils.get_node_at_cursor()} +@span .diff-ins {-+ if node == nil then} +@span .diff-ins {-+ error('No Tree-Sitter parser found.')} +@span .diff-ins {-+ end} + end, { + buffer = true, + noremap = true, diff --git a/src/blog/nvim-ts/get-parent.diff.gsp b/src/blog/nvim-ts/get-parent.diff.gsp new file mode 100644 index 0000000..eebfeb5 --- /dev/null +++ b/src/blog/nvim-ts/get-parent.diff.gsp @@ -0,0 +1,14 @@ + if node == nil then + error('No Tree-Sitter parser found.') + end +@span .diff-ins {-+} +@span .diff-ins {-+ while node ~= nil and node:type() ~= 'operation' do} +@span .diff-ins {-+ node = node:parent()} +@span .diff-ins {-+ end} +@span .diff-ins {-+} +@span .diff-ins {-+ if node ~= nil then} +@span .diff-ins {-+ -- TODO} +@span .diff-ins {-+ end} + end, { + buffer = true, + noremap = true, diff --git a/src/blog/nvim-ts/git-log-2.gsp b/src/blog/nvim-ts/git-log-2.gsp new file mode 100644 index 0000000..fbab82e --- /dev/null +++ b/src/blog/nvim-ts/git-log-2.gsp @@ -0,0 +1,11 @@ +@span .fn {-commit 74ba5ba2b8bdb7708a25283f03542811706072bd} +Author: Thomas Voss +Date: Tue Nov 14 10:12:05 2023 +0100 + + Add new blog post + +@span .fn {-commit a893a1752b1365ec6437095506e6e63979b9236d} +Author: Thomas Voss +Date: Tue Nov 14 10:10:53 2023 +0100 + + Fix various typos diff --git a/src/blog/nvim-ts/git-log.gsp b/src/blog/nvim-ts/git-log.gsp new file mode 100644 index 0000000..2a7ae4d --- /dev/null +++ b/src/blog/nvim-ts/git-log.gsp @@ -0,0 +1,17 @@ +@span .fn {-commit 1893588f4f57024098a538d471caeecd01fbe88d} +Author: Thomas Voss +Date: Tue Nov 14 10:36:33 2023 +0100 + + Fix another typo + +@span .fn {-commit b592402d702379d14415c1becf18f6f40c2d6d76} +Author: Thomas Voss +Date: Tue Nov 14 10:12:05 2023 +0100 + + Add new blog post + +@span .fn {-commit 6ae48a4d7a84fd4c76a08a110514754dd6949d46} +Author: Thomas Voss +Date: Tue Nov 14 10:10:53 2023 +0100 + + Fix various typos diff --git a/src/blog/nvim-ts/git-rebase-2.gsp b/src/blog/nvim-ts/git-rebase-2.gsp new file mode 100644 index 0000000..6987bab --- /dev/null +++ b/src/blog/nvim-ts/git-rebase-2.gsp @@ -0,0 +1,3 @@ +@span .fn {-pick} @span .var {-d620266} Fix various typos +@span .fn {-fixup} @span .var {-4c45214} Fix another typo +@span .fn {-pick} @span .var {-59fa2b6} Add new blog post diff --git a/src/blog/nvim-ts/git-rebase.gsp b/src/blog/nvim-ts/git-rebase.gsp new file mode 100644 index 0000000..d41262a --- /dev/null +++ b/src/blog/nvim-ts/git-rebase.gsp @@ -0,0 +1,34 @@ +@span .fn {-pick} @span .var {-d620266} Fix various typos +@span .fn {-pick} @span .var {-59fa2b6} Add new blog post +@span .fn {-pick} @span .var {-4c45214} Fix another typo + +@span .cmt {-# Rebase 10c3013..4c45214 onto 10c3013 (3 commands)} +@span .cmt {-#} +@span .cmt {-# Commands:} +@span .cmt {-# p, pick = use commit} +@span .cmt {-# r, reword = use commit, but edit the commit message} +@span .cmt {-# e, edit = use commit, but stop for amending} +@span .cmt {-# s, squash = use commit, but meld into previous commit} +@span .cmt {-# f, fixup [-C | -c] = like "squash" but keep only the previous} +@span .cmt {-# commit's log message, unless -C is used, in which case} +@span .cmt {-# keep only this commit's message; -c is same as -C but} +@span .cmt {-# opens the editor} +@span .cmt {-# x, exec = run command (the rest of the line) using shell} +@span .cmt {-# b, break = stop here (continue rebase later with 'git rebase --continue')} +@span .cmt {-# d, drop = remove commit} +@span .cmt {-# l, label