Source

emacs-achievements / basic-achievements.el

Full commit
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
;;; basic-achievements.el --- Some basic achievements

;; Author: Ivan Andrus <darthandrus@gmail.com>
;; Maintainer: Ivan Andrus <darthandrus@gmail.com>
;; Created: 2012-10-07
;; Keywords: games

;;; Commentary:

;; This is the main entry point for achievement defintions.  Other
;; files can be included from here using the `:unlocks' slot.

;;; Code:

(require 'achievements-functions)

;;{{{ meta

(defachievement "Achiever"
  "You used the achievements package."
  :predicate t)

(defachievement "Not All There"
  "You have a fractional achievement score."
  ;; Note: This is meant to be the only one that has fractional score
  :points .5
  :predicate '(/= achievements-score (round achievements-score)))

(defachievement "Unlocker"
  "You have earned over 50 points in Emacs achievements.  Not bad."
  :predicate '(>= achievements-score 50)
  :unlocks 'advanced-achievements)

(defachievement "Over Achiever"
  "You have earned 500 points in Emacs achievements.  Don't you have some real work to do?"
  :predicate '(>= achievements-score 500))

(defachievement "Cheater"
  "You have earned all Emacs achievements.  Actually that's impossible."
  :predicate '(every #'achievements-earned-p achievements-list))

;;}}}
;;{{{ Help

(defachievement "Free Software Zealot"
  "You've read the sales pitch."
  :command '(about-emacs
             describe-copying
             describe-distribution
             describe-gnu-project
             describe-no-warranty))

(defcommand-achievements
  "You learned new things by using `%s'."
  ((help-for-help "First things first")
   (help-with-tutorial "Show me the way") ;; Also one if finished the tutorial
   (info-emacs-manual "RTFM")
   (view-echo-area-messages "Log Auditor")
   (view-emacs-FAQ "FAQ")
   (view-emacs-news "What's new?")
   (view-emacs-problems "Am I the only one?")
   (view-emacs-debugging "Entomologist")
   (view-emacs-todo "Joining the cause")
   (view-external-packages "Where else can I look?")
   ((view-hello-file
     describe-language-environment
     describe-input-method
     describe-coding-system) "World Traveler")
   ((finder-by-keyword describe-package) "Package Hunter")))

(defcommand-achievements
  "You answered a question by using `%s'."
  ((apropos-documentation "I know I read it somewhere")
   (apropos "Apropos of Nothing")
   (apropos-value "Answer in search of a question")
   (describe-bindings "What to type?")
   ((describe-function
     Info-goto-emacs-command-node
     info-lookup-symbol
     describe-variable
     describe-mode) "What does this do?")
   ((describe-key
     describe-key-briefly
     Info-goto-emacs-key-command-node
     where-is) "What happens when I do this?")
   (describe-syntax "When is a word not a word?")
   ((command-history view-lossage) "What did I just do?")))

(defachievement "Shortcut genius"
  "You don't need to learn new shortcuts anymore."
  :variable '(suggest-key-bindings nil))

;; (display-local-help "")              ;; What is this?
;; (defachievement ""
;;   "You have read at least 10 pages of the read the manual.")
;; (defachievement "Book worm"
;;   "You have read at least 100 pages of the read the manual.")
;; eldoc

;;}}}
;;{{{ .emacs

(defachievement "Streamlined"
  "Your .emacs took less that 1 second to load."
  :predicate '(< (float-time (time-subtract after-init-time before-init-time)) 1)
  :transient t)

(defachievement "Oops"
  "Your .emacs file had an error."
  :predicate 'init-file-had-error)

(defachievement "Traditionalist"
  "You use .emacs instead of .emacs.d/init.el."
  :predicate '(string-match "/\\.emacs\\'" user-init-file))

(defachievement "Modernist"
  "You use .emacs.d/init.el instead of .emacs."
  :predicate '(string-match "/init\\.el\\'" user-init-file))

(defachievement "Post Modernist"
  "You don't use .emacs.d/init.el or .emacs."
  :predicate '(not (or (string-match "/init\\.el\\'" user-init-file)
                       (string-match "/\\.emacs\\'" user-init-file))))

(defachievement "Need for Speed"
  "Your .emacs is byte-compiled."
  :predicate '(or (file-exists-p (concat user-init-file "c"))
                  ;; TODO: I _think_ this is right for .emacs
                  (file-exists-p (concat user-init-file ".elc"))))

(defachievement "Last Year's Model"
  "Your byte-compiled .emacs is out of date."
  :predicate '(cond ((file-exists-p (concat user-init-file "c"))
                     (file-newer-than-file-p
                      user-init-file
                      (concat user-init-file "c")))
                    ((file-exists-p (concat user-init-file ".elc"))
                     (file-newer-than-file-p
                      user-init-file
                      (concat user-init-file ".elc")))))

(defachievement "Purest Vanilla"
  "You have no .emacs file.  How is that even possible?"
  :predicate '(not (file-exists-p user-init-file)))

;; Other sizes here
;; (defachievement "Jabba the Hutt"
;;   "Your .emacs is so big, it runs a crime syndicate on Tatooine."
;;   )

;;}}}
;;{{{ Fun and Games

(defcommand-achievements
  "You have enjoyed `%s'."
  ((5x5 "Twenty Five")
   (animate "The Future of Pixar")
   (artist-mode "Van Gogh")
   (blackbox "Hide and Seek")
   (bubbles "Blubb blubb")
   (butterfly "Change the world!")
   (decipher "Spy vs Spy")
   (dissociated-press "Tabloids")
   (doctor "I <3 Eliza")
   (dunnet "Adventure!")
   (gomoku "Connect 5")
   (handwrite "Penmanship")
   (hanoi "Saigon")
   ;; (landmark "") ;; I have no idea what this is
   (life "It's Alive!")
   (morse-region "Telegraph Operator")
   (mpuz "Arithmetician")
   (pong "Ping")
   (snake "Chase your tail")
   (solitaire "All alone?")
   (tetris "Tessellator")
   (yow "Yow!")
   (zone "The Matrix"))
  :min-score 50)

;; These probably need packages.  Also check out
;; http://www.emacswiki.org/emacs/CategoryGames
(defcommand-achievements
  "You have installed and enjoyed `%s'."
  ((emstar "Um, Star?" )
   (fliptext-flip-region "Can you read upside down?")
   (nethack "Hack, hack, hack")
   (nyan-mode "Nyan, Nyan, Nyan"))
  :min-score 100)

;;}}}
;;{{{ Uptimes

(defachievement "Pretty Stable"
  "You have an uptime of over 1 day."
  :package 'uptimes
  :predicate `(> (let* ((uptime (car uptimes-top-n))
                        (seconds (- (cddr uptime) (cadr uptime))))
                   seconds)
                 ,(* 60 60 24 1)))

(defachievement "It keeps going and going..."
  "You have an uptime of over 1 week."
  :package 'uptimes
  :predicate `(> (let* ((uptime (car uptimes-top-n))
                        (seconds (- (cddr uptime) (cadr uptime))))
                   seconds)
                 ,(* 60 60 24 7)))

(defachievement "Marathon Hacker"
  "You have an uptime of over 30 days."
  :package 'uptimes
  :predicate `(> (let* ((uptime (car uptimes-top-n))
                        (seconds (- (cddr uptime) (cadr uptime))))
                   seconds)
                 ,(* 60 60 24 30)))

(defachievement "Methuselah"
  "You have an uptime of over 1 year!?"
  :package 'uptimes
  :predicate `(> (let* ((uptime (car uptimes-top-n))
                        (seconds (- (cddr uptime) (cadr uptime))))
                   seconds)
                 ,(* 60 60 24 365)))

;;}}}
;;{{{ Number of characters written

(defachievement "Short Story"
  "You've written the equivalent of a short story."
  :predicate `(> (achievements-num-times-commands-were-run
                 '(self-insert-command
                   org-self-insert-command))
                 ,(* 2000 6)))        ;; ~ 5/word + space

(defachievement "Nanowrimo"
  "You could have finished Nanowrimo by now."
  :predicate `(> (achievements-num-times-commands-were-run
                 '(self-insert-command
                   org-self-insert-command))
                 ,(* 50000 6)))

(defachievement "War and Peace"
  "You've written the equivalent of War and Peace."
  :predicate `(> (achievements-num-times-commands-were-run
                 '(self-insert-command
                   org-self-insert-command))
                 ,(* 587287 6)))

(defachievement "Proust"
  "You could have beaten Proust for longest novel."
  :predicate `(> (achievements-num-times-commands-were-run
                 '(self-insert-command
                   org-self-insert-command))
                 ,(* 1200000 6)))

;;}}}
;;{{{ Operating system

(defachievement "Loyalist"
  "You use GNU Emacs"
  :predicate '(not (string-match "XEmacs\\|Lucid" emacs-version)))

(defachievement "Patriot or Rebel?"
  "You use XEmacs"
  :predicate '(string-match "XEmacs\\|Lucid" emacs-version))

;; (defachievement "Switch Hitter"
;;   "You use both GNU Emacs and XEmacs")

;; What version of emacs you are using

(defvalue-achievements window-system
  "You have used the %s version Emacs."
  (("Green Glowing faces" nil "console")
   ("X marks the spot" x)
   ("MacPort or Aquamacs" mac)
   ("GNUStep or Cocoa" ns "nextstep")
   ("Windows" w32 "windows")
   ("DOS?" pc "DOS")))

(defvalue-achievements system-type
  "You have used Emacs on a %s system."
  (("Following the Hurd" gnu)
   ("Tux's Friend" gnu/linux)
   ("Beastie's Pal" gnu/kfreebsd)
   ("Friends with Hexley" darwin)
   ("DOS Box" ms-dos)
   ("Windows Machine" windows-nt)
   ("The Swan" cygwin)))

;;}}}
;;{{{ Identity

(defachievement "Anonymous"
  "You have `user-mail-address' set to nil."
  :predicate '(equal user-mail-address nil))

(defachievement "The One and Only"
  "You are Richard Stallman."
  :predicate '(equal user-mail-address "rms@gnu.org")
  :points 50)

;; TODO: need list of old maintainers, as well as for XEmacs
(defachievement "A Well Oiled Machine"
  "You help maintain Emacs."
  :predicate '(member user-mail-address
                      '("rms@gnu.org"
                        "cyd@gnu.org"
                        "monnier@iro.umontreal.ca"))
  :points 50)

;;}}}
;;{{{ packages

(defachievement "Tainted Love"
  "You have enabled non-GNU package repositories."
  :package 'package
  :predicate '(some (lambda (repo)
                      (not (string-match "elpa\\.gnu\\.org" (cdr repo))))
                    package-archives))

(defachievement "Vanilla"
  "You have no installed packages."
  :predicate '(= (length package-alist) 0))

(defachievement "Package Neophyte"
  "You have installed at least 1 package."
  :predicate '(>= (length package-alist) 1))

(defachievement "Package Apprentice"
  "You have installed over 10 packages."
  :predicate '(>= (length package-alist) 10))

(defachievement "Package Journeyman"
  "You have installed over 100 packages."
  :predicate '(>= (length package-alist) 100))

;; (defachievement "Drew Adams fanboy"
;;   "You are using 3 or more packages by Drew Adams.")

;; More package creators ...

;;}}}
;;{{{ Buffers & processess

(defachievement "Clean Desk"
  "You have less than 10 buffers open."
  :predicate '(<= (length (buffer-list)) 10))

(defachievement "Messy Desk"
  "You have over 100 buffers open."
  :predicate '(>= (length (buffer-list)) 100))

(defachievement "Papers to the ceiling"
  "You have over 1000 buffers open."
  :predicate '(>= (length (buffer-list)) 1000))

(defachievement "The Ol' Switcheroo"
  "You've switched to another buffer"
  :command '(switch-to-buffer ido-switch-buffer))

(defachievement "Buffer, buffers, everywhere"
  "You've seen all the buffers that can be seen."
  :command '(list-buffers ibuffer))

(defachievement "Top o' the morning"
  "You've used Emacs as a replacement for top."
  :command 'proced)

;;}}}
;;{{{ Arrow keys

(defun input-in-a-row (input val)
  `(let ((in-a-row 0)
         (success nil))
     (mapc
      (lambda (e)
        (if (memq e ',input)
            (if (>= (incf in-a-row) ,val) (setq success t))
          (setq in-a-row 0)))
      (recent-keys))
     success))

(defachievement "Archer"
  "You use the arrow keys a lot."
  :predicate (input-in-a-row '(right left up down) 5))

(defachievement "William Tell"
  "You use the arrow keys for almost everything."
  :predicate (input-in-a-row '(right left up down) 20))


(defvar achievements--arrow-keys-needing-replacements
  '(right left up down))

(defvar achievements--arrow-key-replacement-commands
  (mapcar
   (lambda (x) (lookup-key global-map (vector x)))
   achievements--arrow-keys-needing-replacements))

(defachievement "No arrows"
  "You know the replacements for the arrow keys."
  :post-command
  (lambda ()
    (when (and (memq this-command achievements--arrow-key-replacement-commands)
               (not (memq last-input-event achievements--arrow-keys-needing-replacements)))
      (setq achievements--arrow-key-replacement-commands
            (delete this-command
                    achievements--arrow-key-replacement-commands))
      (equal 0 (length achievements--arrow-key-replacement-commands)))))

;;}}}

(provide 'basic-achievements)

;;; basic-achievements.el ends here