   (delq nil
   (mapcar (lambda (x) (and (funcall condp x) x)) lst)))
 
+(defun floobits-launch-agent ()
+  (when (boundp 'floobits-twisted-agent)
+    (delete-process floobits-twisted-agent))
+  (start-process "floobits-twisted-agent" "*Messages*" "~/floobits-agent"))
+
 (defun floobits-join-room (floourl)
 "Join a floobits room"
   (interactive (list (read-from-minibuffer "Floobits room URL (owner/room): " "https://floobits.com/r/")))

    (domain (url-host url-struct))
    (port (url-port url-struct))
    (path (url-filename url-struct))
    (_ (string-match "^/r/\\(.*\\)/\\(.*\\)/" path))
    (owner (match-string 1 path))
    (room (match-string 2 path)))
    (print (list path room owner))
    (if (and room owner)
      (progn
        (setq floobits-room room)
        (setq floobits-room-owner owner)
        (floobits-destroy-connection)
        (floobits-create-connection))
    (message "Invalid url! I should look like: https://floobits.com/r/owner/room"))))


;;(add-hook 'before-change-functions 'before-change nil nil)
(add-hook 'after-change-functions 'floobits-after-change nil nil)
(add-hook 'find-file-hook 'floobits-after-new-buffer nil t)
(floobits-launch-agent)
