unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* How to switch off autobackup for files loaded from tramp?
@ 2024-01-29 11:13 Steinar Bang
  2024-01-29 18:52 ` Manuel Giraud via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 9+ messages in thread
From: Steinar Bang @ 2024-01-29 11:13 UTC (permalink / raw)
  To: help-gnu-emacs

Back in September 11 2021 I added the following line to my ~/.emacs:
 (add-to-list 'backup-directory-alist (cons tramp-file-name-regexp nil))

The purpose of that setting was to turn off autobackup for files loaded
from tramp, because emacs on windows went ga-ga when I tried to modify a
file that was loaded from a server that couldn't be contacted at the
time of edit (because of firewalls).

I think the setting worked back in 2021 at whatever emacs was the
current one back then.

But the setting does not work now and looking at the
backup-directory-alist documentation, I think it is because the nil
result just tells autobackup to work as default...?

Anyway: does someone have a current, working, config that will disable
autobackup on files loaded from tramp?

Thanks!


- Steinar



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to switch off autobackup for files loaded from tramp?
  2024-01-29 11:13 How to switch off autobackup for files loaded from tramp? Steinar Bang
@ 2024-01-29 18:52 ` Manuel Giraud via Users list for the GNU Emacs text editor
  2024-01-30  8:13   ` Steinar Bang
  0 siblings, 1 reply; 9+ messages in thread
From: Manuel Giraud via Users list for the GNU Emacs text editor @ 2024-01-29 18:52 UTC (permalink / raw)
  To: Steinar Bang; +Cc: help-gnu-emacs

Steinar Bang <sb@dod.no> writes:

[...]

> Anyway: does someone have a current, working, config that will disable
> autobackup on files loaded from tramp?

Hi,

I have this in my init file:

--8<---------------cut here---------------start------------->8---
(setq backup-enable-predicate
      (lambda (name)
	(and (normal-backup-enable-predicate name)
	     (not (file-remote-p name)))))
--8<---------------cut here---------------end--------------->8---
-- 
Manuel Giraud



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to switch off autobackup for files loaded from tramp?
  2024-01-29 18:52 ` Manuel Giraud via Users list for the GNU Emacs text editor
@ 2024-01-30  8:13   ` Steinar Bang
  2024-01-30  9:21     ` Manuel Giraud via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 9+ messages in thread
From: Steinar Bang @ 2024-01-30  8:13 UTC (permalink / raw)
  To: help-gnu-emacs

>>>>> Manuel Giraud via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>:

> I have this in my init file:

> (setq backup-enable-predicate
>       (lambda (name)
> 	(and (normal-backup-enable-predicate name)
> 	     (not (file-remote-p name)))))

Thanks! This looked good and from the variable and function
documentation it really looked like it should work.

Unfortunately it didn't... emacs still autosaves for me a file loaded
with tramp over a plink (putty SSH) connection.

Some versions:
 GNU Emacs 29.1 (build 2, x86_64-w64-mingw32) of 2023-07-31 (windows 11 enterprise)
 tramp version 2.6.0.29.1

Are there good ways to debug this in an "offending" buffer (ie. a buffer
holding a modified remote file)?

I.e. how to I check what the predicate returns in this buffer?

How do I check what (normal-backup-enable-predicate name) returns in
this buffer?

How do I check what (file-remote-p name) returns in this buffer?

Thanks!


- Steinar



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to switch off autobackup for files loaded from tramp?
  2024-01-30  8:13   ` Steinar Bang
@ 2024-01-30  9:21     ` Manuel Giraud via Users list for the GNU Emacs text editor
  2024-01-30  9:48       ` Steinar Bang
  0 siblings, 1 reply; 9+ messages in thread
From: Manuel Giraud via Users list for the GNU Emacs text editor @ 2024-01-30  9:21 UTC (permalink / raw)
  To: Steinar Bang; +Cc: help-gnu-emacs

Steinar Bang <sb@dod.no> writes:

>>>>>> Manuel Giraud via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>:
>
>> I have this in my init file:
>
>> (setq backup-enable-predicate
>>       (lambda (name)
>> 	(and (normal-backup-enable-predicate name)
>> 	     (not (file-remote-p name)))))
>
> Thanks! This looked good and from the variable and function
> documentation it really looked like it should work.
>
> Unfortunately it didn't... emacs still autosaves for me a file loaded
> with tramp over a plink (putty SSH) connection.

Hi,

It is expected.  Autosaves and backups are two differents things (I
thought you were talking about backups).  Backups is about keeping a
copy(ies) of previous version of your file *at saving time* and
autosaves is about keeping the modifications you've made *until you
save* them.  You could read for more details in the info Emacs manual.

> Some versions:
>  GNU Emacs 29.1 (build 2, x86_64-w64-mingw32) of 2023-07-31 (windows 11 enterprise)
>  tramp version 2.6.0.29.1
>
> Are there good ways to debug this in an "offending" buffer (ie. a buffer
> holding a modified remote file)?
>
> I.e. how to I check what the predicate returns in this buffer?
>
> How do I check what (normal-backup-enable-predicate name) returns in
> this buffer?
>
> How do I check what (file-remote-p name) returns in this buffer?

You could do:
    M-: (normal-backup-enable-predicate (buffer-file-name))
and
    M-: (file-remote-p (buffer-file-name))

But it won't help you for autosaves ;-).  You should read the
corresponding section in the Emacs manual.

Best regards,
-- 
Manuel Giraud



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to switch off autobackup for files loaded from tramp?
  2024-01-30  9:21     ` Manuel Giraud via Users list for the GNU Emacs text editor
@ 2024-01-30  9:48       ` Steinar Bang
  2024-01-30 10:16         ` Manuel Giraud via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 9+ messages in thread
From: Steinar Bang @ 2024-01-30  9:48 UTC (permalink / raw)
  To: help-gnu-emacs

>>>>> Manuel Giraud via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>:

> But it won't help you for autosaves ;-).  You should read the
> corresponding section in the Emacs manual.

Thanks! I know the difference, just bad at terminology.

I have disabled backups everywhere since 1994, because there was a
 sysadmin that hated the "~" files I dropped everyhwere I had edited
 config files.

But at least this gave me the incentive to google up why my 'C-h i' in
my emacs on debian didn't have the emacs manual:
 https://emacs.stackexchange.com/a/48214

So... after
    apt install emacs-common-non-dfsg
I can now read the emacs manual in the emacs info reader...



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to switch off autobackup for files loaded from tramp?
  2024-01-30  9:48       ` Steinar Bang
@ 2024-01-30 10:16         ` Manuel Giraud via Users list for the GNU Emacs text editor
  2024-01-30 11:40           ` Steinar Bang
  0 siblings, 1 reply; 9+ messages in thread
From: Manuel Giraud via Users list for the GNU Emacs text editor @ 2024-01-30 10:16 UTC (permalink / raw)
  To: Steinar Bang; +Cc: help-gnu-emacs

Steinar Bang <sb@dod.no> writes:

>>>>>> Manuel Giraud via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>:
>
>> But it won't help you for autosaves ;-).  You should read the
>> corresponding section in the Emacs manual.
>
> Thanks! I know the difference, just bad at terminology.

Ok :-)

> I have disabled backups everywhere since 1994, because there was a
>  sysadmin that hated the "~" files I dropped everyhwere I had edited
>  config files.

I used to do like you too but now I have this customization:

 '(backup-directory-alist '(("." . "~/.backups")))

and now all backups will end up into this directory.  Backups could save
yourself sometimes.

> But at least this gave me the incentive to google up why my 'C-h i' in
> my emacs on debian didn't have the emacs manual:
>  https://emacs.stackexchange.com/a/48214
>
> So... after
>     apt install emacs-common-non-dfsg
> I can now read the emacs manual in the emacs info reader...

Good.  You are closer to your solution now ;-)
-- 
Manuel Giraud



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to switch off autobackup for files loaded from tramp?
  2024-01-30 10:16         ` Manuel Giraud via Users list for the GNU Emacs text editor
@ 2024-01-30 11:40           ` Steinar Bang
  2024-01-30 11:53             ` Steinar Bang
  0 siblings, 1 reply; 9+ messages in thread
From: Steinar Bang @ 2024-01-30 11:40 UTC (permalink / raw)
  To: help-gnu-emacs

>>>>> Manuel Giraud via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>:

> Good.  You are closer to your solution now ;-)

I have this now in my emacs:

    ;; Avoid doing autosaves when modifying remote files
    (setq auto-save-visited-predicate (lambda () (not (file-remote-p buffer-file-name))))

And this setting works the way I expected, i.e. if i do
    M-x : (funcall auto-save-visited-predicate)
in a file loaded from remote I get nil.

Unfortunately emacs still autosaves the file in the buffer...:-/

But... rummaging through emacs' files.el that 'C-h v' sent me to, I
found this:

(defcustom remote-file-name-inhibit-auto-save-visited nil
  "When nil, `auto-save-visited-mode' will auto-save remote files.
Any other value means that it will not."
  :group 'auto-save
  :type 'boolean
  :version "29.1")

I'll try using this.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to switch off autobackup for files loaded from tramp?
  2024-01-30 11:40           ` Steinar Bang
@ 2024-01-30 11:53             ` Steinar Bang
  2024-01-30 12:13               ` Steinar Bang
  0 siblings, 1 reply; 9+ messages in thread
From: Steinar Bang @ 2024-01-30 11:53 UTC (permalink / raw)
  To: help-gnu-emacs

>>>>> Steinar Bang <sb@dod.no>:
> But... rummaging through emacs' files.el that 'C-h v' sent me to, I
> found this:

> (defcustom remote-file-name-inhibit-auto-save-visited nil
>   "When nil, `auto-save-visited-mode' will auto-save remote files.
> Any other value means that it will not."
>   :group 'auto-save
>   :type 'boolean
>   :version "29.1")

> I'll try using this.

Ok, this was weird:
    M-x : remote-file-name-inhibit-auto-save-visited
in a buffer loaded from remote returns now t, but the buffer still
autosaves when modified

Does tramp do its own thing wrt to autosaving?

Or isn't the tramp file recognized as a remote file?

    M-x : (not (file-remote-p buffer-file-name))
evaluates to nil while the same on ~/.emacs evaluates to t, so I think
that means that file-remote-p sees the tramp buffer file as a remote...?



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to switch off autobackup for files loaded from tramp?
  2024-01-30 11:53             ` Steinar Bang
@ 2024-01-30 12:13               ` Steinar Bang
  0 siblings, 0 replies; 9+ messages in thread
From: Steinar Bang @ 2024-01-30 12:13 UTC (permalink / raw)
  To: help-gnu-emacs

>>>>> Steinar Bang <sb@dod.no>:

>> But... rummaging through emacs' files.el that 'C-h v' sent me to, I
>> found this:

>> (defcustom remote-file-name-inhibit-auto-save-visited nil
>> "When nil, `auto-save-visited-mode' will auto-save remote files.
>> Any other value means that it will not."
>> :group 'auto-save
>> :type 'boolean
>> :version "29.1")

>> I'll try using this.

> Ok, this was weird:
>     M-x : remote-file-name-inhibit-auto-save-visited
> in a buffer loaded from remote returns now t, but the buffer still
> autosaves when modified

> Does tramp do its own thing wrt to autosaving?

> Or isn't the tramp file recognized as a remote file?

The problem wasn't the autosave, the problem was that there was a lock
file created on the remote.

So this in my emacs now works on emacs 29:
    ;; Avoid doing autosaves when modifying remote files
    (setq remote-file-name-inhibit-locks t)
    ;(setq remote-file-name-inhibit-auto-save-visited t)
    (setq auto-save-visited-predicate (lambda () (not (file-remote-p buffer-file-name))))

The reason I use auto-save-visited-predicate is that I still use emacs
28 some places, and remote-file-name-inhibit-auto-save-visited only came
with emacs 29.

When I am on emacs 29 (or later) everywhere I will replace using
auto-save-visited-predicate with remote-file-name-inhibit-auto-save-visited




^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-01-30 12:13 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-29 11:13 How to switch off autobackup for files loaded from tramp? Steinar Bang
2024-01-29 18:52 ` Manuel Giraud via Users list for the GNU Emacs text editor
2024-01-30  8:13   ` Steinar Bang
2024-01-30  9:21     ` Manuel Giraud via Users list for the GNU Emacs text editor
2024-01-30  9:48       ` Steinar Bang
2024-01-30 10:16         ` Manuel Giraud via Users list for the GNU Emacs text editor
2024-01-30 11:40           ` Steinar Bang
2024-01-30 11:53             ` Steinar Bang
2024-01-30 12:13               ` Steinar Bang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).