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., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
27 ;; NOTE: This is an add-on module for Riece.
31 (require 'riece-globals)
32 (require 'riece-options) ;riece-channel-list-buffer-mode
33 (require 'riece-identity) ;riece-format-identity
38 (defgroup riece-highlight nil
39 "Decorate IRC buffers with faces and fonts."
44 (defgroup riece-highlight-faces nil
45 "Faces for highlight IRC buffers."
47 :prefix "riece-highlight-"
48 :group 'riece-highlight)
50 (defface riece-dialogue-change-face
53 (:foreground "cyan" :bold t))
56 (:foreground "RoyalBlue" :bold t))
59 "Face used for displaying \"*** Change:\" line"
60 :group 'riece-highlight-faces)
61 (defvar riece-dialogue-change-face 'riece-dialogue-change-face)
63 (defface riece-dialogue-notice-face
66 (:foreground "green2" :bold t))
69 (:foreground "MidnightBlue" :bold t))
72 "Face used for displaying \"*** Notice:\" line"
73 :group 'riece-highlight-faces)
74 (defvar riece-dialogue-notice-face 'riece-dialogue-notice-face)
76 (defface riece-dialogue-wallops-face
79 (:foreground "yellow" :bold t))
82 (:foreground "blue4" :bold t))
85 "Face used for displaying \"*** Wallops:\" line"
86 :group 'riece-highlight-faces)
87 (defvar riece-dialogue-wallops-face 'riece-dialogue-wallops-face)
89 (defface riece-dialogue-error-face
92 (:foreground "cornflower blue" :bold t))
95 (:foreground "DarkGreen"))
98 "Face used for displaying \"*** Error:\" line"
99 :group 'riece-highlight-faces)
100 (defvar riece-dialogue-error-face 'riece-dialogue-error-face)
102 (defface riece-dialogue-info-face
105 (:foreground "PaleTurquoise" :bold t))
108 (:foreground "RoyalBlue"))
111 "Face used for displaying \"*** Info:\" line"
112 :group 'riece-highlight-faces)
113 (defvar riece-dialogue-info-face 'riece-dialogue-info-face)
115 (defface riece-dialogue-server-face
118 (:foreground "Gray70"))
121 (:foreground "DimGray"))
124 "Face used for displaying \"(from server)\" extent."
125 :group 'riece-highlight-faces)
126 (defvar riece-dialogue-server-face 'riece-dialogue-server-face)
128 (defface riece-dialogue-prefix-face
131 (:foreground "moccasin"))
134 (:foreground "firebrick"))
137 "Face used for displaying \"<nick>\" extent"
138 :group 'riece-highlight-faces)
139 (defvar riece-dialogue-prefix-face 'riece-dialogue-prefix-face)
141 (defcustom riece-dialogue-font-lock-keywords
143 (list (list (concat "^" riece-time-prefix-regexp
144 "\\(<[^>]+>\\|>[^<]+<\\|([^)]+)\\|{[^}]+}\\|=[^=]+=\\)")
145 '(1 riece-dialogue-prefix-face append t)))
146 ;; set property to the whole line
151 "^" riece-time-prefix-regexp "\\("
153 (symbol-value (intern (format "riece-%s-prefix" line))))
155 (list 1 (intern (format "riece-dialogue-%s-face" line)) t t)))
156 '(change notice wallops error info))
157 '((riece-highlight-server-match 0 riece-dialogue-server-face t)))
158 "Default expressions to highlight in riece-dialogue-mode."
159 :type '(repeat (list string))
160 :group 'riece-highlight)
162 (defface riece-channel-list-default-face
164 "Face used for displaying channels."
165 :group 'riece-highlight-faces)
166 (defvar riece-channel-list-default-face 'riece-channel-list-default-face)
168 (defface riece-channel-list-current-face
171 (:foreground "turquoise" :underline t))
174 (:foreground "SeaGreen" :underline t))
177 "Face used for displaying the current channel."
178 :group 'riece-highlight-faces)
179 (defvar riece-channel-list-current-face 'riece-channel-list-current-face)
181 (defcustom riece-channel-list-mark-face-alist
182 '((?* . riece-channel-list-current-face))
183 "An alist mapping marks on riece-channel-list-buffer to faces."
184 :type '(repeat (cons character symbol))
185 :group 'riece-highlight)
187 (defcustom riece-channel-list-font-lock-keywords
188 '(("^[ 0-9][0-9]:\\(.\\)\\(.*\\)"
189 (2 (or (cdr (assq (aref (match-string 1) 0)
190 riece-channel-list-mark-face-alist))
191 riece-channel-list-default-face))))
192 "Default expressions to highlight in riece-channel-list-mode."
193 :type '(repeat (list string))
194 :group 'riece-highlight)
196 (unless (riece-facep 'riece-modeline-current-face)
197 (make-face 'riece-modeline-current-face
198 "Face used for displaying the current channel in modeline.")
199 (if (featurep 'xemacs)
200 (set-face-parent 'riece-modeline-current-face 'modeline))
201 (set-face-foreground 'riece-modeline-current-face
202 (face-foreground 'riece-channel-list-current-face)))
204 (defconst riece-highlight-description
205 "Highlight IRC buffers.")
207 (defun riece-highlight-server-match (limit)
208 (and (re-search-forward "(from [^)]+)$" limit t)
209 (get-text-property (match-beginning 0) 'riece-server-name)))
211 (defun riece-highlight-setup-dialogue ()
212 (make-local-variable 'font-lock-defaults)
213 (setq font-lock-defaults '(riece-dialogue-font-lock-keywords t))
214 ;; In XEmacs, auto-initialization of font-lock is not affective
215 ;; when buffer-file-name is not set.
216 (font-lock-set-defaults)
217 (riece-make-local-hook 'after-change-functions)
218 (add-hook 'after-change-functions
219 'riece-highlight-hide-prefix nil t)
220 (if (get 'riece-highlight 'riece-addon-enabled)
223 (defun riece-highlight-setup-channel-list ()
224 (make-local-variable 'font-lock-defaults)
225 (setq font-lock-defaults '(riece-channel-list-font-lock-keywords t))
226 ;; In XEmacs, auto-initialization of font-lock is not affective
227 ;; when buffer-file-name is not set.
228 (font-lock-set-defaults)
229 (if (get 'riece-highlight 'riece-addon-enabled)
232 (defun riece-highlight-hide-prefix (start end length)
235 (if (looking-at riece-prefix-regexp)
236 (put-text-property (match-beginning 1) (match-end 1) 'invisible t))))
238 (defun riece-highlight-put-overlay-faces (start end)
239 (if (get 'riece-highlight 'riece-addon-enabled)
240 (riece-scan-property-region
244 (riece-overlay-put (riece-make-overlay start end)
246 (get-text-property start 'riece-overlay-face))))))
248 (defun riece-highlight-format-identity-for-channel-list-indicator (index
250 (if (and (get 'riece-highlight 'riece-addon-enabled)
251 (riece-identity-equal identity riece-current-channel))
252 (let ((string (riece-format-identity identity))
255 (while (string-match "%" string start)
256 (setq start (1+ (match-end 0))
257 string (replace-match "%%" nil nil string)))
258 (list (format "%d:" index)
259 (riece-propertize-modeline-string
260 string 'face 'riece-modeline-current-face)))))
262 (defun riece-highlight-insinuate ()
263 (put 'riece-channel-mode 'font-lock-defaults
264 '(riece-dialogue-font-lock-keywords t))
265 (put 'riece-others-mode 'font-lock-defaults
266 '(riece-dialogue-font-lock-keywords t))
267 (put 'riece-dialogue-mode 'font-lock-defaults
268 '(riece-dialogue-font-lock-keywords t))
269 (add-hook 'riece-dialogue-mode-hook
270 'riece-highlight-setup-dialogue)
271 (put 'riece-channel-list-mode 'font-lock-defaults
272 '(riece-channel-list-font-lock-keywords t))
273 (add-hook 'riece-channel-list-mode-hook
274 'riece-highlight-setup-channel-list)
275 (add-hook 'riece-format-identity-for-channel-list-indicator-functions
276 'riece-highlight-format-identity-for-channel-list-indicator)
277 (add-hook 'riece-after-insert-functions
278 'riece-highlight-put-overlay-faces))
280 (defun riece-highlight-uninstall ()
281 (let ((buffers riece-buffer-list))
284 (set-buffer (car buffers))
285 (if (riece-derived-mode-p 'riece-dialogue-mode)
286 (remove-hook 'after-change-functions
287 'riece-highlight-hide-prefix t))
288 (setq buffers (cdr buffers)))))
289 (riece-remprop 'riece-channel-mode 'font-lock-defaults)
290 (riece-remprop 'riece-others-mode 'font-lock-defaults)
291 (riece-remprop 'riece-dialogue-mode 'font-lock-defaults)
292 (remove-hook 'riece-dialogue-mode-hook
293 'riece-highlight-setup-dialogue)
294 (riece-remprop 'riece-channel-list-mode 'font-lock-defaults)
295 (remove-hook 'riece-channel-list-mode-hook
296 'riece-highlight-setup-channel-list)
297 (remove-hook 'riece-format-identity-for-channel-list-indicator-functions
298 'riece-highlight-format-identity-for-channel-list-indicator)
299 (remove-hook 'riece-after-insert-functions
300 'riece-highlight-put-overlay-faces))
302 (defun riece-highlight-enable ()
303 (let ((buffers riece-buffer-list))
305 (if (with-current-buffer (car buffers)
306 (riece-derived-mode-p 'riece-dialogue-mode
307 'riece-channel-list-mode))
308 (with-current-buffer (car buffers)
310 (setq buffers (cdr buffers)))))
312 (defun riece-highlight-disable ()
313 (let ((buffers riece-buffer-list))
315 (if (with-current-buffer (car buffers)
316 (riece-derived-mode-p 'riece-dialogue-mode
317 'riece-channel-list-mode))
318 (with-current-buffer (car buffers)
320 (setq buffers (cdr buffers)))))
322 (provide 'riece-highlight)
324 ;;; riece-highlight.el ends here