changeset 97242:cc5f94eeb1d8

(custom-save-all): Avoid destrying symlink if already visiting the custom file.
author Chong Yidong <cyd@stupidchicken.com>
date Sat, 02 Aug 2008 21:07:20 +0000
parents 145e6327f4da
children 3c62347bccdb
files lisp/cus-edit.el
diffstat 1 files changed, 14 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/cus-edit.el	Sat Aug 02 21:07:06 2008 +0000
+++ b/lisp/cus-edit.el	Sat Aug 02 21:07:20 2008 +0000
@@ -4265,9 +4265,18 @@
 			     (recentf-expand-file-name (custom-file)))
 			    "\\'")
 		    recentf-exclude)))
-	 (old-buffer (find-buffer-visiting filename)))
+	 (old-buffer (find-buffer-visiting filename))
+	 old-buffer-name)
+
     (with-current-buffer (let ((find-file-visit-truename t))
 			   (or old-buffer (find-file-noselect filename)))
+      ;; We'll save using file-precious-flag, so avoid destroying
+      ;; symlinks.  (If we're not already visiting the buffer, this is
+      ;; handled by find-file-visit-truename, above.)
+      (when old-buffer
+	(setq old-buffer-name (buffer-file-name))
+	(set-visited-file-name (file-chase-links filename)))
+
       (unless (eq major-mode 'emacs-lisp-mode)
 	(emacs-lisp-mode))
       (let ((inhibit-read-only t))
@@ -4275,7 +4284,10 @@
 	(custom-save-faces))
       (let ((file-precious-flag t))
 	(save-buffer))
-      (unless old-buffer
+      (if old-buffer
+	  (progn
+	    (set-visited-file-name old-buffer-name)
+	    (set-buffer-modified-p nil))
 	(kill-buffer (current-buffer))))))
 
 ;;;###autoload