 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 (ac-define-source "pjs-classes"
-  '((prefix . pjs-classes-ac-prefix)
+  '(;;(prefix . pjs-classes-ac-prefix)
     (candidates . pjs-classes-ac-candidates)
-;;    (document . pjs-namespaces-functions-ac-document)
-;;    (action . pjs-namespaces-functions-ac-action)
     (symbol . "c ")
     (requires . -1)))
 
-(defun pjs-classes-ac-prefix ()
-  ;; detects the current namespace
+;; (defun pjs-classes-ac-prefix ()
+;;   ;; detects the current namespace
+;;   (save-excursion
+;;     (save-match-data
+;;       (let ((match (re-search-backward (format "\\(\\<plc\\>\\)\\(\\.\\)\\(%s\\)?\\=" *js-variable-name*) (line-beginning-position) t)))
+;; 	(when match
+;; ;;	  (setq *current-pjs-namespace-prefix* "plc")
+;; 	  (1+ (match-beginning 2)))))))
+
+(defun pjs-classes-ac-candidates ()
   (save-excursion
     (save-match-data
-      (let ((match (re-search-backward (format "\\(\\<plc\\>\\)\\(\\.\\)\\(%s\\)?\\=" *js-variable-name*) (line-beginning-position) t)))
-	(when match
-;;	  (setq *current-pjs-namespace-prefix* "plc")
-	  (1+ (match-beginning 2)))))))
-
-(defun pjs-classes-ac-candidates ()
-  (list-pjs-plc-types))
+      (when (re-search-backward (format "\\(\\<plc\\>\\)\\(\\.\\)\\(%s\\)?\\=" *js-variable-name*) (line-beginning-position) t)
+	(list-pjs-plc-types)))))
 
 ;;; find functions and variables from  namespaces.
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 (ac-define-source "pjs-namespaces-functions"
-  '((prefix . pjs-namespaces-functions-ac-prefix)
+  '(;;(prefix . pjs-namespaces-functions-ac-prefix)
     (candidates . pjs-namespaces-functions-ac-candidates)
-;;    (document . pjs-namespaces-functions-ac-document)
-;;    (action . pjs-namespaces-functions-ac-action)
+    (document . pjs-namespaces-functions-ac-document)
+    (action . pjs-namespaces-functions-ac-action)
     (symbol . "f ")
     (requires . -1)))
 
-(defvar *current-pjs-namespace-prefix* nil)
+;;(defvar *current-pjs-namespace-prefix* nil)
+(defvar *pjs-current-docst* nil)
 
 (defun pjs-namespaces-functions-ac-prefix ()
   ;; detects the current namespace

	  (setq *current-pjs-namespace-prefix* (downcase (match-string-no-properties 1)))
	  (1+ (match-beginning 2)))))))

(defun pjs-namespaces-functions-ac-action ()  
  )

(defun pjs-namespaces-functions-ac-candidates ()
  (let ((functions (list-pjs-namespace-functions *current-pjs-namespace-prefix*))
	(vars      (list-pjs-namespace-variables *current-pjs-namespace-prefix*)))
    (append functions vars)))

(defun pjs-namespaces-functions-ac-document (docstr)
  docstr)

;;; find functions from current namespaces.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(ac-define-source "pjs-current-namespace-functions"
  '((candidates . pjs-current-namespace-functions-ac-candidates)
;;    (document . pjs-namespaces-functions-ac-document)
    ;;    (action . pjs-namespaces-functions-ac-action)
    (symbol . "f ")
    (requires . -1)))



(defun candidate-documentation (candidate)
  (get-pos-property 0 'value candidate))

(defun pjs-local-vars-action ()
  (message (candidate-documentation candidate)))
