yow.el 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. ;;; yow.el --- quote random zippyisms
  2. ;; Copyright (C) 1993-1995, 2000-2012 Free Software Foundation, Inc.
  3. ;; Maintainer: FSF
  4. ;; Author: Richard Mlynarik
  5. ;; Keywords: games
  6. ;; This file is part of GNU Emacs.
  7. ;; GNU Emacs is free software: you can redistribute it and/or modify
  8. ;; it under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation, either version 3 of the License, or
  10. ;; (at your option) any later version.
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;; GNU General Public License for more details.
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  17. ;;; Commentary:
  18. ;; Important pinheadery for GNU Emacs.
  19. ;;
  20. ;; See cookie1.el for implementation. Note --- the `n' argument of yow
  21. ;; from the 18.xx implementation is no longer; we only support *random*
  22. ;; random access now.
  23. ;;; Code:
  24. (require 'cookie1)
  25. (defgroup yow nil
  26. "Quote random zippyisms."
  27. :prefix "yow-"
  28. :group 'games)
  29. (defcustom yow-file (concat data-directory "yow.lines")
  30. "File containing pertinent pinhead phrases."
  31. :type 'file
  32. :group 'yow)
  33. (defconst yow-load-message "Am I CONSING yet?...")
  34. (defconst yow-after-load-message "I have SEEN the CONSING!!")
  35. ;;;###autoload
  36. (defun yow (&optional insert display)
  37. "Return or display a random Zippy quotation. With prefix arg, insert it."
  38. (interactive "P\np")
  39. (let ((yow (cookie yow-file yow-load-message yow-after-load-message)))
  40. (cond (insert
  41. (insert yow))
  42. ((not display)
  43. yow)
  44. (t
  45. (message "%s" yow)))))
  46. (defsubst read-zippyism (prompt &optional require-match)
  47. "Read a Zippyism from the minibuffer with completion, prompting with PROMPT.
  48. If optional second arg is non-nil, require input to match a completion."
  49. (read-cookie prompt yow-file yow-load-message yow-after-load-message
  50. require-match))
  51. ;;;###autoload
  52. (defun insert-zippyism (&optional zippyism)
  53. "Prompt with completion for a known Zippy quotation, and insert it at point."
  54. (interactive (list (read-zippyism "Pinhead wisdom: " t)))
  55. (insert zippyism))
  56. ;;;###autoload
  57. (defun apropos-zippy (regexp)
  58. "Return a list of all Zippy quotes matching REGEXP.
  59. If called interactively, display a list of matches."
  60. (interactive "sApropos Zippy (regexp): ")
  61. ;; Make sure yows are loaded
  62. (cookie yow-file yow-load-message yow-after-load-message)
  63. (let* ((case-fold-search t)
  64. (cookie-table-symbol (intern yow-file cookie-cache))
  65. (string-table (symbol-value cookie-table-symbol))
  66. (matches nil)
  67. (len (length string-table))
  68. (i 0))
  69. (save-match-data
  70. (while (< i len)
  71. (and (string-match regexp (aref string-table i))
  72. (setq matches (cons (aref string-table i) matches)))
  73. (setq i (1+ i))))
  74. (and matches
  75. (setq matches (sort matches 'string-lessp)))
  76. (and (called-interactively-p 'interactive)
  77. (cond ((null matches)
  78. (message "No matches found."))
  79. (t
  80. (let ((l matches))
  81. (with-output-to-temp-buffer "*Zippy Apropos*"
  82. (while l
  83. (princ (car l))
  84. (setq l (cdr l))
  85. (and l (princ "\n\n")))
  86. (help-print-return-message))))))
  87. matches))
  88. ;; Yowza!! Feed zippy quotes to the doctor. Watch results.
  89. ;; fun, fun, fun. Entertainment for hours...
  90. ;;
  91. ;; written by Kayvan Aghaiepour
  92. (declare-function doctor-ret-or-read "doctor" (arg))
  93. ;;;###autoload
  94. (defun psychoanalyze-pinhead ()
  95. "Zippy goes to the analyst."
  96. (interactive)
  97. (doctor) ; start the psychotherapy
  98. (message "")
  99. (switch-to-buffer "*doctor*")
  100. (sit-for 0)
  101. (while (not (input-pending-p))
  102. (insert (yow))
  103. (sit-for 0)
  104. (doctor-ret-or-read 1)
  105. (doctor-ret-or-read 1)))
  106. (provide 'yow)
  107. ;;; yow.el ends here