1 ;;; riece-keyword.el --- highlight keywords in channel buffers
2 ;; Copyright (C) 1998-2003 Daiki Ueno
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
6 ;; Keywords: IRC, riece
8 ;; This file is part of Riece.
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;; To use, add the following line to your ~/.riece/init.el:
28 ;; (add-to-list 'riece-addons 'riece-keyword)
32 (require 'riece-message)
34 (defgroup riece-keyword nil
35 "Highlight keyword in IRC buffer."
38 (defcustom riece-keywords nil
39 "Keywords to be highlightened."
40 :type '(repeat (choice (string :tag "Keyword")
41 (cons (string :tag "Regexp")
42 (integer :tag "Match"))))
43 :group 'riece-keyword)
45 (defcustom riece-notify-keyword-functions nil
46 "Functions used to notify keyword match."
47 :type '(list function)
48 :group 'riece-keyword)
50 (defface riece-keyword-face
52 (:foreground "red" :underline t))
55 "Face used for highlightening matching keyword."
56 :group 'riece-highlight-faces)
57 (defvar riece-keyword-face 'riece-keyword-face)
59 ;;; The old XEmacs package doesn't have autoload setting for regexp-opt.
60 (autoload 'regexp-opt "regexp-opt")
61 (defun riece-keyword-message-filter (message)
62 (if (and riece-keywords
63 ;; Ignore messages which belongs to myself.
64 (not (riece-message-own-p message)))
72 (setq keywords (cons matcher keywords)))
75 (list (cons (regexp-opt keywords) 0))))
79 (while (string-match (car (car alist))
80 (riece-message-text message) index)
81 (if (memq 'riece-highlight riece-addons)
82 (put-text-property (match-beginning (cdr (car alist)))
83 (match-end (cdr (car alist)))
85 (riece-message-text message)))
87 (run-hook-with-args 'riece-notify-keyword-functions
88 (match-string (cdr (car alist))
89 (riece-message-text message))))
90 (setq index (match-end (cdr (car alist)))))
91 (setq alist (cdr alist)))))
94 (defun riece-keyword-scan-region (start end)
95 (riece-scan-property-region
99 (riece-overlay-put (riece-make-overlay start end)
100 'face riece-keyword-face))))
102 (defun riece-keyword-requires ()
103 (if (memq 'riece-highlight riece-addons)
106 (defun riece-keyword-insinuate ()
107 (add-hook 'riece-message-filter-functions 'riece-keyword-message-filter)
108 (add-hook 'riece-after-insert-functions 'riece-keyword-scan-region))
110 (provide 'riece-keyword)
112 ;;; riece-keyword.el ends here