Created
March 24, 2010 11:56
-
-
Save arvidj/342222 to your computer and use it in GitHub Desktop.
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
;; Never understood why Emacs doesn't have this function. | |
;; http://steve.yegge.googlepages.com/my-dot-emacs-file | |
(defun rename-file-and-buffer (new-name) | |
"Renames both current buffer and file it's visiting to NEW-NAME." (interactive "sNew name: ") | |
(let ((name (buffer-name)) | |
(filename (buffer-file-name))) | |
(if (not filename) | |
(message "Buffer '%s' is not visiting a file!" name) | |
(if (get-buffer new-name) | |
(message "A buffer named '%s' already exists!" new-name) | |
(progn (rename-file name new-name 1) | |
(rename-buffer new-name) | |
(set-visited-file-name new-name) | |
(set-buffer-modified-p nil)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment