Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tabs vs space indentation: Add option to detect #13860

Open
Bolpat opened this issue Jul 4, 2023 · 1 comment
Open

Tabs vs space indentation: Add option to detect #13860

Bolpat opened this issue Jul 4, 2023 · 1 comment

Comments

@Bolpat
Copy link

Bolpat commented Jul 4, 2023

Description of the Issue

Notepad++ has a setting to tell if tabs should be replaced by spaces (and if so, by how many). This is great for new files, but bad for existing files that already use the opposite of the setting.

It would be great if Notepad++ could detect:

  • if a file uses tabs or spaces for indentation — and
  • for indentation with spaces, the tabulation width.

It need not be perfect, it just has to guess right in most cases. It’s similar to detection of line endings.

As an example, Visual Studio 2022 has such a detection.

For a suggestion on how to implement this:

  • Use the application’s setting unless the file contains lines which have a tab or 2 spaces as their first characters and all those lines start with the same sequence (1 tab or 2 spaces, not mixed). That determines tabs vs spaces. (Maybe exclude lines that consist of only of white space.)
  • If the tabulation is detected as spaces, guess the tab width as the number of initial spaces of the first line that starts with 2 or more spaces, then round that number down to 2, 4, or 8.

I’d guess it’s important to rule out a tabulation width of 1 space for false positives like (documentation) comments of the form:

/* next line starts with 1 space, but it’s not indented by any notion!
 */
@alankilborn
Copy link
Contributor

Check out the EditorConfig plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants