Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
; http://emacs.stackexchange.com/questions/1051/copy-region-from-emacs-without-newlines
(defun my-copy-simple (&optional beg end)
"Save the current region (or line) to the `kill-ring' after stripping extra whitespace and new lines"
(interactive
(if (region-active-p)
(list (region-beginning) (region-end))
(list (line-beginning-position) (line-end-position))))
(let ((my-text (buffer-substring-no-properties beg end)))
(with-temp-buffer
(insert my-text)
(goto-char 1)
(while (looking-at "[ \t\n]")
(delete-char 1))
(let ((fill-column 9333999))
(fill-region (point-min) (point-max)))
(kill-region (point-min) (point-max)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment