;;; annoyance.el --- the annoying Emacs assistant

;; Copyright (C) 2004, 2005 Mario Domenech Goulart

;; Author: Mario Domenech Goulart
;; Maintainer: Mario Domenech Goulart
;; Created: Aug 2005
;; Keywords: annoyance
;; Version: 0.2

;; GNU Emacs 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.

;; GNU Emacs 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 GNU Emacs; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.

;;; Commentary:

;; This is a silly implementation of the annoying MS Word clip for
;; Emacs

;;; Code:

(defconst annoyance-version "0.2")

(defvar annoyance-stupid-clip 
      " __
/  \\
|  |
@  @
|| ||
|| ||
|\\_/|
\\___/\n
")

(defun annoyance-first-change ()
  (annoyance-show 
   "It seems that you are trying to modify\nthis buffer.  Be sure not to mess it!"))

(defun annoyance-talk-about-word ()
  (defun should? (n)
    (< (random 100) n))
  (let ((word (current-word)))
    (when (and (> (random 100) 50) (> (length word) 5))
      (annoyance-show
       (cond ((should? 15)
	      (concat "\"" word "\" is a very nice word!"))
	     ((should? 15)
	      (concat "Are you sure \"" word "\"\nis spelled correctly?"))
	     ((should? 15)
	      (concat "Wouldn't it be better to\nwrite \"" word "\" backwards?"))
	     ((should? 15)
	      (concat "Isn't it weird that \"" word "\" has " (number-to-string (length word)) " letters?"))
	     (t (concat "Should Emacs spell check \"" word "\" for you?"))
	     )))))

(defun annoyance-after-change ()
  (annoyance-show "Now your buffer is safe."))

(defun annoyance-auto-save ()
  (annoyance-show "Emacs will kindly auto-save your buffer."))

(defun annoyance-after-save ()
  (annoyance-show "Emacs has kindly saved your buffer."))

(defvar annoyance-warnings 
  '((first-change-hook . annoyance-first-change)
    (after-save-hook . annoyance-after-change)
    (auto-save-hook . annoyance-auto-save)
    (after-save-hook . annoyance-after-save)
    (post-command-hook . annoyance-talk-about-word)
    ))

(defun annoyance-show (message)
  (interactive)
  (message-box (concat annoyance-stupid-clip "\n" message)))

(defun annoyance-activate ()
  (interactive)
  (mapc (lambda (annoying)
	  (add-hook (car annoying) (cdr annoying)))
	annoyance-warnings))

(defun annoyance-deactivate ()
  (interactive)
  (mapc (lambda (annoying)
	  (remove-hook (car annoying) (cdr annoying)))
	annoyance-warnings))