Skip to content

Instantly share code, notes, and snippets.

@danielmartin

danielmartin/kill-diff.el

Last active Mar 10, 2021
Embed
What would you like to do?
Emacs function to kill added/removed lines of diff output, removing the diff markers
(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