Created
March 25, 2013 23:06
-
-
Save gongo/5241718 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
class PhpCompletion | |
{ | |
public static function make_completion() | |
{ | |
$completion = new self; | |
$completion->print_version(); | |
$completion->make_completion_constants(); | |
$completion->make_completion_functions(); | |
$completion->make_completion_classes(); | |
$completion->make_completion_keywords(); | |
} | |
public function print_version() | |
{ | |
echo ";;; PHP completion list for " . PHP_VERSION . PHP_EOL . PHP_EOL; | |
} | |
public function make_completion_constants() | |
{ | |
$words = array_keys(get_defined_constants()); | |
$this->make_completion_list('constants', $words); | |
} | |
public function make_completion_functions() | |
{ | |
$all_functions = get_defined_functions(); | |
$words = $all_functions['internal']; | |
$this->make_completion_list('functions', $words); | |
} | |
public function make_completion_classes() | |
{ | |
$words = get_declared_classes(); | |
$this->make_completion_list('classes', $words); | |
} | |
public function make_completion_keywords() | |
{ | |
$words = array( | |
"abstract", "and", "array", "as", "break", "case", "catch", | |
"class", "clone", "const", "continue", "declare", "default", | |
"do", "else", "elseif", "enddeclare", "endfor", "endforeach", | |
"endif", "endswitch", "endwhile", "extends", "final", "for", | |
"foreach", "function", "global", "goto", "if", "implements", | |
"interface", "instanceof", "namespace", "new", "or", "private", | |
"protected", "public", "static", "switch", "throw", "try", "use", | |
"var", "while", "xor", "__CLASS__", "__DIR__", "__FILE__", | |
"__LINE__", "__FUNCTION__", "__METHOD__", "__NAMESPACE__", | |
"die", "echo", "empty", "exit", "eval", "include", "include_once", | |
"isset", "list", "require", "require_once", "return", "print", | |
"unset" | |
); | |
if (version_compare(PHP_VERSION, '5.4.0', '>=')) { | |
$words = array_merge($words, | |
array('callable', 'insteadof', 'trait', '__TRAIT__')); | |
} | |
$this->make_completion_list('keywords', $words); | |
} | |
public function make_completion_list($theType, $theList) | |
{ | |
sort($theList); | |
echo "(setq php-completion-list-$theType" . PHP_EOL; | |
echo " '(" . PHP_EOL; | |
foreach ($theList as $word) { | |
echo " \"$word\"" . PHP_EOL; | |
} | |
echo ' ))' . PHP_EOL . PHP_EOL; | |
} | |
} | |
PhpCompletion::make_completion(); | |
/** | |
* ;;; PHP completion list for 5.4.13 | |
* | |
* (setq php-completion-list-constants | |
* '( | |
* "ABDAY_1" | |
* "ABDAY_2" | |
* "ABDAY_3" | |
* ... | |
* )) | |
* | |
* (setq php-completion-list-functions | |
* '( | |
* "abs" | |
* "acos" | |
* "acosh" | |
* ... | |
* )) | |
* | |
* (setq php-completion-list-classes | |
* '( | |
* "AppendIterator" | |
* "ArrayIterator" | |
* "ArrayObject" | |
* ... | |
* )) | |
* | |
* (setq php-completion-list-keywords | |
* '( | |
* "__CLASS__" | |
* "__DIR__" | |
* "__FILE__" | |
* ... | |
* )) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment