(defun delete-trailing-whitespace () "Delete all the trailing whitespace across the current buffer. All whitespace after the last non-whitespace character in a line is deleted. This respects narrowing, created by \\[narrow-to-region] and friends. A formfeed is not considered whitespace by this function." (interactive "*") (save-match-data (save-excursion (goto-char (point-min)) (let ((count 0)) (while (re-search-forward "[ \t\r]+$" nil t) (replace-match "")(setq count (1+ count))) (message "Cleaned %d lines" count)))))