Subject: Re: bug#65022: 29.1; Tramp resets file buffer encoding to UTF-8

From: Michael Albinus <[email-masked]>
Date: Thu, 03 Aug 2023 16:58:49 +0200

Георгий Потапов via "Bug reports for GNU Emacs, the Swiss army knife of
text editors" <[email-masked]> writes:

Hi Georgij,

> I edit my files in cp1251 encoding.
>
> This works fine on local host but when I save files on remote host
> using tramp it resets encoding to utf-8 constantly.

Thanks for the report. I could reproduce the problem locally.

It took me a while for debugging, but finally I could fix it. It was a
stupid scoping error when changing something between Emacs 28 and Emacs
29. The fix, which works for me, is appended.

It is a little bit tricky to install the patch, because it is in a
defmacro of tramp.el. This macro is used in tramp-sh.el. You must
compile both files in this order. Could you pls check?

Best regards, Michael.

diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 29361f8a113..a052b054f03 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -3640,7 +3640,7 @@ tramp-skeleton-write-region

 	     ;; Set the ownership.
              (when need-chown
-               (tramp-set-file-uid-gid filename uid gid)))
+               (tramp-set-file-uid-gid filename uid gid))

 	   ;; Set extended attributes.  We ignore possible errors,
 	   ;; because ACL strings could be incompatible.
@@ -3662,7 +3662,7 @@ tramp-skeleton-write-region
 	   (when (and (null noninteractive)
 		      (or (eq ,visit t) (string-or-null-p ,visit)))
 	     (tramp-message v 0 "Wrote %s" filename))
-	   (run-hooks 'tramp-handle-write-region-hook))))))
+	   (run-hooks 'tramp-handle-write-region-hook)))))))

 ;;; Common file name handler functions for different backends: