Skip to content

Instantly share code, notes, and snippets.

@shrysr
Created April 14, 2020 05:50
Show Gist options
  • Save shrysr/da4c711a0867b62323bd372d0352cd44 to your computer and use it in GitHub Desktop.
Save shrysr/da4c711a0867b62323bd372d0352cd44 to your computer and use it in GitHub Desktop.
; 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