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 '((riece-highlight-server-match 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-server-match (limit)
206 (and (re-search-forward "(from [^)]+)$" limit t)
207 (get-text-property (match-beginning 0) 'riece-server-name)))
209 (defun riece-highlight-setup-dialogue ()
210 (make-local-variable 'font-lock-defaults)
211 (setq font-lock-defaults '(riece-dialogue-font-lock-keywords t))
212 ;; In XEmacs, auto-initialization of font-lock is not affective
213 ;; when buffer-file-name is not set.
214 (font-lock-set-defaults)
215 (make-local-hook 'after-change-functions)
216 (add-hook 'after-change-functions
217 'riece-highlight-hide-prefix nil 'local)
218 (if riece-highlight-enabled
221 (defun riece-highlight-setup-channel-list ()
222 (make-local-variable 'font-lock-defaults)
223 (setq font-lock-defaults '(riece-channel-list-font-lock-keywords t))
224 ;; In XEmacs, auto-initialization of font-lock is not affective
225 ;; when buffer-file-name is not set.
226 (font-lock-set-defaults)
227 (if riece-highlight-enabled
230 (defun riece-highlight-hide-prefix (start end length)
233 (if (looking-at riece-prefix-regexp)
234 (put-text-property (match-beginning 1) (match-end 1) 'invisible t))))
236 (defun riece-highlight-put-overlay-faces (start end)
237 (if riece-highlight-enabled
238 (riece-scan-property-region
242 (riece-overlay-put (riece-make-overlay start end)
244 (get-text-property start 'riece-overlay-face))))))
246 (defun riece-highlight-format-identity-for-channel-list-indicator (index
248 (if (and riece-highlight-enabled
249 (riece-identity-equal identity riece-current-channel))
250 (let ((string (riece-format-identity identity))
253 (while (string-match "%" string start)
254 (setq start (1+ (match-end 0))
255 string (replace-match "%%" nil nil string)))
256 (list (format "%d:" index)
257 (riece-propertize-modeline-string
258 string 'face 'riece-modeline-current-face)))))
260 (defun riece-highlight-insinuate ()
261 (put 'riece-channel-mode 'font-lock-defaults
262 '(riece-dialogue-font-lock-keywords t))
263 (add-hook 'riece-channel-mode-hook
264 'riece-highlight-setup-dialogue)
265 (put 'riece-others-mode 'font-lock-defaults
266 '(riece-dialogue-font-lock-keywords t))
267 (add-hook 'riece-others-mode-hook
268 'riece-highlight-setup-dialogue)
269 (put 'riece-dialogue-mode 'font-lock-defaults
270 '(riece-dialogue-font-lock-keywords t))
271 (add-hook 'riece-dialogue-mode-hook
272 'riece-highlight-setup-dialogue)
273 (put 'riece-channel-list-mode 'font-lock-defaults
274 '(riece-channel-list-font-lock-keywords t))
275 (add-hook 'riece-channel-list-mode-hook
276 'riece-highlight-setup-channel-list)
277 (add-hook 'riece-format-identity-for-channel-list-indicator-functions
278 'riece-highlight-format-identity-for-channel-list-indicator)
279 (add-hook 'riece-after-insert-functions
280 'riece-highlight-put-overlay-faces))
282 (defun riece-highlight-enable ()
283 (let ((buffers riece-buffer-list))
285 (if (memq (derived-mode-class
286 (with-current-buffer (car buffers)
288 '(riece-dialogue-mode riece-channel-list-mode))
289 (with-current-buffer (car buffers)
291 (setq buffers (cdr buffers))))
292 (setq riece-highlight-enabled t))
294 (defun riece-highlight-disable ()
295 (let ((buffers riece-buffer-list))
297 (if (memq (derived-mode-class
298 (with-current-buffer (car buffers)
300 '(riece-dialogue-mode riece-channel-list-mode))
301 (with-current-buffer (car buffers)
303 (setq buffers (cdr buffers))))
304 (setq riece-highlight-enabled nil))
306 (provide 'riece-highlight)
308 ;;; riece-highlight.el ends here