Skip to content

Instantly share code, notes, and snippets.

@am0c
Created November 1, 2012 10:28
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 am0c/3992960 to your computer and use it in GitHub Desktop.
Save am0c/3992960 to your computer and use it in GitHub Desktop.
copy-region-as-fill in Emacs 24
;; copy region as `fill-region`ed even
;; in longlines-mode or visual-line-mode.
;;
;; thanks to @y0ngbin for this idea.
(global-set-key [?\C-x ?\M-w] 'copy-region-as-fill)
(defun copy-region-as-fill (beg end)
(interactive "r")
(when (region-active-p)
(kill-ring-save beg end)
(with-temp-buffer
(yank)
(mark-whole-buffer)
(fill-region (region-beginning) (region-end))
(mark-whole-buffer)
(kill-ring-save (region-beginning) (region-end)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment