0

After leaving Emacs open overnight, the SSH connection expires. However, the buffers that I left open, are still useful, and I want to continue working with them.

However, many actions I do with Emacs in the expired TRAMP buffer lead to an attempt to reconnect to SSH. This is very annoying since it requires entering a password or may even be impossible since remote machines often have downtime, scheduled or unscheduled. I am looking to be able to work on such buffers for a day or two without workflow constantly being interrupted by TRAMP trying, and failing, to connect.

Is there a way to stop Emacs from trying to reconnect on every action that does not require a fresh version of a file explicitly?

This is my TRAMP config:

(use-package tramp
  :straight nil
  :init
  (setq tramp-terminal-type "tramp")
  (setq server-port "1492")
  (setq server-use-tcp t)
  (setq auth-source-save-behavior nil)
  :config
  (add-to-list 'tramp-connection-properties
           (list nil "remote-shell" "/bin/zsh"))
  (setq tramp-completion-reread-directory-timeout nil)
  (setq tramp-default-method "sshx")
  (setq tramp-use-ssh-controlmaster-options nil)
  (setq vc-ignore-dir-regexp
      (format "\\(%s\\)\\|\\(%s\\)"
          vc-ignore-dir-regexp
          tramp-file-name-regexp))
  (setq tramp-verbose 5)
  (setq remote-file-name-inhibit-cache nil)
  (setq tramp-auto-save-directory "~/.emacs.d/tramp-autosave")
)

1 Answer 1

2

Since Emacs 27, there are the commands tramp-rename-files and tramp-rename-these-files. They are intended exactly for this case.

Read the Tramp manual, section Renaming remote files about.

5
  • Thanks, I appreciate the answer, but I'm not sure how this is helpful. At least it does not seem to be solving the problem that I'm facing.
    – xelibrion
    Commented Aug 10, 2022 at 16:15
  • 1
    It gives you the possibility to locate the buffer to another location, preferred on your local machine. Then Tramp is out of the game, and it doesn't try to reconnect the stale host. This might be a temporary relocation, and once the connection is reestablished , you can move the files back. Commented Aug 10, 2022 at 16:55
  • Ah I see, let me try this out, thanks!
    – xelibrion
    Commented Aug 11, 2022 at 9:06
  • Unfortunately this does not seem to work for my case, as when I call tramp-rename-these-files AFTER the connection has been dropped, TRAMP attempts to re-establish the connection - exactly the thing I'd like to avoid.
    – xelibrion
    Commented Aug 12, 2022 at 9:20
  • 1
    It should work. If not, pls write a bug report. Commented Aug 12, 2022 at 10:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.