Subject: bug#54488: 29.0.50; move-to-column/overlay-related regression in latest master, perhaps 28?

From: João Távora <[email-masked]>
Date: Mon, 21 Mar 2022 06:54:46 +0000

Hello maintainers,

This bug I'm about to describe originated in
https://github.com/joaotavora/eglot/issues/860.  I reproduced it with:

* GNU Emacs 29.0.50 (build 2, x86_64-pc-linux-gnu) commit 88d474308e2
* company-mode, a not-too-recent version (but most recent is the same)
* the clangd LSP server 13.0.1
* Eglot d5c7c40bc

We are reasonably sure the bug is in Emacs and is a regression from
Emacs 27.2.  The bug has been "defensively" worked around in the Eglot
in its commit f775187115.

In short, it seems that in the presence of the overlays created by
company-mode and in presence of a narrowing, the move-to-column function
does not function the way it used to.

It should certainly be possible to reproduce the problem without the
reasonably complex Eglot setup, but for the time being this is all I
have.
    
  ~/Source/Emacs/emacs/src/emacs -Q -f package-initialize -L       \
  ~/Source/Emacs/company-mode -l company -f global-company-mode -l \
   eglot.el ~/tmp/issue-860/args_out_of_range.c -f eglot -f        \
   display-line-numbers-mode -f toggle-debug-on-error

Here's the args_out_of_range.c file.

  1 // args_out_of_range.c
  2 struct Book {
  3   int id;
  4   char title[50]
  5 } book = { 1024, "C" };
  6
  7 int main(int argc, char *argv[])
  8 {
  9
 10   // Error when typing the dot to make "book."
 11   book
 12   return 0;
 13 }

When one types the dot after the "book" on line 11, company-mode
displays a two-line overlay that visually encompasses line 12 after
"book", which has the "return 0;" statement.  That line happens to
also hold a warning about incorrect syntax, one that starts at column
2.

Eglot uses 'move-to-column' to go that precise place and highlight the
warning.

In Emacs 27.2, move-to-column is unaffected by previous company-mode
overlays, even if the current line is being co-used visually by the
overlay.  It moves to the right buffer position.

In Emacs master, this isn't true.  It seems to be confounded by the
company-mode overlay and moves to eob, _beyond the narrowing_, which
eventually breaks Eglot with a backtrace such as this one:

Debugger entered--Lisp error: (args-out-of-range #<buffer args_out_of_range.c> 110 124)
  encode-coding-region(110 124 utf-16 t)

Thanks for your time,
João