;;; php-extras-gen-eldoc.el --- Extra features for `php-mode'
|
|
|
|
;; Copyright (C) 2012, 2013 Arne Jørgensen
|
|
|
|
;; Author: Arne Jørgensen <arne@arnested.dk>
|
|
|
|
;; This software is free software: you can redistribute it and/or
|
|
;; modify it under the terms of the GNU General Public License as
|
|
;; published by the Free Software Foundation, either version 3 of the
|
|
;; License, or (at your option) any later version.
|
|
|
|
;; This software is distributed in the hope that it will be useful,
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
;; General Public License for more details.
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
;; along with this software. If not, see
|
|
;; <http://www.gnu.org/licenses/>.
|
|
|
|
;;; Commentary:
|
|
|
|
;; Download and parse PHP manual from php.net and build a new
|
|
;; `php-extras-function-arguments' hash table of PHP functions and
|
|
;; their arguments.
|
|
|
|
;; Please note that build a new `php-extras-function-arguments' is a
|
|
;; slow process and might be error prone.
|
|
|
|
;;; Code:
|
|
|
|
(require 'php-mode)
|
|
(require 'php-extras)
|
|
|
|
|
|
|
|
(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.")
|
|
|
|
|
|
|
|
;;;###autoload
|
|
(defun php-extras-generate-eldoc ()
|
|
"Regenerate PHP function argument hash table from php.net. This is slow!"
|
|
(interactive)
|
|
(when (yes-or-no-p "Regenerate PHP function argument hash table from php.net? This is slow! ")
|
|
(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)
|
|
|
|
;;; %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)))))
|
|
|
|
(provide 'php-extras-gen-eldoc)
|
|
|
|
;;; php-extras-gen-eldoc.el ends here
|