Skip to content

Instantly share code, notes, and snippets.

@tbielawa
Created August 24, 2010 02:12
Show Gist options
  • Save tbielawa/546777 to your computer and use it in GitHub Desktop.
Save tbielawa/546777 to your computer and use it in GitHub Desktop.
(defun delete-trailing-whitespace-except-current-line ()
(interactive)
(let ((begin (line-beginning-position))
(end (line-end-position)))
(save-excursion
(when (< (point-min) begin)
(save-restriction
(narrow-to-region (point-min) (1- begin))
(delete-trailing-whitespace)))
(when (> (point-max) end)
(save-restriction
(narrow-to-region (1+ end) (point-max))
(delete-trailing-whitespace))))))
(add-hook 'before-save-hook 'delete-trailing-whitespace-except-current-line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment