Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Comment main sections, be sure to "provide" 'vimgolf, and re-use buff…

…er killing code
  • Loading branch information...
commit 8c5a1d427e17322f5468c1e1c368c9c7127f853a 1 parent 20cc0ad
Steve Purcell authored November 20, 2011

Showing 1 changed file with 28 additions and 16 deletions. Show diff stats Hide diff stats

  1. 44  emacs/vimgolf.el
44  emacs/vimgolf.el
@@ -95,20 +95,10 @@ with `C-c C-v` prefixes to help in playing VimGolf.
95 95
 (defvar vimgolf-end-buffer-name "*vimgolf-end*")
96 96
 (defvar vimgolf-keystrokes-buffer-name "*vimgolf-keystrokes*")
97 97
 
98  
-(defun vimgolf-solution-correct-p ()
99  
-  "Return t if the work text is identical to the solution, nil otherwise."
100  
-  (let ((case-fold-search nil)
101  
-        (work vimgolf-work-buffer-name)
102  
-        (end vimgolf-end-buffer-name))
103  
-    (flet ((point-min-in (buf) (with-current-buffer buf (point-min)))
104  
-           (point-max-in (buf) (with-current-buffer buf (point-max))))
105  
-      (zerop (compare-buffer-substrings
106  
-              (get-buffer work) (point-min-in work) (point-max-in work)
107  
-              (get-buffer end) (point-min-in end) (point-max-in end))))))
108 98
 
109  
-(defun vimgolf-wrong-solution ()
110  
-  (message "Wrong!")
111  
-  (vimgolf-diff))
  99
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  100
+;; Keystroke logging
  101
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
112 102
 
113 103
 (defmacro vimgolf-with-saved-command-environment (&rest body)
114 104
   `(let ((deactivate-mark nil)
@@ -179,6 +169,27 @@ unknown key sequence was entered).")
179 169
 (defun vimgolf-count-keystrokes ()
180 170
   (apply '+ (mapcar 'length (mapcar 'car vimgolf-keystrokes))))
181 171
 
  172
+
  173
+
  174
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  175
+;; Managing and scoring challenges
  176
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  177
+
  178
+(defun vimgolf-solution-correct-p ()
  179
+  "Return t if the work text is identical to the solution, nil otherwise."
  180
+  (let ((case-fold-search nil)
  181
+        (work vimgolf-work-buffer-name)
  182
+        (end vimgolf-end-buffer-name))
  183
+    (flet ((point-min-in (buf) (with-current-buffer buf (point-min)))
  184
+           (point-max-in (buf) (with-current-buffer buf (point-max))))
  185
+      (zerop (compare-buffer-substrings
  186
+              (get-buffer work) (point-min-in work) (point-max-in work)
  187
+              (get-buffer end) (point-min-in end) (point-max-in end))))))
  188
+
  189
+(defun vimgolf-wrong-solution ()
  190
+  (message "Wrong!")
  191
+  (vimgolf-diff))
  192
+
182 193
 (defun vimgolf-right-solution ()
183 194
   (message "Hurray! You solved %s in %d keystrokes!" vimgolf-challenge (vimgolf-count-keystrokes)))
184 195
 
@@ -233,10 +244,8 @@ unknown key sequence was entered).")
233 244
 (defun vimgolf-quit ()
234 245
   "Cancel the competition."
235 246
   (interactive)
236  
-  (if (get-buffer vimgolf-start-buffer-name) (kill-buffer vimgolf-start-buffer-name))
237  
-  (if (get-buffer vimgolf-work-buffer-name) (kill-buffer vimgolf-work-buffer-name))
238  
-  (if (get-buffer vimgolf-end-buffer-name) (kill-buffer vimgolf-end-buffer-name))
239 247
   (vimgolf-enable-capture nil)
  248
+  (vimgolf-kill-existing-session)
240 249
   (set-window-configuration vimgolf-prior-window-configuration)
241 250
   (message "I declare you, n00b!"))
242 251
 
@@ -264,6 +273,7 @@ unknown key sequence was entered).")
264 273
     (vimgolf-mode t)))
265 274
 
266 275
 (defun vimgolf-kill-existing-session ()
  276
+  "Kill any vimgolf-related buffers."
267 277
   (dolist (buf (list vimgolf-start-buffer-name
268 278
                      vimgolf-work-buffer-name
269 279
                      vimgolf-end-buffer-name
@@ -315,4 +325,6 @@ unknown key sequence was entered).")
315 325
 
316 326
         (vimgolf-enable-capture t)))))
317 327
 
  328
+
  329
+(provide 'vimgolf)
318 330
 ;;; vimgolf.el ends here

0 notes on commit 8c5a1d4

Please sign in to comment.
Something went wrong with that request. Please try again.