From: Mark Wooding Date: Wed, 6 May 2020 17:51:58 +0000 (+0100) Subject: el/dot-emacs.el: Advise `rename-file' to rename buffers at the same time. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/profile/commitdiff_plain/3782446f0bbdc76405aadc6c73f78ce37153fd55?ds=sidebyside el/dot-emacs.el: Advise `rename-file' to rename buffers at the same time. I remember investigating this hack a while ago and finding that it looked very difficult. This time, it's nearly trivial. What gives? --- diff --git a/el/dot-emacs.el b/el/dot-emacs.el index 0c402be..23b2c97 100644 --- a/el/dot-emacs.el +++ b/el/dot-emacs.el @@ -588,6 +588,15 @@ (defadvice display-buffer (before mdw-inhibit-other-frames activate) Pretend they don't exist. They might be on other display devices." (ad-set-arg 2 nil)) +;; Rename buffers along with files. + +(defadvice rename-file (after mdw-rename-buffers (from to &optional forcep) + compile activate) + (let ((buffer (get-file-buffer from))) + (when buffer + (with-current-buffer buffer + (set-visited-file-name to nil t))))) + ;;;-------------------------------------------------------------------------- ;;; Improved compilation machinery.