emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master b19d040a4fe: New user option remote-file-name-inhibit-auto-save


From: Michael Albinus
Subject: master b19d040a4fe: New user option remote-file-name-inhibit-auto-save
Date: Thu, 23 Mar 2023 12:10:06 -0400 (EDT)

branch: master
commit b19d040a4fe709b032143d8e569690073befabdf
Author: Michael Albinus <michael.albinus@gmx.de>
Commit: Michael Albinus <michael.albinus@gmx.de>

    New user option remote-file-name-inhibit-auto-save
    
    * doc/misc/tramp.texi (Auto-save File Lock and Backup):
    Mention remote-file-name-inhibit-auto-save.
    (Frequently Asked Questions): Describe, how to suppress auto-save.
    
    * etc/NEWS: Add remote-file-name-inhibit-auto-save.
    
    * lisp/simple.el (remote-file-name-inhibit-auto-save): New defcustom.
    (auto-save-mode): Handle it.  (Bug#62260)
    
    * lisp/net/tramp-integration.el
    (tramp-set-connection-local-variables-for-buffer): Declare.
    (find-file-hook): Add `tramp-set-connection-local-variables-for-buffer'.
---
 doc/misc/tramp.texi           | 36 ++++++++++++++++++++++++++++++++++++
 etc/NEWS                      |  5 +++++
 lisp/net/tramp-integration.el | 11 ++++++++++-
 lisp/simple.el                | 10 ++++++++++
 4 files changed, 61 insertions(+), 1 deletion(-)

diff --git a/doc/misc/tramp.texi b/doc/misc/tramp.texi
index 6f14fc875f4..5d6def75f2f 100644
--- a/doc/misc/tramp.texi
+++ b/doc/misc/tramp.texi
@@ -3190,6 +3190,11 @@ auto-saved files to the same directory as the original 
file.
 Alternatively, set the user option @code{tramp-auto-save-directory}
 to direct all auto saves to that location.
 
+@c Since Emacs 30.
+@vindex remote-file-name-inhibit-auto-save
+If you want to suppress auto-saving of remote files at all, set user
+option @code{remote-file-name-inhibit-auto-save} to non-@code{nil}.
+
 @c Since Emacs 29.
 @vindex remote-file-name-inhibit-auto-save-visited
 An alternative to @code{auto-save-mode} is
@@ -4906,6 +4911,36 @@ Disable file locks.  Set 
@code{remote-file-name-inhibit-locks} to
 @code{t} if you know that different Emacs sessions are not modifying
 the same remote file.
 
+@item
+@vindex remote-file-name-inhibit-auto-save
+Keep auto-save files local.  This is already the default configuration
+in Emacs, don't change it.  If you want to disable auto-saving for
+remote files at all, set @code{remote-file-name-inhibit-auto-save} to
+@code{t}, but think about the consequences!
+
+If you want to disable auto-saving just for selected connections, for
+example due to security considerations, use connection-local variables
+in order to set @code{buffer-auto-save-file-name}.  If you, for
+example, want to disable auto-saving for all @option{sudo}
+connections, apply the following code.
+@ifinfo
+@xref{Connection Variables, , , emacs}.
+@end ifinfo
+
+@lisp
+@group
+(connection-local-set-profile-variables
+  'my-auto-save-profile
+  '((buffer-auto-save-file-name . nil)))
+@end group
+
+@group
+(connection-local-set-profiles
+ '(:application tramp :protocol "sudo")
+ 'my-auto-save-profile)
+@end group
+@end lisp
+
 @item
 Disable excessive traces.  Set @code{tramp-verbose} to 3 or lower,
 default being 3.  Increase trace levels temporarily when hunting for
@@ -5220,6 +5255,7 @@ HISTFILE=/dev/null
 @item
 Where are remote files trashed to?
 
+@vindex remote-file-name-inhibit-delete-by-moving-to-trash
 Emacs can trash file instead of deleting
 @ifinfo
 them, @ref{Misc File Ops, Trashing , , emacs}.
diff --git a/etc/NEWS b/etc/NEWS
index 80413c00965..ffce2baf2d0 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -50,6 +50,11 @@ as it has in batch mode since Emacs 24.
 When non-nil, this option suppresses moving remote files to the local
 trash when deleting.  Default is nil.
 
+---
+** New user option 'remote-file-name-inhibit-auto-save'.
+If this user option is non-nil, 'auto-save-mode' will not auto-save
+remote buffers.  The default is nil.
+
 +++
 ** New user option 'yes-or-no-prompt'.
 This allows the user to customize the prompt that is appended by
diff --git a/lisp/net/tramp-integration.el b/lisp/net/tramp-integration.el
index 5b3259eab03..d7fcd8afefa 100644
--- a/lisp/net/tramp-integration.el
+++ b/lisp/net/tramp-integration.el
@@ -42,9 +42,10 @@
 (declare-function shortdoc-add-function "shortdoc")
 (declare-function tramp-dissect-file-name "tramp")
 (declare-function tramp-file-name-equal-p "tramp")
-(declare-function tramp-tramp-file-p "tramp")
 (declare-function tramp-rename-files "tramp-cmds")
 (declare-function tramp-rename-these-files "tramp-cmds")
+(declare-function tramp-set-connection-local-variables-for-buffer "tramp")
+(declare-function tramp-tramp-file-p "tramp")
 (defvar eshell-path-env)
 (defvar ido-read-file-name-non-ido)
 (defvar info-lookup-alist)
@@ -549,6 +550,14 @@ See `tramp-process-attributes-ps-format'.")
    '(:application tramp :machine "localhost")
    local-profile))
 
+;; Set connection-local variables for buffers visiting a file.
+
+(add-hook 'find-file-hook #'tramp-set-connection-local-variables-for-buffer 
-50)
+(add-hook 'tramp-unload-hook
+         (lambda ()
+           (remove-hook
+             'find-file-hook 
#'tramp-set-connection-local-variables-for-buffer)))
+
 (add-hook 'tramp-unload-hook
          (lambda () (unload-feature 'tramp-integration 'force)))
 
diff --git a/lisp/simple.el b/lisp/simple.el
index 80c75d4d7c3..1447c7e53ff 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -9108,6 +9108,13 @@ presented."
   "Toggle buffer size display in the mode line (Size Indication mode)."
   :global t :group 'mode-line)
 
+(defcustom remote-file-name-inhibit-auto-save nil
+  "When nil, `auto-save-mode' will auto-save remote files.
+Any other value means that it will not."
+  :group 'auto-save
+  :type 'boolean
+  :version "30.1")
+
 (define-minor-mode auto-save-mode
   "Toggle auto-saving in the current buffer (Auto Save mode).
 
@@ -9130,6 +9137,9 @@ For more details, see Info node `(emacs) Auto Save'."
                  (setq buffer-auto-save-file-name
                        (cond
                         ((null val) nil)
+                        ((and buffer-file-name 
remote-file-name-inhibit-auto-save
+                              (file-remote-p buffer-file-name))
+                         nil)
                         ((and buffer-file-name auto-save-visited-file-name
                               (not buffer-read-only))
                          buffer-file-name)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]