Bug 474505

Summary: Kate auto-detects unsuitable indentation
Product: [Applications] kate Reporter: Ingo Klöcker <kloecker>
Component: indentationAssignee: KWrite Developers <kwrite-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: christoph, waqar.17a
Priority: NOR    
Version First Reported In: 23.08.0   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed/Implemented In: 6.4.0
Sentry Crash Report:
Attachments: Markdown file for which Kate auto-detects indentation width 7

Description Ingo Klöcker 2023-09-13 20:59:42 UTC
Created attachment 161612 [details]
Markdown file for which Kate auto-detects indentation width 7

For the attached file Kate auto-detects an indentation of 7. I think it shouldn't assume any indentation width for this file and instead use the default.

STEPS TO REPRODUCE
1. Enable "Automatically detect file indentation"
2. Open the attached file

OBSERVED RESULT
Kate automatically sets indentation to 7. Shows "Soft Tabs: 7 (4)" in the status bar.

EXPECTED RESULT
Kate uses standard indentation, i.e. 4.

Even though the file ends with many lines which seem to suggest an indentation of 7, there are many other lines which suggest indentations of 4, 12, 32. I think, in case of an indentation histogram with multiple peaks without a common divisor, Kate shouldn't assume a non-standard indentation. Or it should switch from fixed width indentation to "smart indentation" (i.e. indentation based on the next non-empty line above the cursor).
Comment 1 Waqar Ahmed 2023-09-14 06:19:21 UTC
I think it's best that we switch off auto-detect for md files as it's rather arbitrary what it can contain and detecting indent make a lot of sense in md files.
Comment 2 Christoph Cullmann 2024-03-23 22:08:10 UTC
Hmm, the question is if we ever should detect indents that are not even a multiple of 2.
Comment 3 Christoph Cullmann 2024-06-18 18:56:49 UTC
Git commit 0662c13838970f25e57c6af986b561619b840427 by Christoph Cullmann.
Committed on 18/06/2024 at 18:56.
Pushed by cullmann into branch 'master'.

prefer even indent sizes

only guess non-even ones if there are no even matches

A  +402  -0    autotests/input/indent_detect/bogus7spaces.md
M  +1    -0    autotests/src/indentdetect_test.cpp
M  +5    -5    src/utils/kateindentdetecter.cpp

https://invent.kde.org/frameworks/ktexteditor/-/commit/0662c13838970f25e57c6af986b561619b840427