Created
January 27, 2016 14:37
-
-
Save davazp/39d31aa596284f575294 to your computer and use it in GitHub Desktop.
Cleanup whitespaces in a magit diff hunk
This file contains 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 davazp/magit-cleanup-hunk-whitespace () | |
"Cleanup the whitespaces in the diff hunk under the cursor." | |
(interactive) | |
(let ((current (magit-current-section))) | |
(when (eq 'hunk (magit-section-type current)) | |
(let ((file (magit-file-at-point)) | |
(context (caddr (magit-section-value current)))) | |
(cl-destructuring-bind (first-line count) | |
(mapcar #'string-to-number (split-string context ",")) | |
(save-excursion | |
(with-current-buffer (find-file-noselect file) | |
(let (start end) | |
(goto-char (point-min)) | |
(forward-line (1- first-line)) | |
(setq start (point)) | |
(forward-line (1- count)) | |
(setq end (point)) | |
(whitespace-cleanup-region start end) | |
(magit-refresh))))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bind it with