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
34 (defgroup riece-highlight nil
35 "Highlight IRC buffers"
40 (defgroup riece-highlight-faces nil
41 "Faces for highlight IRC buffers"
43 :prefix "riece-highlight-"
44 :group 'riece-highlight)
46 (defface riece-dialogue-change-face
49 (:foreground "cyan" :bold t))
52 (:foreground "RoyalBlue" :bold t))
55 "Face used for displaying \"*** Change:\" line"
56 :group 'riece-highlight-faces)
57 (defvar riece-dialogue-change-face 'riece-dialogue-change-face)
59 (defface riece-dialogue-notice-face
62 (:foreground "green2" :bold t))
65 (:foreground "MidnightBlue" :bold t))
68 "Face used for displaying \"*** Notice:\" line"
69 :group 'riece-highlight-faces)
70 (defvar riece-dialogue-notice-face 'riece-dialogue-notice-face)
72 (defface riece-dialogue-wallops-face
75 (:foreground "yellow" :bold t))
78 (:foreground "blue4" :bold t))
81 "Face used for displaying \"*** Wallops:\" line"
82 :group 'riece-highlight-faces)
83 (defvar riece-dialogue-wallops-face 'riece-dialogue-wallops-face)
85 (defface riece-dialogue-error-face
88 (:foreground "cornflower blue" :bold t))
91 (:foreground "DarkGreen"))
94 "Face used for displaying \"*** Error:\" line"
95 :group 'riece-highlight-faces)
96 (defvar riece-dialogue-error-face 'riece-dialogue-error-face)
98 (defface riece-dialogue-info-face
101 (:foreground "PaleTurquoise" :bold t))
104 (:foreground "RoyalBlue"))
107 "Face used for displaying \"*** Info:\" line"
108 :group 'riece-highlight-faces)
109 (defvar riece-dialogue-info-face 'riece-dialogue-info-face)
111 (defface riece-dialogue-server-face
114 (:foreground "Gray70"))
117 (:foreground "DimGray"))
120 "Face used for displaying \"(from server)\" extent."
121 :group 'riece-highlight-faces)
122 (defvar riece-dialogue-server-face 'riece-dialogue-server-face)
124 (defface riece-dialogue-prefix-face
127 (:foreground "moccasin"))
130 (:foreground "firebrick"))
133 "Face used for displaying \"<nick>\" extent"
134 :group 'riece-highlight-faces)
135 (defvar riece-dialogue-prefix-face 'riece-dialogue-prefix-face)
137 (defcustom riece-dialogue-font-lock-keywords
139 (list (list (concat "^" riece-time-prefix-regexp
140 "\\(<[^>]+>\\|>[^<]+<\\|([^)]+)\\|{[^}]+}\\|=[^=]+=\\)")
141 '(1 riece-dialogue-prefix-face append t)))
142 ;; set property to the whole line
147 "^" riece-time-prefix-regexp "\\("
149 (symbol-value (intern (format "riece-%s-prefix" line))))
151 (list 1 (intern (format "riece-dialogue-%s-face" line)) t t)))
152 '(change notice wallops error info))
153 (list (list "(from [^)]+)$" 0 riece-dialogue-server-face t)))
154 "Default expressions to highlight in riece-dialogue-mode."
155 :type '(repeat (list string))
156 :group 'riece-highlight)
158 (defface riece-channel-list-default-face
160 "Face used for displaying channels."
161 :group 'riece-highlight-faces)
162 (defvar riece-channel-list-default-face 'riece-channel-list-default-face)
164 (defface riece-channel-list-current-face
167 (:foreground "turquoise" :underline t))
170 (:foreground "SeaGreen" :underline t))
173 "Face used for displaying the current channel."
174 :group 'riece-highlight-faces)
175 (defvar riece-channel-list-current-face 'riece-channel-list-current-face)
177 (defcustom riece-channel-list-mark-face-alist
178 '((?* . riece-channel-list-current-face))
179 "An alist mapping marks on riece-channel-list-buffer to faces."
181 :group 'riece-highlight)
183 (defcustom riece-channel-list-font-lock-keywords
184 '(("^[ 0-9][0-9]:\\(.\\)\\(.*\\)"
185 (2 (or (cdr (assq (aref (match-string 1) 0)
186 riece-channel-list-mark-face-alist))
187 riece-channel-list-default-face))))
188 "Default expressions to highlight in riece-channel-list-mode."
189 :type '(repeat (list string))
190 :group 'riece-highlight)
192 (unless (riece-facep 'riece-modeline-current-face)
193 (make-face 'riece-modeline-current-face
194 "Face used for displaying the current channel in modeline.")
195 (if (featurep 'xemacs)
196 (set-face-parent 'riece-modeline-current-face 'modeline))
197 (set-face-foreground 'riece-modeline-current-face
198 (face-foreground 'riece-channel-list-current-face)))
200 (defvar riece-highlight-enabled nil)
202 (defconst riece-highlight-description
203 "Highlight IRC buffers")
205 (defun riece-highlight-setup-dialogue ()
206 (make-local-variable 'font-lock-defaults)
207 (setq font-lock-defaults '(riece-dialogue-font-lock-keywords t))
208 ;; In XEmacs, auto-initialization of font-lock is not affective
209 ;; when buffer-file-name is not set.
210 (font-lock-set-defaults)
211 (make-local-hook 'after-change-functions)
212 (add-hook 'after-change-functions
213 'riece-highlight-hide-prefix nil 'local)
214 (if riece-highlight-enabled
217 (defun riece-highlight-setup-channel-list ()
218 (make-local-variable 'font-lock-defaults)
219 (setq font-lock-defaults '(riece-channel-list-font-lock-keywords t))
220 ;; In XEmacs, auto-initialization of font-lock is not affective
221 ;; when buffer-file-name is not set.
222 (font-lock-set-defaults)
223 (if riece-highlight-enabled
226 (defun riece-highlight-hide-prefix (start end length)
229 (if (looking-at riece-prefix-regexp)
230 (put-text-property (match-beginning 1) (match-end 1) 'invisible t))))
232 (defun riece-highlight-put-overlay-faces (start end)
233 (if riece-highlight-enabled
234 (riece-scan-property-region
238 (riece-overlay-put (riece-make-overlay start end)
240 (get-text-property start 'riece-overlay-face))))))
242 (defun riece-highlight-format-identity-for-channel-list-indicator (index
244 (if (and riece-highlight-enabled
245 (riece-identity-equal identity riece-current-channel))
246 (let ((string (riece-format-identity identity))
249 (while (string-match "%" string start)
250 (setq start (1+ (match-end 0))
251 string (replace-match "%%" nil nil string)))
252 (list (format "%d:" index)
253 (riece-propertize-modeline-string
254 string 'face 'riece-modeline-current-face)))))
256 (defun riece-highlight-insinuate ()
257 (put 'riece-channel-mode 'font-lock-defaults
258 '(riece-dialogue-font-lock-keywords t))
259 (add-hook 'riece-channel-mode-hook
260 'riece-highlight-setup-dialogue)
261 (put 'riece-others-mode 'font-lock-defaults
262 '(riece-dialogue-font-lock-keywords t))
263 (add-hook 'riece-others-mode-hook
264 'riece-highlight-setup-dialogue)
265 (put 'riece-dialogue-mode 'font-lock-defaults
266 '(riece-dialogue-font-lock-keywords t))
267 (add-hook 'riece-dialogue-mode-hook
268 'riece-highlight-setup-dialogue)
269 (put 'riece-channel-list-mode 'font-lock-defaults
270 '(riece-channel-list-font-lock-keywords t))
271 (add-hook 'riece-channel-list-mode-hook
272 'riece-highlight-setup-channel-list)
273 (add-hook 'riece-format-identity-for-channel-list-indicator-functions
274 'riece-highlight-format-identity-for-channel-list-indicator)
275 (add-hook 'riece-after-insert-functions
276 'riece-highlight-put-overlay-faces))
278 (defun riece-highlight-enable ()
279 (let ((buffers riece-buffer-list))
281 (if (memq (derived-mode-class
282 (with-current-buffer (car buffers)
284 '(riece-dialogue-mode riece-channel-list-mode))
285 (with-current-buffer (car buffers)
287 (setq buffers (cdr buffers))))
288 (setq riece-highlight-enabled t))
290 (defun riece-highlight-disable ()
291 (let ((buffers riece-buffer-list))
293 (if (memq (derived-mode-class
294 (with-current-buffer (car buffers)
296 '(riece-dialogue-mode riece-channel-list-mode))
297 (with-current-buffer (car buffers)
299 (setq buffers (cdr buffers))))
300 (setq riece-highlight-enabled nil))
302 (provide 'riece-highlight)
304 ;;; riece-highlight.el ends here