Code Monkey home page Code Monkey logo

ac-php's Introduction

ac-php MELPA MELPA Stable

emacs auto-complete for php

support auto-complete and company-mode

use phpctags gen tags

and use ac-php work with tags

  • support system function

  • support system class

core: SPL SplFileInfo DOMDocument SimpleXMLElement ...

externed: PDO Http mysqli Imagick SQLite3 Memcache ...

externed: Redis ,Swoole

  • support user self class system

  • example:

example.gif

Table of Contents

Install

UBUNTU

  • install php-cli command for phpctags
localhost:~/$ sudo apt-get install php-cli 
  • install cscope command for ac-php-cscope-find-egrep-pattern
localhost:~/$ sudo apt-get install cscope

MAC OSX

 brew  install homebrew/php/php56
 brew  install cscope 

check php,cscope existed

localhost:~$ php --version
PHP 5.5.20 (cli) (built: Feb 25 2015 23:30:53) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
localhost:~$ cscope --version
cscope: version 15.8a

Test

#backup old .emacs
cp ~/.emacs ~/.emacs.bak

save it as ~/.emacs

  (setq package-archives
        '(("melpa" . "https://melpa.org/packages/")) )
  (package-initialize)
  (unless (package-installed-p 'ac-php )
    (package-refresh-contents)
    (package-install 'ac-php )
    )
  (require 'cl)
  (require 'php-mode)
  (add-hook 'php-mode-hook
            '(lambda ()
               (auto-complete-mode t)
               (require 'ac-php)
               (setq ac-sources  '(ac-source-php ) )
               (yas-global-mode 1)
               (define-key php-mode-map  (kbd "C-]") 'ac-php-find-symbol-at-point)   ;goto define
               (define-key php-mode-map  (kbd "C-t") 'ac-php-location-stack-back   ) ;go back
               ))
cd ~/
git clone https://github.com/xcwen/ac-php/
#test php files in ~/ac-php/phptest
#open file for test
emacs ~/ac-php/phptest/testb.php

Usage

  • install ac-php from melpa
  (setq package-archives
        '(("melpa" . "https://melpa.org/packages/")) )

"M-x" :package-list-packages find ac-php install

  • emacs php-mode function define

work for auto-complete-mode , Company-mode config at here

  (add-hook 'php-mode-hook
            '(lambda ()
               (auto-complete-mode t)
               (require 'ac-php)
               (setq ac-sources  '(ac-source-php ) )
               (yas-global-mode 1)
               (define-key php-mode-map  (kbd "C-]") 'ac-php-find-symbol-at-point)   ;goto define
               (define-key php-mode-map  (kbd "C-t") 'ac-php-location-stack-back   ) ;go back
               ))
  • create file ".ac-php-conf.json" in root of project
cd /project/to/path #  root dir of project
touch .ac-php-conf.json 
  • DONE

  • command

cmd info
ac-php-remake-tags if source is changed ,re run this commond for update tags
ac-php-remake-tags-all **if you find a error, run it an retest**
ac-php-find-symbol-at-point goto define
ac-php-location-stack-back go back
ac-php-show-tip show define at point
ac-php-cscope-find-egrep-pattern find current-word in project

Usage Company

"M-x" :package-list-packages find company-php install

(add-hook 'php-mode-hook
          '(lambda ()
             (require 'company-php)
             (company-mode t)
             (add-to-list 'company-backends 'company-ac-php-backend )))

use M-x: company-complete for complete

Php Doc for complete

define class memeber type :

public $v1; =>

/**
 * @var classtype
 */
public $v1;

if you won't define public $v1 you can define in class comment ,like this =>

/**
  * @property  \Test\Testa  $v1
  * @method  int add($a,$b) 
  * @use  \Test\TestC
 */
class Testb  extends Ta { 
...
}

define class function return type:

public function get_v1() =>

/**
 * @return classtype 
 */
public function get_v1()

or define use php7 :

public function get_v1() :classtype  {

}

or define in doc:

/**
  * @method  classtype get_v1()
 */
class Testb  extends Ta { 
...
}

define variable: (**if function or member no define reutrn value you need define it **)

$value=ff(); =>

/** @var $value  Testa */
$value=ff();

like this

/**
   class define ..
   @property  \Test\Testa  $v8
 */
class Testa {

    /**
     * @var int; 
     */
	const CON=1;

    
    /**
     * @var Testb; 
     */
	public  $v1;
    /**
     * @var \Test\TestC; 
     */
	public  $v2;
    public function set_v1($v){

        //for complete system function 
        $v=trim($v);

        $c=new Testb();
        //can complete
        $c->get_v2();

        //for complete memeber 
        $this->v1=$v;


        //for complete function  return type  
        $this-> get_v2()->testC();

        //for complete field from comment
        $this->v8->testA();

        //for complete system class 
        $q=new SplQueue ();
        $q->push(11);

       //jump for class function point
        $f=array($this->v8, "test_A" );
        $f();

    }

    /**
     * 
     * @return  \Test\TestC; 
     */
    public function get_v2(){
        $this->v2;
    }
}

Tags

tags file location dir is in ~/.ac-php/project_dir for example: ~/.ac-php/tags-home-jim-ac-php-phptest/

localhost:~/.ac-php$ tree tags-home-jim-ac-php-phptest/
tags-home-jim-ac-php-phptest/
├── cache-files.json
├── tags-data-cache2.el
├── tags-data.el
└── tags_dir_jim
    ├── a.el
    ├── dir1-sss.el
    ├── testa.el
    ├── testb.el
    └── testc.el
1 directory, 8 files

Configue PHP file Search for Large Project

config file name is .ac-php-conf.json

when run ac-php-remake-tags will .ac-php-conf.json set default json config when it's empty

like this

{
  "use-cscope" : false,
  "filter": {
    "php-file-ext-list": [
      "php"
    ],
    "php-path-list": [
      "."
    ],
    "php-path-list-without-subdir": []
  }
}

php-file-ext-list : file extern name list;

php-path-list: find php files recursion ;

php-path-list-without-subdir: find php files no recursion no find php from subdir ;

for exmaple:

├── dir1
│   ├── 1.php
│   └── dir11
│       └── 11.php
├── dir2
│   └── 2.php
└── dir3
    ├── 3.php
    ├── dir31
    │   └── 31.php
    ├── dir32
    │   └── 32.php
    └── dir33
        └── 33.php
{
  "filter": {
    "php-file-ext-list": [
      "php"
    ],
    "php-path-list": [
      "./dir1",
      "./dir2",
      "./dir3/dir32/"
    ],
    "php-path-list-without-subdir": [
      "./dir3"
     ]
  }
}

filter result is:

├── dir1
│   ├── 1.php
│   └── dir11
│       └── 11.php
├── dir2
│   └── 2.php
└── dir3
    ├── 3.php
    ├── dir32
    │   └── 32.php

31.php 33.php will not gen tags;

for laravel example

{
  "use-cscope": false,
  "filter": {
    "php-file-ext-list": [
      "php"
    ],
    "php-path-list": [
        "./app",
        "./database",
        "./vendor/laravel/framework/src/Illuminate"
    ],
    "php-path-list-without-subdir": []
  }
}

Disable Cscope Config

set use-cscope: false in .ac-php-conf.json

Rebuild Tags

if source is changed ,re run this commond for update tags: ac-php-remake-tags

if php file cannot pass from phpctags.

you can find any error from Messages buffer fix it and next

like this

phpctags[/home/jim/phptest/testa.php] ERROR:PHPParser: Unexpected token '}' on line 11 - 

you need fix testa.php error and re run ac-php-remake-tags

if show:

no find  file .ac-php-conf.json dir in path list :/home/jim/phptest/ 

you need create file ".ac-php-conf.json" in root of project

like this:

touch /home/jim/phptest/.ac-php-conf.json

or

touch /home/jim/.ac-php-conf.json

FQA

for all any question 

you find a question

exec : M-x: ac-php-remake-tags-all

and retest

ac-php's People

Contributors

ksjogo avatar purcell avatar syohex avatar xcwen avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.