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
32 (defgroup riece-highlight nil
33 "Highlight your IRC buffer"
38 (defgroup riece-highlight-faces nil
39 "Faces for highlight your IRC buffer"
41 :prefix "riece-highlight-"
42 :group 'riece-highlight)
44 (defface riece-dialogue-change-face
47 (:foreground "cyan" :bold t))
50 (:foreground "RoyalBlue" :bold t))
53 "Face used for displaying \"*** Change:\" line"
54 :group 'riece-highlight-faces)
55 (defvar riece-dialogue-change-face 'riece-dialogue-change-face)
57 (defface riece-dialogue-notice-face
60 (:foreground "green2" :bold t))
63 (:foreground "MidnightBlue" :bold t))
66 "Face used for displaying \"*** Notice:\" line"
67 :group 'riece-highlight-faces)
68 (defvar riece-dialogue-notice-face 'riece-dialogue-notice-face)
70 (defface riece-dialogue-wallops-face
73 (:foreground "yellow" :bold t))
76 (:foreground "blue4" :bold t))
79 "Face used for displaying \"*** Wallops:\" line"
80 :group 'riece-highlight-faces)
81 (defvar riece-dialogue-wallops-face 'riece-dialogue-wallops-face)
83 (defface riece-dialogue-error-face
86 (:foreground "cornflower blue" :bold t))
89 (:foreground "DarkGreen"))
92 "Face used for displaying \"*** Error:\" line"
93 :group 'riece-highlight-faces)
94 (defvar riece-dialogue-error-face 'riece-dialogue-error-face)
96 (defface riece-dialogue-info-face
99 (:foreground "PaleTurquoise" :bold t))
102 (:foreground "RoyalBlue"))
105 "Face used for displaying \"*** Info:\" line"
106 :group 'riece-highlight-faces)
107 (defvar riece-dialogue-info-face 'riece-dialogue-info-face)
109 (defface riece-dialogue-server-face
112 (:foreground "Gray70"))
115 (:foreground "DimGray"))
118 "Face used for displaying \"(from server)\" extent."
119 :group 'riece-highlight-faces)
120 (defvar riece-dialogue-server-face 'riece-dialogue-server-face)
122 (defface riece-dialogue-prefix-face
125 (:foreground "moccasin"))
128 (:foreground "firebrick"))
131 "Face used for displaying \"<nick>\" extent"
132 :group 'riece-highlight-faces)
133 (defvar riece-dialogue-prefix-face 'riece-dialogue-prefix-face)
135 (defcustom riece-dialogue-font-lock-keywords
137 (list (list (concat "^" riece-time-prefix-regexp
138 "\\(<[^>]+>\\|>[^<]+<\\|([^)]+)\\|{[^}]+}\\|=[^=]+=\\)")
139 '(1 riece-dialogue-prefix-face append t)))
140 ;; set property to the whole line
145 "^" riece-time-prefix-regexp "\\("
147 (symbol-value (intern (format "riece-%s-prefix" line))))
149 (list 1 (intern (format "riece-dialogue-%s-face" line)) t t)))
150 '(change notice wallops error info))
151 (list (list "(from [^)]+)$" 0 riece-dialogue-server-face t)))
152 "Default expressions to highlight in riece-dialogue-mode."
153 :type '(repeat (list string))
154 :group 'riece-highlight)
156 (defface riece-channel-list-default-face
158 "Face used for displaying channels."
159 :group 'riece-highlight-faces)
160 (defvar riece-channel-list-default-face 'riece-channel-list-default-face)
162 (defface riece-channel-list-current-face
165 (:foreground "turquoise" :underline t))
168 (:foreground "SeaGreen" :underline t))
171 "Face used for displaying the current channel."
172 :group 'riece-highlight-faces)
173 (defvar riece-channel-list-current-face 'riece-channel-list-current-face)
175 (defcustom riece-channel-list-mark-face-alist
176 '((?* . riece-channel-list-current-face))
177 "An alist mapping marks on riece-channel-list-buffer to faces."
179 :group 'riece-highlight)
181 (defcustom riece-channel-list-font-lock-keywords
182 '(("^[ 0-9][0-9]:\\(.\\)\\(.*\\)"
183 (2 (or (cdr (assq (aref (match-string 1) 0)
184 riece-channel-list-mark-face-alist))
185 riece-channel-list-default-face))))
186 "Default expressions to highlight in riece-channel-list-mode."
187 :type '(repeat (list string))
188 :group 'riece-highlight)
190 (defun riece-dialogue-schedule-turn-on-font-lock ()
191 (add-hook 'riece-channel-mode-hook
192 'riece-dialogue-turn-on-font-lock)
193 (add-hook 'riece-others-mode-hook
194 'riece-dialogue-turn-on-font-lock)
195 (add-hook 'riece-dialogue-mode-hook
196 'riece-dialogue-turn-on-font-lock))
198 (defun riece-channel-list-schedule-turn-on-font-lock ()
199 (add-hook 'riece-channel-list-mode-hook
200 'riece-channel-list-turn-on-font-lock))
202 (defvar font-lock-support-mode)
203 (defun riece-dialogue-turn-on-font-lock ()
204 (make-local-variable 'font-lock-defaults)
205 (setq font-lock-defaults '(riece-dialogue-font-lock-keywords t))
206 (make-local-variable 'font-lock-verbose)
207 (setq font-lock-verbose nil)
208 (when (boundp 'font-lock-support-mode)
209 (make-local-variable 'font-lock-support-mode)
210 (setq font-lock-support-mode nil))
211 (make-local-hook 'font-lock-mode-hook)
212 (setq font-lock-mode-hook nil)
214 (make-local-hook 'after-change-functions)
215 (add-hook 'after-change-functions
216 'riece-dialogue-hide-prefix nil 'local))
218 (defun riece-dialogue-hide-prefix (start end length)
221 (if (looking-at riece-prefix-regexp)
222 (put-text-property (match-beginning 1) (match-end 1) 'invisible t))))
224 (defun riece-put-overlay-faces (start end)
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-channel-list-turn-on-font-lock ()
234 (make-local-variable 'font-lock-defaults)
235 (setq font-lock-defaults '(riece-channel-list-font-lock-keywords t))
236 (make-local-variable 'font-lock-verbose)
237 (setq font-lock-verbose nil)
238 (when (boundp 'font-lock-support-mode)
239 (make-local-variable 'font-lock-support-mode)
240 (setq font-lock-support-mode nil))
241 (make-local-hook 'font-lock-mode-hook)
242 (setq font-lock-mode-hook nil)
245 (defun riece-highlight-format-identity-for-channel-list-indicator (index
247 (if (riece-identity-equal identity riece-current-channel)
248 (let ((string (riece-format-identity identity))
251 (while (string-match "%" string start)
252 (setq start (1+ (match-end 0))
253 string (replace-match "%%" nil nil string)))
254 (list (format "%d:" index)
255 (riece-propertize-modeline-string
256 string 'face 'riece-channel-list-current-face)))))
258 (defun riece-highlight-insinuate ()
259 (put 'riece-channel-mode 'font-lock-defaults
260 '(riece-dialogue-font-lock-keywords t))
261 (put 'riece-others-mode 'font-lock-defaults
262 '(riece-dialogue-font-lock-keywords t))
263 (put 'riece-dialogue-mode 'font-lock-defaults
264 '(riece-dialogue-font-lock-keywords t))
265 (add-hook 'riece-after-load-startup-hook
266 'riece-dialogue-schedule-turn-on-font-lock)
267 (put 'riece-channel-list-mode 'font-lock-defaults
268 '(riece-channel-list-font-lock-keywords t))
269 (add-hook 'riece-after-load-startup-hook
270 'riece-channel-list-schedule-turn-on-font-lock)
271 (add-hook 'riece-format-identity-for-channel-list-indicator-functions
272 'riece-highlight-format-identity-for-channel-list-indicator)
273 (add-hook 'riece-after-insert-functions 'riece-put-overlay-faces))
275 (provide 'riece-highlight)
277 ;;; riece-highlight.el ends here