 
 (defun candidate-documentation (candidate)
   (get-pos-property 0 'value candidate))
-
-(defvar *my-candidate* nil)
 
 (defun pjs-local-vars-action ()
   (message (candidate-documentation candidate)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(ac-define-source "pjs-variable-members"
  '((prefix . pjs-variable-members-ac-prefix)
    (candidates . pjs-variable-members-ac-candidates)
;;    (document . pjs-namespaces-functions-ac-document)
;;    (action . pjs-namespaces-functions-ac-action)
    (symbol . "m ")
    (requires . -1)))

(defvar *current-pjs-variable* nil)

(defun pjs-variable-members-ac-prefix ()
  ;; detects the current namespace
  (save-excursion
    (save-match-data
      (let ((match (re-search-backward (format "\\(\\<%s\\>\\)\\([.]\\)\\(%s\\)?\\=" *js-variable-name* *js-variable-name*) (line-beginning-position) t)))	
	(when match
	  (1+ (setq *current-pjs-variable* (match-beginning 2))))))))

(defun pjs-variable-members-ac-candidates ()
  ;; get the type of the variable
  (let ((var-type (get-variable-type-in-context *current-pjs-variable*))
	res)
    (when var-type
      (let* ((members (pjs-class-members (car var-type) (cdr var-type)))
	     (res (pjs-class-methods (car var-type) (cdr var-type))))
	(maphash #'(lambda (k v)
		     (push k res)) members)
	res))))

;;; find locally defined variables
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(ac-define-source "pjs-classes"
  '(;;(prefix . pjs-classes-ac-prefix)
    (candidates . pjs-classes-ac-candidates)
    (symbol . "c ")
    (requires . -1)))

;; (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
      (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)
    (candidates . pjs-namespaces-functions-ac-candidates)
    (document . pjs-namespaces-functions-ac-document)
    (action . pjs-namespaces-functions-ac-action)
    (symbol . "f ")
    (requires . -1)))

;;(defvar *current-pjs-namespace-prefix* nil)
(defvar *pjs-current-docst* nil)

(defun pjs-namespaces-functions-ac-prefix ()
  ;; detects the current namespace
