diff mbox series

[committed] libstdc++: Add .editorconfig files

Message ID 20240916091852.36521-1-jwakely@redhat.com
State New
Headers show
Series [committed] libstdc++: Add .editorconfig files | expand

Commit Message

Jonathan Wakely Sept. 16, 2024, 9:11 a.m. UTC
As mentioned in the Q&A session in Prague, I've been using these files
for years in my local GCC tree to help with formatting libstdc++ files.
I'll come up with similar files for the top-level and elsewhere in the
GCC tree. As Jakub mentioned, we certainly don't want to trim trailing
whitespace from testsuite files, because some of those files are
specifically testing correct handling of whitespace.

Editorconfig only handles the most basic settings (but those are things
we shouldn't be wasting our time doing by hand): trailing whitespace,
tabs vs spaces, number of columns to indent etc. For proper formatting
of code in libstdc++ I use https://github.com/mattkretz/vim-gnuindent
which does a great job (neither GNU indent nor clang-format can format
things the way we do it in libstdc++).

Pushed to trunk.

-- >8 --

These config files set default formatting behaviour for a large number
of common editors, see https://editorconfig.org

The root=true setting in libstdc++-v3/.editorconfig prevents looking in
parent directories for additional settings. If we add a .editorconfig at
the top-level we might want to use root=true there instead, and allow
libstdc++-v3/.editorconfig to inherit some some settings from there (and
only override things we want to do differently).

libstdc++-v3/ChangeLog:

	* .editorconfig: New file.
	* include/std/.editorconfig: New file.
---
 libstdc++-v3/.editorconfig             | 38 ++++++++++++++++++++++++++
 libstdc++-v3/include/std/.editorconfig | 10 +++++++
 2 files changed, 48 insertions(+)
 create mode 100644 libstdc++-v3/.editorconfig
 create mode 100644 libstdc++-v3/include/std/.editorconfig

Comments

Jonathan Wakely Sept. 16, 2024, 9:23 a.m. UTC | #1
On Mon, 16 Sept 2024 at 10:19, Jonathan Wakely wrote:
>
> As mentioned in the Q&A session in Prague, I've been using these files
> for years in my local GCC tree to help with formatting libstdc++ files.
> I'll come up with similar files for the top-level and elsewhere in the
> GCC tree. As Jakub mentioned, we certainly don't want to trim trailing
> whitespace from testsuite files, because some of those files are
> specifically testing correct handling of whitespace.
>
> Editorconfig only handles the most basic settings (but those are things
> we shouldn't be wasting our time doing by hand): trailing whitespace,
> tabs vs spaces, number of columns to indent etc. For proper formatting
> of code in libstdc++ I use https://github.com/mattkretz/vim-gnuindent
> which does a great job (neither GNU indent nor clang-format can format
> things the way we do it in libstdc++).

Arsen mentioned that he has some similar emacs config for formatting
libstdc++ code which should probably be added to the repo somewhere (I
don't know enough about emacs to know where that should be, or how to
make it only apply to the libstdc++ sub-directory).


>
> Pushed to trunk.
>
> -- >8 --
>
> These config files set default formatting behaviour for a large number
> of common editors, see https://editorconfig.org
>
> The root=true setting in libstdc++-v3/.editorconfig prevents looking in
> parent directories for additional settings. If we add a .editorconfig at
> the top-level we might want to use root=true there instead, and allow
> libstdc++-v3/.editorconfig to inherit some some settings from there (and
> only override things we want to do differently).
>
> libstdc++-v3/ChangeLog:
>
>         * .editorconfig: New file.
>         * include/std/.editorconfig: New file.
> ---
>  libstdc++-v3/.editorconfig             | 38 ++++++++++++++++++++++++++
>  libstdc++-v3/include/std/.editorconfig | 10 +++++++
>  2 files changed, 48 insertions(+)
>  create mode 100644 libstdc++-v3/.editorconfig
>  create mode 100644 libstdc++-v3/include/std/.editorconfig
>
> diff --git a/libstdc++-v3/.editorconfig b/libstdc++-v3/.editorconfig
> new file mode 100644
> index 00000000000..88107cedda2
> --- /dev/null
> +++ b/libstdc++-v3/.editorconfig
> @@ -0,0 +1,38 @@
> +# top-most EditorConfig file for libstdc++-v3
> +root = true
> +
> +[*]
> +end_of_line = lf
> +insert_final_newline = true
> +
> +[*.h,*.cc]
> +charset = utf-8
> +indent_style = tab
> +indent_size = 2
> +tab_width = 8
> +trim_trailing_whitespace = true
> +
> +[Makefile*,ChangeLog*]
> +indent_style = tab
> +indent_size = 8
> +trim_trailing_whitespace = true
> +
> +[ChangeLog*]
> +charset = utf-8
> +
> +[*.xml]
> +charset = utf-8
> +indent_size = 2
> +tab_width = 8
> +trim_trailing_whitespace = true
> +
> +[*.py]
> +indent_style = space
> +indent_size = 4
> +trim_trailing_whitespace = true
> +
> +[*.exp]
> +indent_style = tab
> +indent_size = 4
> +tab_width = 8
> +trim_trailing_whitespace = true
> diff --git a/libstdc++-v3/include/std/.editorconfig b/libstdc++-v3/include/std/.editorconfig
> new file mode 100644
> index 00000000000..97ca1923cf8
> --- /dev/null
> +++ b/libstdc++-v3/include/std/.editorconfig
> @@ -0,0 +1,10 @@
> +# Inherit settings from EditorConfig files above this dir.
> +root = false
> +
> +# All files under this directory are C++ headers.
> +[*]
> +charset = utf-8
> +indent_style = tab
> +indent_size = 2
> +tab_width = 8
> +trim_trailing_whitespace = true
> --
> 2.46.0
>
Mike Stump Sept. 16, 2024, 5:34 p.m. UTC | #2
On Sep 16, 2024, at 2:23 AM, Jonathan Wakely <jwakely@redhat.com> wrote:
> 
> Arsen mentioned that he has some similar emacs config for formatting
> libstdc++ code which should probably be added to the repo somewhere (I
> don't know enough about emacs to know where that should be, or how to
> make it only apply to the libstdc++ sub-directory).

Isn't the answer obvious?  meta.ai("In gnu emacs, how can I make certain editing style variables apply only to a certain subdirectory heirachy?")
diff mbox series

Patch

diff --git a/libstdc++-v3/.editorconfig b/libstdc++-v3/.editorconfig
new file mode 100644
index 00000000000..88107cedda2
--- /dev/null
+++ b/libstdc++-v3/.editorconfig
@@ -0,0 +1,38 @@ 
+# top-most EditorConfig file for libstdc++-v3
+root = true
+
+[*]
+end_of_line = lf
+insert_final_newline = true
+
+[*.h,*.cc]
+charset = utf-8
+indent_style = tab
+indent_size = 2
+tab_width = 8
+trim_trailing_whitespace = true
+
+[Makefile*,ChangeLog*]
+indent_style = tab
+indent_size = 8
+trim_trailing_whitespace = true
+
+[ChangeLog*]
+charset = utf-8
+
+[*.xml]
+charset = utf-8
+indent_size = 2
+tab_width = 8
+trim_trailing_whitespace = true
+
+[*.py]
+indent_style = space
+indent_size = 4
+trim_trailing_whitespace = true
+
+[*.exp]
+indent_style = tab
+indent_size = 4
+tab_width = 8
+trim_trailing_whitespace = true
diff --git a/libstdc++-v3/include/std/.editorconfig b/libstdc++-v3/include/std/.editorconfig
new file mode 100644
index 00000000000..97ca1923cf8
--- /dev/null
+++ b/libstdc++-v3/include/std/.editorconfig
@@ -0,0 +1,10 @@ 
+# Inherit settings from EditorConfig files above this dir.
+root = false
+
+# All files under this directory are C++ headers.
+[*]
+charset = utf-8
+indent_style = tab
+indent_size = 2
+tab_width = 8
+trim_trailing_whitespace = true