[docs,style]:

- clean readme again
    - change function name from what I had it as in my configs to
      something more fitting for the repo
main
McAuleyPenney 3 years ago
parent 472ce3b347
commit 9acc5686ce

@ -1,12 +1,12 @@
-- MP -- MP
-- These sources did all the work -- These sources did all the work
-- 1. https://vim.fandom.com/wiki/Remove_unwanted_spaces#Automatically_removing_all_trailing_whitespace -- 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 = {} local M = {}
function M.clear_spaces() function M.tidy_up()
-- 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 )
@ -26,11 +26,10 @@ function M.clear_spaces()
position tuple is greater than the position tuple is greater than the
line count after empty line deletion line count after empty line deletion
(meaning that the cursor was inside of (meaning that the cursor was inside of
the empty lines at the end of the file the group of empty lines at the end of
when they were deleted), set the cursor the file when they were deleted), set
row to the last line the cursor row to the last line
]] ]]
if pos[1] > end_row then if pos[1] > end_row then
pos[1] = end_row pos[1] = end_row
end end

@ -1,5 +1,5 @@
augroup Tidy augroup Tidy
au! au!
au BufWritePre * lua require( "tidy.init" ).clear_spaces() au BufWritePre * lua require( "tidy.init" ).tidy_up()
augroup END augroup END

@ -1,12 +1,16 @@
## tidy.nvim 🧹 ## tidy.nvim 🧹
A function and autocommand pair that removes all trailing whitespace \ A function and autocommand pair that removes all
and all empty lines at the end of the buffer on every `BufWritePre`.
- 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 https://user-images.githubusercontent.com/59481467/138811091-05031eb1-96fc-4915-a349-e41d87c921ea.mp4
Credits: Credits:
1. https://vim.fandom.com/wiki/Remove_unwanted_spaces#Automatically_removing_all_trailing_whitespace 1. [Vim Tips Wiki entry for removing unwanted spaces](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 2. ib., the author of [this stack overflow answer](https://stackoverflow.com/a/7501902)

Loading…
Cancel
Save