* How to adjust the lexer used by pygments highlighting
@ 2023-01-22 14:30 Simon Sobisch
2023-02-10 17:07 ` Tom Tromey
0 siblings, 1 reply; 2+ messages in thread
From: Simon Sobisch @ 2023-01-22 14:30 UTC (permalink / raw)
To: GDB User Mailing List
The highlighting via pygments actually works quite fine in general, but
in some cases it uses the wrong lexer and then has bad results.
It _seems_ that pygments' "filename (extension) based" language lookup
is not used, because tested files using `pygmentize` are always well
colored, the ones in GDB sometimes use the wrong lexer.
Question: How can we adjust the lexer used by pygments syntax
higlighting in GDB for a given file?
Is it possible to setup a filename extension-based selection when GDB
does not know of the language ("set language " _seems_ to have no effect
on highlighting, but that would only work if the language is known to
GDB)? If not can the "normal" extension list [1] be added to GDB or the
decision which lexer to be used passed on to pygments?
Thank you for any insights,
Simon
[1]: https://pygments.org/languages/
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: How to adjust the lexer used by pygments highlighting
2023-01-22 14:30 How to adjust the lexer used by pygments highlighting Simon Sobisch
@ 2023-02-10 17:07 ` Tom Tromey
0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2023-02-10 17:07 UTC (permalink / raw)
To: Simon Sobisch via Gdb; +Cc: Simon Sobisch
>>>>> "Simon" == Simon Sobisch via Gdb <gdb@sourceware.org> writes:
Simon> The highlighting via pygments actually works quite fine in general,
Simon> but in some cases it uses the wrong lexer and then has bad results.
Simon> It _seems_ that pygments' "filename (extension) based" language lookup
Simon> is not used, because tested files using `pygmentize` are always well
Simon> colored, the ones in GDB sometimes use the wrong lexer.
Simon> Question: How can we adjust the lexer used by pygments syntax
Simon> higlighting in GDB for a given file?
There's no customization to be done here, as far as I know, but the code
is in gdb/python/lib/gdb/styling.py.
Simon> Is it possible to setup a filename extension-based selection when GDB
Simon> does not know of the language ("set language " _seems_ to have no
Simon> effect on highlighting, but that would only work if the language is
Simon> known to GDB)? If not can the "normal" extension list [1] be added to
Simon> GDB or the decision which lexer to be used passed on to pygments?
From what I can see it does appear to use just the filename and not the
current language:
def colorize(filename, contents):
# Don't want any errors.
try:
lexer = lexers.get_lexer_for_filename(filename, stripnl=False)
formatter = get_formatter()
return highlight(contents, lexer, formatter).encode(
gdb.host_charset(), "backslashreplace"
)
except:
return None
We're definitely open to accepting improvements here.
One thing is to be sure you're using pygments and not Source Highlight.
Tom
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-02-10 17:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-22 14:30 How to adjust the lexer used by pygments highlighting Simon Sobisch
2023-02-10 17:07 ` Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).