mirror of
				https://github.com/tiyn/tidy.nvim.git
				synced 2025-10-31 11:11:23 +01:00 
			
		
		
		
	chore, docs:
- update section that discusses what the
      script does
    - add a few comments and organize patterns
			
			
This commit is contained in:
		| @@ -1,9 +1,11 @@ | |||||||
| # tidy.nvim 🧹 | # tidy.nvim 🧹 | ||||||
|  |  | ||||||
| A function and autocommand pair that removes all | A function and autocommand pair that can | ||||||
|  |  | ||||||
|     - trailing whitespace |     - remove all empty lines at the top of the buffer | ||||||
|     - empty lines at the end of the buffer |     - remove all trailing whitespace | ||||||
|  |     - remove a variable amount of empty lines at the end of the buffer | ||||||
|  |     - condense multiple empty lines into one | ||||||
|  |  | ||||||
| on every `BufWritePre`. | on every `BufWritePre`. | ||||||
|  |  | ||||||
|   | |||||||
| @@ -11,7 +11,6 @@ local M = { | |||||||
| } | } | ||||||
|  |  | ||||||
| function M.setup(user_config) | function M.setup(user_config) | ||||||
|  |  | ||||||
|     -- integrate user configuration |     -- integrate user configuration | ||||||
|     M.config = vim.tbl_deep_extend("force", M.config, user_config or {}) |     M.config = vim.tbl_deep_extend("force", M.config, user_config or {}) | ||||||
|  |  | ||||||
| @@ -27,22 +26,23 @@ function M.tidy_up() | |||||||
|     local cmd_mods = ":keepjumps keeppatterns silent! " |     local cmd_mods = ":keepjumps keeppatterns silent! " | ||||||
|  |  | ||||||
|     local patterns = { |     local patterns = { | ||||||
|         -- delete all new lines at beginning of file |         -- delete all lines at end of buffer, see sources | ||||||
|  |  | ||||||
|         sof = [[%s/\%^\n*/]], |  | ||||||
|         -- delete all lines at end of buffer, see source 2 |  | ||||||
|  |  | ||||||
|         eof = [[0;/^\%(\n*.\)\@!/ + ]] .. M.config.eof_quant ..  ",$d", |         eof = [[0;/^\%(\n*.\)\@!/ + ]] .. M.config.eof_quant ..  ",$d", | ||||||
|         -- compress all instances of multiple newlines into one |  | ||||||
|  |  | ||||||
|  |         -- compress all instances of multiple newlines into one, see sources | ||||||
|         multi = [[:%s/\n\{2,}/\r\r/e]], |         multi = [[:%s/\n\{2,}/\r\r/e]], | ||||||
|         -- delete all whitespace, see source 1 |  | ||||||
|  |         -- delete all new lines at beginning of file | ||||||
|  |         sof = [[%s/\%^\n*/]], | ||||||
|  |  | ||||||
|  |         -- delete all whitespace, see sources | ||||||
|         ws = [[%s/\s\+$//e]] |         ws = [[%s/\s\+$//e]] | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     -- get tuple of cursor position before making changes |     -- get tuple of cursor position before making changes | ||||||
|     local pos = vim.api.nvim_win_get_cursor(0) |     local pos = vim.api.nvim_win_get_cursor(0) | ||||||
|  |  | ||||||
|  |     -- execute chosen patterns | ||||||
|     for _, fmt_type in ipairs(M.config.fmts) do |     for _, fmt_type in ipairs(M.config.fmts) do | ||||||
|         vim.cmd(cmd_mods .. patterns[fmt_type]) |         vim.cmd(cmd_mods .. patterns[fmt_type]) | ||||||
|     end |     end | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user