Include the message sender in desktop notification
[riece] / lisp / riece-keyword.el
index 03b1727..f80ac3d 100644 (file)
@@ -1,4 +1,4 @@
-;;; riece-keyword.el --- detect keywords in IRC buffers
+;;; riece-keyword.el --- detect keywords in IRC buffers -*- lexical-binding: t -*-
 ;; Copyright (C) 1998-2003 Daiki Ueno
 
 ;; Author: Daiki Ueno <ueno@unixuser.org>
@@ -19,8 +19,8 @@
 
 ;; 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:
 
 
 (defcustom riece-notify-keyword-functions nil
   "Functions used to notify keyword match."
-  :type '(list function)
+  :type '(repeat function)
   :group 'riece-keyword)
 
 (make-obsolete-variable 'riece-notify-keyword-functions
-                       'riece-keyword-notify-functions)
+                       'riece-keyword-notify-functions
+                       "2003-12-22")
 
 (defcustom riece-keyword-notify-functions nil
   "Functions used to notify keyword match.
 Two arguments are passed to each function: the keyword used to match
 and the matched message object."
-  :type '(list function)
+  :type '(repeat function)
   :group 'riece-keyword)
 
 (defface riece-keyword-face
@@ -66,15 +67,13 @@ and the matched message object."
   :group 'riece-highlight-faces)
 (defvar riece-keyword-face 'riece-keyword-face)
 
-(defvar riece-keyword-enabled nil)
-
 (defconst riece-keyword-description
   "Detect keywords in IRC buffers.")
 
 ;;; The old XEmacs package doesn't have autoload setting for regexp-opt.
 (autoload 'regexp-opt "regexp-opt")
 (defun riece-keyword-message-filter (message)
-  (if (and riece-keyword-enabled
+  (if (and (get 'riece-keyword 'riece-addon-enabled)
           riece-keywords
           ;; Ignore messages which belongs to myself.
           (not (riece-message-own-p message)))
@@ -88,23 +87,26 @@ and the matched message object."
                                 (setq keywords (cons matcher keywords)))
                              matcher))
                          riece-keywords))
-              (list (cons (regexp-opt keywords) 0))))
+              (if keywords
+                  (list (cons (regexp-opt keywords) 0)))))
             index)
        (while alist
          (setq index 0)
-         (while (string-match (car (car alist))
-                              (riece-message-text message) index)
+         (while (and (< index (length (riece-message-text message)))
+                     (string-match (car (car alist))
+                                   (riece-message-text message) index))
            (put-text-property (match-beginning (cdr (car alist)))
                               (match-end (cdr (car alist)))
                               'riece-overlay-face riece-keyword-face
                               (riece-message-text message))
-           (run-hook-with-args 'riece-notify-keyword-functions
-                               (match-string (cdr (car alist))
-                                             (riece-message-text message)))
-           (run-hook-with-args 'riece-keyword-notify-functions
-                               (cdr (car alist))
-                               message)
-           (setq index (match-end (cdr (car alist)))))
+           (save-match-data
+             (run-hook-with-args 'riece-notify-keyword-functions
+                                 (match-string (cdr (car alist))
+                                               (riece-message-text message)))
+             (run-hook-with-args 'riece-keyword-notify-functions
+                                 (cdr (car alist))
+                                 message))
+           (setq index (1+ (match-end (cdr (car alist))))))
          (setq alist (cdr alist)))))
   message)
 
@@ -115,12 +117,9 @@ and the matched message object."
 (defun riece-keyword-insinuate ()
   (add-hook 'riece-message-filter-functions 'riece-keyword-message-filter))
 
-(defun riece-keyword-enable ()
-  (setq riece-keyword-enabled t))
-
-(defun riece-keyword-disable ()
-  (setq riece-keyword-enabled nil))
+(defun riece-keyword-uninstall ()
+  (remove-hook 'riece-message-filter-functions 'riece-keyword-message-filter))
 
 (provide 'riece-keyword)
 
-;;; riece-keyword.el ends here
\ No newline at end of file
+;;; riece-keyword.el ends here