f1572b23d9f4787df5d9cc7aad6ec93a775d7d1e
[riece] / lisp / riece-foolproof.el
1 ;;; riece-foolproof.el --- channel miss killer
2 ;; Copyright (C) 2004 TAKAHASHI Kaoru
3
4 ;; Author: TAKAHASHI "beatmaria" Kaoru <kaoru@kaisei.org>
5 ;; Keywords: IRC, riece
6
7 ;; This file is part of Riece.
8
9 ;; This program is free software; you can redistribute it and/or
10 ;; modify it under the terms of the GNU General Public License as
11 ;; published by the Free Software Foundation; either version 2, or (at
12 ;; your option) any later version.
13
14 ;; This program is distributed in the hope that it will be useful, but
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 ;; General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
23
24 ;;; Commentary:
25
26 ;; NOTE: This is an add-on module for Riece.
27
28 ;;; Code:
29
30 (eval-when-compile
31   (require 'riece-identity)
32   (require 'riece-display))
33
34 (defvar riece-foolproof-enabled nil)
35
36 (defconst riece-foolproof-description
37   "Channel miss killer")
38
39 (defun riece-foolproof-get-channel-window (identity)
40   (get-buffer-window
41    (cdr (riece-identity-assoc
42          identity riece-channel-buffer-alist))))
43
44 (defun riece-foolproof-command-send-message-function ()
45   (when riece-foolproof-enabled
46     (unless (or (not riece-channel-buffer-mode)
47                 (riece-foolproof-get-channel-window
48                  riece-current-channel))
49       (error "Channel %s is not displayed"
50              (riece-identity-prefix riece-current-channel)))
51     (when (text-property-not-all
52            (riece-line-beginning-position) (riece-line-end-position)
53            'invisible nil)
54       (error "Invisible text included: %s"
55              (buffer-substring-no-properties
56               (riece-line-beginning-position)
57               (riece-line-end-position))))
58     (when executing-kbd-macro
59       (error "%s" "Forbidden to run keyboard macro"))))
60
61 (defun riece-foolproof-insinuate ()
62   (add-hook 'riece-command-send-message-hook
63             'riece-foolproof-command-send-message-function))
64
65 (defun riece-foolproof-uninstall ()
66   (remove-hook 'riece-command-send-message-hook
67                'riece-foolproof-command-send-message-function))
68
69 (defun riece-foolproof-enable ()
70   (setq riece-foolproof-enabled t))
71
72 (defun riece-foolproof-disable ()
73   (setq riece-foolproof-enabled nil))
74
75 (provide 'riece-foolproof)
76
77 ;;; riece-foolproof.el ends here