From 2c51c5f4e3a1a3fc3eb6f2c3b9429462b2ba08cb Mon Sep 17 00:00:00 2001 From: ueno Date: Mon, 13 Oct 2003 21:48:46 +0000 Subject: [PATCH] * riece-xemacs.el (riece-make-overlay): New alias. (riece-overlay-put): New alias. (riece-overlay-start): New alias. (riece-overlay-buffer): New alias. * riece-emacs.el (riece-make-overlay): New alias. (riece-overlay-put): New alias. (riece-overlay-start): New alias. (riece-overlay-buffer): New alias. * riece-keyword.el: New add-on. * COMPILE (riece-modules): Add riece-keyword. * Makefile.am (EXTRA_DIST): Add riece-keyword.el * riece-message.el (riece-message-filter-functions): New user option. (riece-display-message-1): New function. (riece-display-message): Use it. --- lisp/COMPILE | 3 +- lisp/ChangeLog | 20 ++++++++++ lisp/riece-button.el | 4 +- lisp/riece-emacs.el | 5 +++ lisp/riece-keyword.el | 106 +++++++++++++++++++++++++++++++++++++++++++++++++ lisp/riece-message.el | 18 ++++++++- lisp/riece-xemacs.el | 5 +++ 7 files changed, 156 insertions(+), 5 deletions(-) create mode 100644 lisp/riece-keyword.el diff --git a/lisp/COMPILE b/lisp/COMPILE index 2cbc846..5e7f64e 100644 --- a/lisp/COMPILE +++ b/lisp/COMPILE @@ -53,7 +53,8 @@ riece-skk-kakutei riece-guess riece-history - riece-button)))) + riece-button + riece-keyword)))) (defun riece-compile-modules (modules) (let ((load-path (cons nil load-path))) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 643f623..5868949 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,5 +1,25 @@ 2003-10-13 Daiki Ueno + * riece-xemacs.el (riece-make-overlay): New alias. + (riece-overlay-put): New alias. + (riece-overlay-start): New alias. + (riece-overlay-buffer): New alias. + + * riece-emacs.el (riece-make-overlay): New alias. + (riece-overlay-put): New alias. + (riece-overlay-start): New alias. + (riece-overlay-buffer): New alias. + + * riece-keyword.el: New add-on. + * COMPILE (riece-modules): Add riece-keyword. + * Makefile.am (EXTRA_DIST): Add riece-keyword.el + + * riece-message.el (riece-message-filter-functions): New user option. + (riece-display-message-1): New function. + (riece-display-message): Use it. + +2003-10-13 Daiki Ueno + * riece.el (riece-channel-list-mode): Initialize riece-update-buffer-functions. (riece-user-list-mode): Ditto. diff --git a/lisp/riece-button.el b/lisp/riece-button.el index 21b7039..cba6fd3 100644 --- a/lisp/riece-button.el +++ b/lisp/riece-button.el @@ -65,8 +65,8 @@ ;; window, overlay, position. (riece-format-identity (if overlay - (with-current-buffer (overlay-buffer overlay) - (widget-value (widget-at (overlay-start overlay)))) + (with-current-buffer (riece-overlay-buffer overlay) + (widget-value (widget-at (riece-overlay-start overlay)))) (widget-value widget/window)))))) (defun riece-button-switch-to-identity (widget &optional event) diff --git a/lisp/riece-emacs.el b/lisp/riece-emacs.el index 8d0de2e..6f5eca6 100644 --- a/lisp/riece-emacs.el +++ b/lisp/riece-emacs.el @@ -72,6 +72,11 @@ (boundp 'mark-active) mark-active)) +(defalias 'riece-make-overlay 'make-overlay) +(defalias 'riece-overlay-put 'overlay-put) +(defalias 'riece-overlay-start 'overlay-start) +(defalias 'riece-overlay-buffer 'overlay-buffer) + (provide 'riece-emacs) ;;; riece-emacs.el ends here diff --git a/lisp/riece-keyword.el b/lisp/riece-keyword.el new file mode 100644 index 0000000..37ae4af --- /dev/null +++ b/lisp/riece-keyword.el @@ -0,0 +1,106 @@ +;;; riece-keyword.el --- highlight keywords in channel buffers +;; Copyright (C) 1998-2003 Daiki Ueno + +;; Author: Daiki Ueno +;; Created: 1998-09-28 +;; Keywords: IRC, riece + +;; This file is part of Riece. + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 2, or (at your option) +;; any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; 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. + +;;; Commentary: + +;; To use, add the following line to your ~/.riece/init.el: +;; (add-to-list 'riece-addons 'riece-keyword) + +;;; Code: + +(defgroup riece-keyword nil + "Highlight keyword in IRC buffer." + :group 'riece-vars) + +(defcustom riece-keywords nil + "Keywords to be highlightened." + :type '(repeat string) + :group 'riece-keyword) + +(defcustom riece-notify-keyword-functions nil + "Functions used to notify keyword match." + :type '(list function) + :group 'riece-keyword) + +(defface riece-keyword-face + '((((class color)) + (:foreground "red" :underline t)) + (t + ())) + "Face used for highlightening matching keyword." + :group 'riece-highlight-faces) +(defvar riece-keyword-face 'riece-keyword-face) + +;;; 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))))) + message) + +(defun riece-keyword-map-region (start end function) + (catch 'done + (while t + ;; Search for the beginning of the button region. + (unless (get-text-property start 'riece-keyword) + (setq start (next-single-property-change start 'riece-keyword + nil end))) + (if (= start end) + (throw 'done nil)) + ;; Search for the end of the button region. + (let ((button-end (next-single-property-change start 'riece-keyword + nil end))) + (if (= button-end end) + (throw 'done nil)) + (funcall function start button-end) + (setq start button-end))))) + +(defun riece-keyword-scan-region (start end) + (riece-keyword-map-region + 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)) + +(provide 'riece-keyword) + +;;; riece-keyword.el ends here \ No newline at end of file diff --git a/lisp/riece-message.el b/lisp/riece-message.el index 8a20efb..bac5784 100644 --- a/lisp/riece-message.el +++ b/lisp/riece-message.el @@ -35,6 +35,11 @@ :prefix "riece-" :group 'riece) +(defcustom riece-message-filter-functions nil + "Functions to filter incoming messages." + :type 'function + :group 'riece-message) + (defcustom riece-message-make-open-bracket-function #'riece-message-make-open-bracket "Function which makes `open-bracket' string for each message." @@ -138,8 +143,7 @@ Normally they are *Dialogue* and/or *Others*." (list riece-dialogue-buffer riece-others-buffer) riece-dialogue-buffer))) -(defun riece-display-message (message) - "Display MESSAGE object." +(defun riece-display-message-1 (message) (let ((open-bracket (funcall riece-message-make-open-bracket-function message)) (close-bracket @@ -170,6 +174,16 @@ Normally they are *Dialogue* and/or *Others*." " (from " server-name ")\n"))) (run-hook-with-args 'riece-after-display-message-functions message))) +(defun riece-display-message (message) + "Display MESSAGE object." + (let ((functions riece-message-filter-functions)) + (setq message (copy-sequence message)) + (while functions + (setq message (funcall (car functions) message) + functions (cdr functions))) + (if message + (riece-display-message-1 message)))) + (defun riece-make-message (speaker target text &optional type own-p) "Make an instance of message object. Arguments are appropriate to the sender, the receiver, and text diff --git a/lisp/riece-xemacs.el b/lisp/riece-xemacs.el index f884117..72efb4c 100644 --- a/lisp/riece-xemacs.el +++ b/lisp/riece-xemacs.el @@ -91,6 +91,11 @@ Modify whole identification by side effect." ;;; stolen (and renamed) from gnus-xmas.el. (defalias 'riece-region-active-p 'region-active-p) +(defalias 'riece-make-overlay 'make-extent) +(defalias 'riece-overlay-put 'set-extent-property) +(defalias 'riece-overlay-start 'extent-start-position) +(defalias 'riece-overlay-buffer 'extent-buffer) + (provide 'riece-xemacs) ;;; riece-xemacs.el ends here -- 1.7.10.4