0

I have web-mode and company installed but company just seems to autocomplete the variables without underscores:

With Emacs Lisp Mode

enter image description here

With Web-mode enter image description here

;; --- Company ---
;; Autocomplete with dropdown system

(use-package company
  :ensure t
  
  :init
  
  :config
  (setq company-dabbrev-ignore-case t)
  (setq company-dabbrev-downcase nil)
  
  (setq company-idle-delay 0.2)
  (setq company-echo-delay 0)
  (setq company-minimum-prefix-length 2)
  (setq company-tooltip-minimum-width 110)

  (setq company-dabbrev-code-everywhere t)
  (setq company-dabbrev-code-modes t)
  (setq company-tooltip-align-annotations t)
  (setq company-selection-wrap-around t)

  (setq company-transformers '(company-sort-by-occurrence
                           company-sort-by-backend-importance))

  ;; (define-key global-map (kbd "C-.") 'company-files)
  
  (add-hook 'after-init-hook 'global-company-mode)

  (setq company-backends
        '((company-files
           company-yasnippet
           company-dabbrev
           company-keywords
           company-capf
           company-php
           )))

  )

2 Answers 2

2

In your setting of company-backends, don't use company-dabbrev in that group, use company-dabbrev-code.

1
  • 1
    I marked this one as the proper answer, my own works as well, but this one is far cleaner and less intrusive than changing the syntax of Emacs. thank you.
    – Fabman
    Jan 16, 2021 at 8:24
1

I found out the problem is not a company problem but the syntax of the mode. By default Emacs consider the underscores as a word separator so the variable new_var are two words instead of one.

To make Emacs consider new_var as one word you have to change the syntax with a hook:

(add-hook 'web-mode-hook (lambda () (modify-syntax-entry ?_ "w")))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.