* riece-commands.el (riece-command-send-message): Run
[riece] / lisp / riece-foolproof.el
index 226d654..f691a0a 100644 (file)
 
 ;;; Code:
 
 
 ;;; Code:
 
-(eval-when-compile (require 'riece))
+(eval-when-compile
+  (require 'riece-identity)
+  (require 'riece-display))
 
 (defvar riece-foolproof-enabled nil)
 
 (defconst riece-foolproof-description
 
 (defvar riece-foolproof-enabled nil)
 
 (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)))
+  "Channel miss killer")
 
 (defun riece-foolproof-get-channel-window (identity)
   (get-buffer-window
    (cdr (riece-identity-assoc
         identity riece-channel-buffer-alist))))
 
 
 (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 riece-foolproof-enabled
     (unless (or (not riece-channel-buffer-mode)
                (riece-foolproof-get-channel-window
                 riece-current-channel))
     (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)))))
+      (error "Channel %s is not displayed"
+            (riece-identity-prefix riece-current-channel)))
+    (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-enable ()
 
 (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 ()
   (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))
 
 (provide 'riece-foolproof)
   (setq riece-foolproof-enabled nil))
 
 (provide 'riece-foolproof)