Created
July 17, 2021 14:19
-
-
Save guiyuanju/01b3db017f9d0a052e4df669a3b65512 to your computer and use it in GitHub Desktop.
emacs: rename current file and visit new file in current buffer
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
| ;; based on https://stackoverflow.com/a/384346 | |
| (defun my/rename-current-file () | |
| (interactive) | |
| (let ((name (buffer-name)) | |
| (file-name (buffer-file-name))) | |
| (if file-name | |
| (let ((new-name (read-from-minibuffer | |
| (concat "New name for: ") | |
| file-name))) | |
| (if (get-buffer new-name) | |
| (message "A buffer named %s already exists." new-name) | |
| (progn | |
| (rename-file file-name new-name) | |
| (set-visited-file-name new-name) | |
| (set-buffer-modified-p nil)))) | |
| (message "This buffer is not visiting a file.")))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment