Skip to content

Instantly share code, notes, and snippets.

@andis
Last active December 18, 2015 16:29
Show Gist options
  • Save andis/5811891 to your computer and use it in GitHub Desktop.
Save andis/5811891 to your computer and use it in GitHub Desktop.
Create a new file from the current region.
(defun extract-region-to-file (filename)
"Extract text in the region to a file"
(interactive "FExtract to file: ")
(save-excursion
(if buffer-read-only
(copy-region-as-kill (region-beginning) (region-end))
(kill-region (region-beginning) (region-end)))
(find-file filename)
(end-of-buffer)
(unless (= (buffer-size) 0)
(newline))
(yank)))
(define-key global-map (kbd "C-x X") 'extract-region-to-file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment