emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Colorful line numbers


From: Eli Zaretskii
Subject: Re: Colorful line numbers
Date: Fri, 22 Jul 2022 14:42:09 +0300

> From: João Távora <joaotavora@gmail.com>
> Cc: emacs-devel@gnu.org
> Date: Fri, 22 Jul 2022 12:29:59 +0100
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> >> Could we implement one such mechanism?
> > No.  The native line-number display is implemented inside the low
> > level of the display code, and I don't want to call to Lisp from
> > there.  If nothing else, it will slow down redisplay when line numbers
> > are used, whereas avoiding that slowdown was an explicit goal of
> > developing native line-number display.
> 
> Does checking for a given text property on some buffer text call into
> Lisp?  If it isn't, and it's cheap, then this hypothetical feature could
> have very low overhead when not used.

You want the line number to have the same face as the character
displayed immediately after it?  That can be done from C without
calling Lisp, but how would that work reliably?  Any change in the
buffer text will risk breaking the feature.

And even this is already a complication I'd like to avoid: line number
of a line is rendered before we examine the buffer text of the line
(and even know whether there is any text there).  Now we would need to
look forward in the buffer and get text properties of that text.
Which might not work correctly, btw, if jit-lock was not yet invoked
to produce the faces there.  Likewise if the line is hscrolled, so
that the first character displayed to the right of the line number is
not the first character of the physical line.

> Even if you're opposed the idea, could you perhaps some pointers on how
> to implement it, so that I try my hand at it and benchmark the
> before/after?

The implementation is in maybe_produce_line_number in xdisp.c.

> > Why aren't the existing faces enough?  
> 
> I would like to propertize each line number's background with a
> different color based on assembler information.
> 
> This would create a visually cue similar to the one used in Matt
> Godbolt's "Compiler explorer" which works in the browser.  There, you
> have two side-by-side windows of source code, you enter some C code on
> the left and it starts compiling it immediately.  If compilation
> succeeds, it immediately shows the assembly code on the right.  Finally,
> it colorizes the lines with a unique and dynamically determined, color
> based on the assembler code that each line produces when the file
> compiled (according to gcc -g).  The reader can visually match these
> colors in the left and right windeos to see, to some extent, how the
> compiler proceeded.

You can change the colors of the text without affecting the line
numbers.  Line numbers have a distinct face for a good reason.

> I've recently discovered Jay Kamat's most excellent rmsbolt.el.  It is
> is even better than godbolt.org in many aspects but is missing this last
> feature, which I would like to add.  But instead of highlighting the
> whole line, I thought it would be nicer and less distracting if I just
> highlighted the line number's background.

Why not put some indication on the fringe instead?

> > And if they aren't enough, why cannot you use line-number-mode?
> 
> I do use line-number-mode, but I don't understand how it can help me
> here.  AFAIK it shows me one line number at a time in the modeline, not
> besides the text.

Sorry, I meant linum-mode.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]