Bug 512587

Summary: Syntax highlighting breaks with listings-package if language defined while starting the environment
Product: [Applications] kile Reporter: Ville Aakko <ville.aakko>
Component: editorAssignee: Michel Ludwig <michel.ludwig>
Status: REPORTED ---    
Severity: normal    
Priority: NOR    
Version First Reported In: master   
Target Milestone: ---   
Platform: Arch Linux   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: A simple test case

Description Ville Aakko 2025-11-25 10:00:45 UTC
Created attachment 187153 [details]
A simple test case

SUMMARY

Syntax highlighting breaks when using the listings -package, if a language is defined when starting the environment. I.e. `\begin{lstlisting}[language=python]` will cause all syntax highlighting to be gray afterwards for the whole remainder of the document, despite the document being syntactically valid.

As a workaround, one could use \lstset{language=python} instead.

STEPS TO REPRODUCE

1. Load the example document in KILE.
2. Look at syntax highlighting

OBSERVED RESULT

Syntax highlighting will fail / be disabled from the start of the \begin{lstlisting} until the end of the document (text is grey).

EXPECTED RESULT

Syntax highlighting should work.

SOFTWARE/OS VERSIONS
Operating System: Arch Linux 
KDE Plasma Version: 6.5.3
KDE Frameworks Version: 6.20.0
Qt Version: 6.10.0
Kernel Version: 6.16.5-zen1-1-zen (64-bit)
Graphics Platform: X11
Processors: 16 × AMD Ryzen 7 PRO 5850U with Radeon Graphics
Memory: 16 GiB of RAM (11.5 GiB usable)
Graphics Processor: AMD Radeon Graphics

kile-git (3.0b4_r3843.g28ec5acd-1)

ADDITIONAL INFORMATION

- The actual language set seems irrelevant and will fail, as long as a valid language is set (an invalid language will, of course, cause compilation to fail, but syntax highlighting will still work in Kile). 
- (Any?) other key=value pairs is set in a similar way will not cause syntax highlighting to fail
Comment 1 Ville Aakko 2025-11-25 10:25:49 UTC
I've also noticed putting the language inside braces, which is needed if giving an optional keyword argument (such as a dialect), e.g. `\begin{lstlisting}[language={[3]python}]`, or just language={R}, breaks in a slightly different, but less annoying way. Now only the rest of the line will be marked as "invalid" (red, underlined) but at least syntax highlighting will work (Kile will pick up the \end{lstlisting} and resume syntax highlighting correctly).