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

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

bug#28844: 26.0.90; display-line-numbers-mode should call window-configu


From: Eli Zaretskii
Subject: bug#28844: 26.0.90; display-line-numbers-mode should call window-configuration-change-hook
Date: Sun, 15 Oct 2017 17:47:52 +0300

> Date: Sun, 15 Oct 2017 14:12:30 +0200
> From: martin rudalics <rudalics@gmx.at>
> Cc: 28844@debbugs.gnu.org
> 
> You could use ‘window-scroll-functions’ (remembering the old line number
> widths) for scrolling but this would not handle simple point movements.

Simple point movements (for some value of "simple") don't affect the
width used for line numbers.

> Eli will decide what to do.

I actually don't understand why a hook is needed.  If a Lisp
application wants/needs to be sensitive to the width of the
line-number display, it should simply call line-number-display-width
each time it needs to know the value.  This function is guaranteed to
return zero when display-line-numbers is nil, and it's also guaranteed
(barring bugs ;-) to return the exact same value as what the display
engine will use, provided that the window-start doesn't move between
the call to line-number-display-width and when you need to use the
value.  So it will correctly reflect any changes in the width used for
the line numbers.

What am I missing?

>                           If an existing hook must be chosen, I'd
> rather (mis-)use ‘window-size-change-functions’ - strictly spoken,
> display of line numbers never affects the size of windows (something
> which is not true vice-versa IIUC).

Precisely.  Which IMO makes window-size-change-functions inappropriate
for this purpose.

> But better, provide a separate hook like
> ‘line-number-width-changed-functions’ with the corresponding window
> as argument (and maybe the old line number width as second).

I have hard time imagining how to implement such a hook (or any hook
which needs to be called "when the width changes").  You see, the
display engine doesn't know that the width changed -- it computes the
required width once, when it's about to redisplay a window, keeps the
computed value only as long as it needs to display that window, and
doesn't store it anywhere where it would survive until the next
redisplay.  So implementing such a hook would need some non-trivial
changes, because the previous width will have to be stored in the
window object, and we will need to manage that stored value (e.g.,
invalidate it when we switch buffers in a window).

Moreover, hooks that are to be called by the display engine are
usually a bad idea if they are to be used to affect redisplay, because
they more often than not require an immediate additional cycle of
redisplay, which makes Emacs sluggish.

I provided the line-number-display-width function in the hope that it
will serve any Lisp program that needs to be sensitive to the screen
estate taken by line numbers.  If it somehow doesn't fit this bill,
please tell why, maybe it should be extended.





reply via email to

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