|
1 | 1 | ;;; php-extras-gen-eldoc.el --- Extra features for `php-mode' |
2 | 2 |
|
3 | | -;; Copyright (C) 2012, 2013 Arne Jørgensen |
| 3 | +;; Copyright (C) 2012, 2013, 2014 Arne Jørgensen |
4 | 4 |
|
5 | 5 | ;; Author: Arne Jørgensen <[email protected]> |
6 | 6 |
|
|
31 | 31 |
|
32 | 32 | (require 'php-mode) |
33 | 33 | (require 'php-extras) |
| 34 | +(require 'json) |
34 | 35 |
|
35 | 36 |
|
36 | 37 |
|
37 | | -(defvar php-extras-gen-eldoc-temp-methodname nil) |
38 | | - |
39 | | -(defvar php-extras-php-funcsummary-url |
40 | | - "http://svn.php.net/repository/phpdoc/doc-base/trunk/funcsummary.txt" |
41 | | - "URL of the funcsummary.txt list of PHP functions.") |
| 38 | +(defvar php-extras-php-doc-url |
| 39 | + "http://doc.php.net/downloads/json/php_manual_en.json" |
| 40 | + "URL of the JSON list of PHP functions.") |
42 | 41 |
|
43 | 42 |
|
44 | 43 |
|
|
50 | 49 | (php-extras-generate-eldoc-1 t))) |
51 | 50 |
|
52 | 51 | (defun php-extras-generate-eldoc-1 (&optional byte-compile) |
53 | | - (let ((function-arguments-temp (make-hash-table |
54 | | - :size 5000 |
55 | | - :rehash-threshold 1.0 |
56 | | - :rehash-size 100 |
57 | | - :test 'equal))) |
58 | | - (with-temp-buffer |
59 | | - (url-insert-file-contents php-extras-php-funcsummary-url) |
60 | | - (goto-char (point-min)) |
61 | | - (let ((line-count (count-lines (point-min) (point-max)))) |
62 | | - (with-syntax-table php-mode-syntax-table |
63 | | - (while (not (eobp)) |
64 | | - (let ((current-line (buffer-substring (point-at-bol) (point-at-eol)))) |
65 | | - ;; Skip methods for now: is there anything more intelligent |
66 | | - ;; we could do with them? |
67 | | - (unless (string-match-p "::" current-line) |
68 | | - (search-forward "(" (point-at-eol)) |
69 | | - (goto-char (match-beginning 0)) |
70 | | - (let ((function-name (thing-at-point 'symbol)) |
71 | | - (help-string (replace-regexp-in-string "[[:space:]]+" " " |
72 | | - current-line)) |
73 | | - (progress (* 100 (/ (float (line-number-at-pos)) line-count)))) |
74 | | - (message "[%2d%%] Parsing %s..." progress function-name) |
75 | | - (puthash function-name help-string function-arguments-temp)))) |
76 | | - ;; Skip over function description |
77 | | - (forward-line 2))))) |
78 | | - (let* ((file (concat php-extras-eldoc-functions-file ".el")) |
79 | | - (base-name (file-name-nondirectory php-extras-eldoc-functions-file))) |
80 | | - (with-temp-file file |
81 | | - (insert (format |
82 | | - ";;; %s.el -- file auto generated by `php-extras-generate-eldoc' |
83 | | -
|
84 | | - \(require 'php-extras) |
85 | | -
|
86 | | - \(setq php-extras-function-arguments %S) |
87 | | -
|
88 | | - \(provide 'php-extras-eldoc-functions) |
| 52 | + (with-current-buffer (url-retrieve-synchronously php-extras-php-doc-url) |
| 53 | + (search-forward-regexp "^$") |
| 54 | + (let* ((data (json-read)) |
| 55 | + (count 0) |
| 56 | + (progress 0) |
| 57 | + (length (length data)) |
| 58 | + (function-arguments-temp (make-hash-table |
| 59 | + :size length |
| 60 | + :rehash-threshold 1.0 |
| 61 | + :rehash-size 100 |
| 62 | + :test 'equal))) |
| 63 | + (dolist (elem data) |
| 64 | + (setq count (+ count 1)) |
| 65 | + ;; Skip methods for now: is there anything more intelligent we |
| 66 | + ;; could do with them? |
| 67 | + (unless (string-match-p "::" (symbol-name (car elem))) |
| 68 | + (setq progress (* 100 (/ (float count) length))) |
| 69 | + (message "[%2d%%] Adding function: %s..." progress (car elem)) |
| 70 | + (puthash (symbol-name (car elem)) (cdr elem) function-arguments-temp))) |
| 71 | + ;; PHP control structures are not present in JSON list. We add |
| 72 | + ;; them here (hard coded - there are not so many of them). |
| 73 | + (let ((php-control-structures '("if" "else" "elseif" "while" "do.while" "for" "foreach" "break" "continue" "switch" "declare" "return" "require" "include" "require_once" "include_once" "goto"))) |
| 74 | + (dolist (php-control-structure php-control-structures) |
| 75 | + (message "Adding control structure: %s..." php-control-structure) |
| 76 | + (puthash php-control-structure |
| 77 | + '((purpose . "Control structure") |
| 78 | + (id . (concat "control-structures." php-control-structure))) |
| 79 | + function-arguments-temp))) |
| 80 | + (let* ((file (concat php-extras-eldoc-functions-file ".el")) |
| 81 | + (base-name (file-name-nondirectory php-extras-eldoc-functions-file))) |
| 82 | + (with-temp-file file |
| 83 | + (insert (format |
| 84 | + ";;; %s.el -- file auto generated by `php-extras-generate-eldoc' |
| 85 | +
|
| 86 | +\(require 'php-extras) |
| 87 | +
|
| 88 | +\(setq php-extras-function-arguments %S) |
| 89 | +
|
| 90 | +\(provide 'php-extras-eldoc-functions) |
89 | 91 |
|
90 | 92 | ;;; %s.el ends here |
91 | 93 | " |
92 | | - base-name |
93 | | - function-arguments-temp |
94 | | - base-name))) |
95 | | - (when byte-compile |
96 | | - (message "Byte compiling and loading %s ..." file) |
97 | | - (byte-compile-file file t) |
98 | | - (message "Byte compiling and loading %s ... done." file))))) |
| 94 | + base-name |
| 95 | + function-arguments-temp |
| 96 | + base-name))) |
| 97 | + (when byte-compile |
| 98 | + (message "Byte compiling and loading %s ..." file) |
| 99 | + (byte-compile-file file t) |
| 100 | + (message "Byte compiling and loading %s ... done." file)))))) |
99 | 101 |
|
100 | 102 | (provide 'php-extras-gen-eldoc) |
101 | 103 |
|
|
0 commit comments