all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Scrolling jumpy when line-spacing > 0
@ 2017-04-21 10:13 Yuri Khan
  2017-04-21 11:03 ` Yuri Khan
  2017-04-21 14:40 ` Eli Zaretskii
  0 siblings, 2 replies; 8+ messages in thread
From: Yuri Khan @ 2017-04-21 10:13 UTC (permalink / raw
  To: help-gnu-emacs@gnu.org

Hello everybody,

I am trying to configure line-wise scrolling. Basically, I want to
press Ctrl+Up and Ctrl+Down and have Emacs scroll the current window
in the corresponding direction, with point remaining stationary wrt
buffer content.

(defun yk-scroll-up ()
  (interactive)
  (scroll-up 1))
(defun yk-scroll-down ()
  (interactive)
  (scroll-down 1))
(global-set-key (kbd "C-<up>") 'yk-scroll-down)
(global-set-key (kbd "C-<down>") 'yk-scroll-up)

This works so far.

Next, I also want my lines spaced a bit more widely.

(setq line-spacing 0.5)

And this is where I have a problem.

When the window displays what I perceive as an integer number of
lines, and the point is on the bottommost visible line, and I press
C-<down>, I expect the buffer content to scroll one line, and the
point to move one line up wrt the window. However I observe that the
buffer content scrolls almost a whole page, so the point is now on the
topmost visible line.

Minimized recipe:

$ emacs -Q
M-x emacs-version RET
GNU Emacs 24.5.1 (x86_64-pc-linux-gnu, GTK+ Version 3.18.9) of
2016-04-17 on lgw01-04, modified by Debian
M-x view-emacs-news RET
M-x set-variable RET line-spacing RET 0.5 RET
M-x split-window-vertically

Use the mouse to drag the top window’s modeline so that it is
immediately (two pixels or so) after the line, “See files NEWS.23,
NEWS.22, NEWS.21, NEWS.20, NEWS.19, NEWS.18,”.

Position the point on that line, using a mouse click.

M-: (scroll-up 1)

Observed behavior: Point is on the same line and the line is at the
top of window.

Expected behavior: Point is on the same line and the line is second
from the bottom of window. The next line, “and NEWS.1-17 for changes
in older Emacs versions.”, is visible.


The issue is easier to reproduce with larger values of line-spacing.
Basically, as long as the additional spacing of the current line spans
beyond the window, the jump happens.

Does anybody else see this? Is there an easy workaround?



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Scrolling jumpy when line-spacing > 0
  2017-04-21 10:13 Scrolling jumpy when line-spacing > 0 Yuri Khan
@ 2017-04-21 11:03 ` Yuri Khan
  2017-04-21 14:44   ` Eli Zaretskii
  2017-04-21 14:40 ` Eli Zaretskii
  1 sibling, 1 reply; 8+ messages in thread
From: Yuri Khan @ 2017-04-21 11:03 UTC (permalink / raw
  To: help-gnu-emacs@gnu.org

On Fri, Apr 21, 2017 at 5:13 PM, Yuri Khan <yuri.v.khan@gmail.com> wrote:

> M-: (scroll-up 1)
>
> Observed behavior: Point is on the same line and the line is at the
> top of window.
>
> Expected behavior: Point is on the same line and the line is second
> from the bottom of window. The next line, “and NEWS.1-17 for changes
> in older Emacs versions.”, is visible.

OK, here’s what I came up with, as a kludge.

(defun yk-scroll-up-line ()
  (interactive)
  (let ((last-line-start
         (save-excursion
           (goto-char (window-end))
           (forward-line -1)
           (point)))
        (orig-point (point)))
    ;; If in the bottommost visible line, move to a safe place (line up).
    (when (<= last-line-start orig-point)
      (previous-line))
    (scroll-up 1)
    ;; If we were in the topmost line,
    ;; the original point is now outside the view,
    ;; and the point is now on the new topmost line. Leave it there.
    ;; Otherwise, the original point is still visible. Restore it.
    (when (pos-visible-in-window-p orig-point)
      (goto-char orig-point))))



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Scrolling jumpy when line-spacing > 0
  2017-04-21 10:13 Scrolling jumpy when line-spacing > 0 Yuri Khan
  2017-04-21 11:03 ` Yuri Khan
@ 2017-04-21 14:40 ` Eli Zaretskii
  2017-04-21 17:58   ` Yuri Khan
  1 sibling, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2017-04-21 14:40 UTC (permalink / raw
  To: help-gnu-emacs

> From: Yuri Khan <yuri.v.khan@gmail.com>
> Date: Fri, 21 Apr 2017 17:13:32 +0700
> 
> (defun yk-scroll-up ()
>   (interactive)
>   (scroll-up 1))
> (defun yk-scroll-down ()
>   (interactive)
>   (scroll-down 1))
> (global-set-key (kbd "C-<up>") 'yk-scroll-down)
> (global-set-key (kbd "C-<down>") 'yk-scroll-up)
> 
> This works so far.
> 
> Next, I also want my lines spaced a bit more widely.
> 
> (setq line-spacing 0.5)
> 
> And this is where I have a problem.

(Why do people report bugs here, rather than with report-emacs-bug?)

> $ emacs -Q
> M-x emacs-version RET
> GNU Emacs 24.5.1 (x86_64-pc-linux-gnu, GTK+ Version 3.18.9) of
> 2016-04-17 on lgw01-04, modified by Debian
> M-x view-emacs-news RET
> M-x set-variable RET line-spacing RET 0.5 RET
> M-x split-window-vertically
> 
> Use the mouse to drag the top window’s modeline so that it is
> immediately (two pixels or so) after the line, “See files NEWS.23,
> NEWS.22, NEWS.21, NEWS.20, NEWS.19, NEWS.18,”.
> 
> Position the point on that line, using a mouse click.
> 
> M-: (scroll-up 1)
> 
> Observed behavior: Point is on the same line and the line is at the
> top of window.

I can see this in Emacs 24.5 and in Emacs 25, but not on the master
branch.  On the master branch, when you click on the bottom line of
the window, which is only partially visible in the above scenario,
Emacs scrolls the window half-window up.  To be able to put point on
the bottom line, you will need to set window-resize-pixelwise non-nil,
and drag the mode line down pixel by pixel until Emacs lets you put
point there.  Once this happens, "M-: (scroll-up 1) RET" produces the
effect you expected.

What happens in Emacs 25 and older is that Emacs decides that the
window-start is no good and needs to be recomputed.  It then makes
point the window-start point, and that has the effect of a full window
scroll.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Scrolling jumpy when line-spacing > 0
  2017-04-21 11:03 ` Yuri Khan
@ 2017-04-21 14:44   ` Eli Zaretskii
  0 siblings, 0 replies; 8+ messages in thread
From: Eli Zaretskii @ 2017-04-21 14:44 UTC (permalink / raw
  To: help-gnu-emacs

> From: Yuri Khan <yuri.v.khan@gmail.com>
> Date: Fri, 21 Apr 2017 18:03:43 +0700
> 
> OK, here’s what I came up with, as a kludge.
> 
> (defun yk-scroll-up-line ()
>   (interactive)
>   (let ((last-line-start
>          (save-excursion
>            (goto-char (window-end))
>            (forward-line -1)
>            (point)))

Doesn't pos-visible-in-window-p allow you to compute this more
elegantly, without moving point at all?



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Scrolling jumpy when line-spacing > 0
  2017-04-21 14:40 ` Eli Zaretskii
@ 2017-04-21 17:58   ` Yuri Khan
  2017-04-21 18:56     ` Eli Zaretskii
  0 siblings, 1 reply; 8+ messages in thread
From: Yuri Khan @ 2017-04-21 17:58 UTC (permalink / raw
  To: Eli Zaretskii; +Cc: help-gnu-emacs@gnu.org

On Fri, Apr 21, 2017 at 9:40 PM, Eli Zaretskii <eliz@gnu.org> wrote:

> (Why do people report bugs here, rather than with report-emacs-bug?)

To check if that is indeed a bug worth reporting, or if it is already
known, or even already fixed?

> On the master branch, when you click on the bottom line of
> the window, which is only partially visible in the above scenario,
> Emacs scrolls the window half-window up. To be able to put point on
> the bottom line, you will need to set window-resize-pixelwise non-nil,
> and drag the mode line down pixel by pixel until Emacs lets you put
> point there.

Which point is that? When the whole additional spacing is visible?

As a user, I’d expect that additional spacing does not count toward
whether the line is considered visible.

> Once this happens, "M-: (scroll-up 1) RET" produces the
> effect you expected.

Thank you.

> Doesn't pos-visible-in-window-p allow you to compute this more
> elegantly, without moving point at all?

I was in the middle of a $DAYJOB task, and reached for the quickest fix.

But no, not really. On the contrary, I am compelled to add more
kludges^W idiosyncratic code.

There are two special cases. One when the point is initially in the
bottommost visible line whose additional spacing is outside view; in
this case, (scroll-up 1) would cause the jump. This can indeed be
detected with (pos-visible-in-window-p) returning nil.

The other special case is when the point is in the topmost visible
line. In this case, (scroll-up 1) is forced to move the point into
view. The point is moved to the beginning of the new topmost visible
line, even if it was in the middle of the line initially. Here I want
behavior equivalent to (next-line) followed by (scroll-up), i.e. to
keep column position.

I see no practical way to detect this condition without moving point.
The easiest that comes to mind is to check if the position one visual
line up from point is outside view.

Factoring out all relevant special case detection, I end up with this:

(defun yk-scroll--in-bottommost-line ()
  (not (pos-visible-in-window-p)))
(defun yk-scroll--in-topmost-line ()
  (save-excursion
    (let ((line-move-visual t))
      (previous-line))
    (not (pos-visible-in-window-p))))
(defun yk-scroll-up ()
  (interactive)
  (cond
   ((yk-scroll--in-bottommost-line)
    (save-excursion
      (previous-line)
      (scroll-up 1)))
   ((yk-scroll--in-topmost-line)
    (let ((line-move-visual t))
      (next-line))
    (scroll-up 1))
   (t (scroll-up 1))))
(defun yk-scroll-down ()
  (interactive)
  (cond
   ((yk-scroll--in-bottommost-line)
    (previous-line)
    (scroll-down 1))
   (t (scroll-down 1))))



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Scrolling jumpy when line-spacing > 0
  2017-04-21 17:58   ` Yuri Khan
@ 2017-04-21 18:56     ` Eli Zaretskii
  2017-04-21 19:30       ` Yuri Khan
  0 siblings, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2017-04-21 18:56 UTC (permalink / raw
  To: help-gnu-emacs

> From: Yuri Khan <yuri.v.khan@gmail.com>
> Date: Sat, 22 Apr 2017 00:58:08 +0700
> Cc: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
> 
> On Fri, Apr 21, 2017 at 9:40 PM, Eli Zaretskii <eliz@gnu.org> wrote:
> 
> > (Why do people report bugs here, rather than with report-emacs-bug?)
> 
> To check if that is indeed a bug worth reporting, or if it is already
> known, or even already fixed?

All of these are good enough reasons to post to the bug tracker.  The
chances that people who subscribe to the bug list will quickly point
you to the solution or a similar bug report, if they exist, are way
higher than hearing that here.

> > On the master branch, when you click on the bottom line of
> > the window, which is only partially visible in the above scenario,
> > Emacs scrolls the window half-window up. To be able to put point on
> > the bottom line, you will need to set window-resize-pixelwise non-nil,
> > and drag the mode line down pixel by pixel until Emacs lets you put
> > point there.
> 
> Which point is that? When the whole additional spacing is visible?

Yes.

> As a user, I’d expect that additional spacing does not count toward
> whether the line is considered visible.

The Emacs display engine was designed to avoid having point in a
partially visible line, for whatever reasons.  The code which checks
for partial visibility doesn't care what is in the invisible part,
because checking for that would take non-trivial processing, and the
subtlety isn't important enough to slow down redisplay.

> > Doesn't pos-visible-in-window-p allow you to compute this more
> > elegantly, without moving point at all?
> 
> I was in the middle of a $DAYJOB task, and reached for the quickest fix.
> 
> But no, not really. On the contrary, I am compelled to add more
> kludges^W idiosyncratic code.

Actually, I understand the answer is YES for the purpose for which you
wrote the code on which I commented, except that there are additional
situations which you need to handle, where yet more code is called
for.

> The other special case is when the point is in the topmost visible
> line. In this case, (scroll-up 1) is forced to move the point into
> view. The point is moved to the beginning of the new topmost visible
> line, even if it was in the middle of the line initially. Here I want
> behavior equivalent to (next-line) followed by (scroll-up), i.e. to
> keep column position.
> 
> I see no practical way to detect this condition without moving point.

Doesn't posn-at-point allow you to find out whether point is in the
topmost window line?  (Caveat: this could require special
consideration when there's a non-nil header-line-format in the
window.)



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Scrolling jumpy when line-spacing > 0
  2017-04-21 18:56     ` Eli Zaretskii
@ 2017-04-21 19:30       ` Yuri Khan
  2017-04-22  7:38         ` Eli Zaretskii
  0 siblings, 1 reply; 8+ messages in thread
From: Yuri Khan @ 2017-04-21 19:30 UTC (permalink / raw
  To: Eli Zaretskii; +Cc: help-gnu-emacs@gnu.org

On Sat, Apr 22, 2017 at 1:56 AM, Eli Zaretskii <eliz@gnu.org> wrote:

>> > (Why do people report bugs here, rather than with report-emacs-bug?)
>>
>> To check if that is indeed a bug worth reporting, or if it is already
>> known, or even already fixed?
>
> All of these are good enough reasons to post to the bug tracker.

Okay.

>> As a user, I’d expect that additional spacing does not count toward
>> whether the line is considered visible.
>
> The Emacs display engine was designed to avoid having point in a
> partially visible line, for whatever reasons.  The code which checks
> for partial visibility doesn't care what is in the invisible part,
> because checking for that would take non-trivial processing, and the
> subtlety isn't important enough to slow down redisplay.

How come Emacs 24 lets me put point in that partially fully visible
line? Was something simplified between 24 and master?

To me, that kind of subtlety is important. Not that important to cry
regression, but important enough to wonder if I could afford the
slowdown. I’m even mildly bothered by the fact that spacing is
conceptually below its line; I’d find it nicer if half of it was
above.

>> The other special case is when the point is in the topmost visible
>> line.
>> […]
>> I see no practical way to detect this condition without moving point.
>
> Doesn't posn-at-point allow you to find out whether point is in the
> topmost window line?  (Caveat: this could require special
> consideration when there's a non-nil header-line-format in the
> window.)

Maybe. Maybe not. On the one hand, I do have a non-nil
header-line-format at all times. (For tabbar-mode.) On the other hand,
when I evaluate (posn-at-point) with point in the topmost window line,
I get zero Y and ROW values. It is not immediately clear if I can rely
on that.

On the third hand, using motion relative to the point is immediately
clear. What’s the downside? Is it going to be slow? Slow enough to be
noticeable at a key repeat rate of 40 Hz?



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Scrolling jumpy when line-spacing > 0
  2017-04-21 19:30       ` Yuri Khan
@ 2017-04-22  7:38         ` Eli Zaretskii
  0 siblings, 0 replies; 8+ messages in thread
From: Eli Zaretskii @ 2017-04-22  7:38 UTC (permalink / raw
  To: help-gnu-emacs

> From: Yuri Khan <yuri.v.khan@gmail.com>
> Date: Sat, 22 Apr 2017 02:30:25 +0700
> Cc: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
> 
> >> As a user, I’d expect that additional spacing does not count toward
> >> whether the line is considered visible.
> >
> > The Emacs display engine was designed to avoid having point in a
> > partially visible line, for whatever reasons.  The code which checks
> > for partial visibility doesn't care what is in the invisible part,
> > because checking for that would take non-trivial processing, and the
> > subtlety isn't important enough to slow down redisplay.
> 
> How come Emacs 24 lets me put point in that partially fully visible
> line? Was something simplified between 24 and master?

Not simplified, fixed.  What Emacs 24 and 25 did caused
display-related bugs in some cases, and those bugs were fixed in v26.

> To me, that kind of subtlety is important. Not that important to cry
> regression, but important enough to wonder if I could afford the
> slowdown.

You could perhaps afford the slowdown, but you (and the rest of us)
couldn't afford the bugs.

> I’m even mildly bothered by the fact that spacing is conceptually
> below its line; I’d find it nicer if half of it was above.

Patches to make spacing display like that are welcome.

> > Doesn't posn-at-point allow you to find out whether point is in the
> > topmost window line?  (Caveat: this could require special
> > consideration when there's a non-nil header-line-format in the
> > window.)
> 
> Maybe. Maybe not. On the one hand, I do have a non-nil
> header-line-format at all times. (For tabbar-mode.) On the other hand,
> when I evaluate (posn-at-point) with point in the topmost window line,
> I get zero Y and ROW values. It is not immediately clear if I can rely
> on that.

You can rely on that.  Reporting these values reliably is that
function's sole purpose, so if it doesn't, it's a bug that should be
reported.

If all you care about is whether point is in the first screen line of
the window, and if you don't need to support too old Emacs versions
(where AFAIR there was some inconsistency wrt the first line's
coordinates), then the existence of header-line is not an issue for
you, and you should have no reason to avoid that function and roll
your own, because your own code will have similar subtleties, which
posn-at-point is supposed to have solved already.

> On the third hand, using motion relative to the point is immediately
> clear. What’s the downside? Is it going to be slow? Slow enough to be
> noticeable at a key repeat rate of 40 Hz?

The main downside is that you might expose the motion to the user
under some circumstances, like C-g or some position-related hooks.  It
is also slower, yes (because posn-at-point is implemented entirely in
C and doesn't involve the Lisp interpreter).



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2017-04-22  7:38 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-04-21 10:13 Scrolling jumpy when line-spacing > 0 Yuri Khan
2017-04-21 11:03 ` Yuri Khan
2017-04-21 14:44   ` Eli Zaretskii
2017-04-21 14:40 ` Eli Zaretskii
2017-04-21 17:58   ` Yuri Khan
2017-04-21 18:56     ` Eli Zaretskii
2017-04-21 19:30       ` Yuri Khan
2017-04-22  7:38         ` Eli Zaretskii

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.