 
 (define-minor-mode vimgolf-mode
   "Toggle VimGolf mode.
-     With no argument, this command toggles the mode. Non-null
-     prefix argument turns on the mode. Null prefix argument
-     turns off the mode.
-
-     When VimGolf mode is enabled, several key bindings are
-     defined with `C-c C-v` prefixes to help in playing VimGolf.
+
+With no argument, this command toggles the mode. Non-null prefix
+argument turns on the mode. Null prefix argument turns off the
+mode.
+
+When VimGolf mode is enabled, several key bindings are defined
+with `C-c C-v` prefixes to help in playing VimGolf.
 
 \\{vimgolf-mode-map}"
   ;; The initial value.

  :keymap vimgolf-mode-map
  :group 'vimgolf)

;;;###autoload
(defun vimgolf (challenge-id)
  "Open a VimGolf Challenge"
  (interactive "sChallenge ID: ")
  (progn
    (setq vimgolf-prior-window-configuration (current-window-configuration)
          vimgolf-challenge challenge-id)
    (let* ((vimgolf-yaml-buffer (url-retrieve-synchronously (concat "http://vimgolf.com/challenges/" challenge-id ".yaml"))))
      (save-current-buffer
        (set-buffer vimgolf-yaml-buffer)
        (goto-char (point-min))
        (search-forward "data: |+\n" nil t)
        (if (get-buffer "*vimgolf-start*") (kill-buffer "*vimgolf-start*"))
        (if (get-buffer "*vimgolf-work*") (kill-buffer "*vimgolf-work*"))
        (if (get-buffer "*vimgolf-end*") (kill-buffer "*vimgolf-end*"))
        (let ((vimgolf-start-buffer (get-buffer-create "*vimgolf-start*"))
              (vimgolf-work-buffer (get-buffer-create "*vimgolf-work*"))
              (vimgolf-end-buffer (get-buffer-create "*vimgolf-end*")))
          (progn
            (append-to-buffer vimgolf-start-buffer (point) (point-max))
            (append-to-buffer vimgolf-work-buffer (point) (point-max))
            (save-current-buffer
              (set-buffer vimgolf-start-buffer)
              (goto-char (point-min))
              (search-forward "    \n  type: input" nil t)
              (delete-region (match-beginning 0) (point-max))
              (decrease-left-margin (point-min) (point-max) 4)
              (goto-char (point-min))
              (vimgolf-mode t))
            (save-current-buffer
              (set-buffer vimgolf-work-buffer)
              (goto-char (point-min))
              (search-forward "    \n  type: input" nil t)
              (delete-region (match-beginning 0) (point-max))
              (decrease-left-margin (point-min) (point-max) 4)
              (goto-char (point-min))
              (vimgolf-mode t))
            (search-forward "data: |+\n" nil t)
            (append-to-buffer vimgolf-end-buffer (point) (point-max))
            (save-current-buffer
              (set-buffer vimgolf-end-buffer)
              (goto-char (point-min))
              (search-forward "    \n  type: output")
              (delete-region (match-beginning 0) (point-max))
              (decrease-left-margin (point-min) (point-max) 4)
              (goto-char (point-min))
              (vimgolf-mode t))
            (delete-other-windows)
            (display-buffer vimgolf-end-buffer 'display-buffer-pop-up-window)
            (set-window-buffer (selected-window) vimgolf-work-buffer)))))))



;; Use dribble file to allow for running from within emacs
;; Main interface should be `M-x vimgolf Challenge ID: <Enter ID> RET <Do Your Editing> C-c C-v C-c`
;; Could also use C-c C-v o to get the challenge ID prompt

;; We don't load up a vanilla mode. This could be used for sharing useful general code snippets that

;; Important to emphasis a 'good sport' attitude where the community enforces an anti-special solution attitude

;; Load up two buffers. One with the solution, one with the start.
;; Open a dribble file

  "A list of functions to call upon the initialization of vimgolf-mode."
  :type 'hook
  :group 'vimgolf)

(defvar vimgolf-mode-map
  (let ((map (make-sparse-keymap)))
