1 ;;; riece-highlight.el --- highlight IRC 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 (require 'riece-globals)
28 (require 'riece-options) ;riece-channel-list-buffer-mode
29 (require 'riece-identity) ;riece-format-identity
33 (defgroup riece-highlight nil
34 "Highlight IRC buffers"
39 (defgroup riece-highlight-faces nil
40 "Faces for highlight IRC buffers"
42 :prefix "riece-highlight-"
43 :group 'riece-highlight)
45 (defface riece-dialogue-change-face
48 (:foreground "cyan" :bold t))
51 (:foreground "RoyalBlue" :bold t))
54 "Face used for displaying \"*** Change:\" line"
55 :group 'riece-highlight-faces)
56 (defvar riece-dialogue-change-face 'riece-dialogue-change-face)
58 (defface riece-dialogue-notice-face
61 (:foreground "green2" :bold t))
64 (:foreground "MidnightBlue" :bold t))
67 "Face used for displaying \"*** Notice:\" line"
68 :group 'riece-highlight-faces)
69 (defvar riece-dialogue-notice-face 'riece-dialogue-notice-face)
71 (defface riece-dialogue-wallops-face
74 (:foreground "yellow" :bold t))
77 (:foreground "blue4" :bold t))
80 "Face used for displaying \"*** Wallops:\" line"
81 :group 'riece-highlight-faces)
82 (defvar riece-dialogue-wallops-face 'riece-dialogue-wallops-face)
84 (defface riece-dialogue-error-face
87 (:foreground "cornflower blue" :bold t))
90 (:foreground "DarkGreen"))
93 "Face used for displaying \"*** Error:\" line"
94 :group 'riece-highlight-faces)
95 (defvar riece-dialogue-error-face 'riece-dialogue-error-face)
97 (defface riece-dialogue-info-face
100 (:foreground "PaleTurquoise" :bold t))
103 (:foreground "RoyalBlue"))
106 "Face used for displaying \"*** Info:\" line"
107 :group 'riece-highlight-faces)
108 (defvar riece-dialogue-info-face 'riece-dialogue-info-face)
110 (defface riece-dialogue-server-face
113 (:foreground "Gray70"))
116 (:foreground "DimGray"))
119 "Face used for displaying \"(from server)\" extent."
120 :group 'riece-highlight-faces)
121 (defvar riece-dialogue-server-face 'riece-dialogue-server-face)
123 (defface riece-dialogue-prefix-face
126 (:foreground "moccasin"))
129 (:foreground "firebrick"))
132 "Face used for displaying \"<nick>\" extent"
133 :group 'riece-highlight-faces)
134 (defvar riece-dialogue-prefix-face 'riece-dialogue-prefix-face)
136 (defcustom riece-dialogue-font-lock-keywords
138 (list (list (concat "^" riece-time-prefix-regexp
139 "\\(<[^>]+>\\|>[^<]+<\\|([^)]+)\\|{[^}]+}\\|=[^=]+=\\)")
140 '(1 riece-dialogue-prefix-face append t)))
141 ;; set property to the whole line
146 "^" riece-time-prefix-regexp "\\("
148 (symbol-value (intern (format "riece-%s-prefix" line))))
150 (list 1 (intern (format "riece-dialogue-%s-face" line)) t t)))
151 '(change notice wallops error info))
152 (list (list "(from [^)]+)$" 0 riece-dialogue-server-face t)))
153 "Default expressions to highlight in riece-dialogue-mode."
154 :type '(repeat (list string))
155 :group 'riece-highlight)
157 (defface riece-channel-list-default-face
159 "Face used for displaying channels."
160 :group 'riece-highlight-faces)
161 (defvar riece-channel-list-default-face 'riece-channel-list-default-face)
163 (defface riece-channel-list-current-face
166 (:foreground "turquoise" :underline t))
169 (:foreground "SeaGreen" :underline t))
172 "Face used for displaying the current channel."
173 :group 'riece-highlight-faces)
174 (defvar riece-channel-list-current-face 'riece-channel-list-current-face)
176 (defcustom riece-channel-list-mark-face-alist
177 '((?* . riece-channel-list-current-face))
178 "An alist mapping marks on riece-channel-list-buffer to faces."
180 :group 'riece-highlight)
182 (defcustom riece-channel-list-font-lock-keywords
183 '(("^[ 0-9][0-9]:\\(.\\)\\(.*\\)"
184 (2 (or (cdr (assq (aref (match-string 1) 0)
185 riece-channel-list-mark-face-alist))
186 riece-channel-list-default-face))))
187 "Default expressions to highlight in riece-channel-list-mode."
188 :type '(repeat (list string))
189 :group 'riece-highlight)
191 (defvar riece-highlight-enabled nil)
193 (defconst riece-highlight-description
194 "Highlight IRC buffers")
196 (defun riece-highlight-setup-dialogue ()
197 (make-local-variable 'font-lock-defaults)
198 (setq font-lock-defaults '(riece-dialogue-font-lock-keywords t))
199 ;; In XEmacs, auto-initialization of font-lock is not affective
200 ;; when buffer-file-name is not set.
201 (font-lock-set-defaults)
202 (make-local-hook 'after-change-functions)
203 (add-hook 'after-change-functions
204 'riece-highlight-hide-prefix nil 'local)
205 (if riece-highlight-enabled
208 (defun riece-highlight-setup-channel-list ()
209 (make-local-variable 'font-lock-defaults)
210 (setq font-lock-defaults '(riece-channel-list-font-lock-keywords t))
211 ;; In XEmacs, auto-initialization of font-lock is not affective
212 ;; when buffer-file-name is not set.
213 (font-lock-set-defaults)
214 (if riece-highlight-enabled
217 (defun riece-highlight-hide-prefix (start end length)
220 (if (looking-at riece-prefix-regexp)
221 (put-text-property (match-beginning 1) (match-end 1) 'invisible t))))
223 (defun riece-highlight-put-overlay-faces (start end)
224 (if riece-highlight-enabled
225 (riece-scan-property-region
229 (riece-overlay-put (riece-make-overlay start end)
231 (get-text-property start 'riece-overlay-face))))))
233 (defun riece-highlight-format-identity-for-channel-list-indicator (index
235 (if (and riece-highlight-enabled
236 (riece-identity-equal identity riece-current-channel))
237 (let ((string (riece-format-identity identity))
240 (while (string-match "%" string start)
241 (setq start (1+ (match-end 0))
242 string (replace-match "%%" nil nil string)))
243 (list (format "%d:" index)
244 (riece-propertize-modeline-string
245 string 'face 'riece-channel-list-current-face)))))
247 (defun riece-highlight-insinuate ()
248 (put 'riece-channel-mode 'font-lock-defaults
249 '(riece-dialogue-font-lock-keywords t))
250 (add-hook 'riece-channel-mode-hook
251 'riece-highlight-setup-dialogue)
252 (put 'riece-others-mode 'font-lock-defaults
253 '(riece-dialogue-font-lock-keywords t))
254 (add-hook 'riece-others-mode-hook
255 'riece-highlight-setup-dialogue)
256 (put 'riece-dialogue-mode 'font-lock-defaults
257 '(riece-dialogue-font-lock-keywords t))
258 (add-hook 'riece-dialogue-mode-hook
259 'riece-highlight-setup-dialogue)
260 (put 'riece-channel-list-mode 'font-lock-defaults
261 '(riece-channel-list-font-lock-keywords t))
262 (add-hook 'riece-channel-list-mode-hook
263 'riece-highlight-setup-channel-list)
264 (add-hook 'riece-format-identity-for-channel-list-indicator-functions
265 'riece-highlight-format-identity-for-channel-list-indicator)
266 (add-hook 'riece-after-insert-functions
267 'riece-highlight-put-overlay-faces))
269 (defun riece-highlight-enable ()
270 (let ((buffers riece-buffer-list))
272 (if (memq (derived-mode-class
273 (with-current-buffer (car buffers)
275 '(riece-dialogue-mode riece-channel-list-mode))
276 (with-current-buffer (car buffers)
278 (setq buffers (cdr buffers))))
279 (setq riece-highlight-enabled t))
281 (defun riece-highlight-disable ()
282 (let ((buffers riece-buffer-list))
284 (if (memq (derived-mode-class
285 (with-current-buffer (car buffers)
287 '(riece-dialogue-mode riece-channel-list-mode))
288 (with-current-buffer (car buffers)
290 (setq buffers (cdr buffers))))
291 (setq riece-highlight-enabled nil))
293 (provide 'riece-highlight)
295 ;;; riece-highlight.el ends here