X-Git-Url: http://cgit.sxemacs.org/?a=blobdiff_plain;f=lisp%2Friece-keyword.el;h=37056e2270b50c9f12d413f279c782b6cd6a130e;hb=f88a663c1b379044573897f6f2ae44e5f5172ed6;hp=92e5f055a8c110a5f205a950c60cd4c034ba69cc;hpb=81f575fa1889e307eadb980d9c5671b02ce9757c;p=riece diff --git a/lisp/riece-keyword.el b/lisp/riece-keyword.el index 92e5f05..37056e2 100644 --- a/lisp/riece-keyword.el +++ b/lisp/riece-keyword.el @@ -37,7 +37,9 @@ (defcustom riece-keywords nil "Keywords to be highlightened." - :type '(repeat string) + :type '(repeat (choice (string :tag "Keyword") + (cons (string :tag "Regexp") + (integer :tag "Match")))) :group 'riece-keyword) (defcustom riece-notify-keyword-functions nil @@ -45,6 +47,16 @@ :type '(list function) :group 'riece-keyword) +(make-obsolete-variable 'riece-notify-keyword-functions + 'riece-keyword-notify-functions) + +(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) + :group 'riece-keyword) + (defface riece-keyword-face '((((class color)) (:foreground "red" :underline t)) @@ -59,19 +71,36 @@ (defun riece-keyword-message-filter (message) (if (and riece-keywords ;; Ignore messages which belongs to myself. - (riece-identity-equal (riece-message-speaker message) - riece-current-nickname)) - (let ((regexp (regexp-opt riece-keywords)) - (index 0)) - (while (string-match regexp (riece-message-text message) index) - (if (memq 'riece-highlight riece-addons) - (put-text-property (match-beginning 0) (match-end 0) - 'riece-keyword t - (riece-message-text message))) - (save-match-data + (not (riece-message-own-p message))) + (let* (keywords + (alist + (nconc + (delq nil (mapcar + (lambda (matcher) + (if (stringp matcher) + (ignore + (setq keywords (cons matcher keywords))) + matcher)) + riece-keywords)) + (list (cons (regexp-opt keywords) 0)))) + index) + (while alist + (setq index 0) + (while (string-match (car (car alist)) + (riece-message-text message) index) + (if (memq 'riece-highlight riece-addons) + (put-text-property (match-beginning (cdr (car alist))) + (match-end (cdr (car alist))) + 'riece-keyword t + (riece-message-text message))) (run-hook-with-args 'riece-notify-keyword-functions - (match-string 0 (riece-message-text message)))) - (setq index (match-end 0))))) + (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))))) + (setq alist (cdr alist))))) message) (defun riece-keyword-scan-region (start end)