public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: Simon Sobisch via Gdb <gdb@sourceware.org>
Cc: Simon Sobisch <simonsobisch@gnu.org>
Subject: Re: How to adjust the lexer used by pygments highlighting
Date: Fri, 10 Feb 2023 10:07:32 -0700	[thread overview]
Message-ID: <87fsbdxxd7.fsf@tromey.com> (raw)
In-Reply-To: <9aa7a6cf-93f8-3a96-c99f-3f9a71e41333@gnu.org> (Simon Sobisch via Gdb's message of "Sun, 22 Jan 2023 15:30:19 +0100")

>>>>> "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

      reply	other threads:[~2023-02-10 17:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-22 14:30 Simon Sobisch
2023-02-10 17:07 ` Tom Tromey [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87fsbdxxd7.fsf@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb@sourceware.org \
    --cc=simonsobisch@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).