Skip to content

Commit

Permalink
Merge branch 'release/2.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
arnested committed Apr 5, 2014
2 parents 72a963d + 1e7c4e9 commit 82956cb
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 2 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Currently includes:
* `php-extras-eldoc-documentation-function`
* Auto complete source for PHP functions based on
`php-extras-eldoc-documentation-function`
* Company completion back-end for PHP functions based on
`php-extras-eldoc-documentation-function`


## `php-extras-insert-previous-variable`
Expand Down Expand Up @@ -67,6 +69,12 @@ The source we provide with `php-extras` will hopefully be more up to
date.


## Company completion back-end for PHP functions based

Users of [company-mode](http://company-mode.github.io/) will also get
in-buffer completion based on the extracted PHP functions.


## Installation

The easiest way to install `php-extras` is probably to install it via
Expand All @@ -93,7 +101,7 @@ If you insist on installing it manually try to follow this recipe:
* Add this to your `.emacs` / `.emacs.d/init.el`:

```lisp
(add-to-list 'load-path "/somewhere/on/your/disk/php-xtras")
(add-to-list 'load-path "/somewhere/on/your/disk/php-extras")
(eval-after-load 'php-mode
(require 'php-extras))
```
Expand Down
73 changes: 72 additions & 1 deletion php-extras.el
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
;; Author: Arne Jørgensen <arne@arnested.dk>
;; URL: https://github.com/arnested/php-extras
;; Created: June 28, 2012
;; Version: 2.1.1
;; Version: 2.2.0
;; Package-Requires: ((php-mode "1.5.0"))
;; Keywords: programming, php

Expand Down Expand Up @@ -36,6 +36,14 @@

(require 'eldoc)
(require 'thingatpt)
(eval-when-compile (require 'cl-lib))

;; Silence byte-compiler warnings
(declare-function php-get-pattern "php-mode" ())
(declare-function company-doc-buffer "company" (&optional string))
(declare-function company-grab-symbol "company" ())
(declare-function company-begin-backend "company" (backend &optional callback))
(defvar company-backends)

(defvar php-extras-php-variable-regexp
(format "\\(\\$[a-zA-Z_%s-%s][a-zA-Z0-9_%s-%s]*\\(\\[.*\\]\\)*\\)"
Expand Down Expand Up @@ -204,6 +212,69 @@ The candidates are generated from the
;;;###autoload
(add-hook 'php-mode-hook #'php-extras-completion-setup)


;;; Backend for `company-mode'

;;;###autoload
(defun php-extras-company (command &optional candidate &rest ignore)
"`company-mode' back-end using `php-extras-function-arguments'."
(interactive (list 'interactive))
(when (derived-mode-p 'php-mode)
(cl-case command
(interactive
(company-begin-backend 'php-extras-company))

(init
(php-extras-load-eldoc)
(unless (hash-table-p php-extras-function-arguments)
;; Signaling an error here will cause company-mode to remove
;; this backend from the list, so we need not check that the
;; hash table exists later
(error "No PHP function information loaded")))

(prefix
(company-grab-symbol))

(candidates
(all-completions candidate php-extras-function-arguments))

(annotation
(let ((prototype (php-extras-get-function-property candidate 'prototype)))
(and prototype
(replace-regexp-in-string "\\`[^(]*" "" prototype))))

(meta
(php-extras-get-function-property candidate 'purpose))

(doc-buffer
(let ((docs (php-extras-get-function-property candidate 'documentation)))
(when docs
(company-doc-buffer docs))))

(post-completion
(php-extras-ac-insert-action)))))

;;;###autoload
(defun php-extras-company-setup ()
;; Add `php-extras-company' to `company-backends' only if it's not
;; already present in the list, to avoid overwriting any user
;; preference for the order and merging of backends (as configured
;; via customize, e.g.). Elements of `company-backends' may be
;; lists of backends to merge together, so this is more complicated
;; than just (memq ..)
(when (boundp 'company-backends)
(unless
(cl-loop
for backend in company-backends
thereis (or (eq backend 'php-extras-company)
(and (listp backend)
(memq 'php-extras-company backend))))
(add-to-list 'company-backends 'php-extras-company))))

;;;###autoload
(eval-after-load 'company
'(php-extras-company-setup))



;;;###autoload
Expand Down

0 comments on commit 82956cb

Please sign in to comment.