Skip to content

Commit

Permalink
Merge branch 'release/2.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
arnested committed Mar 8, 2014
2 parents dfb5464 + 00cf842 commit 1c3c41c
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 62 deletions.
3 changes: 0 additions & 3 deletions Cask
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
(package-file "php-extras.el")

(source marmalade)

(development
(depends-on "php-mode" "1.5.0"))
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

CASK?=cask
EMACS?=emacs
TAR?=bsdtar
TAR?=COPYFILE_DISABLE=1 bsdtar
PANDOC?=pandoc --atx-headers

VERSION?=$(shell $(CASK) version)
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
100 changes: 51 additions & 49 deletions php-extras-gen-eldoc.el
Original file line number Diff line number Diff line change
@@ -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 <arne@arnested.dk>

Expand Down Expand Up @@ -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.")



Expand All @@ -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)

Expand Down
13 changes: 9 additions & 4 deletions php-extras.el
Original file line number Diff line number Diff line change
@@ -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 <arne@arnested.dk>
;; 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

Expand Down Expand Up @@ -91,18 +91,23 @@ 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."
(when (eq php-extras-function-arguments 'not-loaded)
(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)
Expand Down

0 comments on commit 1c3c41c

Please sign in to comment.