From 1b230b404518e3e30e6b86a6bda1dc20816ec85e Mon Sep 17 00:00:00 2001 From: McAuley Penney Date: Sat, 8 Jan 2022 10:51:32 -0700 Subject: [PATCH] chore: - update readme - mention cfg branch - include todo section - fix capitalization typos - remove initials from source --- README.md | 9 +++++++-- lua/tidy/init.lua | 13 +++++-------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index c6a641b..7160b36 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,10 @@ on every `BufWritePre`. ![tidy](https://user-images.githubusercontent.com/59481467/142785684-96559135-88e7-4c50-a848-56f2c65262ef.gif) +**Note**: See the `cfg` branch for increased functionality and configuration. -## install + +## Installation - Packer ```lua @@ -24,8 +26,11 @@ or with lazy-loading use{ "McAuleyPenney/tidy.nvim", event = "BufWritePre" } ``` +## Todo +- [ ] preserve undotree + -## Credits: +## Credits - [Vim Tips Wiki entry for removing unwanted spaces](https://vim.fandom.com/wiki/Remove_unwanted_spaces#Automatically_removing_all_trailing_whitespace) - ib., the author of [this stack overflow answer](https://stackoverflow.com/a/7501902) diff --git a/lua/tidy/init.lua b/lua/tidy/init.lua index ab7e04f..f3b728a 100644 --- a/lua/tidy/init.lua +++ b/lua/tidy/init.lua @@ -1,20 +1,17 @@ --- MP - local M = {} function M.tidy_up() - -- 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) -- delete all whitespace, see source 1 - vim.cmd[[:keepjumps keeppatterns %s/\s\+$//e]] + vim.cmd([[:keepjumps keeppatterns %s/\s\+$//e]]) -- delete all lines at end of buffer, see source 2 - vim.cmd[[:keepjumps keeppatterns silent! 0;/^\%(\n*.\)\@!/,$d]] + vim.cmd([[:keepjumps keeppatterns silent! 0;/^\%(\n*.\)\@!/,$d]]) -- get row count after line deletion - local end_row = vim.api.nvim_buf_line_count( 0 ) + local end_row = vim.api.nvim_buf_line_count(0) --[[ if the row value in the original cursor @@ -29,7 +26,7 @@ function M.tidy_up() pos[1] = end_row end - vim.api.nvim_win_set_cursor( 0, pos ) + vim.api.nvim_win_set_cursor(0, pos) end return M