Skip to content

Instantly share code, notes, and snippets.

@danielmartin
Last active March 10, 2021 09:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielmartin/803a77d34b2c1f70e19ae8231de0567f to your computer and use it in GitHub Desktop.
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
(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