commiting current state
This commit is contained in:
		
							parent
							
								
									12e53eecd6
								
							
						
					
					
						commit
						0834c03385
					
				@ -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,23 +24,21 @@ 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
 | 
					        vim.api.nvim_win_set_cursor(0, {current_line_nr, 1})
 | 
				
			||||||
        if vim.fn.getline(current_line_nr) == '' then
 | 
					        local node = ts_utils.get_node_at_cursor(0)
 | 
				
			||||||
            current_line_nr = current_line_nr + 1
 | 
					        local parent = node:parent()
 | 
				
			||||||
        else
 | 
					        while (parent ~= nil and node:type() ~= 'block_mapping_pair') do
 | 
				
			||||||
            vim.api.nvim_win_set_cursor(0, {current_line_nr, 1})
 | 
					            node = parent
 | 
				
			||||||
            local node = ts_utils.get_node_at_cursor(0)
 | 
					            parent = node:parent()
 | 
				
			||||||
            local parent = node:parent()
 | 
					 | 
				
			||||||
            while (parent ~= nil and node:type() ~= 'block_mapping_pair') do
 | 
					 | 
				
			||||||
                node = parent
 | 
					 | 
				
			||||||
                parent = node:parent()
 | 
					 | 
				
			||||||
            end
 | 
					 | 
				
			||||||
            local start_row, start_column, end_row, end_column = node:range()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            lines[current_line_nr] = vim.fn.getline(start_row + 1, end_row + 1)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            current_line_nr = current_line_nr + 1 + (end_row - start_row)
 | 
					 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
 | 
					        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)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        current_line_nr = current_line_nr + 1 + (end_row - start_row)
 | 
				
			||||||
    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`
 | 
				
			||||||
@ -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]
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user