Subject: 29.1; Tramp resets file buffer encoding to UTF-8
From: Георгий Потапов <[email-masked]>
To: [email-masked]
Date: Wed, 2 Aug 2023 16:11:49 +0300
List-Id: <debbugs-submit.debbugs.gnu.org>

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.

Even if I do |(set-buffer-file-coding-system)| to cp1251, it sets the 
encoding for awhile, but after saving the file it immediately resets to 
utf-8-unix. The saved file appears in cp1251 as desired, but the buffer 
encoding becomes utf-8-unix and subsequent saving appears in utf-8-unix

For example, I do |(set-buffer-file-coding-system 'cp1251)|

save file

the file on disk is in cp1251 encoding, but the encoding flag in the 
left bottom becomes U for utf-8

save file again

it is in utf-8 encoding

It happens regardless of if the file contains only ASCII symbols or 
non-ASCII symbols.

Local files are saved normally.

The issue appeared in emacs 29.1, everything was ok in 28.1

workaround

|(defun set-remote-encoding () "set buffer encoding to cp1251" 
(set-buffer-file-coding-system 'cp1251)) (add-hook 'before-save-hook 
'set-remote-encoding) |

In GNU Emacs 29.1 (build 2, x86_64-w64-mingw32) of 2023-07-31 built on
  AVALON
Windowing system distributor 'Microsoft Corp.', version 10.0.19045
System Description: Microsoft Windows 10 Pro (v10.0.2009.19045.3208)

Configured using:
  'configure --with-modules --without-dbus --with-native-compilation=aot
  --without-compress-install --with-tree-sitter CFLAGS=-O2'

Configured features:
ACL GIF GMP GNUTLS HARFBUZZ JPEG JSON LCMS2 LIBXML2 MODULES NATIVE_COMP
NOTIFY W32NOTIFY PDUMPER PNG RSVG SOUND SQLITE3 THREADS TIFF
TOOLKIT_SCROLL_BARS TREE_SITTER WEBP XPM ZLIB

(NATIVE_COMP present but libgccjit not available)

Important settings:
   value of $LANG: RUS
   locale-coding-system: cp1251

Major mode: Fundamental

Minor modes in effect:
   poke-line-global-mode: t
   winner-mode: t
   smartparens-global-mode: t
   smartparens-global-strict-mode: t
   pixel-scroll-mode: t
   global-hi-lock-mode: t
   global-display-line-numbers-mode: t
   global-display-fill-column-indicator-mode: t
   display-time-mode: t
   shell-dirtrack-mode: t
   evil-mode: t
   windmove-mode: t
   tooltip-mode: t
   global-eldoc-mode: t
   electric-indent-mode: t
   mouse-wheel-mode: t
   menu-bar-mode: t
   file-name-shadow-mode: t
   global-font-lock-mode: t
   buffer-read-only: t
   column-number-mode: t
   line-number-mode: t
   auto-fill-function: do-auto-fill
   indent-tabs-mode: t
   transient-mark-mode: t
   auto-composition-mode: t
   auto-encryption-mode: t
   auto-compression-mode: t

Load-path shadows:
c:/home/.emacs.d/lisp/j-mode hides 
c:/home/.emacs.d/elpa/j-mode-20171224.1856/j-mode
c:/home/.emacs.d/elpa/transient-20230120.1559/transient hides 
c:/emacs/emacs-29.1/emacs-29.1/share/emacs/29.1/lisp/transient
c:/home/.emacs.d/elpa/use-package-20210207.1926/use-package hides 
c:/emacs/emacs-29.1/emacs-29.1/share/emacs/29.1/lisp/use-package/use-package
c:/home/.emacs.d/elpa/use-package-20210207.1926/use-package-lint hides 
c:/emacs/emacs-29.1/emacs-29.1/share/emacs/29.1/lisp/use-package/use-package-lint
c:/home/.emacs.d/elpa/use-package-20210207.1926/use-package-jump hides 
c:/emacs/emacs-29.1/emacs-29.1/share/emacs/29.1/lisp/use-package/use-package-jump
c:/home/.emacs.d/elpa/use-package-20210207.1926/use-package-ensure hides 
c:/emacs/emacs-29.1/emacs-29.1/share/emacs/29.1/lisp/use-package/use-package-ensure
c:/home/.emacs.d/elpa/use-package-20210207.1926/use-package-diminish 
hides 
c:/emacs/emacs-29.1/emacs-29.1/share/emacs/29.1/lisp/use-package/use-package-diminish
c:/home/.emacs.d/elpa/use-package-20210207.1926/use-package-delight 
hides 
c:/emacs/emacs-29.1/emacs-29.1/share/emacs/29.1/lisp/use-package/use-package-delight
c:/home/.emacs.d/elpa/use-package-20210207.1926/use-package-core hides 
c:/emacs/emacs-29.1/emacs-29.1/share/emacs/29.1/lisp/use-package/use-package-core
c:/home/.emacs.d/elpa/use-package-20210207.1926/use-package-bind-key 
hides 
c:/emacs/emacs-29.1/emacs-29.1/share/emacs/29.1/lisp/use-package/use-package-bind-key
c:/home/.emacs.d/elpa/bind-key-20210210.1609/bind-key hides 
c:/emacs/emacs-29.1/emacs-29.1/share/emacs/29.1/lisp/use-package/bind-key
c:/home/.emacs.d/elpa/prolog-1.22/prolog hides 
c:/emacs/emacs-29.1/emacs-29.1/share/emacs/29.1/lisp/progmodes/prolog
c:/home/.emacs.d/elpa/hierarchy-20190425.842/hierarchy hides 
c:/emacs/emacs-29.1/emacs-29.1/share/emacs/29.1/lisp/emacs-lisp/hierarchy

Features:
(shadow sort mail-extr emacsbug message yank-media puny dired
dired-loaddefs rfc822 mml mml-sec epa epg rfc6068 epg-config gnus-util
mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils
mailheader sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr
mail-utils poke-line poke-line-types tramp tramp-loaddefs trampver
tramp-integration files-x tramp-compat parse-time iso8601 time-date
semantic/idle semantic/analyze semantic/sort semantic/scope
semantic/analyze/fcn semantic/db eieio-base semantic/format ezimage
semantic/tag-ls semantic/find semantic/ctxt easy-mmode srcery-theme
winner smartparens semantic/util-modes semantic/util semantic pp
semantic/tag semantic/lex semantic/fw mode-local find-func cedet
pixel-scroll cua-base hl-line hi-lock display-line-numbers
display-fill-column-indicator eyebrowse format-spec dash elec-pair time
cus-load quail cyril-util mmm-mode mmm-univ mmm-class mmm-region
mmm-auto mmm-vars mmm-utils mmm-compat gperl-mode derived flymake-proc
flymake project compile text-property-search pcase folding-isearch
folding lilliputify evil evil-keybindings evil-integration evil-maps
evil-commands reveal flyspell ispell evil-jumps evil-command-window
evil-search evil-ex shell pcomplete comint ansi-osc ansi-color
evil-types evil-macros evil-repeat evil-states evil-core comp comp-cstr
warnings icons cl-extra help-mode advice evil-common windmove calc
calc-loaddefs calc-macs thingatpt rect evil-digraphs evil-vars ring
edmacro kmacro finder-inf rx slime-autoloads info package browse-url url
url-proxy url-privacy url-expand url-methods url-history url-cookie
generate-lisp-file url-domsuf url-util mailcap url-handlers url-parse
auth-source cl-seq eieio eieio-core cl-macs password-cache json subr-x
map byte-opt gv bytecomp byte-compile url-vars cl-loaddefs cl-lib rmc
iso-transl tooltip cconv eldoc paren electric uniquify ediff-hook
vc-hooks lisp-float-type elisp-mode mwheel dos-w32 ls-lisp disp-table
term/w32-win w32-win w32-vars term/common-win tool-bar dnd fontset image
regexp-opt fringe tabulated-list replace newcomment text-mode lisp-mode
prog-mode register page tab-bar menu-bar rfn-eshadow isearch easymenu
timer select scroll-bar mouse jit-lock font-lock syntax font-core
term/tty-colors frame minibuffer nadvice seq simple cl-generic
indonesian philippine cham georgian utf-8-lang misc-lang vietnamese
tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs
theme-loaddefs faces cus-face macroexp files window text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget keymap
hashtable-print-readable backquote threads w32notify w32 lcms2 multi-tty
make-network-process native-compile emacs)

Memory information:
((conses 16 462564 18444)
  (symbols 48 40503 1)
  (strings 32 192102 6856)
  (string-bytes 1 5120517)
  (vectors 16 45388)
  (vector-slots 8 1202977 28692)
  (floats 8 138 59)
  (intervals 56 593 0)
  (buffers 984 12))