Last active
March 10, 2021 09:16
-
-
Save danielmartin/803a77d34b2c1f70e19ae8231de0567f to your computer and use it in GitHub Desktop.
Emacs function to kill added/removed lines of diff output, removing the diff markers
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 dm/kill-diff (arg) | |
"Kill added/removed lines of diff output, removing the diff markers. | |
Without a prefix argument or a positive argument, kill the added | |
lines. With a negative argument, kill the removed lines." | |
(interactive "P") | |
(kill-new | |
(thread-last (buffer-substring-no-properties | |
(region-beginning) | |
(region-end)) | |
(replace-regexp-in-string | |
(format "^\\%c.*\n?" (if (< (prefix-numeric-value arg) 0) ?+ ?-)) | |
"") | |
(replace-regexp-in-string "^[ \\+\\-]" "")))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment