emacs-php / emacs-php/php-mode
Using ede-php-autoload with PHP-mode
- Dominant language
- Emacs Lisp
- Stars
- 602
- Forks
- 117
- Avg merge
- 12h 54m
- Merged PRs (30d)
- 3
Description
[**ede-php-autoload**](https://github.com/stevenremot/ede-php-autoload) is a fantastic package that enables Emacs to understand the dependencies of PHP projects, the most immediate benefit of this is that Emacs can translate class names into files, for example allowing you to jump to the definition of a third-party package with the flick of a button.
The package provides PSR-0 and PSR-4 autoload capabilities to the [SemanticDB](http://www.gnu.org/software/emacs/manual/html_mono/semantic.html#SemanticDB) Emacs subsystem and it can be either used as part of the [Semantic](ttp://www.gnu.org/software/emacs/manual/html_mono/semantic.html) parsing system, or with some customisation as a standalone package that doesn't require `semantic-mode` to be active on your php buffers.
Since `ede-php-autoload` is by nature designed to work in conjunction with semantic PHP parsers, here's a couple of implementations that's worth knowing about:
- @jorissteyn's [EDEP](https://github.com/jorissteyn/edep/) package [is being updated](https://github.com/jorissteyn/edep/issues/4#issuecomment-113292674) to work in tandem with `ede-php-autoload`.
- @stevenremot has originally written `ede-php-autoload` as part of his work to update the CEDET contrib PHP parser to suit the updated PHP syntax, so it's inherently designed to work with it. [Here's a version of the CEDET Contrib PHP parser that works with `ede-php-autoload`](https://gist.github.com/trashofmasters/28449030bab9e196e4bf) and the built-in CEDET version shipped with Emacs 24 and 25.
I personally am using `ede-php-autoload` without `semantic-mode` so I've hacked a function that uses it to jump to the declaration of a class imported with `use`.
``` elisp
(defun ofc/tags-find-at-point ()
"Finds the definitions of the symbol at point using a tag file."
(interactive)
(xref-find-definitions (thing-at-point 'sexp)))
(defun ofc/visit-class-file-at-point ()
"Maps a FQN into a file name using PHP autoload resolution."
(interactive)
(let* ((class-name (replace-regexp-in-string "^\\\\" "" (thing-at-point 'sexp)))
(class-file (ede-php-autoload-find-class-def-file (ede-current-project) class-name)))
(when class-file
(xref-push-marker-stack)
(find-file class-file))))
(defun ofc/php-tags-find-at-point ()
"When called on a FQN, it resolves its name and jumps to the file where it's defined.
When called on anything else it forwards the call to a tag search function."
(interactive)
(unless (ofc/visit-class-file-at-point)
(ofc/tags-find-at-point)))
(global-ede-mode 1)
(add-hook 'php-mode-hook #'ede-php-autoload-mode)
(define-key php-mode-map (kbd "M-.") 'ofc/php-tags-find-at-point)
```
I would be interested in knowing how @jorissteyn and @stevenremot are using it.
Contributor guide
Assessment
This issue has not been assessed yet.