Skip to content

Odd Behavior with Carriage Return (CR) #375

@gabedesanta

Description

@gabedesanta

Emacs handles files with different end-of-line (EOL) conventions well, but when using .editorconfig, it exhibits strange behavior. For example, in VSCode, when .editorconfig is configured with end_of_line = lf and you open a file with CRLF line endings, the file opens normally without any Carriage Return characters appearing. After saving, the file is automatically converted to LF line endings as per the .editorconfig settings.

However, in Emacs, when end_of_line is set to lf in .editorconfig and you open a file with CRLF line endings, the Carriage Return (^M) characters immediately appear. This behavior is unexpected, as without .editorconfig, Emacs correctly handles the conversion of CRLF to LF without any issues. It seems that the conversion forced by .editorconfig causes the escaped Carriage Return symbols to appear.

(I'm using UTF-8 because it's my usual encoding. However, since the issue is related to CRLF line endings, it should be reproducible with any character encoding.)

I expect the behavior to be similar to other text editors, where the file opens with its original EOL and is only converted when saved. With this behavior, Emacs opens the file in dos mode, so the CR characters do not escape. If I make changes and save the file, it gets fully converted to LF, and Emacs then displays it in unix mode. I’m not sure if this behavior can be changed with a setting, as I’ve tried to find one but haven’t had any luck.

Steps to Reproduce:

  1. Create a folder with a .editorconfig file containing the following configuration:
root = true

[*]
end_of_line = lf
  1. Create a text file encoded in UTF-8 with CRLF line endings.
  2. Open the file in Emacs (tested on Emacs 30.1 with MSYS64 on Windows).
  3. The file opens and immediately displays the ^M Carriage Return characters.
Image

The image shows the result of the reproducible steps. Emacs is configured with a clean setup, with the only content in the init.el being (editorconfig-mode 1).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions