-;;; riece-foolproof.el --- channel miss killer
+;;; riece-foolproof.el --- prevent miss-operation in the command buffer -*- lexical-binding: t -*-
;; Copyright (C) 2004 TAKAHASHI Kaoru
-;; Author: TAKAHASHI "beatmaria" Kaoru <kaoru@kaisei.org>
+;; Author: TAKAHASHI Kaoru <kaoru@kaisei.org>
;; Keywords: IRC, riece
;; This file is part of Riece.
;; 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.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
;;; Commentary:
-;; This add-on channel miss hold in check
-
-;; To use, add the following line to your ~/.riece/init.el:
-;; (add-to-list 'riece-addons 'riece-foolproof)
+;; NOTE: This is an add-on module for Riece.
;;; Code:
-(eval-when-compile (require 'riece))
-
-(defvar riece-foolproof-enabled nil)
+(eval-when-compile
+ (require 'riece-identity)
+ (require 'riece-display))
(defconst riece-foolproof-description
- "Disable channel miss")
-
-(defun riece-foolproof-command-enter-message ()
- "Send the current line to the current channel."
- (interactive)
- (when (riece-foolproof)
- (riece-command-enter-message)))
-
-(defun riece-foolproof-command-enter-message-as-notice ()
- "Send the current line to the current channel as NOTICE."
- (interactive)
- (when (riece-foolproof)
- (riece-command-enter-message-as-notice)))
+ "Prevent miss-operation in the command buffer.")
(defun riece-foolproof-get-channel-window (identity)
(get-buffer-window
(cdr (riece-identity-assoc
identity riece-channel-buffer-alist))))
-(defun riece-foolproof-insinuate ()
- (defadvice riece-command-send-message (before riece-foolproof)
+(defun riece-foolproof-command-send-message-function ()
+ (when (get 'riece-foolproof 'riece-addon-enabled)
(unless (or (not riece-channel-buffer-mode)
(riece-foolproof-get-channel-window
riece-current-channel))
- (error "%s is not displayed. (maybe channel miss)"
- (riece-identity-prefix riece-current-channel)))))
-
-(defun riece-foolproof-enable ()
- (ad-enable-advice 'riece-command-send-message 'before 'riece-foolproof)
- (ad-activate 'riece-command-send-message)
- (setq riece-foolproof-enabled t))
-
-(defun riece-foolproof-disable ()
- (ad-disable-advice 'riece-command-send-message 'before 'riece-foolproof)
- (ad-activate 'riece-command-send-message)
- (setq riece-foolproof-enabled nil))
+ (error "Channel %s is not displayed"
+ (riece-identity-prefix riece-current-channel)))
+ (when (text-property-not-all
+ (riece-line-beginning-position) (riece-line-end-position)
+ 'invisible nil)
+ (error "Invisible text included: %s"
+ (buffer-substring-no-properties
+ (riece-line-beginning-position)
+ (riece-line-end-position))))
+ (when executing-kbd-macro
+ (error "%s" "Forbidden to run keyboard macro"))))
+
+(defun riece-foolproof-insinuate ()
+ (add-hook 'riece-command-send-message-hook
+ 'riece-foolproof-command-send-message-function))
+
+(defun riece-foolproof-uninstall ()
+ (remove-hook 'riece-command-send-message-hook
+ 'riece-foolproof-command-send-message-function))
(provide 'riece-foolproof)