* riece-unread.el (riece-unread-after-display-message-function):
[riece] / lisp / riece-highlight.el
1 ;;; riece-highlight.el --- coloring IRC buffers
2 ;; Copyright (C) 1998-2003 Daiki Ueno
3
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
5 ;; Created: 1998-09-28
6 ;; Keywords: IRC, riece
7
8 ;; This file is part of Riece.
9
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)
13 ;; any later version.
14
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.
19
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.
24
25 ;;; Code:
26
27 (require 'riece-globals)
28 (require 'font-lock)
29
30 (defgroup riece-highlight nil
31   "Highlight your IRC buffer"
32   :tag "Highlight"
33   :prefix "riece-"
34   :group 'riece)
35
36 (defgroup riece-highlight-faces nil
37   "Faces for highlight your IRC buffer"
38   :tag "Faces"
39   :prefix "riece-highlight-"
40   :group 'riece-highlight)
41
42 (defcustom riece-dialogue-change-face 'riece-dialogue-change-face
43   "Face used for displaying \"*** Change:\" line."
44   :type 'face
45   :group 'riece-highlight-faces)
46
47 (defcustom riece-dialogue-notice-face 'riece-dialogue-notice-face
48   "Face used for displaying \"*** Notice:\" line."
49   :type 'face
50   :group 'riece-highlight-faces)
51
52 (defcustom riece-dialogue-wallops-face 'riece-dialogue-wallops-face
53   "Face used for displaying \"*** Wallops:\" line."
54   :type 'face
55   :group 'riece-highlight-faces)
56   
57 (defcustom riece-dialogue-error-face 'riece-dialogue-error-face
58   "Face used for displaying \"*** Error:\" line."
59   :type 'face
60   :group 'riece-highlight-faces)
61
62 (defcustom riece-dialogue-info-face 'riece-dialogue-info-face
63   "Face used for displaying \"*** Info:\" line."
64   :type 'face
65   :group 'riece-highlight-faces)
66
67 (defcustom riece-dialogue-server-face 'riece-dialogue-server-face
68   "Face used for displaying \"(from server)\" extent."
69   :type 'face
70   :group 'riece-highlight-faces)
71
72 (defcustom riece-dialogue-prefix-face 'riece-dialogue-prefix-face
73   "Face used for displaying \"<nick>\" extent."
74   :type 'face
75   :group 'riece-highlight-faces)
76
77 (defface riece-dialogue-change-face
78   '((((class color)
79       (background dark))
80      (:foreground "cyan" :bold t))
81     (((class color)
82       (background light))
83      (:foreground "RoyalBlue" :bold t))
84     (t
85      (:bold t)))
86   "Face used for displaying \"*** Change:\" line"
87   :group 'riece-highlight-faces)
88
89 (defface riece-dialogue-notice-face
90   '((((class color)
91       (background dark))
92      (:foreground "green2" :bold t))
93     (((class color)
94       (background light))
95      (:foreground "MidnightBlue" :bold t))
96     (t
97      (:bold t)))
98   "Face used for displaying \"*** Notice:\" line"
99   :group 'riece-highlight-faces)
100
101 (defface riece-dialogue-wallops-face
102   '((((class color)
103       (background dark))
104      (:foreground "yellow" :bold t))
105     (((class color)
106       (background light))
107      (:foreground "blue4" :bold t))
108     (t
109      (:bold t)))
110   "Face used for displaying \"*** Wallops:\" line"
111   :group 'riece-highlight-faces)
112
113 (defface riece-dialogue-error-face
114   '((((class color)
115       (background dark))
116      (:foreground "cornflower blue" :bold t))
117     (((class color)
118       (background light))
119      (:foreground "DarkGreen"))
120     (t
121      (:bold t)))
122   "Face used for displaying \"*** Error:\" line"
123   :group 'riece-highlight-faces)
124
125 (defface riece-dialogue-info-face
126   '((((class color)
127       (background dark))
128      (:foreground "PaleTurquoise" :bold t))
129     (((class color)
130       (background light))
131      (:foreground "RoyalBlue"))
132     (t
133      (:bold t)))
134   "Face used for displaying \"*** Info:\" line"
135   :group 'riece-highlight-faces)
136
137 (defface riece-dialogue-server-face
138   '((((class color)
139       (background dark))
140      (:foreground "Gray70"))
141     (((class color)
142       (background light))
143      (:foreground "DimGray"))
144     (t
145      (:bold t)))
146   "Face used for displaying \"(from server)\" extent."
147   :group 'riece-highlight-faces)
148
149 (defface riece-dialogue-prefix-face
150   '((((class color)
151       (background dark))
152      (:foreground "moccasin"))
153     (((class color)
154       (background light))
155      (:foreground "firebrick"))
156     (t
157      (:bold nil)))
158   "Face used for displaying \"<nick>\" extent"
159   :group 'riece-highlight-faces)
160
161 (defcustom riece-dialogue-font-lock-keywords
162   (append
163    (list (list (concat "^" riece-time-prefix-regexp
164                        "\\(<[^>]+>\\|>[^<]+<\\|([^)]+)\\|{[^}]+}\\|=[^=]+=\\)")
165                '(1 riece-dialogue-prefix-face append t)))
166    ;; set property to the whole line
167    (mapcar
168     (lambda (line)
169       (cons
170        (concat
171         "^" riece-time-prefix-regexp "\\("
172         (regexp-quote
173          (symbol-value (intern (format "riece-%s-prefix" line))))
174         ".*\\)$")
175        (list 1 (intern (format "riece-dialogue-%s-face" line)) t t)))
176     '(change notice wallops error info))
177    (list (list "(from [^)]+)$" 0 riece-dialogue-server-face t)))
178   "Default expressions to highlight in riece-dialogue-mode."
179   :type '(repeat (list string))
180   :group 'riece-highlight)
181
182 (defcustom riece-channel-list-default-face 'riece-channel-list-default-face
183   "Face used for displaying channels."
184   :type 'face
185   :group 'riece-highlight-faces)
186
187 (defcustom riece-channel-list-current-face 'riece-channel-list-current-face
188   "Face used for displaying the current channel."
189   :type 'face
190   :group 'riece-highlight-faces)
191
192 (defface riece-channel-list-default-face
193   '((t ()))
194   "Face used for displaying channels."
195   :group 'riece-highlight-faces)
196
197 (defface riece-channel-list-current-face
198   '((((class color)
199       (background dark))
200      (:foreground "PaleTurquoise" :underline t))
201     (((class color)
202       (background light))
203      (:foreground "ForestGreen" :underline t))
204     (t
205      ()))
206   "Face used for displaying the current channel."
207   :group 'riece-highlight-faces)
208
209 (defcustom riece-channel-list-mark-face-alist
210   '((?* . riece-channel-list-current-face))
211   "An alist mapping marks on riece-channel-list-buffer to faces."
212   :type 'list
213   :group 'riece-highlight)
214
215 (defcustom riece-channel-list-font-lock-keywords
216   '(("^[ 0-9][0-9]:\\(.\\)\\(.*\\)"
217      (2 (or (cdr (assq (aref (match-string 1) 0)
218                        riece-channel-list-mark-face-alist))
219             riece-channel-list-default-face))))
220   "Default expressions to highlight in riece-channel-list-mode."
221   :type '(repeat (list string))
222   :group 'riece-highlight)
223
224 (defun riece-dialogue-schedule-turn-on-font-lock ()
225   (add-hook 'riece-channel-mode-hook
226             'riece-dialogue-turn-on-font-lock)
227   (add-hook 'riece-others-mode-hook
228             'riece-dialogue-turn-on-font-lock)
229   (add-hook 'riece-dialogue-mode-hook
230             'riece-dialogue-turn-on-font-lock))
231
232 (defun riece-channel-list-schedule-turn-on-font-lock ()
233   (add-hook 'riece-channel-list-mode-hook
234             'riece-channel-list-turn-on-font-lock))
235
236 (defvar font-lock-support-mode)
237 (defun riece-dialogue-turn-on-font-lock ()
238   (make-local-variable 'font-lock-defaults)
239   (setq font-lock-defaults '(riece-dialogue-font-lock-keywords t))
240   (make-local-variable 'font-lock-verbose)
241   (setq font-lock-verbose nil)
242   (when (boundp 'font-lock-support-mode)
243     (make-local-variable 'font-lock-support-mode)
244     (setq font-lock-support-mode nil))
245   (make-local-hook 'font-lock-mode-hook)
246   (setq font-lock-mode-hook nil)
247   (turn-on-font-lock)
248   (make-local-hook 'after-change-functions)
249   (add-hook 'after-change-functions
250             'riece-dialogue-hide-prefix nil 'local))
251
252 (defun riece-dialogue-hide-prefix (start end length)
253   (save-excursion
254     (goto-char start)
255     (if (looking-at riece-prefix-regexp)
256         (put-text-property (match-beginning 1) (match-end 1) 'invisible t))))
257
258 (defun riece-channel-list-mark-current-channel (last)
259   (if (and riece-channel-list-buffer-mode
260            riece-current-channel)
261       (save-excursion
262         (set-buffer riece-channel-list-buffer)
263         (let ((inhibit-read-only t)
264               buffer-read-only)
265           (goto-char (point-min))
266           (if (re-search-forward "^\\( ?[0-9]+:\\)\\*" nil t)
267               (replace-match "\\1 "))
268           (goto-char (point-min))
269           (if (re-search-forward
270                (concat
271                 "^\\( ?[0-9]+:\\).\\("
272                 (regexp-quote (riece-format-identity riece-current-channel))
273                 "\\)$") nil t)
274               (replace-match "\\1*\\2"))))))
275
276 (defun riece-channel-list-turn-on-font-lock ()
277   (make-local-variable 'font-lock-defaults)
278   (setq font-lock-defaults '(riece-channel-list-font-lock-keywords t))
279   (make-local-variable 'font-lock-verbose)
280   (setq font-lock-verbose nil)
281   (when (boundp 'font-lock-support-mode)
282     (make-local-variable 'font-lock-support-mode)
283     (setq font-lock-support-mode nil))
284   (make-local-hook 'font-lock-mode-hook)
285   (setq font-lock-mode-hook nil)
286   (turn-on-font-lock))
287
288 (defun riece-highlight-insinuate ()
289   (put 'riece-channel-mode 'font-lock-defaults
290        '(riece-dialogue-font-lock-keywords t))
291   (put 'riece-others-mode 'font-lock-defaults
292        '(riece-dialogue-font-lock-keywords t))
293   (put 'riece-dialogue-mode 'font-lock-defaults
294        '(riece-dialogue-font-lock-keywords t))
295   (add-hook 'riece-after-load-startup-hook
296             'riece-dialogue-schedule-turn-on-font-lock)
297   (put 'riece-channel-list-mode 'font-lock-defaults
298        '(riece-channel-list-font-lock-keywords t))
299   (add-hook 'riece-after-switch-to-channel-functions
300             'riece-channel-list-mark-current-channel)
301   (add-hook 'riece-after-load-startup-hook
302             'riece-channel-list-schedule-turn-on-font-lock))
303
304 (provide 'riece-highlight)
305
306 ;;; riece-highlight.el ends here