Closed erikdubois closed 3 months ago
This is something I wanted to do for some time since the indentation of code seems so to be quite inconsistent (I assume because of the patches). Perhaps you could use the tool indent
(maybe with some arguments) to automatically format all the source files. I would also assume that the config file needs some manual tweaking, especially the comments. Some variables also need to be renamed so they are on the same case (for example, new_window_attach_on_end
to newwindowattachonend
) and the code should also be populated with comments so that we know where each patch is located in the code. These could all be separate PRs though.
We can also agree to use visual studio code (or something else) and choose between extensions and have a uniform layout/indentation that way
To use the indent
command to apply a universal indentation style to all your files, you can use it with the appropriate options to match your desired coding style. Here's an example of how to use the indent
command to format a file and some common options you might want to use:
indent filename.c
This command will format the file filename.c
according to the default style.
Here are some common options you might use to customize the formatting:
-kr
: Use Kernighan & Ritchie style.-gnu
: Use GNU style.-iN
: Set indentation level to N spaces.-nut
: Use spaces instead of tabs.-tsN
: Set tab size to N spaces.-br
: Put braces on the same line as control statements.To apply a universal indent style, such as the GNU style with 4-space indentation and no tabs, you would use:
indent -gnu -i4 -nut -ts4 filename.c
To apply this to all your C source files in the current directory, you can use a loop or find command in your shell:
for file in *.c; do
indent -gnu -i4 -nut -ts4 "$file"
done
find
find . -name '*.c' -exec indent -gnu -i4 -nut -ts4 {} \;
If you want to avoid typing the options every time, you can create a configuration file named .indent.pro
in your home directory or the root of your project:
.indent.pro
Content-gnu
-i4
-nut
-ts4
Once you have the .indent.pro
file set up, you can simply run:
indent filename.c
Or to apply it to all C files:
for file in *.c; do
indent "$file"
done
Or:
find . -name '*.c' -exec indent {} \;
By using the indent
command with appropriate options or a configuration file, you can ensure a consistent indentation style across all your files. The provided examples show how to apply the formatting to individual files or all files in a directory.
I guess you need to decide how you want your code to become
new_window_attach_on_end
I would prefer keeping the underscores for readability
only 4 references
we can decide on indentation maybe at the end when we have merged more code into your github if you are willing to accept more code?
idea : shall we open up discussions on your github of chadwm to be able to communicate faster/better
maybe this one ?
indent -kr -i4 -ts4 drw.c
idea : shall we open up discussions on your github of chadwm to be able to communicate faster/better
Checking code for spaces and tabs