0

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/")))
Rorschach
  • 31,301
  • 5
  • 78
  • 129
James
  • 87
  • 1
  • 8

3 Answers3

1

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.

Rorschach
  • 31,301
  • 5
  • 78
  • 129
  • maybe spacemacs loads and configures company in a somewhat different way, in either case I couldn't get the above config to have any effect, maybe not in the right place. So tried to find spacemacs specific info and got here [https://develop.spacemacs.org/layers/+completion/auto-completion/README.html] . None of that did what I needed either, except disabling return key completion. – James Feb 15 '20 at 07:00
  • 1
    you can just evaluate `M-:` `(setq company-minimum-prefix-length 2)` from your html buffer to test. I'm assuming you're using `company-mode` for autocompletion, ie. if you evaluate the value of `M-:` `company-mode` is `t`, in which case you should post the value of the active `company-backends` in your html buffer as well (Note: if spacemacs overrides `M-:`, that is equivalent to `M-x eval-expression`) – Rorschach Feb 15 '20 at 11:44
  • That is helpful. I apparently need to set the variable in a different place. I had added `(setq company-minimum-prefix-length 1)` to .spacemacs in the user-config function, but this did nothing. I'm at a loss as to where I am supposed to put it though. Evaluating the expression directly from the html buffer as you suggest works fine. Now that i understand the problem better I see that [This question](https://emacs.stackexchange.com/questions/53110/for-spacemacs-how-do-i-override-a-layers-setting-company-minimum-prefix-leng) is essentially the same – James Feb 15 '20 at 12:33
  • well, normally, one would set those company variables globally -- but if you want a special value for just `html-mode` (or `web-mode`), you would set a `(setq-local company-minimum-prefix-length ...)` in your `html-mode-hook`. Spacemacs probably has a user-configurable mechanism for setting mode hooks, otherwise you should just be able to setup a hook per usual – Rorschach Feb 15 '20 at 13:40
0

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

Terrance
  • 1
  • 1
0

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)