Thomas пре 10 месеци
родитељ
комит
2f092c25e0
1 измењених фајлова са 40 додато и 3 уклоњено
  1. 40 3
      lua/config/mappings.lua

+ 40 - 3
lua/config/mappings.lua

@@ -2,14 +2,51 @@ local wk = require("which-key")
 local telescope = require("telescope.builtin")
 local gitsigns = require("gitsigns")
 
+function FormatBufferLines()
+	local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
+	local formatted_lines = {}
+
+	for _, line in ipairs(lines) do
+		if #line <= 80 then
+			table.insert(formatted_lines, line)
+		else
+			local words = {}
+			for word in line:gmatch("%S+") do
+				table.insert(words, word)
+			end
+
+			local current_line = ""
+			for _, word in ipairs(words) do
+				if #current_line + #word + 1 > 80 then
+					table.insert(formatted_lines, current_line)
+					current_line = word
+				else
+					if current_line ~= "" then
+						current_line = current_line .. " " .. word
+					else
+						current_line = word
+					end
+				end
+			end
+			if current_line ~= "" then
+				table.insert(formatted_lines, current_line)
+			end
+		end
+	end
+
+	vim.api.nvim_buf_set_lines(0, 0, -1, false, formatted_lines)
+	print("Buffer formatted: lines wrapped at 80 characters")
+end
+
 -- local tree = require "nvim-tree.api"
 
 function FormatBuffer()
 	-- Save the current cursor position
 	local cursor_position = vim.fn.getpos(".")
-	local command = "fmt"
+	FormatBufferLines();
+	-- local command = "fmt"
 	-- -- Run the formatter command on the current buffer
-	vim.cmd(":%! " .. command)
+	-- vim.cmd(":%! " .. command)
 	-- Restore the cursor position
 	vim.fn.setpos(".", cursor_position)
 
@@ -113,7 +150,7 @@ wk.add({
 		{
 			"<leader>fm",
 			function()
-				require("conform").format({ lsp_fallback = true })
+				require("conform").format()
 			end,
 			desc = "format files",
 		},