chiark / gitweb /
el/dot-emacs.el: Advise `rename-file' to rename buffers at the same time.
authorMark Wooding <mdw@distorted.org.uk>
Wed, 6 May 2020 17:51:58 +0000 (18:51 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Wed, 6 May 2020 18:11:53 +0000 (19:11 +0100)
I remember investigating this hack a while ago and finding that it
looked very difficult.  This time, it's nearly trivial.  What gives?

el/dot-emacs.el

index 0c402be42a882d8392cb29e4a2eede1f36dc5ff5..23b2c97ba0dffdbadf420e6d04170590fb32d810 100644 (file)
@@ -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.