Bug 498518

Summary: Kate status bar doesn't notice when the language is changed with a modeline
Product: [Applications] kate Reporter: Piotr Doroszewski <piotrekd>
Component: generalAssignee: KWrite Developers <kwrite-bugs-null>
Status: RESOLVED NOT A BUG    
Severity: normal CC: christoph, waqar.17a
Priority: NOR    
Version First Reported In: 24.12.0   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: a screenshot

Description Piotr Doroszewski 2025-01-11 07:22:33 UTC
SUMMARY
When a file with a modeline (a rarely mentioned feature of Kate BTW) is opened, the language used for syntax highlighting is set properly, but the status bar keeps the automatically detected one.

Moreover, when the user sets the language via the menu shown after clicking the status bar element, the syntax highlighting mechanism switches to the one I chose, but after saving the file with a(n already existent) language-setting modeline, it's switched to that (previous) one, but the status bar still shows the one chosen by the user.


STEPS TO REPRODUCE
1.  Create a file with an extension known to Kate (e.g., `test.md`).
2. Add a modeline with another language (e.g., `// kate: syntax C`)
3. Hit Ctrl+S.

OBSERVED RESULT
The syntax highlighting starts using the language defined by the modeline (e.g., C), but the status bar stays the same.

EXPECTED RESULT
The status bar should show the language really used to highlight the text, one way or another.

OPTIONAL FURTHER STEPS
4. Reopen the same file in Kate.

SOFTWARE/OS VERSIONS
Kate version: 24.12.0
KDE Frameworks version: 6.9.0
Qt version: 6.8.1

ADDITIONAL INFORMATION
I didn't test the behavior of LSP when a modeline is used, it may also cause bugs. I also didn't test KWrite and KDevelop.

The modeline feature, if it's still there, could be advertised a little more than in a 2006 blog post.
Comment 1 Piotr Doroszewski 2025-01-11 07:28:58 UTC
Created attachment 177276 [details]
a screenshot

I forgot to upload a screenshot from a real-life situation – probably not too frequent in a case like this – an ERB script used to generate a Typst document (in this case, my résumé) in different variants. Since there is more Typst than Ruby in here, I prefer to have Typst syntax highlighting despite the `.erb` extension.
Comment 2 Waqar Ahmed 2025-01-30 07:20:12 UTC
It will work if you write:

// kate: mode C

So, I think its working as intended atm. 

However, I think The mode/highlighting difference in Kate is just unnecessary complexity. It just confuses users including myself
Comment 3 Christoph Cullmann 2025-02-03 19:09:04 UTC
It works as expected, the split in mode and highlighting api and ui wise in perhaps not perfect, but altering that might break more stuff than keeping it as is.