X-Git-Url: http://cgit.sxemacs.org/?a=blobdiff_plain;f=lisp%2Friece-keyword.el;h=f80ac3dfff9d5986151f353b036b8d3e131b3135;hb=7b398394dc42099e919682f965fab0f61383ce76;hp=5855d429e476bec9253eaac11d483bb72008842d;hpb=478bffcd22a1ec6dea4e8ed2ecbb0f562cbd41a2;p=riece diff --git a/lisp/riece-keyword.el b/lisp/riece-keyword.el index 5855d42..f80ac3d 100644 --- a/lisp/riece-keyword.el +++ b/lisp/riece-keyword.el @@ -1,4 +1,4 @@ -;;; riece-keyword.el --- highlight keywords in channel buffers +;;; riece-keyword.el --- detect keywords in IRC buffers -*- lexical-binding: t -*- ;; Copyright (C) 1998-2003 Daiki Ueno ;; Author: Daiki Ueno @@ -19,74 +19,107 @@ ;; 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: -;; To use, add the following line to your ~/.riece/init.el: -;; (add-to-list 'riece-addons 'riece-keyword) +;; NOTE: This is an add-on module for Riece. ;;; Code: (require 'riece-message) (defgroup riece-keyword nil - "Highlight keyword in IRC buffer." - :group 'riece-vars) + "Detect keywords in IRC buffers." + :prefix "riece-" + :group 'riece) (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 "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 + "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 '(repeat function) :group 'riece-keyword) (defface riece-keyword-face '((((class color)) (:foreground "red" :underline t)) (t - ())) + (:underline t))) "Face used for highlightening matching keyword." :group 'riece-highlight-faces) (defvar riece-keyword-face 'riece-keyword-face) +(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 riece-keywords - (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 - (run-hook-with-args 'riece-notify-keyword-functions - (match-string 0 (riece-message-text message)))) - (setq index (match-end 0))))) + (if (and (get 'riece-keyword 'riece-addon-enabled) + riece-keywords + ;; Ignore messages which belongs to myself. + (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)) + (if keywords + (list (cons (regexp-opt keywords) 0))))) + index) + (while alist + (setq index 0) + (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)) + (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) -(defun riece-keyword-scan-region (start end) - (riece-scan-property-region - 'riece-keyword - start end - (lambda (start end) - (riece-overlay-put (riece-make-overlay start end) - 'face riece-keyword-face)))) - (defun riece-keyword-requires () (if (memq 'riece-highlight riece-addons) '(riece-highlight))) (defun riece-keyword-insinuate () - (add-hook 'riece-message-filter-functions 'riece-keyword-message-filter) - (add-hook 'riece-after-insert-functions 'riece-keyword-scan-region)) + (add-hook 'riece-message-filter-functions 'riece-keyword-message-filter)) + +(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