2

I do have a strange issue when working on PHP files.

I have company-mode installed and it works for function completion but not for local variables.

For others languages such as Ruby or Lisp, everything is fine. But not for PHP.

In the following gif, as you can see, I can complete functions that begins by "str" but not the local variable that begins by "$tot"

enter image description here

And here is my very simplified config used for this example:

;; Requires and internal modes settings
(require 'package)

(ido-mode 1)
(show-paren-mode 1)
(transient-mark-mode 1)

;; Internal vars

(setq debug-on-error t
      case-fold-search t
      kill-whole-line t)

(fset 'yes-or-no-p 'y-or-n-p)

;; Use package

(setq package-enable-at-startup nil
      package-archives '(("melpa" . "http://melpa.org/packages/")
                         ("gnu" . "http://elpa.gnu.org/packages/")
                         ("marmalade" . "http://marmalade-repo.org/packages/")))

(package-initialize)

(when (not package-archive-contents) (package-refresh-contents))
(unless (package-installed-p 'use-package) (package-install 'use-package))
(eval-when-compile (require 'use-package))

;; Package :: completion

(use-package company :ensure t :init (global-company-mode 1))

;; Packages :: web

(use-package php-mode :ensure t)
(use-package php-extras :ensure t)
(use-package rainbow-mode :ensure t)
(use-package web-mode :ensure t)

Do you guys have any idea of what's going on ?

Thanks in advance.

EDIT:

  • C-h v major-mode gives php-mode
  • C-h v company-backend gives nil
  • C-h v company-backends gives:

    Its value is (php-extras-company company-bbdb company-nxml company-css company-eclim company-semantic company-clang company-xcode company-cmake company-capf company-files (company-dabbrev-code company-gtags company-etags company-keywords) company-oddmuse company-dabbrev)

    Original value was (company-bbdb company-nxml company-css company-eclim company-semantic company-clang company-xcode company-cmake company-capf company-files (company-dabbrev-code company-gtags company-etags company-keywords) company-oddmuse company-dabbrev)

3
  • C-h v major-mode and C-h v company-backends, you need provide these two variables' values.
    – chen bin
    Jun 16, 2016 at 13:34
  • Its value is php-mode and Its value is nil ... so here is a clue, thanks to you, @chenbin ! I should now define a proper backend, isn't it ?
    – SmartyLisp
    Jun 16, 2016 at 13:37
  • Sorry, company-backends: (php-extras-company company-bbdb company-nxml company-css company-eclim company-semantic company-clang company-xcode company-cmake company-capf company-files (company-dabbrev-code company-gtags company-etags company-keywords) company-oddmuse company-dabbrev) Original value was (company-bbdb company-nxml company-css company-eclim company-semantic company-clang company-xcode company-cmake company-capf company-files (company-dabbrev-code company-gtags company-etags company-keywords) company-oddmuse company-dabbrev)
    – SmartyLisp
    Jun 16, 2016 at 13:42

1 Answer 1

3

You only need php-extras-company and company-dabbrev, place them in the same group and at the BEGINNING of the company-backends,

(add-hook 'php-mode-hook
            (lambda ()
              (set (make-local-variable 'company-backends)
                   '((php-extras-company company-dabbrev) company-capf company-files))))

See https://github.com/company-mode/company-mode/issues/182 @dgutov comments.

1
  • Oh yes, @chenbin ! Thank you very much. Just replaced company-dabbrev by company-dabbrev-code and everything is fine !
    – SmartyLisp
    Jun 16, 2016 at 14:07

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.