bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#36472: 27.0.50; Convey information by showing line numbers using dif


From: Dmitry Gutov
Subject: bug#36472: 27.0.50; Convey information by showing line numbers using different colors?
Date: Mon, 8 Jul 2019 02:46:50 +0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2

On 03.07.2019 19:14, Eli Zaretskii wrote:

There's some misunderstanding here, perhaps mine.  What I wanted to
say is that you may get a relative line-number string such as "-2",
which will probably tell you nothing about the position of that line.

Like I wrote in the example docstring, the hook functions would be called with point temporary changed to the corresponding line's beginning. You didn't like that, so I suggested the position would be passed as a second parameter to the functions. Or it can be a dynamic variable. Whichever option looks best to you.

IOW, a line number is not a good API design in this case, because the
display engine doesn't always know the absolute line number of each
line, whereas your function must have an unambiguous descriptor of the
line's location.

The display engine doesn't, but the display-line-numbers feature clearly does. Knowing line numbers is in its job description.

Or are you hinting at some optimization where, when the style is `relative', it doesn't bother to compute the absolute numbers?

Anyway, it doesn't matter for this particular use case: I only need line-beginning-position, not its absolute number.

Although if we just make a hook that would return a face to use, that
would work just as well for me.

A face would be much easier to use from the display engine, I think.
I assume the face attributes can only specify colors?

Sure. Although some other users of this hook could also want to specify other properties. Maybe we'll want to combine the return values?

Either the calling code would temporarily change point

That's an absolute no-no for the display engine, because such changes
sooner or later leak to userland and cause adverse effects.

OK.

Normally they are changed in after-save-hook. But there is an option
that makes that happen on a timer.

Ouch!  Another performance killer.

That feature already exists, you know. And it updates fringe or margin indicators. People seem to like it. In my limited testing, I haven't observed any major slowdowns.

Redisplay should and does happen, but it tries very hard to determine
which portions of the window actually need to be redrawn.  For some
features, the answer is "the entire window", and that makes redisplay
slower.

So is there an optimization that looks at new overlays, checks that it only has a before-string with a fringe spec, and then only updates the fringe?

My question was how local are the changes caused by this
feature, i.e. could it happen that changes in some place in a buffer
cause changes on display in remote places?

In my case, the hook function would just look up a property on overlays at bol. Thus no far-reaching changes. But it's hard to guarantee, API-wise.

But on that subject, maybe it'd be fine to just document what the
functions on the new hook are allowed and not allowed to do. And then
see if we really have to add actual restrictions to force third-party
code to behave.

I don't know about "allowed".  Would it be reasonable to say don't
switch buffers and/or don't select another window?

Sure, I guess. Though I would like to know why a temporary changes in the current buffer or the selected window would be so bad.

There are also
things you cannot really disallow, because the caller doesn't know
enough about what happens under the hood and doesn't control that.
For example, if the Lisp function calls vertical-motion or
posn-at-point, that invokes display routines, so the code in question
could be re-entered; but how can we tell Lisp programmers "don't call
anything that could call vertical-motion"?  And where to put such
limitations for them to be visible and discoverable enough in the
first place?

I suppose the display code could check for re-entrance (e.g. by setting a variable at the beginning of the redisplay routine) and abort any such attempts with a Lisp-level error. Thus the limitation would be enforced at runtime, which is not perfect, but if the error is intelligible, it shouldn't be hard for a programmer to understand the reasons and change their code.





reply via email to

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