diff --git a/Cask b/Cask index 3a6c8f0..aead016 100644 --- a/Cask +++ b/Cask @@ -1,6 +1,3 @@ (package-file "php-extras.el") (source marmalade) - -(development - (depends-on "php-mode" "1.5.0")) diff --git a/Makefile b/Makefile index 66de872..742942c 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ CASK?=cask EMACS?=emacs -TAR?=bsdtar +TAR?=COPYFILE_DISABLE=1 bsdtar PANDOC?=pandoc --atx-headers VERSION?=$(shell $(CASK) version) @@ -19,6 +19,7 @@ README: README.md $(PANDOC) -t plain -o $@ $^ php-extras-eldoc-functions.el: php-extras-gen-eldoc.el + $(CASK) install $(CASK) exec $(EMACS) --batch -l php-extras.el -l php-extras-gen-eldoc.el -f php-extras-generate-eldoc-1 $(ARCHIVE_NAME)-pkg.el: $(ARCHIVE_NAME).el diff --git a/README.md b/README.md index 8405f4d..5ba703d 100644 --- a/README.md +++ b/README.md @@ -43,14 +43,14 @@ to look up the function definition. `php-extras` provides such a function for looking up all the core PHP functions. -The function `php-extras-generate-eldoc` will download the PHP -function summary -[PHP Subversion repository](http://svn.php.net/repository/phpdoc/doc-base/trunk/funcsummary.txt) +The function `php-extras-generate-eldoc` will download the +[PHP function list](http://doc.php.net/downloads/json/php_manual_en.json) and extract the function definitions (slow) and store them in a hash table on disk for you. -If you install `php-extras` as an ELPA package the hash table is -already generated for you. +If you install `php-extras` as an ELPA package from +[Marmalade](http://marmalade-repo.org/packages/php-extras) the hash +table is already generated for you. ## Auto complete source for PHP functions based diff --git a/php-extras-gen-eldoc.el b/php-extras-gen-eldoc.el index 72aca5f..edbfd81 100644 --- a/php-extras-gen-eldoc.el +++ b/php-extras-gen-eldoc.el @@ -1,6 +1,6 @@ ;;; php-extras-gen-eldoc.el --- Extra features for `php-mode' -;; Copyright (C) 2012, 2013 Arne Jørgensen +;; Copyright (C) 2012, 2013, 2014 Arne Jørgensen ;; Author: Arne Jørgensen @@ -31,14 +31,13 @@ (require 'php-mode) (require 'php-extras) +(require 'json) -(defvar php-extras-gen-eldoc-temp-methodname nil) - -(defvar php-extras-php-funcsummary-url - "http://svn.php.net/repository/phpdoc/doc-base/trunk/funcsummary.txt" - "URL of the funcsummary.txt list of PHP functions.") +(defvar php-extras-php-doc-url + "http://doc.php.net/downloads/json/php_manual_en.json" + "URL of the JSON list of PHP functions.") @@ -50,52 +49,55 @@ (php-extras-generate-eldoc-1 t))) (defun php-extras-generate-eldoc-1 (&optional byte-compile) - (let ((function-arguments-temp (make-hash-table - :size 5000 - :rehash-threshold 1.0 - :rehash-size 100 - :test 'equal))) - (with-temp-buffer - (url-insert-file-contents php-extras-php-funcsummary-url) - (goto-char (point-min)) - (let ((line-count (count-lines (point-min) (point-max)))) - (with-syntax-table php-mode-syntax-table - (while (not (eobp)) - (let ((current-line (buffer-substring (point-at-bol) (point-at-eol)))) - ;; Skip methods for now: is there anything more intelligent - ;; we could do with them? - (unless (string-match-p "::" current-line) - (search-forward "(" (point-at-eol)) - (goto-char (match-beginning 0)) - (let ((function-name (thing-at-point 'symbol)) - (help-string (replace-regexp-in-string "[[:space:]]+" " " - current-line)) - (progress (* 100 (/ (float (line-number-at-pos)) line-count)))) - (message "[%2d%%] Parsing %s..." progress function-name) - (puthash function-name help-string function-arguments-temp)))) - ;; Skip over function description - (forward-line 2))))) - (let* ((file (concat php-extras-eldoc-functions-file ".el")) - (base-name (file-name-nondirectory php-extras-eldoc-functions-file))) - (with-temp-file file - (insert (format - ";;; %s.el -- file auto generated by `php-extras-generate-eldoc' - - \(require 'php-extras) - - \(setq php-extras-function-arguments %S) - - \(provide 'php-extras-eldoc-functions) + (with-current-buffer (url-retrieve-synchronously php-extras-php-doc-url) + (search-forward-regexp "^$") + (let* ((data (json-read)) + (count 0) + (progress 0) + (length (length data)) + (function-arguments-temp (make-hash-table + :size length + :rehash-threshold 1.0 + :rehash-size 100 + :test 'equal))) + (dolist (elem data) + (setq count (+ count 1)) + ;; Skip methods for now: is there anything more intelligent we + ;; could do with them? + (unless (string-match-p "::" (symbol-name (car elem))) + (setq progress (* 100 (/ (float count) length))) + (message "[%2d%%] Adding function: %s..." progress (car elem)) + (puthash (symbol-name (car elem)) (cdr elem) function-arguments-temp))) + ;; PHP control structures are not present in JSON list. We add + ;; them here (hard coded - there are not so many of them). + (let ((php-control-structures '("if" "else" "elseif" "while" "do.while" "for" "foreach" "break" "continue" "switch" "declare" "return" "require" "include" "require_once" "include_once" "goto"))) + (dolist (php-control-structure php-control-structures) + (message "Adding control structure: %s..." php-control-structure) + (puthash php-control-structure + '((purpose . "Control structure") + (id . (concat "control-structures." php-control-structure))) + function-arguments-temp))) + (let* ((file (concat php-extras-eldoc-functions-file ".el")) + (base-name (file-name-nondirectory php-extras-eldoc-functions-file))) + (with-temp-file file + (insert (format + ";;; %s.el -- file auto generated by `php-extras-generate-eldoc' + +\(require 'php-extras) + +\(setq php-extras-function-arguments %S) + +\(provide 'php-extras-eldoc-functions) ;;; %s.el ends here " - base-name - function-arguments-temp - base-name))) - (when byte-compile - (message "Byte compiling and loading %s ..." file) - (byte-compile-file file t) - (message "Byte compiling and loading %s ... done." file))))) + base-name + function-arguments-temp + base-name))) + (when byte-compile + (message "Byte compiling and loading %s ..." file) + (byte-compile-file file t) + (message "Byte compiling and loading %s ... done." file)))))) (provide 'php-extras-gen-eldoc) diff --git a/php-extras.el b/php-extras.el index e90dd3d..ee8988b 100644 --- a/php-extras.el +++ b/php-extras.el @@ -1,11 +1,11 @@ ;;; php-extras.el --- Extra features for `php-mode' -;; Copyright (C) 2012, 2013 Arne Jørgensen +;; Copyright (C) 2012, 2013, 2014 Arne Jørgensen ;; Author: Arne Jørgensen ;; URL: https://github.com/arnested/php-extras ;; Created: June 28, 2012 -;; Version: 1.0.0 +;; Version: 2.0.0 ;; Package-Requires: ((php-mode "1.5.0")) ;; Keywords: programming, php @@ -91,6 +91,11 @@ variable. If prefix argument is negative search forward." (insert (match-string-no-properties 1)) (message "No variable to insert."))) +(defun php-extras-get-function-property (symbol property) + "Get property of symbol. +Property can be: 'versions, 'return, 'prototype, 'purpose, or 'id." + (cdr (assoc property (gethash symbol php-extras-function-arguments)))) + ;;;###autoload (defun php-extras-eldoc-documentation-function () "Get function arguments for core PHP function at point." @@ -98,11 +103,11 @@ variable. If prefix argument is negative search forward." (php-extras-load-eldoc)) (when (hash-table-p php-extras-function-arguments) (or - (gethash (php-get-pattern) php-extras-function-arguments) + (php-extras-get-function-property (php-get-pattern) 'prototype) (save-excursion (ignore-errors (backward-up-list) - (gethash (php-get-pattern) php-extras-function-arguments)))))) + (php-extras-get-function-property (php-get-pattern) 'prototype)))))) ;;;###autoload (add-hook 'php-mode-hook 'php-extras-eldoc-setup)