From 9acc5686ce44780422e8cd09b5f0b2e34e07e960 Mon Sep 17 00:00:00 2001 From: McAuleyPenney <134115@gmail.com> Date: Tue, 26 Oct 2021 01:25:20 -0700 Subject: [PATCH] [docs,style]: - clean readme again - change function name from what I had it as in my configs to something more fitting for the repo --- lua/tidy/init.lua | 11 +++++------ plugin/tidy.vim | 2 +- readme.md | 12 ++++++++---- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lua/tidy/init.lua b/lua/tidy/init.lua index bf2d98f..6babc40 100644 --- a/lua/tidy/init.lua +++ b/lua/tidy/init.lua @@ -1,12 +1,12 @@ -- MP -- These sources did all the work -- 1. https://vim.fandom.com/wiki/Remove_unwanted_spaces#Automatically_removing_all_trailing_whitespace --- 2. https://stackoverflow.com/questions/7495932/how-can-i-trim-blank-lines-at-the-end-of-file-in-vim +-- 2. https://stackoverflow.com/a/7501902 local M = {} -function M.clear_spaces() +function M.tidy_up() -- get tuple of cursor position before making changes local pos = vim.api.nvim_win_get_cursor( 0 ) @@ -26,11 +26,10 @@ function M.clear_spaces() position tuple is greater than the line count after empty line deletion (meaning that the cursor was inside of - the empty lines at the end of the file - when they were deleted), set the cursor - row to the last line + the group of empty lines at the end of + the file when they were deleted), set + the cursor row to the last line ]] - if pos[1] > end_row then pos[1] = end_row end diff --git a/plugin/tidy.vim b/plugin/tidy.vim index 7f61b67..f1297e9 100644 --- a/plugin/tidy.vim +++ b/plugin/tidy.vim @@ -1,5 +1,5 @@ augroup Tidy au! - au BufWritePre * lua require( "tidy.init" ).clear_spaces() + au BufWritePre * lua require( "tidy.init" ).tidy_up() augroup END diff --git a/readme.md b/readme.md index fc17626..2603eaf 100644 --- a/readme.md +++ b/readme.md @@ -1,12 +1,16 @@ ## tidy.nvim 🧹 -A function and autocommand pair that removes all trailing whitespace \ -and all empty lines at the end of the buffer on every `BufWritePre`. +A function and autocommand pair that removes all + + - trailing whitespace + - empty lines at the end of the buffer + +on every `BufWritePre`. https://user-images.githubusercontent.com/59481467/138811091-05031eb1-96fc-4915-a349-e41d87c921ea.mp4 Credits: -1. https://vim.fandom.com/wiki/Remove_unwanted_spaces#Automatically_removing_all_trailing_whitespace -2. ib. from https://stackoverflow.com/questions/7495932/how-can-i-trim-blank-lines-at-the-end-of-file-in-vim +1. [Vim Tips Wiki entry for removing unwanted spaces](https://vim.fandom.com/wiki/Remove_unwanted_spaces#Automatically_removing_all_trailing_whitespace) +2. ib., the author of [this stack overflow answer](https://stackoverflow.com/a/7501902)