summary refs log tree commit diff stats
path: root/emacs/elisp/eldoc-php.el
diff options
context:
space:
mode:
Diffstat (limited to 'emacs/elisp/eldoc-php.el')
-rw-r--r--emacs/elisp/eldoc-php.el48
1 files changed, 48 insertions, 0 deletions
diff --git a/emacs/elisp/eldoc-php.el b/emacs/elisp/eldoc-php.el
new file mode 100644
index 0000000..8101fea
--- /dev/null
+++ b/emacs/elisp/eldoc-php.el
@@ -0,0 +1,48 @@
+(require 'xml)
+(provide 'eldoc-php)
+
+(setq my-php-function-doc-hash (make-hash-table :test 'equal))
+
+
+(defun my-php-fetch-function-doc (function)
+  (let ((doc (gethash function my-php-function-doc-hash 'nope)))
+    (when (eq doc 'nope)
+      (setq doc nil)
+
+      (let ((buf (url-retrieve-synchronously (concat "http://uk3.php.net/manual-lookup.php?pattern=" function))))
+        (with-current-buffer buf
+          (goto-char (point-min))
+          (let (desc)
+            (when (re-search-forward "<div class=\"methodsynopsis dc-description\">\\(\\(.\\|\n\\)*?\\)</div>" nil t)
+              (setq desc
+                    (replace-regexp-in-string
+                     " +" " "
+                     (replace-regexp-in-string
+                      "\n" ""
+                      (replace-regexp-in-string "<.*?>" "" (match-string-no-properties 1)))))
+              ;; Don't show the function description
+              ;; (when (re-search-forward "<p class=\"para rdfs-comment\">\\(\\(.\\|\n\\)*?\\)</p>" nil t)
+              ;;   (setq desc
+              ;;         (concat desc "\n\n"
+              ;;                 (replace-regexp-in-string
+              ;;                  " +" " "
+              ;;                  (replace-regexp-in-string
+              ;;                   "\n" ""
+              ;;                   (replace-regexp-in-string "<.*?>" "" (match-string-no-properties 1)))))))
+              )
+
+            (if desc
+                (setq doc (xml-substitute-special desc)))))
+
+        (kill-buffer buf))
+
+      (puthash function doc my-php-function-doc-hash))
+
+    doc))
+
+
+(defun my-php-eldoc-function ()
+  (let ((symbol (thing-at-point 'symbol)))
+    (if (and symbol
+             (not (eq (elt symbol 0) ?$)))
+        (my-php-fetch-function-doc symbol))))