Created
August 16, 2013 19:02
-
-
Save bergmark/6252591 to your computer and use it in GitHub Desktop.
If there are two linebreaks at the end of a file, keep them, if there's only one it is kept as is to not add extra changes to commits.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defun delete-trailing-whitespace-and-extra-nl () | |
| (interactive) | |
| (let ((two? (ends-with-two-linebreaks?))) | |
| (progn | |
| (delete-trailing-whitespace) | |
| (if (and two? (string-match "silk" (buffer-file-name))) | |
| (save-excursion | |
| (let ((undo-list (undo-copy-list buffer-undo-list))) | |
| (progn | |
| (buffer-disable-undo) | |
| (goto-char (point-max)) | |
| (insert ?\n) | |
| (buffer-enable-undo) | |
| (setq buffer-undo-list undo-list) | |
| (set-buffer-modified-p nil) | |
| ))))))) | |
| (defun ends-with-two-linebreaks? () | |
| (equal '(?\n ?\n) | |
| (list (char-before (point-max)) | |
| (char-before (1- (point-max))) | |
| ))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment