From 208ddaa76019af05d1e0f352912dab38ceedad6b Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Fri, 23 Feb 2024 15:19:26 +0100 Subject: Add nvim-ts article --- src/blog/index.gsp | 44 ++++++++ src/blog/nvim-ts/change-command.diff | 9 ++ src/blog/nvim-ts/final.lua | 28 +++++ src/blog/nvim-ts/final.webm | Bin 0 -> 207067 bytes src/blog/nvim-ts/get-cursor.diff | 12 ++ src/blog/nvim-ts/get-parent.diff | 14 +++ src/blog/nvim-ts/git-log | 17 +++ src/blog/nvim-ts/git-log-2 | 11 ++ src/blog/nvim-ts/git-rebase | 34 ++++++ src/blog/nvim-ts/git-rebase-2 | 3 + src/blog/nvim-ts/index.gsp | 205 +++++++++++++++++++++++++++++++++++ src/blog/nvim-ts/skeleton.lua | 14 +++ src/blog/nvim-ts/ts-tree.scm | 12 ++ 13 files changed, 403 insertions(+) create mode 100644 src/blog/index.gsp create mode 100644 src/blog/nvim-ts/change-command.diff create mode 100644 src/blog/nvim-ts/final.lua create mode 100644 src/blog/nvim-ts/final.webm create mode 100644 src/blog/nvim-ts/get-cursor.diff create mode 100644 src/blog/nvim-ts/get-parent.diff create mode 100644 src/blog/nvim-ts/git-log create mode 100644 src/blog/nvim-ts/git-log-2 create mode 100644 src/blog/nvim-ts/git-rebase create mode 100644 src/blog/nvim-ts/git-rebase-2 create mode 100644 src/blog/nvim-ts/index.gsp create mode 100644 src/blog/nvim-ts/skeleton.lua create mode 100644 src/blog/nvim-ts/ts-tree.scm (limited to 'src/blog') diff --git a/src/blog/index.gsp b/src/blog/index.gsp new file mode 100644 index 0000000..4d4aab8 --- /dev/null +++ b/src/blog/index.gsp @@ -0,0 +1,44 @@ +html lang="en" { + head { HEAD } + body { + header { + div .head { + h1 {-Blog Posts} + INCLUDE(nav.gsp) + } + + figure .quote { + blockquote { + p {= + Object-oriented programming is an exceptionally bad idea which could + only have originated in California. + } + } + figcaption {-Edsgar W. Dijkstra} + } + } + + main { + p {= + On this section of the site you will find my blog. Most of what I post + here is related to software-development and -design, although maybe + you’ll find something unrelated on here too. + } + + p {-Posts:} + + ul { + m4_dnl ARTICLE(grab, {-Making Grep Better}) + m4_dnl ARTICLE(andy-val, {-Values in Andy}) + m4_dnl ARTICLE(new-sh, {-Making a New Shell}) + m4_dnl ARTICLE(extend, {-Extensible Scripting}) + m4_dnl ARTICLE(gsp, {-Writing an HTML Preprocessor (feat. Tree-Sitter)}) + m4_dnl ARTICLE(fw-ec, {-Patching My Laptop’s Embedded Controller}) + + ARTICLE(nvim-ts, {-Hacking with Tree-Sitter on Neovim}) + } + } + + footer { FOOT } + } +} diff --git a/src/blog/nvim-ts/change-command.diff b/src/blog/nvim-ts/change-command.diff new file mode 100644 index 0000000..43bcdf9 --- /dev/null +++ b/src/blog/nvim-ts/change-command.diff @@ -0,0 +1,9 @@ + end + + if node ~= nil then +- -- TODO ++ local sr, sc, er, ec = node:child(0):range() ++ 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 b/src/blog/nvim-ts/final.lua new file mode 100644 index 0000000..948ee30 --- /dev/null +++ b/src/blog/nvim-ts/final.lua @@ -0,0 +1,28 @@ +local ts_utils = require('nvim-treesitter.ts_utils') + +local function map(lhs, rhs) + vim.keymap.set('n', lhs, function() + local node = ts_utils.get_node_at_cursor() + if node == nil then + error('No tree-sitter parser found.') + end + + while node ~= nil and node:type() ~= 'operation' do + node = node:parent() + end + + if node ~= nil then + local sr, sc, er, ec = node:child(0):range() + vim.api.nvim_buf_set_text(0, sr, sc, er, ec, { rhs }) + end + end, { + buffer = true, + noremap = true, + silent = true, + }) +end + +map('p', 'pick') +map('r', 'reword') +map('s', 'squash') +map('f', '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 b/src/blog/nvim-ts/get-cursor.diff new file mode 100644 index 0000000..3e34afc --- /dev/null +++ b/src/blog/nvim-ts/get-cursor.diff @@ -0,0 +1,12 @@ ++local ts_utils = require('nvim-treesitter.ts_utils') ++ + local function map(lhs, rhs) + vim.keymap.set('n', lhs, function() +- -- TODO ++ local node = ts_utils.get_node_at_cursor() ++ if node == nil then ++ error('No Tree-Sitter parser found.') ++ end + end, { + buffer = true, + noremap = true, diff --git a/src/blog/nvim-ts/get-parent.diff b/src/blog/nvim-ts/get-parent.diff new file mode 100644 index 0000000..9599792 --- /dev/null +++ b/src/blog/nvim-ts/get-parent.diff @@ -0,0 +1,14 @@ + if node == nil then + error('No Tree-Sitter parser found.') + end ++ ++ while node ~= nil and node:type() ~= 'operation' do ++ node = node:parent() ++ end ++ ++ if node ~= nil then ++ -- TODO ++ end + end, { + buffer = true, + noremap = true, diff --git a/src/blog/nvim-ts/git-log b/src/blog/nvim-ts/git-log new file mode 100644 index 0000000..d6f7870 --- /dev/null +++ b/src/blog/nvim-ts/git-log @@ -0,0 +1,17 @@ +commit 1893588f4f57024098a538d471caeecd01fbe88d +Author: Thomas Voss +Date: Tue Nov 14 10:36:33 2023 +0100 + + Fix another typo + +commit b592402d702379d14415c1becf18f6f40c2d6d76 +Author: Thomas Voss +Date: Tue Nov 14 10:12:05 2023 +0100 + + Add new blog post + +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-log-2 b/src/blog/nvim-ts/git-log-2 new file mode 100644 index 0000000..0f34811 --- /dev/null +++ b/src/blog/nvim-ts/git-log-2 @@ -0,0 +1,11 @@ +commit 74ba5ba2b8bdb7708a25283f03542811706072bd +Author: Thomas Voss +Date: Tue Nov 14 10:12:05 2023 +0100 + + Add new blog post + +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-rebase b/src/blog/nvim-ts/git-rebase new file mode 100644 index 0000000..f8c3a91 --- /dev/null +++ b/src/blog/nvim-ts/git-rebase @@ -0,0 +1,34 @@ +pick d620266 Fix various typos +pick 59fa2b6 Add new blog post +pick 4c45214 Fix another typo + +# Rebase 10c3013..4c45214 onto 10c3013 (3 commands) +# +# Commands: +# p, pick = use commit +# r, reword = use commit, but edit the commit message +# e, edit = use commit, but stop for amending +# s, squash = use commit, but meld into previous commit +# f, fixup [-C | -c] = like "squash" but keep only the previous +# commit's log message, unless -C is used, in which case +# keep only this commit's message; -c is same as -C but +# opens the editor +# x, exec = run command (the rest of the line) using shell +# b, break = stop here (continue rebase later with 'git rebase --continue') +# d, drop = remove commit +# l, label