Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Point jumps around screen when the pop-up appears #1336

Closed
jaouadmourtada opened this issue Aug 8, 2022 · 12 comments
Closed

Point jumps around screen when the pop-up appears #1336

jaouadmourtada opened this issue Aug 8, 2022 · 12 comments

Comments

@jaouadmourtada
Copy link

Hi,

I have been getting a strange bug with Company lately (it started about a few months ago, but has recently started to become unbearable).

The behavior can be seen on the caption attached HERE: bug; the output of the command M-x company-diag (in particular, my current setup) is given below.

Roughly speaking, in some circumstances, when the Company pop-up appears, the cursor suddenly moves around the buffer. This makes editing impossible and I have to turn off company when this happens.
I should mention that this occurs mainly when the current point is about at the middle of the buffer vertically.

I mainly use Emacs in Auctex-mode, and this is where the described issue occurs.

Thank you very much for your contribution to Company and for your help in this issue. I'd be happy to provide further details or perform some tests.

In the meantime, any "hot fix" would be really appreciated, such as how to disable the pop-up (but keep the one-line autocompletion).

Best wishes,
J

Output of the command M-x company-diag

Emacs 28.1 (aarch64-apple-darwin21.1.0) of 2022-05-11 on armbob.lan
Company 0.9.13

company-backends: ((company-auctex-macros company-auctex-symbols company-auctex-environments)
company-auctex-bibs company-auctex-labels company-bbdb company-semantic company-cmake company-capf company-clang company-files
(company-dabbrev-code company-gtags company-etags company-keywords)
company-oddmuse company-dabbrev)

Used backend: company-dabbrev
Major mode: latex-mode
Prefix: ""

Completions:
[skipped for brevity; contains a list of 2000+ words]

@dgutov
Copy link
Member

dgutov commented Aug 9, 2022

Hi!

Company 0.9.13

Is that the version installed from GNU ELPA?

If so, any change you could try the development version first? You can install it from MELPA.

@jaouadmourtada
Copy link
Author

Hi!
The version I have is Company 20220731.2333 from MELPA.

@jaouadmourtada
Copy link
Author

Hi!
Just a quick update: after doing a few tests, this behavior does not seem to come from Company itself: it only appears when global-linum-mode is activated.
So I don't know to which extent this issue is within the scope of company itself, rather it is due to the interaction between the company pop-up and linum-mode.

@jaouadmourtada
Copy link
Author

jaouadmourtada commented Aug 9, 2022

So since the issue in my case was due to interaction with linum-mode, and since auto-completion is (to me) much more useful than displaying line numbers, a simple fix was to simply de-activate linum-mode.

Besides, linum-mode leads to other performance issues (for instance, when used together with folding), and also seems to be somewhat deprecated: this page https://www.emacswiki.org/emacs/LineNumbers suggests that "display-line-numbers-mode" is the favored line numbering mode for newer versions of emacs.

All of this to say that there may not be any "issue" to be fixed. Perhaps one could add a warning somewhere that linum-mode interacts badly with company (leading to the pointer jumping around screen), and suggest either to ditch line numbering or to opt for display-line-numbers-mode.

For the record, my linum configuration was:
(global-linum-mode t)
(setq linum-format "%3d")

@dgutov
Copy link
Member

dgutov commented Aug 9, 2022

Interesting. Have you tried display-line-numbers-mode instead? It's available since Emacs 27.

@dgutov
Copy link
Member

dgutov commented Aug 9, 2022

(setq display-line-numbers-width 3) should correspond to the above value of linum-format.

@jaouadmourtada
Copy link
Author

Indeed this fixes the issue. Thanks!

@dgutov
Copy link
Member

dgutov commented Aug 10, 2022

Glad you got this working better. 👍

Now, I wouldn't mind actually to look into fixing this for linum, or at least to dig deeper first: maybe it's something that would affect other features/modes/etc, just in rare cases that are annoying to reproduce and consequently go unreported. If it's something tricky and linum-specific, then probably not.

Anyway, if you sometime manage to write down a step-by-step repro how to reproduce this, with specific file, and attach it here (the file and the steps), I'll be sure to take a look.

No hurry anyway. :-)

@jaouadmourtada
Copy link
Author

Sure!

Here is a setup where it appears in my case:

With this init file (put in .txt as github does not accept .el)
init.txt

and this sample text file:
sample.txt

Instructions:
open the "sample" text file, and go to the portion with "%%%".
Then, center vertically (C-l).
Then, start typing a word starting with "con".
At this point, the cursor should jump across screen.
With these steps, this is what I get:
jump

===
Output of the command M-x company-diag:
Emacs 28.1 (aarch64-apple-darwin21.1.0) of 2022-05-11 on armbob.lan
Company 0.9.13

company-backends: (company-bbdb company-semantic company-cmake company-capf company-clang company-files
(company-dabbrev-code company-gtags company-etags company-keywords)
company-oddmuse company-dabbrev)

Used backend: company-dabbrev
Major mode: text-mode
Prefix: ""
Completions:
.....

@dgutov
Copy link
Member

dgutov commented Aug 12, 2022

Thanks! For future reference: any unnecessary step in your reproduction scenario (like aggressive-indent-mode or visual-line-mode) means I end up spending extra time making sure they are not the culprit.

Anyway, it does seem specifc to linum-mode. I've tinkered with this for a whole but haven't managed to dig deep enough to figure out the exact problem. But it installs after-modification (and other) hooks which work by inserting overlays with before-string property. There are other conditions for the bug to occur, like the window to be short enough: apparently that forces its scrolling during redisplay, and that, in turn, moves point.

To compare to a similar package which also uses margins, I installed nlinum, a later, apparently more efficient incarnation of this package. The difference is it performs this work during fontification instead. And it doesn't seem to trigger the problem.

So, after all, I simply recommend to use either of the alternatives: display-line-numbers-mode or nlinum. The former is said to be the fastest option, but I have no personal experience to back that claim.

@jaouadmourtada
Copy link
Author

That sounds good, thanks!
I can confirm that nlinum works. It also has the advantage of having the same appearance as linum, whereas display-line-numbers-mode takes up a bit more space.

@monnier
Copy link
Contributor

monnier commented Aug 26, 2022

If so, any change you could try the development version first? You can install it from MELPA.

Of course, you can also install it from GNU-devel ELPA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants