Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to skip certain filetypes. #2

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ Strip trailing whitespace as you are editing.
use {
'lewis6991/spaceless.nvim',
config = function()
require'spaceless'.setup()
require'spaceless'.setup({
-- example config
ignore_filetypes = { "markdown" }
})
end
}
```
15 changes: 13 additions & 2 deletions lua/spaceless.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ local function stripWhitespace(top, bottom)
return
end

-- print(vim.inspect(require("spaceless").options.ignore_filetypes))
if vim.tbl_contains(require("spaceless").options.ignore_filetypes, vim.api.nvim_buf_get_option(0, "filetype")) then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if vim.tbl_contains(require("spaceless").options.ignore_filetypes, vim.api.nvim_buf_get_option(0, "filetype")) then
if vim.tbl_contains(M.options.ignore_filetypes, vim.bo.filetype) then

return
end

if not top then return end

-- All conditions passed, go ahead and strip
Expand Down Expand Up @@ -83,9 +88,15 @@ local function onBufEnter()
end
end

local M = {}
local M = {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this to the top.

options = {
ignore_filetypes = {}
}
}

function M.setup(options)
M.options = vim.tbl_extend("force", M.options, options or {})

function M.setup()
local group = api.nvim_create_augroup('spaceless', {})

local function au(event, callback)
Expand Down