Created
February 14, 2011 09:29
-
-
Save anton0xf/825659 to your computer and use it in GitHub Desktop.
emacs:rename-buffer-file
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 rename-buffer-file (newname &optional ok-if-already-exists) | |
"rename visited file (buffer-file-name) to NEWNAME | |
and appropriately change buffer name (set-visited-file-name NEWNAME). | |
NEWNAME must be string. | |
Signals a `file-already-exists' error if a file NEWNAME already exists | |
unless optional third argument OK-IF-ALREADY-EXISTS is non-nil. | |
A number as third arg means request confirmation if NEWNAME already exists. | |
This is what happens in interactive use with M-x." | |
(interactive "FRename to: \np") | |
(let ((file (buffer-file-name))) | |
(when file | |
(message "Rename buffer file %s to %s" file newname) | |
(rename-file file newname ok-if-already-exists) | |
(set-visited-file-name newname)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment