From 86cde3f8d0d3502172902c4d89459bab553eef76 Mon Sep 17 00:00:00 2001 From: Ivar Fatland Date: Thu, 6 Jul 2023 20:05:36 +0200 Subject: [PATCH] Added documentation to split_line --- init.lua | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/init.lua b/init.lua index ed15097..7ea0a50 100644 --- a/init.lua +++ b/init.lua @@ -20,7 +20,7 @@ local keymap = { -- n leader_key = ';', - split_line = "s", --TODO Not complete yet. Too tired atm + split_line = "s", -- n move_to_panel_left = '', @@ -286,21 +286,14 @@ do ) end --- local function split_line() --- local line = vim.api.nvim_get_current_line() --- local items = vim.split(line, ", *") --- local indent = string.match(line, "^%s*") - --- local formatted_items = {items[1] .. ','} --- for i = 2, #items -1 do --- table.insert(formatted_items, indent .. tab_whitespace .. items[i] .. ',') --- end --- table.insert(formatted_items, indent .. tab_whitespace .. items[#items] ) - --- local row, _ = unpack(vim.api.nvim_win_get_cursor(0)) --- vim.api.nvim_buf_set_lines(0, row-1, row, false, formatted_items) --- end +---Splits the line under the cursor into multiple lines. +---Works on lines with properly opening and closing brackets: (),[],{} +---Starts at the cursor position and moves to the right until it finds an opening bracket. +---Then formats all comma separated items within that bracket scope, and splits the line into multiple. +---The function is aware for strings starting with ' or ", and keeps track of how deeply nested it is +---in the brackets. +---@type function local split_line do local TAB_WHITESPACE = ''