The artist mode of Emacs can be used to remove the whitespaces in an Emacs buffer. This can be done as follows:
1. Add the following lines of code to your .emacs file
Now bind this function to a keyboard shortcut of your choice. I personally chose f6, so in the case of f6 add the following lines to your .emacs file
(global-set-key [f6] 'clean-whitespace)
This shall be enabled the next time you run emacs.
If you wish to update it in your current session, then open the .emacs file. Select the lines of code added and execute M-x eval-region.