commiting current state

This commit is contained in:
Navid Sassan 2024-05-31 22:03:25 +02:00
parent 12e53eecd6
commit 0834c03385

View File

@ -12,6 +12,10 @@ local M = {}
M.example = function() M.example = function()
local lines = {} local lines = {}
-- TOOD
-- correctly handle comments
-- removing all empty lines is back for raw blocks
-- remove all whitespace, we will create new blocks separated by empty lines after -- remove all whitespace, we will create new blocks separated by empty lines after
local last_search = vim.fn.getreg('/') local last_search = vim.fn.getreg('/')
vim.api.nvim_command('g/^$/d') vim.api.nvim_command('g/^$/d')
@ -20,10 +24,6 @@ M.example = function()
local buf_handle = vim.api.nvim_win_get_buf(0) local buf_handle = vim.api.nvim_win_get_buf(0)
local last_line_nr = vim.api.nvim_buf_line_count(buf_handle) local last_line_nr = vim.api.nvim_buf_line_count(buf_handle)
while (current_line_nr <= last_line_nr) do while (current_line_nr <= last_line_nr) do
-- skip empty lines
if vim.fn.getline(current_line_nr) == '' then
current_line_nr = current_line_nr + 1
else
vim.api.nvim_win_set_cursor(0, {current_line_nr, 1}) vim.api.nvim_win_set_cursor(0, {current_line_nr, 1})
local node = ts_utils.get_node_at_cursor(0) local node = ts_utils.get_node_at_cursor(0)
local parent = node:parent() local parent = node:parent()
@ -32,12 +32,14 @@ M.example = function()
parent = node:parent() parent = node:parent()
end end
local start_row, start_column, end_row, end_column = node:range() local start_row, start_column, end_row, end_column = node:range()
-- print('start_row=', start_row)
-- print('end_row=', end_row)
-- print('line:', vim.inspect(vim.fn.getline(start_row + 1, end_row + 1)))
lines[current_line_nr] = vim.fn.getline(start_row + 1, end_row + 1) lines[current_line_nr] = vim.fn.getline(start_row + 1, end_row + 1)
current_line_nr = current_line_nr + 1 + (end_row - start_row) current_line_nr = current_line_nr + 1 + (end_row - start_row)
end end
end
-- sort does not work if the index is not a continuous integer, so lets make sure it is. if we are sure that we dont need the original line number, we can do this from the start in `lines` -- sort does not work if the index is not a continuous integer, so lets make sure it is. if we are sure that we dont need the original line number, we can do this from the start in `lines`
a = {} a = {}
@ -48,6 +50,7 @@ M.example = function()
return k1[1] < k2[1] return k1[1] < k2[1]
end end
) )
-- print(vim.inspect(a))
insert_row = 1 insert_row = 1
last_prefix = vim.split(a[1][1], '__')[1] last_prefix = vim.split(a[1][1], '__')[1]