2

I mainly use Linux (arch) but for work, I have to use Windows 10. So I share some files between Emacs (28.2 installed via chocolatey) on Windows and Emacs (28.2) on Linux.

I never had any encoding issues on Linux, but when I use Emacs on Windows, it's messing up with some files (specially org files that have accents (é, è, ï, etc.)).

In order to avoid these problems I tried to force Emacs on Windows to only use Unicode and EOL: LF, by modifying init.

I tried many different tweaks found on:

But nothing works... The best result I managed to obtain is either:

  • saving files in utf-8 but with EOL: CRLF

    U -- utf-8-dos (alias: mule-utf-8-dos cp65001-dos)
    UTF-8 (no signature (BOM))
    Type: utf-8 (UTF-8: Emacs internal multibyte form)
    EOL type: CRLF
    This coding system encodes the following charsets: unicode

  • or saving files in ascii with EOL: LF

    -- undecided-unix (alias: unix)
    No conversion on encoding, automatic conversion on decoding.
    Type: undecided (do automatic conversion)
    EOL type: LF
    This coding system encodes the following charsets: ascii

When I'm trying to save new files (like .org files) from Emacs on Windows in utf-8 EOL: LF.

crocefisso
  • 1,141
  • 7
  • 15

1 Answers1

2

Add these lines to your init:

(prefer-coding-system 'utf-8-unix)
(setq coding-system-for-read 'utf-8-unix)
(setq coding-system-for-write 'utf-8-unix)

If you're using the same init for Windows & Linux you can do:

(cond ((eq system-type 'windows-nt)
     ;; Windows-specific code goes here.
     (prefer-coding-system 'utf-8-unix)
     (setq coding-system-for-read 'utf-8-unix)
     (setq coding-system-for-write 'utf-8-unix)
       )
      ((eq system-type 'gnu/linux)
       ;; Linux-specific code goes here. 
       ))

With this, buffers now show:

U -- utf-8-unix (alias: mule-utf-8-unix cp65001-unix)\
UTF-8 (no signature (BOM))\
Type: utf-8 (UTF-8: Emacs internal multibyte form)\
EOL type: LF\
This coding system encodes the following charsets: unicode

And M-x describe-coding-system (C-h C RET) shows:

Coding system for saving this buffer:
  U -- utf-8-unix (alias: mule-utf-8-unix cp65001-unix)

Default coding system (for new files):
  U -- utf-8-unix (alias: mule-utf-8-unix cp65001-unix)

Coding system for keyboard input:
  1 -- iso-latin-1-unix (alias: iso-8859-1-unix latin-1-unix)

Coding system for terminal output:
  U -- utf-8-unix (alias: mule-utf-8-unix cp65001-unix)

Coding system for inter-client cut and paste:
  U -- utf-16le-dos

Defaults for subprocess I/O:
  decoding: U -- utf-8-dos (alias: mule-utf-8-dos cp65001-dos)

  encoding: U -- utf-8-unix (alias: mule-utf-8-unix cp65001-unix)


Priority order for recognizing coding systems when reading files:
  1. utf-8 (alias: mule-utf-8 cp65001)
  2. iso-latin-1 (alias: iso-8859-1 latin-1)
  ...
crocefisso
  • 1,141
  • 7
  • 15