Last active
December 18, 2015 16:29
-
-
Save andis/5811891 to your computer and use it in GitHub Desktop.
Create a new file from the current region.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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