X-Git-Url: https://cgit.sxemacs.org/?a=blobdiff_plain;ds=sidebyside;f=lisp%2Friece-keyword.el;h=37056e2270b50c9f12d413f279c782b6cd6a130e;hb=be2acc33c38d2001a6e0342de584dfb361bb4f65;hp=1e1e3b8655ee1b0289c22dd2f7a94456fb6b4a1c;hpb=2bd2d7c67faad7ddb6bf4ee1ddff01a920cc64a4;p=riece diff --git a/lisp/riece-keyword.el b/lisp/riece-keyword.el index 1e1e3b8..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)) @@ -60,17 +72,35 @@ (if (and riece-keywords ;; Ignore messages which belongs to myself. (not (riece-message-own-p message))) - (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 + (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)