[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 13fdded: Allow preserving symlinks with file-precious-flag set
From: |
Lars Ingebrigtsen |
Subject: |
master 13fdded: Allow preserving symlinks with file-precious-flag set |
Date: |
Fri, 20 Aug 2021 10:20:58 -0400 (EDT) |
branch: master
commit 13fdded2c19823d9216b391d0636345029cf3e81
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
Allow preserving symlinks with file-precious-flag set
* doc/lispref/files.texi (Saving Buffers): Document it.
* lisp/files.el (file-preserve-symlinks-on-save): New user option
(bug#18125).
(basic-save-buffer-2): Use it.
---
doc/lispref/files.texi | 7 +++++++
etc/NEWS | 5 +++++
lisp/files.el | 17 ++++++++++++++++-
3 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/doc/lispref/files.texi b/doc/lispref/files.texi
index 266501d..12c0611 100644
--- a/doc/lispref/files.texi
+++ b/doc/lispref/files.texi
@@ -503,6 +503,13 @@ all hard links between the file you save and other file
names.
Some modes give this variable a non-@code{nil} buffer-local value
in particular buffers.
+
+@vindex file-preserve-symlinks-on-save
+If this option is non-@code{nil} and you're visiting files via a
+symbolic link, Emacs break the symbolic link and write the buffer to a
+file with the same name as the symbolic link. To instead write to the
+file the symbolic link points to (and thereby preserving the link),
+set @code{file-preserve-symlinks-on-save} to @code{t}.
@end defopt
@defopt require-final-newline
diff --git a/etc/NEWS b/etc/NEWS
index 7cd0c5f..cdc70d6 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2461,6 +2461,11 @@ images are marked.
** Miscellaneous
+++
+*** New user option 'file-preserve-symlinks-on-save'.
+This controls what Emacs does when saving buffers visited via a
+symbolic link, and 'file-precious-flag' is non-nil.
+
++++
*** New user option 'copy-directory-create-symlink'.
If non-nil, will make `copy-directory' (when used on a symbolic
link) copy the link instead of following the link.
diff --git a/lisp/files.el b/lisp/files.el
index 90de149..6a617fe 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -5446,6 +5446,14 @@ symbolic link and copy the contents instead."
:version "28.1"
:group 'files)
+(defcustom file-preserve-symlinks-on-save nil
+ "If non-nil, saving a buffer visited via a symlink won't overwrite the
symlink.
+This is only relevant if `file-precious-flag' is non-nil -- if
+this is nil, Emacs will preserve the symlinks anyway."
+ :type 'boolean
+ :version "28.1"
+ :group 'files)
+
(defvar-local save-buffer-coding-system nil
"If non-nil, use this coding system for saving the buffer.
More precisely, use this coding system in place of the
@@ -5648,7 +5656,14 @@ Before and after saving the buffer, this function runs
buffer-file-name)))
;; We succeeded in writing the temp file,
;; so rename it.
- (rename-file tempname buffer-file-name t))
+ (rename-file tempname
+ (if (and file-preserve-symlinks-on-save
+ (file-symlink-p buffer-file-name))
+ ;; Write to the file that the symlink
+ ;; points to.
+ (file-chase-links buffer-file-name)
+ buffer-file-name)
+ t))
;; If file not writable, see if we can make it writable
;; temporarily while we write it.
;; But no need to do so if we have just backed it up
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 13fdded: Allow preserving symlinks with file-precious-flag set,
Lars Ingebrigtsen <=