How do I get spacemacs web-mode autocomplete to relax a little?

1.2k Views Asked by At

I'm new to Spacemacs and Emacs. When I'm editing in web-mode, like an html document, I'm often triggering the autocomplete prompt when I haven't typed anything relevant yet. I don't have this problem in the html blocks, that I remember, but when in script (js) or css blocks it gets pretty cumbersome to have to swat away the menu constantly.

autocomplete suggestions triggered by semiconlon

You can see from the above example that I'm editing css and after completing the property definition with a semicolon the autocompletion pops up meaning that hitting semicolon and enter to start the next line will instead add useless text to the line after the semicolon. how can I alter this behaviour?

Similar behaviour inside a script tag

You can see here again I have almost the same problem when editing inside the script tag. Opening a function definition with a curly brace and hitting enter to go to the next line instead inserts useless text after the brace.

The file I am editing is .svelte, but I've told emacs to use web-mode

My dotspacemacs/user-config has the following:

(add-hook 'text-mode-hook 'turn-on-visual-line-mode)
(add-to-list 'auto-mode-alist '("\\.svelte?\\'" . web-mode))
(setq web-mode-markup-indent-offset 2)
(setq web-mode-css-indent-offset 2)
(setq web-mode-code-indent-offset 2)

(setq configuration-layer--elpa-archives
      '(("melpa-cn" . "http://elpa.emacs-china.org/melpa/")
        ("org-cn"   . "http://elpa.emacs-china.org/org/")
        ("gnu-cn"   . "http://elpa.emacs-china.org/gnu/")))
3

There are 3 best solutions below

0
On

Try adding this to the dotspacemacs-configuration-layers section of your spacemacs file spc + fed

     (auto-completion :variables
                      auto-completion-enable-snippets-in-popup t
                      auto-completion-return-key-behavior nil
                      auto-completion-tab-key-behavior 'complete)
0
On

I'm new to emacs also. I think this is the same question as

https://emacs.stackexchange.com/questions/53110/for-spacemacs-how-do-i-override-a-layers-setting-company-minimum-prefix-leng

Basically it's because of this fucntion in .emacs.d/layers/+lang/html/func.el

 (defun spacemacs//company-web-minimum-prefix-length ()
    "Set company minimum prefix length to 0 for the current buffer only."
    (set (make-local-variable 'company-minimum-prefix-length) 0))

related to https://github.com/osv/company-web/issues/4

You could change the minimum length to some value other than 0

4
On

Not a spacemacs user myself, but it appears you have set company-minimum-prefix-length to 0, whereas you probably want it to be at least 2. You could also consider increasing company-idle-delay which would cause candidates to be presented slower.