From f02deb48b46d25764852a82371b9a5b35a7c8910 Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Fri, 2 Apr 2010 20:50:30 +0200 Subject: [PATCH] Added rename-file-and-buffer. --- emacs.el | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/emacs.el b/emacs.el index 8d4c2f0..b582fa2 100644 --- a/emacs.el +++ b/emacs.el @@ -672,6 +672,26 @@ occurrences " ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; http://blog.tuxicity.se/elisp/emacs/2010/03/26/rename-file-and-buffer-in-emacs.htm + +(defun rename-file-and-buffer () + "Renames current buffer and file it is visiting." + (interactive) + (let ((name (buffer-name)) + (filename (buffer-file-name))) + (if (not (and filename (file-exists-p filename))) + (message "Buffer '%s' is not visiting a file!" name) + (let ((new-name (read-file-name "New name: " filename))) + (cond ((get-buffer new-name) + (message "A buffer named '%s' already exists!" new-name)) + (t + (rename-file name new-name 1) + (rename-buffer new-name) + (set-visited-file-name new-name) + (set-buffer-modified-p nil))))))) + +(global-set-key (kbd "C-c r") 'rename-file-and-buffer) + (defun ff/non-existing-filename (dir prefix suffix) "Returns a filename of the form DIR/PREFIX[.n].SUFFIX whose file does not exist" -- 2.39.5