6

Is it possible to obtain a package which supports Intellisense PHP in emacs? As I've set up cedet now and I would like to add autocomplete for PHP code in emacs.

I know you can do it in vim.

  • 2
    Look into company-mode as an "intellisense" frontend. I don't know of any intelligent scope-aware completion backends, but keywords, dabbrev, and other methods may suffice. – PythonNut Dec 27 '14 at 20:42
  • In addition to NateEag's suggestions, have a look at PHP Extras which includes a more updated Auto complete and company mode source (Although I don't think it's intelligent) and other features that you might also want. – shadowthief Jan 12 '15 at 6:49
  • there are extensive youtube videos on php emacs setup here are a few: youtube.com/watch?v=GLdkYyGlSBg youtube.com/watch?v=E4ZOWnLdAqs – Moshi Aug 22 '15 at 16:06
6

Edit: In the past few months I've started using the php-language-server with lsp-mode (which are both components built on Microsoft's Language Server Protocol).

It's not a perfect answer yet, but I have jump-to-definition that's working pretty solidly in a large, old PHP codebase, and that alone is worth quite a bit. Other components like docstring/function signature display and completion-at-point work too (though neither of those are perfect yet).

This direction looks more promising to me than any of the options in my original answer, because when an LSP backend improves, all editors benefit from it, so the core backend intelligence should get gains from a wider community. Similarly, improvements and extensions to lsp-mode should benefit integration with other language backends, not just the one it was originally built for.

Disclosure: I have contributed some to this solution. I submitted a PR to make emacs-lsp compatible with php-language-server and hacked up my own simple PHP backend, which I replaced with the lsp-php package when it popped up one day in my list-packages buffer.

Original answer below

I have yet to find a fully satisfactory solution for PHP intelligence in Emacs, but here's what I have found.

auto-complete is similar to company-mode in that it provides a UI for autocompletion. I prefer its UI to company-mode's - try both and see what you like.

php-auto-yasnippets is useful for auto-completion of built-in PHP functions, complete with argument order.

pfff is a static analysis tool with good PHP support. Its stags command will generate Emacs tags files, which can then be used for jumping to definitions. You should be able to use this to get some sort of auto-completion too, but I don't know how useful it would really be.

Finally, emacs-eclim uses Eclipse as a code-intelligence daemon. It works very well for Java, and in principle it's possible to install Eclipse's PDT plugin and use eclim for PHP completion and jump-to-definition. The last time I tried it, the PHP support in the Emacs plugin was pretty limited. Some elisp hacking would probably get you there.

If I were going back to this personally, I'd probably work on emacs-eclim PHP support. I think it's the solution that's most likely to work well, and PDT seems to make steady progress forward.

| improve this answer | |
1

If you install php-ext (https://savannah.nongnu.org/projects/php-ext-el/), you will have autocompletion and skeleton templates for many, many php functions:

$ cd ~

$ mkdir mydir

$ cd mydir

$ git clone git://git.savannah.nongnu.org/php-ext-el.git

Edit you .emacs and add:

(setq php-ext-path "~/mydir")

(load (concat php-ext-path "php-ext.el"))
| improve this answer | |
  • I only see skeletons there, no actual auto-completion code. – wasamasa May 12 '15 at 21:05
  • You can autocomplete any skeleton from M-x and writing your skeleton function. – user949842 May 15 '15 at 15:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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