 (defvar vimgolf-start-buffer-name "*vimgolf-start*")
 (defvar vimgolf-end-buffer-name "*vimgolf-end*")
 (defvar vimgolf-keystrokes-buffer-name "*vimgolf-keystrokes*")
+
+; Prevent the server from compressing the response
+(setq url-mime-encoding-string "identity")
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Keystroke logging

      (kill-buffer buf))))

(defun get-text (var response)
  (format "%s" (assoc-default 'data (assq var (request-response-data response)))))

(defun vimgolf-setup (status challenge-id)
  (defvar cid challenge-id)
  (deferred:$
    (request-deferred
     (format "%s" (vimgolf-challenge-url challenge-id))
     :parser 'json-read)
    (deferred:nextc it
      (lambda (response)

        (vimgolf-clear-keystrokes)
        (setq vimgolf-prior-window-configuration (current-window-configuration)
              vimgolf-challenge cid)
        (goto-char (point-min))

        (let* ((start-text (get-text 'in response))
               (end-text   (get-text 'out response)))
          (vimgolf-kill-existing-session)

          (let ((vimgolf-start-buffer (get-buffer-create vimgolf-start-buffer-name))
                (vimgolf-work-buffer (get-buffer-create vimgolf-work-buffer-name))
                (vimgolf-end-buffer (get-buffer-create vimgolf-end-buffer-name)))

            (vimgolf-init-buffer vimgolf-start-buffer start-text)
            (vimgolf-init-buffer vimgolf-end-buffer end-text)
            (with-current-buffer vimgolf-end-buffer (setq buffer-read-only t))
            (vimgolf-reset-work-buffer)

            ;; Set up windows
            (delete-other-windows)
            (display-buffer vimgolf-end-buffer 'display-buffer-pop-up-window)
            (set-window-buffer (selected-window) vimgolf-work-buffer)
            (switch-to-buffer vimgolf-work-buffer)
            (setq vimgolf-working-window-configuration (current-window-configuration))

            (vimgolf-continue)))))))

(defvar *vimgolf-browse-list* nil
  "Holds a list of parsed VimGolf challenges.")

;;; Code:

(require 'json)

(defgroup vimgolf nil
  "Compete on VimGolf with the One True Editor."
