git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Add an EditorConfig file

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Sep 17, 2018, 23:03 UTC
Message-ID
<20180917230307.588334-1-sandals@crustytoothpaste.net>

Contributors to Git use a variety of editors, each with their own configuration files. Because C lacks the defined norms on how to indent and style code that other languages, such as Ruby and Rust, have, it's possible for various contributors, especially new ones, to have configured their editor to use a style other than the style the Git community prefers.

To make automatically configuring one's editor easier, provide an EditorConfig file. This is an INI-style configuration file that can be used to specify editor settings and can be understood by a wide variety of editors. Some editors include this support natively; others require a plugin. Regardless, providing such a file allows users to automatically configure their editor of choice with the correct settings by default.

Provide global settings to set the character set to UTF-8 and insert a final newline into files. Provide language-specific settings for C, Shell, Perl, and Python files according to what CodingGuidelines already specifies. Since the indentation of other files varies, especially certain AsciiDoc files, don't provide any settings for them until a clear consensus forward emerges.

Don't specify an end of line type. While the Git community uses Unix-style line endings in the repository, some Windows users may use Git's auto-conversion support and forcing Unix-style line endings might cause problems for those users.

Finally, leave out a root directive, which would prevent reading other EditorConfig files higher up in the tree, in case someone wants to set the end of line type for their system in such a file.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
I was incentivized to write this when I started using worktrees for
development and found that I had inserted spaces into all the work I was
doing because I was outside of my normal git.git clone.

This is the easiest way to set per-repo configuration across editors, especially since people may work on various C codebases with different indentation standards.

 .editorconfig | 11 +++++++++++
 1 file changed, 11 insertions(+)
 create mode 100644 .editorconfig
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000000..8963d83fdb
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,11 @@
+[*]
+charset = utf-8
+insert_final_newline = true
+
+[*.{c,h,sh,perl}]
+indent_style = tab
+tab_width = 8
+
+[*.py]
+indent_style = space
+indent_size = 4
Next: Taylor Blau
Message 1 of 12 in “Add an EditorConfig file”
  1. Add an EditorConfig filebrian m. carlson, Sep 17, 2018
  2. Taylor BlauSep 17, 2018
  3. brian m. carlsonSep 20, 2018
  4. Junio C HamanoSep 19, 2018
  5. brian m. carlsonSep 20, 2018
  6. Junio C HamanoSep 20, 2018
  7. brian m. carlsonSep 21, 2018
  8. Junio C HamanoSep 24, 2018
  9. brian m. carlsonSep 27, 2018
  10. Eric SunshineSep 21, 2018
  11. Jeff KingSep 21, 2018
  12. brian m. carlsonSep 21, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.