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

Remove trailing whitespaces #49

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

etanot
Copy link
Contributor

@etanot etanot commented Sep 13, 2021

This commit contains following changes:

  • Remove trailing whitespaces.
    Usually, we don't want to have trailing whitespaces at the end of
    line. It makes diff uglier and maintenance of code harder.
  • Replace non-breaking whitespace with simple whitespace.
    Like trailing whitespaces, we also don't want to have non-breaking
    whitespace1 in our source files.

This commit contains following changes:
  - Remove trailing whitespaces.
      Usually, we don't want to have trailing whitespaces at the end of
      line. It makes diff uglier and maintenance of code harder.
  - Replace non-breaking whitespace with simple whitespace.
      Like trailing whitespaces, we also don't want to have non-breaking
      whitespace[1] in our source files.

[1]: https://en.wikipedia.org/wiki/Non-breaking_space
@kushaldas
Copy link
Owner

Many of these whitespaces are from command output pasting, if we remove them, it will be a trouble for everytime we update those outputs. In my mind I am okay to keep those.

@etanot
Copy link
Contributor Author

etanot commented Jan 11, 2022

If you want, I can drop changes which contains commands output. But IMHO, a good solution would be to never have these changes at the first place. We could configure our text editor display different non-printable characters and automatically clean them on pressing some key bindings. For example, in Vim, I've added following code snippet to my vimrc file to display different non-printable characters:

" ======= Display non-printable characters =======
set list
set listchars=eol:⏎
set listchars+=extends:set listchars+=nbsp:⍽
set listchars+=precedes:set listchars+=tab:⇥‧
set listchars+=trail:" ==============================================

and defined a function to remove trailing whitespaces:

" Remove trailing whitespace(s) and replace non-breaking whitespace
" character(s) with whitespace on save, useful for some filetypes.

function! CleanFiles#CleanWhitespaces()
    let save_cursor = getpos(".")
    let old_query = getreg('/')

    " Remove trailing whitespace(s).
    silent! %s/\s\+$//e

    " Replace non-breaking whitespace character(s) with whitespace.
    silent! %s/\%u00a0/ /e

    call setpos('.', save_cursor)
    call setreg('/', old_query)
endfunction

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.

2 participants