 
 (defun before-change (begin end)
   (let ((text (get-text begin end)))
-    (add-to-list 'floobits-change-set (cons 'before `(,begin ,end ,text)))))
+    (add-to-list 'floobits-change-set (cons 'before `(,begin ,end ,text))))) 
 
 (defun after-change (begin end old_length)
-  (let ((text (get-text begin end)))
+  (let ((text (get-text begin end)))  
     (add-to-list 'floobits-change-set (cons 'after `(,begin ,end ,text)))
-    (send-to-agent floobits-change-set)
+    (send-to-agent floobits-change-set 'change)
   (setq floobits-change-set)))
 
 (defun after-new-buffer ()
   (let ((req '("event" "new-buffer")))
     (add-to-list 'req (cons 'text (get-text point-min point-max)))
     (add-to-list 'req (cons 'path (file-name-directory load-file-name)))
-    (send-to-agent req)))
+    (send-to-agent req 'new-buffer)))
 
 (add-hook 'before-change-functions 'before-change nil t)
 (add-hook 'after-change-functions 'after-change nil t)


(defun floobits-switch (text)
  (print text))
;  (let* ((json-key-type 'string) 
;	 (req (json-read-from-string text)))
;;    (message "%s" req)))

(defun floobits-listener(process response)
  (setq floobits-agent-buffer (concat floobits-agent-buffer response))
  (let ((position (search "\n" floobits-agent-buffer)))
       (if (not (eq nil position))
	   (progn (print position)
		  (floobits-switch (substring floobits-agent-buffer 0 position))
		  (setq floobits-agent-buffer 
			(substring floobits-agent-buffer 
				   (if (> (length floobits-agent-buffer) position) (+ 1 position) position)))
		  (floobits-listener process "")))))


(setq floobits-change-set ())
(setq floobits-agent-buffer "")

(defcustom floobits-username "kans"
  "Username for floobits"
  :type 'string
  )

(defcustom floobits-secret "1aiwkewqzwauexwnmqk9u9q3c"
  "Secret for floobits"
  :type 'string
  )

(defcustom floobits-room "test"
  "Room for floobits"
  :type 'stringq
  )

(defcustom floobits-room-owner "ggreer"
  "Room for floobits"
  :type 'stringq
  )
