A
download flame.el
Language: Lisp
License: GPL
Copyright: (C) 1986, 1987 Ian G. Batten (C) 1994, 2002 Noah S. Friedman
LOC: 554
Project Info
Galatea
Server: BerliOS (SVN)
Type: svn
...alatea\trank\.xemacs\elisp\
   active-menu.el
   autorevert.el
   color-theme.el.flc
   ctypes.el
   dired-single.el
   dos2unix.el
   doxymacs.el
   doxymacs.el.flc
   face-list.el
   file-confirm.el
   flame.el
   follow.el
   gtags.el
   highlight-completion.el
   highlight-current-line.el
   iv-mode.el
   member-functions.el
   nc.el
   nc.el.flc
   plsql.el
   psql-mode.el
   psvn.el
   psvn.el.flc
   searchmenu.el
   session.el
   shell-command.el
   template.el
   tex-site.el
   xml-parse.el

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
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
;;; flame.el --- automatic generation of flamage, as if we needed more

;; Copyright (C) 1986, 1987 Ian G. Batten
;; Copyright (C) 1994, 2002 Noah S. Friedman

;; Author: Ian G. Batten <batten@uk.ac.bham.multics>
;;         Noah Friedman <friedman@splode.com>
;; Maintainer: Noah Friedman <friedman@splode.com>
;; Keywords: games

;; $Id: flame.el,v 1.1.1.1 2003/03/10 20:23:15 michael Exp $

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, you can either send email to this
;; program's maintainer or write to: The Free Software Foundation,
;; Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA.

;;; Commentary:

;; This program was inspired from a version written in 1986 by
;; Ian G. Batten <batten@uk.ac.bham.multics>, which had been derived from
;; an ancient yacc program.  Other than reusing the same sentence fragment
;; templates for the grammar below, this is a complete rewrite.

;; The comments from the original version read as follows:
;;
;;         "Flame" program.  This has a chequered past.
;;
;;         The original was on a Motorola 286 running Vanilla V.1,
;;         about 2 years ago.  It was couched in terms of a yacc (I think)
;;         script.  I pulled the data out of it and rewrote it as a piece
;;         of PL/1 on Multics.  Now I've moved it into an emacs-lisp
;;         form.  If the original author cares to contact me, I'd
;;         be very happy to credit you!
;;
;;         Ian G. Batten, Batten@uk.ac.bham.multics
;;
;; On 1994-01-09, I discovered that rms dropped this file from the Emacs 19
;; distribution; this was sometime before 19.7 was released.  He made no
;; ChangeLog entry and didn't keep the source file around (by convention,
;; we usually renamed files we wanted to keep but not go into official
;; distributions so that they started with `=', e.g. `=flame.el').  This is
;; all he had to say about it when I asked:
;;
;;       I think I decided I was unhappy with the legal papers for it.
;;       Removing it took less time than trying to deal with it
;;       any other way.
;;
;; At the time, I was unable to locate Ian Batten though he has sinced
;; resurfaced via the web.

;;; Code:

(defvar flame-grammar
  '((sentence
     "*adjective *group-adj *der-term!"
     "*der-term!"
     "*statement, huh?  So, *statement?"
     "*statement, right?"
     "*statement."
     "ban *thing^s!"
     "ban the war on *war-thing!"
     "don't you realise that *statement?"
     "furthermore, you *der-term, *statement."
     "how can you be so *adjective?"
     "how can you say that *statement?"
     "I can't believe how *adjective you are."
     "I couldn't care less about your *thing."
     "I don't want to hear about your *thing."
     "I firmly believe that *statement."
     "I have many *group-adj friends."
     "I mean, *sentence"
     "I'll bet you think that *thing^s are *adjective."
     "I've never heard anything as ridiculous as the idea that *statement."
     "it takes a *group-adj *der-term like you to say that *statement."
     "it's well known that *statement."
     "let me tell you something, you *der-term, *statement."
     "man, *sentence"
     "no nukes!"
     "only a *der-term like you would say that *statement."
     "save the *thing^s!"
     "why, *statement!"
     "you have the *quality of a *der-term."
     "you know, *statement."
     "you make me sick."
     "you must be a real *der-term to think that *statement."
     "you sound like a real *der-term."
     "you *adjective *group-adj *der-term!"
     "you're a typical *group-adj person, totally *adjective."
     "you're always totally wrong."
     "you're probably *group-adj yourself."
     "your *quality is matched only by your *quality."
     "your *quality reminds me of a *thing.")

    (quality
     "*adjective *quality"
     "bad grammar"
     "depravity"
     "dishonesty"
     "ignorance"
     "lack of common decency"
     "lack of intelligence"
     "lousiness"
     "narrow-mindedness"
     "nastiness"
     "poor hygiene"
     "prejudice"
     "rotten spelling"
     "stupidity"
     "subtlety"
     "ugliness"
     "worthlessness")

    (adjective
     "*adjective and *adjective"
     "abusive"
     "as *adjective as a *thing"
     "bad"
     "blasphemous"
     "bloated"
     "boring"
     "braindamaged"
     "cheesy"
     "crass"
     "criminal"
     "depressing"
     "disgusting"
     "dogmatic"
     "dumb"
     "egocentric"
     "egregious"
     "fallacious"
     "fatuous"
     "felonious"
     "flatulent"
     "foul"
     "gratuitous"
     "heretical"
     "hilarious"
     "histrionic"
     "hypocritical"
     "idiotic"
     "ignorant"
     "improper"
     "incompetent"
     "insipid"
     "intolerable"
     "libelous"
     "lousy"
     "ludicrous"
     "malignant"
     "misanthropic"
     "nasty"
     "nonsensical"
     "odious"
     "pathetic"
     "pedantic"
     "perverted"
     "phoney"
     "pompous"
     "ponderous"
     "preposterous"
     "presumptuous"
     "primitive"
     "psychotic"
     "puerile"
     "repellent"
     "repugnant"
     "sadistic"
     "satanic"
     "selfish"
     "shallow"
     "sick"
     "sophomoric"
     "stupid"
     "superfluous"
     "unpleasant"
     "vacuous")

    (der-term
     "*adjective *der-term"
     "*der-term *der-term"
     "arsehole"
     "beast"
     "capitalist"
     "coward"
     "creep"
     "cretin"
     "DAF driver"
     "disease carrier"
     "dogmatist"
     "drunk"
     "fascist"
     "fathead"
     "fool"
     "geek"
     "goof"
     "idiot"
     "ignoramus"
     "incompetent"
     "jerk"
     "lamer"
     "lunkhead"
     "luser"
     "maniac"
     "marxist"
     "meathead"
     "moron"
     "Nazi"
     "Neanderthal"
     "pea brain"
     "peasant"
     "quiche-eater"
     "racist"
     "rat"
     "sadist"
     "sexist"
     "slimebag"
     "spaz"
     "SysThug"
     "terrorist"
     "twit"
     "wally"
     "wanker"
     "weakling"
     "weasel"
     "whimpering scumbag"
     "wimp")

    (thing
     "*adjective *thing"
     "bug fix"
     "business plan"
     "cardboard cut-out"
     "computer"
     "copyright"
     "cruise missile"
     "disease"
     "dog"
     "drug habit"
     "graphics editor"
     "Honeywell dps8"
     "Jewish grandmother"
     "lawyer"
     "license agreement"
     "Lisp Machine"
     "mental problem"
     "MicroVAX II"
     "MP3"
     "operation"
     "PAD"
     "processed lunch meat"
     "prostitute"
     "punk haircut"
     "random frob"
     "real-time clock"
     "religion"
     "right wing death squad"
     "sexist joke"
     "sexual fantasy"
     "sexual problem"
     "shopping mall"
     "source license"
     "surfboard"
     "system call"
     "ten-incher"
     "terrorist"
     "text editor"
     "TI 99/4a"
     "vegetable"
     "venereal disease"
     "venture capitalist"
     "VIC-20"
     "whale"
     "wood-burning stove")

    (group-adj
     "*adjective"
     "*thing^-loving"
     "black"
     "Chinese"
     "communist"
     "crazy"
     "dead"
     "fascist"
     "feminist"
     "foreign"
     "French"
     "funny-looking"
     "gay"
     "homosexual"
     "intellectual"
     "Iranian"
     "Italian"
     "Jewish"
     "lesbian"
     "mentally retarded"
     "Mexican"
     "Moonie"
     "Nicaraguan"
     "old"
     "Polish"
     "poor"
     "Puerto Rican"
     "religious"
     "rich"
     "short"
     "unborn"
     "underpriviledged"
     "white"
     "working"
     "young")

    (statement
     "*group-adj people are all *adjective *der-term^s"
     "*group-adj people are all *adjective because *reason"
     "*group-adj people are inherently superior to *group-adj people"
     "*group-adj people are *adjective"
     "*group-adj people are *adjective, and *reason"
     "*group-adj people don't get married to *group-adj people because *reason"
     "*person's ghost is living in your *thing"
     "*person's *quality is *adjective"
     "*person is a cool dude"
     "*person is a *der-term"
     "*person is just a figment of your imagination"
     "*person is secretly *group-adj"
     "*person is *adjective"
     "*person is *group-adj"
     "*person killed *person"
     "*person was *group-adj"
     "*quality is pretty fun"
     "*statement, and *statement"
     "*statement, because *statement"
     "*statement, but *statement"
     "*thing^s are fun"
     "a *group-adj man ain't got nothing in the world these days"
     "all *group-adj dudes should get *thing^s"
     "breathing causes cancer"
     "every *group-adj person is a *der-term"
     "everything is really a *thing"
     "God is Dead"
     "I was *person in a previous life"
     "I wish I had a *thing"
     "I wish I were a *thing"
     "if you've seen one *thing, you've seen them all"
     "it's a wonderful day"
     "it's fun to be really *adjective"
     "it's OK to run down *group-adj people"
     "just because you read it in the *paper that doesn't mean it's true"
     "Lassie was *group-adj"
     "life is a *thing"
     "life is *quality"
     "men are inherently superior to women"
     "most *group-adj people have *thing^s"
     "*computer-os is a really *adjective operating system"
     "my *thing is pretty good"
     "people are dying every day"
     "technology is evil"
     "the *conspirators killed *person"
     "the Earth is flat"
     "the Martians are coming"
     "the more *thing^s you have, the better"
     "the oceans are full of dirty fish"
     "the *conspirators are tapping your phone"
     "the sexual revolution is over"
     "the system staff is fascist"
     "the world is full of *der-term^s"
     "the *group-adj culture is fascinating"
     "the *group-adj people have really got it all together"
     "the *paper is always right"
     "the *war-thing is great"
     "there is life after death"
     "there's a *thing in *person's brain"
     "trees are *adjective"
     "we should end the war on *war-thing"
     "we should fight the war on *war-thing"
     "when ya gotta go ya gotta go"
     "women are inherently superior to men"
     "you have a *thing"
     "you hope that *statement"
     "you look like a *thing"
     "you must be a *adjective *der-term to think that *person said *statement"
     "you remind me of *person"
     "you should have a *thing"
     "you think that *statement"
     "you wish you were a *thing"
     "you wish you were *group-adj"
     "you're a *der-term"
     "you're *group-adj"
     "your *thing is great")

    (paper
     "Beano"
     "Boston Glob"
     "Centre Bulletin"
     "Daily Express"
     "Daily Mail"
     "Daily Mirror"
     "Daily Telegraph"
     "Multics Manual"
     "New York Times"
     "Pravda"
     "Sun"
     "Wall Street Journal")

    (person
     "\"Head-for-the-mountains\" Bush"
     "Alaric the Visigoth"
     "Attilla the Hun"
     "Bill Gates"
     "Caesar"
     "Fidel Castro"
     "Dennis Ritchie"
     "Gadaffi"
     "Groucho"
     "Heidegger"
     "Henry Kissinger"
     "Hitler"
     "JFK"
     "Karl Marx"
     "Ken Thompson"
     "Michael Jackson"
     "Napoleon"
     "Nietzsche"
     "Nixon"
     "Reagan"
     "Thatcher"
     "the Pope"
     "Yassir Arafat")

    (conspirators
     "CIA"
     "Cubans"
     "Democrats"
     "drug cartels"
     "FBI"
     "Illuminati"
     "Israelis"
     "KGB"
     "Mafia"
     "Martians"
     "NSA"
     "PLO"
     "Republicans"
     "Russians"
     "Yakuza")

    (computer-os
     "AIX"
     "CP/M"
     "Genera"
     "ITS"
     "Linux"
     "MS-DOG"
     "Multics"
     "MVS"
     "OS/9"
     "OSX"
     "Primos"
     "Unix"
     "Windoze"
     "VMS")

    (war-thing
     "*der-term^s"
     "democracy"
     "drugs"
     "freedom"
     "homelessness"
     "poverty"
     "spammers"
     "terrorism")

    (reason
     "*person wouldn't have done it"
     "they can't afford *thing^s"
     "they can't spray paint that small"
     "they can't tell them apart from *group-adj dudes"
     "they don't have *thing^s"
     "they don't know how"
     "they don't want their children to grow up to be too lazy to steal"
     "they're too *adjective")))

(defmacro flame-random (n)
  (if (and (numberp n)
           (string-lessp emacs-version "19"))
      (list '% '(abs (random)) n)
    (list 'random n)))


;; public functions

;;;###autoload
(defun flame (&optional n insertp)
  "Generate a random flame.
Prefix argument N means generated a flame of N sentences.

If called interactively, the results are displayed in a temporary buffer.
 Use \\[insert-flame] to insert a flame into the current buffer.

If called from lisp, a list of N sentences is returned.
If optional arg INSERTP is non-nil, the sentences are inserted into the
 current buffer at point, formatted as a paragraph.
 \(Use `flame-paragraph' to obtain a formatted paragraph as a string.\)"
  (interactive "p")
  (or n (setq n 1))
  (let ((l nil))
    (while (not (zerop n))
      (setq l (cons (flame-string) l))
      (setq n (1- n)))
    (and (or insertp (interactive-p))
         (flame-display (mapconcat 'identity l "  ") "*Flame*" insertp))
    l))

;;;###autoload
(defun insert-flame (&optional n)
  "Insert a flame into the current buffer.
Prefix argument N means insert N sentences, formatted as a paragraph."
  (interactive "p")
  (flame n t))

;;;###autoload
(defun flame-string ()
  "Generate an inflammatory statement, and return it."
  (flame-capitalize (flame-substitute 'sentence) t))

;;;###autoload
(defun flame-paragraph (&optional n)
  "Generate a paragraph of inflammatory stagements, and return it.
Argument N determines how many sentences are in the paragraph."
  (let ((buf (generate-new-buffer " *flame-paragraph*")))
    (unwind-protect
        (save-excursion
          (set-buffer buf)
          (insert-flame n)
          ;; don't return final newline
          (buffer-substring (point-min) (1- (point-max))))
      (kill-buffer buf))))

;;;###autoload
(defun psychoanalyze-flamer ()
  "Mr. Angry goes to the analyst."
  (interactive)
  (doctor)                              ; start the psychotherapy
  (message "")
  (switch-to-buffer "*doctor*")
  (sit-for 0)
  (while (not (input-pending-p))
    (insert-flame (1+ (flame-random 2)))
    (insert "\n")
    (sit-for 0)
    (doctor-ret-or-read 1)))


(defun flame-display (string temp-buffer-name insertp)
  (let ((temp-buffer-show-function temp-buffer-show-function)
        (temp-buffer-show-hook
         (function (lambda ()
                     (fill-paragraph nil)))))

    (cond (insertp
           (save-restriction
             (narrow-to-region (point) (point))
             (insert string)
             (fill-paragraph nil)))

          (t
           ;; Play nice with JBW's temp-buffer window height
           ;; minimization hacks
           (and (eq temp-buffer-show-function 'show-temp-buffer)
                (setq temp-buffer-show-function
                      (function (lambda (buf)
                                  (save-excursion
                                    (set-buffer buf)
                                    (fill-paragraph nil))
                                  (show-temp-buffer buf)))))
           (with-output-to-temp-buffer temp-buffer-name
             (princ string))))))

;; Return a random member of list L.
(defun flame-random-member (l)
  (and (consp l)
       (nth (flame-random (length l)) l)))

;; Tokenize sentence so substitution words are separated.
;; The character `^' can be used to join suffixes to the end of a
;; substitution token, but do not show up in the resulting list.
;; e.g. "Many *word^s with *sub, with 2^32 at *end."
;;      => ("Many " "*word" "s with " "*sub" ", with 2^32 at " "*end" ".")
(defun flame-split (s)
  (let ((l nil)
        (p 0)
        (len (length s))
        (md (match-data)))
    (while (and p (string-match "[*!][a-z-]+" s p))
      (and (< p (match-beginning 0))
           (setq l (cons (substring s p (match-beginning 0)) l)))
      (setq l (cons (substring s (match-beginning 0) (match-end 0)) l))
      (setq p (match-end 0))
      (cond ((>= p len)
             (setq p nil))
            ((char-equal ?^ (aref s p))
             (setq p (1+ p)))))
    (and p
         (< p len)
         (setq l (cons (substring s p) l)))
    (store-match-data md)
    (nreverse l)))

;; Rudimentary pluralization correction
(defun flame-plural-correct (l)
  (let ((p l)
        elt end)
    (while (and p (cdr p))
      (cond ((char-equal ?s (aref (car (cdr p)) 0))
             (setq elt (car p))
             (setq end (aref elt (1- (length elt))))
             (cond ((char-equal end ?y)
                    (setcar p (concat (substring elt 0 -1) "ie")))
                   ((char-equal end ?x)
                    (setcar p (concat elt "e"))))))
      (setq p (cdr p))))
  l)

;; Iterate over string STR, replacing all substrings beginning
;; with a '*' or '!'  with a random selection from the appropriate list.
(defun flame-iterate-list (str)
  (let* ((l (flame-split str))
         (p l)
         elt)
    (while p
      (setq elt (car p))
      (cond ((= (length elt) 1))
            ((= (aref elt 0) ?*)
             (setcar p (flame-substitute elt)))
            ((= (aref elt 0) ?!)
             (setcar p (flame-capitalize (flame-substitute elt)))))
      (setq p (cdr p)))
    (mapconcat 'identity (flame-plural-correct l) "")))

(defun flame-substitute (category)
  (let ((tbl (flame-category category)))
    (if tbl
        (flame-iterate-list (flame-random-member tbl))
      category)))

(defun flame-category (category)
  (and (stringp category)
       (setq category (intern (substring category 1))))
  (cdr (assq category flame-grammar)))

(defun flame-capitalize (s &optional destructive)
  (or destructive
      (setq s (copy-sequence s)))
  (aset s 0 (upcase (aref s 0)))
  s)

(provide 'flame)
(provide 'friedman-flame)

;; flame.el ends here.

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us