Subject: 28.0.50; Automatic hscroll does not consider line numbers when checking hscroll-margin, causing point to get stuck in the margin when using a small hscroll-step
From: Leonardo Dagnino <[email-masked]>
To: [email-masked]
Date: Thu, 5 Aug 2021 00:32:25 -0300
List-Id: <debbugs-submit.debbugs.gnu.org>

Steps to reproduce in emacs -Q:
(display-line-numbers-mode)
(setq truncate-lines t
  hscroll-step 1)
(insert-char ?a 200)

Then press left arrow until point gets in hscroll-margin. The point
will be inside the margin, at buffer's column hscroll-margin minus
display-line-numbers's current width. Even pressing right arrow still
has point inside the margin, triggering the bug again, making it
"stuck" at that column.

Also happens when lines are truncated because of
`truncate-partial-width-windows'.

Slightly different cases where this bug occurs (tested by setting
display-line-numbers-width to the desired line-number-display-width):
- In emacs -Q, it will work as expected if line-number-display-width
>= hscroll-margin -1 (example: 7 and 8, respectively). However it is
still buggy on my personal init.el, point gets briefly (maybe about
0.1s?) drawn on the rightmost column of the line number (the one that
usually never has anything on it, right before the buffer's text
starts). Maybe it's because with emacs -Q this second draw happens so
fast the first one is not visible?
- gets stuck in hscroll-margin if line-number-display-width <
hscroll-margin - 2 (example: 5 and 8, respectively)
- when line-number-display-width == hscroll-margin - 2, alternates
between "stuck in the margin" and "hscroll-margin columns from window
edge" every time you press the left arrow (example: 6 and 8).

In GNU Emacs 28.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
3.24.30, cairo version 1.17.4)
 of 2021-08-04 built on shinsou
Repository revision: 4b729ff60887f2de320a99cf1fb4c734d1145b00
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12013000
System Description: Arch Linux

Configured using:
 'configure --prefix=/usr --sysconfdir=/etc --libexecdir=/usr/lib
 --localstatedir=/var --mandir=/usr/share/man --with-gameuser=:games
 --with-sound=alsa --with-modules --without-gconf --without-gsettings
 --enable-link-time-optimization --with-x-toolkit=gtk3 --without-xaw3d
 --without-compress-install
 '--program-transform-name=s/\([ec]tags\)/\1.emacs/'
 'CFLAGS=-march=x86-64 -mtune=generic -O2 -pipe -fno-plt -fexceptions
 -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security
 -fstack-clash-protection -fcf-protection -flto -fuse-linker-plugin'
 LDFLAGS=-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM HARFBUZZ JPEG JSON LCMS2
LIBOTF LIBSYSTEMD LIBXML2 M17N_FLT MODULES NOTIFY INOTIFY PDUMPER PNG
RSVG SECCOMP SOUND THREADS TIFF TOOLKIT_SCROLL_BARS X11 XDBE XIM XPM
GTK3 ZLIB

Important settings:
  value of $LC_MONETARY: pt_BR.UTF-8
  value of $LC_NUMERIC: pt_BR.UTF-8
  value of $LC_TIME: pt_BR.UTF-8
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  display-line-numbers-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message rmc puny dired dired-loaddefs
rfc822 mml mml-sec epa derived epg epg-config gnus-util rmail
rmail-loaddefs auth-source cl-seq eieio eieio-core cl-macs
eieio-loaddefs password-cache json map text-property-search mm-decode
mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader
sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils
time-date subr-x cl-extra seq byte-opt gv bytecomp byte-compile cconv pp
cl-print help-fns radix-tree help-mode cl-loaddefs cl-lib
display-line-numbers iso-transl tooltip eldoc electric uniquify
ediff-hook vc-hooks lisp-float-type mwheel term/x-win x-win
term/common-win x-dnd tool-bar dnd fontset image regexp-opt fringe
tabulated-list replace newcomment text-mode elisp-mode lisp-mode
prog-mode register page tab-bar menu-bar rfn-eshadow isearch easymenu
timer select scroll-bar mouse jit-lock font-lock syntax font-core
term/tty-colors frame minibuffer cl-generic cham georgian utf-8-lang
misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms
cp51932 hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese composite charscript charprop case-table epa-hook
jka-cmpr-hook help simple abbrev obarray cl-preloaded nadvice button
loaddefs faces cus-face macroexp files window text-properties overlay
sha1 md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote threads dbusbind inotify lcms2
dynamic-setting font-render-setting cairo move-toolbar gtk x-toolkit x
multi-tty make-network-process emacs)

Memory information:
((conses 16 374670 144142)
 (symbols 48 26281 2)
 (strings 32 100311 5337)
 (string-bytes 1 3452695)
 (vectors 16 51112)
 (vector-slots 8 1507408 148478)
 (floats 8 756 670)
 (intervals 56 8951 4879)
 (buffers 992 25))