Skip to content

Conversation

@Cimbali
Copy link
Collaborator

@Cimbali Cimbali commented Jan 23, 2018

This whole post explains the first commit of the PR (Cimbali/vim-better-whitespace@c0ad20c): Buffer-local stripping of whitespace

Setting whether we strip whitespace on save per buffer will solve some problems, both of clarity and blacklist.

Now both stripping and highlighting whitespace have different buffer variables controlling them, thus you can play globally with:

  • enabling/disabling whitespace highlighting globally with g:better_whitespace_enabled
  • enabling/disabling whitespace stripping globally with g:strip_whitespace_on_save
  • disabling both highlighting + stripping per buffer type with g:better_whitespace_filetypes_blacklist (only relevant if it was enabled globally)
  • enabling/disabling whitespace highlighting per individual buffer with Enable/Disable/ToggleWhitespace (under the hood b:better_whitespace_enabled)
  • enabling/disabling whitespace stripping per individual buffer with Enable/Disable/ToggleStripWhitespaceOnSave (under the hood b:strip_whitespace_on_save)

As far as I can tell this works well even in buffers where FileType is never triggered (e.g. empty buffers, falling back to global defaults), and even if the DisableWhitespace is called befoere the ShouldSkipHighlight that sets up the local variable (i.e. we don't overwrite specific settings with general defaults).

This simplifies a lot the global enabling/disabling of global saving of stripping that was recommended in the doc:

autocmd FileType <desired_filetypes> autocmd BufEnter <buffer> EnableStripWhitespaceOnSave

becomes:

autocmd FileType <desired_filetypes> EnableStripWhitespaceOnSave

The documentation is updated as well, so this should fix #53 as well.


After this commit users should do let g:strip_whitespace_on_save = 1 to enable stripping globally instead of using autocmd BufEnter * EnableStripWhitespaceOnSave, which then makes the blacklist work as expected (fixing #68).

To have for example whitespace highlighting + stripping by default, and only highlighting (no stripping) in Markdown (as requested in #53), the vimrc would contain:

" enable both features globally
let g:better_whitespace_enabled = 1
let g:strip_whitespace_on_save = 1
" blacklist without markdown
let g:better_whitespace_filetypes_blacklist=['diff', 'gitcommit', 'unite', 'qf', 'help']
" disable stripping for markdown files
autocmd FileType markdown DisableStripWhitespaceOnSave

(or alternately leave it in the blacklist and call EnableWhitespace for markdown files)

@Cimbali
Copy link
Collaborator Author

Cimbali commented Jan 24, 2018

I merged all the other branches/PRs in here so it can be merged all together. Fix all issues/PRs except 1) asking confirmation before stripping 2) limit stripping to edited lines.
The original buffer-local branch is still available at Cimbali/vim-better-whitespace@c0ad20c.

@Cimbali Cimbali changed the title Buffer-local stripping of whitespace Fix various issues/PRs and update documentation Jan 24, 2018
@ntpeters ntpeters merged commit 8f488a4 into ntpeters:master Feb 25, 2018
@ntpeters
Copy link
Owner

This is awesome! Thanks for all the great work on this! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Confusing README regarding filetypes blacklisting

5 participants