|
From: | Herman |
Subject: | bug#67514: 30.0.50; completion preview symbol length calculation should use point |
Date: | Wed, 29 Nov 2023 00:17:42 +0100 |
Eshel Yaron <me@eshelyaron.com> writes:
Géza Herman <geza.herman@gmail.com> writes:There is a thing which maybe can be improved (so this is not a bugreport, just a suggestion): it's how completion-preview-require-minimum-symbol-length calculates thelength. Currently it just returns the length of the symbol under the cursor. I think it would be better to use the length of the part that actually will be used for completion, because if the point is inside a word, then it should only consider the part between the symbol startend the point.Could you please explain why you consider that preferable? The current behavior is intentional and, unless I'm missing something, correct. `completion-at-point-functions` take into account text that follows point as well as the text that precedes point, and Completion Preview mode works also when you're typing in the middle of a symbol. Forexample, consider the following text in an Elisp buffer:--8<---------------cut here---------------start------------->8---(minor--8<---------------cut here---------------end--------------->8---With point between the opening parenthesis and the letter "m", type "define-". The completion preview displays "-mode" just after "minor", suggesting that you complete to "define-minor-mode". That's because thetext after point ("minor", in this case) plays a role too.
I didn't know about this behavior, it makes sense how it works in emacs-lisp-mode. I tried this feature with lsp-mode (using the clangd language server), and it doesn't play this nicely.
Suppose that you have this C code: --8<---------------cut here---------------start------------->8--- int main() { int longVariableName = 0; VariableName = 1; } --8<---------------cut here---------------end--------------->8---And the point is at the first character at VariableName. Now, pressing "l" will preview longVariableName, but it doesn't do anything with VariableName, so the buffer looks like l(ongVariableName)VariableName (parentheses are not part of the text, I used them to mark the greyed out part).
My suggestion doesn't fix this, it just postpones this problem until I write "lon", and then the same thing will happen. The reason that I suggested this is that I use evil-mode, and I put evil-insert to completion-preview-commands. So whenever I enter insert mode, preview could happen. And a lot of cases, I enter insert mode while the point is at the beginning of some word. So with my suggestion, preview won't be happening, if the point is at the beginning of the word. But currently when I enter insert mode, a random preview will be presented, because completion uses an empty string. Perhaps this is what makes the difference? While emacs-lisp-mode uses the whole word for completion (so my suggestion doesn't make sense in this case), but lsp-mode/clangd uses just part of the word until the point (my suggestion makes some sense in this case)?
[Prev in Thread] | Current Thread | [Next in Thread] |