Commit | Line | Data |
---|---|---|
bd43c990 RS |
1 | ;;; rcirc.el --- default, simple IRC client. |
2 | ||
d7a0267c | 3 | ;; Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc. |
bd43c990 RS |
4 | |
5 | ;; Author: Ryan Yeske | |
bd43c990 RS |
6 | ;; URL: http://www.nongnu.org/rcirc |
7 | ;; Keywords: comm | |
8 | ||
b71cef5c | 9 | ;; This file is part of GNU Emacs. |
bd43c990 RS |
10 | |
11 | ;; This file is free software; you can redistribute it and/or modify | |
12 | ;; it under the terms of the GNU General Public License as published by | |
ceaeecb0 | 13 | ;; the Free Software Foundation; either version 3, or (at your option) |
bd43c990 RS |
14 | ;; any later version. |
15 | ||
16 | ;; This file is distributed in the hope that it will be useful, | |
17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
92c4adc1 | 18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd43c990 RS |
19 | ;; GNU General Public License for more details. |
20 | ||
21 | ;; You should have received a copy of the GNU General Public License | |
b71cef5c RF |
22 | ;; along with GNU Emacs; see the file COPYING. If not, write to the |
23 | ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
24 | ;; Boston, MA 02110-1301, USA. | |
bd43c990 RS |
25 | |
26 | ;;; Commentary: | |
27 | ||
adf794e4 EZ |
28 | ;; Internet Relay Chat (IRC) is a form of instant communication over |
29 | ;; the Internet. It is mainly designed for group (many-to-many) | |
30 | ;; communication in discussion forums called channels, but also allows | |
31 | ;; one-to-one communication. | |
32 | ||
33 | ;; Rcirc has simple defaults and clear and consistent behaviour. | |
34 | ;; Message arrival timestamps, activity notification on the modeline, | |
35 | ;; message filling, nick completion, and keepalive pings are all | |
36 | ;; enabled by default, but can easily be adjusted or turned off. Each | |
37 | ;; discussion takes place in its own buffer and there is a single | |
38 | ;; server buffer per connection. | |
bd43c990 | 39 | |
bd43c990 RS |
40 | ;; Open a new irc connection with: |
41 | ;; M-x irc RET | |
42 | ||
7faa3f8c MB |
43 | ;;; Todo: |
44 | ||
bd43c990 RS |
45 | ;;; Code: |
46 | ||
47 | (require 'ring) | |
48 | (require 'time-date) | |
49 | (eval-when-compile (require 'cl)) | |
50 | ||
adf794e4 EZ |
51 | (defgroup rcirc nil |
52 | "Simple IRC client." | |
53 | :version "22.1" | |
2fbed782 | 54 | :prefix "rcirc-" |
e8f10ddb | 55 | :link '(custom-manual "(rcirc)") |
adf794e4 EZ |
56 | :group 'applications) |
57 | ||
0ffab1eb | 58 | (defcustom rcirc-server-alist |
195eca78 SM |
59 | '(("irc.freenode.net" :channels ("#rcirc"))) |
60 | "An alist of IRC connections to establish when running `rcirc'. | |
61 | Each element looks like (SERVER-NAME PARAMETERS). | |
62 | ||
63 | SERVER-NAME is a string describing the server to connect | |
64 | to. | |
65 | ||
0ffab1eb TTN |
66 | The optional PARAMETERS come in pairs PARAMETER VALUE. |
67 | ||
68 | The following parameters are recognized: | |
69 | ||
70 | `:nick' | |
71 | ||
72 | VALUE must be a string. If absent, `rcirc-default-nick' is used | |
73 | for this connection. | |
74 | ||
75 | `:port' | |
76 | ||
77 | VALUE must be a number or string. If absent, | |
78 | `rcirc-default-port' is used. | |
79 | ||
80 | `:user-name' | |
81 | ||
82 | VALUE must be a string. If absent, `rcirc-default-user-name' is | |
83 | used. | |
84 | ||
85 | `:full-name' | |
86 | ||
87 | VALUE must be a string. If absent, `rcirc-default-full-name' is | |
88 | used. | |
89 | ||
90 | `:channels' | |
91 | ||
92 | VALUE must be a list of strings describing which channels to join | |
93 | when connecting to this server. If absent, no channels will be | |
94 | connected to automatically." | |
95 | :type '(alist :key-type string | |
a0a5c583 GM |
96 | :value-type (plist :options ((:nick string) |
97 | (:port integer) | |
98 | (:user-name string) | |
99 | (:full-name string) | |
100 | (:channels (repeat string))))) | |
adf794e4 | 101 | :group 'rcirc) |
bd43c990 | 102 | |
a2524d26 | 103 | (defcustom rcirc-default-port 6667 |
adf794e4 EZ |
104 | "The default port to connect to." |
105 | :type 'integer | |
106 | :group 'rcirc) | |
bd43c990 | 107 | |
a2524d26 | 108 | (defcustom rcirc-default-nick (user-login-name) |
adf794e4 EZ |
109 | "Your nick." |
110 | :type 'string | |
111 | :group 'rcirc) | |
bd43c990 | 112 | |
a2524d26 | 113 | (defcustom rcirc-default-user-name (user-login-name) |
adf794e4 EZ |
114 | "Your user name sent to the server when connecting." |
115 | :type 'string | |
116 | :group 'rcirc) | |
bd43c990 | 117 | |
0ffab1eb TTN |
118 | (defcustom rcirc-default-full-name (if (string= (user-full-name) "") |
119 | rcirc-default-user-name | |
120 | (user-full-name)) | |
adf794e4 EZ |
121 | "The full name sent to the server when connecting." |
122 | :type 'string | |
123 | :group 'rcirc) | |
bd43c990 | 124 | |
adf794e4 EZ |
125 | (defcustom rcirc-fill-flag t |
126 | "*Non-nil means line-wrap messages printed in channel buffers." | |
127 | :type 'boolean | |
128 | :group 'rcirc) | |
bd43c990 | 129 | |
adf794e4 EZ |
130 | (defcustom rcirc-fill-column nil |
131 | "*Column beyond which automatic line-wrapping should happen. | |
195eca78 SM |
132 | If nil, use value of `fill-column'. If 'frame-width, use the |
133 | maximum frame width." | |
adf794e4 EZ |
134 | :type '(choice (const :tag "Value of `fill-column'") |
135 | (const :tag "Full frame width" frame-width) | |
136 | (integer :tag "Number of columns")) | |
137 | :group 'rcirc) | |
bd43c990 | 138 | |
adf794e4 | 139 | (defcustom rcirc-fill-prefix nil |
bd43c990 RS |
140 | "*Text to insert before filled lines. |
141 | If nil, calculate the prefix dynamically to line up text | |
adf794e4 EZ |
142 | underneath each nick." |
143 | :type '(choice (const :tag "Dynamic" nil) | |
144 | (string :tag "Prefix text")) | |
145 | :group 'rcirc) | |
bd43c990 | 146 | |
adf794e4 EZ |
147 | (defvar rcirc-ignore-buffer-activity-flag nil |
148 | "If non-nil, ignore activity in this buffer.") | |
149 | (make-variable-buffer-local 'rcirc-ignore-buffer-activity-flag) | |
bd43c990 | 150 | |
a2524d26 EZ |
151 | (defvar rcirc-low-priority-flag nil |
152 | "If non-nil, activity in this buffer is considered low priority.") | |
153 | (make-variable-buffer-local 'rcirc-low-priority-flag) | |
154 | ||
195eca78 SM |
155 | (defvar rcirc-omit-mode nil |
156 | "Non-nil if Rcirc-Omit mode is enabled. | |
157 | Use the command `rcirc-omit-mode' to change this variable.") | |
158 | (make-variable-buffer-local 'rcirc-omit-mode) | |
159 | ||
adf794e4 | 160 | (defcustom rcirc-time-format "%H:%M " |
bd43c990 | 161 | "*Describes how timestamps are printed. |
adf794e4 EZ |
162 | Used as the first arg to `format-time-string'." |
163 | :type 'string | |
164 | :group 'rcirc) | |
bd43c990 | 165 | |
adf794e4 EZ |
166 | (defcustom rcirc-input-ring-size 1024 |
167 | "*Size of input history ring." | |
168 | :type 'integer | |
169 | :group 'rcirc) | |
bd43c990 | 170 | |
adf794e4 | 171 | (defcustom rcirc-read-only-flag t |
2e398771 | 172 | "*Non-nil means make text in IRC buffers read-only." |
adf794e4 EZ |
173 | :type 'boolean |
174 | :group 'rcirc) | |
bd43c990 | 175 | |
adf794e4 | 176 | (defcustom rcirc-buffer-maximum-lines nil |
bd43c990 RS |
177 | "*The maximum size in lines for rcirc buffers. |
178 | Channel buffers are truncated from the top to be no greater than this | |
92c4adc1 | 179 | number. If zero or nil, no truncating is done." |
adf794e4 EZ |
180 | :type '(choice (const :tag "No truncation" nil) |
181 | (integer :tag "Number of lines")) | |
182 | :group 'rcirc) | |
bd43c990 | 183 | |
d40ac716 | 184 | (defcustom rcirc-scroll-show-maximum-output t |
195eca78 SM |
185 | "*If non-nil, scroll buffer to keep the point at the bottom of |
186 | the window." | |
f8db61b2 EZ |
187 | :type 'boolean |
188 | :group 'rcirc) | |
7faa3f8c | 189 | |
db58efbf EZ |
190 | (defcustom rcirc-authinfo nil |
191 | "List of authentication passwords. | |
192 | Each element of the list is a list with a SERVER-REGEXP string | |
193 | and a method symbol followed by method specific arguments. | |
194 | ||
195 | The valid METHOD symbols are `nickserv', `chanserv' and | |
196 | `bitlbee'. | |
bd43c990 RS |
197 | |
198 | The required ARGUMENTS for each METHOD symbol are: | |
db58efbf EZ |
199 | `nickserv': NICK PASSWORD |
200 | `chanserv': NICK CHANNEL PASSWORD | |
201 | `bitlbee': NICK PASSWORD | |
bd43c990 RS |
202 | |
203 | Example: | |
db58efbf EZ |
204 | ((\"freenode\" nickserv \"bob\" \"p455w0rd\") |
205 | (\"freenode\" chanserv \"bob\" \"#bobland\" \"passwd99\") | |
206 | (\"bitlbee\" bitlbee \"robert\" \"sekrit\"))" | |
207 | :type '(alist :key-type (string :tag "Server") | |
208 | :value-type (choice (list :tag "NickServ" | |
209 | (const nickserv) | |
210 | (string :tag "Nick") | |
211 | (string :tag "Password")) | |
212 | (list :tag "ChanServ" | |
213 | (const chanserv) | |
214 | (string :tag "Nick") | |
215 | (string :tag "Channel") | |
216 | (string :tag "Password")) | |
217 | (list :tag "BitlBee" | |
218 | (const bitlbee) | |
219 | (string :tag "Nick") | |
220 | (string :tag "Password")))) | |
adf794e4 | 221 | :group 'rcirc) |
bd43c990 | 222 | |
db58efbf | 223 | (defcustom rcirc-auto-authenticate-flag t |
bd43c990 | 224 | "*Non-nil means automatically send authentication string to server. |
db58efbf | 225 | See also `rcirc-authinfo'." |
adf794e4 EZ |
226 | :type 'boolean |
227 | :group 'rcirc) | |
bd43c990 | 228 | |
adf794e4 | 229 | (defcustom rcirc-prompt "> " |
2e398771 | 230 | "Prompt string to use in IRC buffers. |
bd43c990 RS |
231 | |
232 | The following replacements are made: | |
233 | %n is your nick. | |
234 | %s is the server. | |
235 | %t is the buffer target, a channel or a user. | |
236 | ||
adf794e4 EZ |
237 | Setting this alone will not affect the prompt; |
238 | use either M-x customize or also call `rcirc-update-prompt'." | |
239 | :type 'string | |
240 | :set 'rcirc-set-changed | |
241 | :initialize 'custom-initialize-default | |
242 | :group 'rcirc) | |
243 | ||
f8db61b2 EZ |
244 | (defcustom rcirc-keywords nil |
245 | "List of keywords to highlight in message text." | |
246 | :type '(repeat string) | |
247 | :group 'rcirc) | |
248 | ||
2c8abe90 AS |
249 | (defcustom rcirc-ignore-list () |
250 | "List of ignored nicks. | |
251 | Use /ignore to list them, use /ignore NICK to add or remove a nick." | |
252 | :type '(repeat string) | |
253 | :group 'rcirc) | |
254 | ||
255 | (defvar rcirc-ignore-list-automatic () | |
256 | "List of ignored nicks added to `rcirc-ignore-list' because of renaming. | |
257 | When an ignored person renames, their nick is added to both lists. | |
258 | Nicks will be removed from the automatic list on follow-up renamings or | |
259 | parts.") | |
260 | ||
f8db61b2 EZ |
261 | (defcustom rcirc-bright-nicks nil |
262 | "List of nicks to be emphasized. | |
02f47e86 | 263 | See `rcirc-bright-nick' face." |
f8db61b2 | 264 | :type '(repeat string) |
02f47e86 MB |
265 | :group 'rcirc) |
266 | ||
f8db61b2 EZ |
267 | (defcustom rcirc-dim-nicks nil |
268 | "List of nicks to be deemphasized. | |
02f47e86 | 269 | See `rcirc-dim-nick' face." |
f8db61b2 | 270 | :type '(repeat string) |
02f47e86 MB |
271 | :group 'rcirc) |
272 | ||
adf794e4 EZ |
273 | (defcustom rcirc-print-hooks nil |
274 | "Hook run after text is printed. | |
275 | Called with 5 arguments, PROCESS, SENDER, RESPONSE, TARGET and TEXT." | |
276 | :type 'hook | |
277 | :group 'rcirc) | |
bd43c990 | 278 | |
db58efbf EZ |
279 | (defcustom rcirc-always-use-server-buffer-flag nil |
280 | "Non-nil means messages without a channel target will go to the server buffer." | |
281 | :type 'boolean | |
282 | :group 'rcirc) | |
283 | ||
02f47e86 | 284 | (defcustom rcirc-decode-coding-system 'utf-8 |
a2524d26 EZ |
285 | "Coding system used to decode incoming irc messages." |
286 | :type 'coding-system | |
287 | :group 'rcirc) | |
288 | ||
289 | (defcustom rcirc-encode-coding-system 'utf-8 | |
290 | "Coding system used to encode outgoing irc messages." | |
291 | :type 'coding-system | |
292 | :group 'rcirc) | |
293 | ||
294 | (defcustom rcirc-coding-system-alist nil | |
f8db61b2 | 295 | "Alist to decide a coding system to use for a channel I/O operation. |
a2524d26 EZ |
296 | The format is ((PATTERN . VAL) ...). |
297 | PATTERN is either a string or a cons of strings. | |
298 | If PATTERN is a string, it is used to match a target. | |
299 | If PATTERN is a cons of strings, the car part is used to match a | |
300 | target, and the cdr part is used to match a server. | |
301 | VAL is either a coding system or a cons of coding systems. | |
302 | If VAL is a coding system, it is used for both decoding and encoding | |
303 | messages. | |
304 | If VAL is a cons of coding systems, the car part is used for decoding, | |
305 | and the cdr part is used for encoding." | |
306 | :type '(alist :key-type (choice (string :tag "Channel Regexp") | |
307 | (cons (string :tag "Channel Regexp") | |
308 | (string :tag "Server Regexp"))) | |
309 | :value-type (choice coding-system | |
310 | (cons (coding-system :tag "Decode") | |
311 | (coding-system :tag "Encode")))) | |
312 | :group 'rcirc) | |
313 | ||
314 | (defcustom rcirc-multiline-major-mode 'fundamental-mode | |
315 | "Major-mode function to use in multiline edit buffers." | |
316 | :type 'function | |
317 | :group 'rcirc) | |
318 | ||
319 | (defvar rcirc-nick nil) | |
320 | ||
bd43c990 RS |
321 | (defvar rcirc-prompt-start-marker nil) |
322 | (defvar rcirc-prompt-end-marker nil) | |
323 | ||
324 | (defvar rcirc-nick-table nil) | |
325 | ||
a0a5c583 GM |
326 | (defvar rcirc-recent-quit-alist nil |
327 | "Alist of nicks that have recently quit or parted the channel.") | |
328 | ||
2c8abe90 AS |
329 | (defvar rcirc-nick-syntax-table |
330 | (let ((table (make-syntax-table text-mode-syntax-table))) | |
331 | (mapc (lambda (c) (modify-syntax-entry c "w" table)) | |
332 | "[]\\`_^{|}-") | |
333 | (modify-syntax-entry ?' "_" table) | |
334 | table) | |
335 | "Syntax table which includes all nick characters as word constituents.") | |
336 | ||
adf794e4 EZ |
337 | ;; each process has an alist of (target . buffer) pairs |
338 | (defvar rcirc-buffer-alist nil) | |
339 | ||
bd43c990 | 340 | (defvar rcirc-activity nil |
a2524d26 | 341 | "List of buffers with unviewed activity.") |
bd43c990 RS |
342 | |
343 | (defvar rcirc-activity-string "" | |
344 | "String displayed in modeline representing `rcirc-activity'.") | |
345 | (put 'rcirc-activity-string 'risky-local-variable t) | |
346 | ||
a2524d26 EZ |
347 | (defvar rcirc-server-buffer nil |
348 | "The server buffer associated with this channel buffer.") | |
bd43c990 RS |
349 | |
350 | (defvar rcirc-target nil | |
351 | "The channel or user associated with this buffer.") | |
352 | ||
bd43c990 RS |
353 | (defvar rcirc-urls nil |
354 | "List of urls seen in the current buffer.") | |
7faa3f8c | 355 | (put 'rcirc-urls 'permanent-local t) |
bd43c990 | 356 | |
2e875089 | 357 | (defvar rcirc-timeout-seconds 600 |
8216fbaf | 358 | "Kill connection after this many seconds if there is no activity.") |
bd43c990 | 359 | |
adf794e4 | 360 | (defconst rcirc-id-string (concat "rcirc on GNU Emacs " emacs-version)) |
bd43c990 | 361 | \f |
bd43c990 | 362 | (defvar rcirc-startup-channels nil) |
195eca78 | 363 | |
bd43c990 | 364 | ;;;###autoload |
db58efbf | 365 | (defun rcirc (arg) |
0ffab1eb | 366 | "Connect to all servers in `rcirc-server-alist'. |
195eca78 SM |
367 | |
368 | Do not connect to a server if it is already connected. | |
369 | ||
370 | If ARG is non-nil, instead prompt for connection parameters." | |
db58efbf EZ |
371 | (interactive "P") |
372 | (if arg | |
0ffab1eb TTN |
373 | (let* ((server (completing-read "IRC Server: " |
374 | rcirc-server-alist | |
195eca78 | 375 | nil nil |
0ffab1eb TTN |
376 | (caar rcirc-server-alist))) |
377 | (server-plist (cdr (assoc-string server rcirc-server-alist))) | |
378 | (port (read-string "IRC Port: " | |
195eca78 SM |
379 | (number-to-string |
380 | (or (plist-get server-plist 'port) | |
381 | rcirc-default-port)))) | |
382 | (nick (read-string "IRC Nick: " | |
383 | (or (plist-get server-plist 'nick) | |
384 | rcirc-default-nick))) | |
db58efbf EZ |
385 | (channels (split-string |
386 | (read-string "IRC Channels: " | |
0ffab1eb | 387 | (mapconcat 'identity |
195eca78 SM |
388 | (plist-get server-plist |
389 | 'channels) | |
390 | " ")) | |
db58efbf | 391 | "[, ]+" t))) |
195eca78 | 392 | (rcirc-connect server port nick rcirc-default-user-name |
0ffab1eb | 393 | rcirc-default-full-name |
db58efbf | 394 | channels)) |
0ffab1eb | 395 | ;; connect to servers in `rcirc-server-alist' |
195eca78 | 396 | (let (connected-servers) |
0ffab1eb | 397 | (dolist (c rcirc-server-alist) |
195eca78 | 398 | (let ((server (car c)) |
0ffab1eb TTN |
399 | (nick (or (plist-get (cdr c) :nick) rcirc-default-nick)) |
400 | (port (or (plist-get (cdr c) :port) rcirc-default-port)) | |
401 | (user-name (or (plist-get (cdr c) :user-name) | |
195eca78 | 402 | rcirc-default-user-name)) |
0ffab1eb TTN |
403 | (full-name (or (plist-get (cdr c) :full-name) |
404 | rcirc-default-full-name)) | |
405 | (channels (plist-get (cdr c) :channels))) | |
195eca78 SM |
406 | (when server |
407 | (let (connected) | |
408 | (dolist (p (rcirc-process-list)) | |
409 | (when (string= server (process-name p)) | |
410 | (setq connected p))) | |
411 | (if (not connected) | |
412 | (condition-case e | |
0ffab1eb | 413 | (rcirc-connect server port nick user-name |
195eca78 | 414 | full-name channels) |
0ffab1eb | 415 | (quit (message "Quit connecting to %s" server))) |
195eca78 SM |
416 | (with-current-buffer (process-buffer connected) |
417 | (setq connected-servers | |
418 | (cons (process-contact (get-buffer-process | |
419 | (current-buffer)) :host) | |
420 | connected-servers)))))))) | |
421 | (when connected-servers | |
422 | (message "Already connected to %s" | |
a0a5c583 GM |
423 | (if (cdr connected-servers) |
424 | (concat (mapconcat 'identity (butlast connected-servers) ", ") | |
425 | ", and " | |
426 | (car (last connected-servers))) | |
427 | (car connected-servers))))))) | |
195eca78 | 428 | |
bd43c990 RS |
429 | ;;;###autoload |
430 | (defalias 'irc 'rcirc) | |
431 | ||
432 | \f | |
433 | (defvar rcirc-process-output nil) | |
bd43c990 RS |
434 | (defvar rcirc-topic nil) |
435 | (defvar rcirc-keepalive-timer nil) | |
ad8121fe | 436 | (defvar rcirc-last-server-message-time nil) |
8216fbaf EZ |
437 | (defvar rcirc-server nil) ; server provided by server |
438 | (defvar rcirc-server-name nil) ; server name given by 001 response | |
439 | (defvar rcirc-timeout-timer nil) | |
440 | (defvar rcirc-user-disconnect nil) | |
441 | (defvar rcirc-connecting nil) | |
442 | (defvar rcirc-process nil) | |
8d214091 RF |
443 | |
444 | ;;;###autoload | |
0ffab1eb | 445 | (defun rcirc-connect (server &optional port nick user-name full-name |
195eca78 | 446 | startup-channels) |
bd43c990 RS |
447 | (save-excursion |
448 | (message "Connecting to %s..." server) | |
449 | (let* ((inhibit-eol-conversion) | |
2fbed782 EZ |
450 | (port-number (if port |
451 | (if (stringp port) | |
452 | (string-to-number port) | |
453 | port) | |
a2524d26 | 454 | rcirc-default-port)) |
a2524d26 EZ |
455 | (nick (or nick rcirc-default-nick)) |
456 | (user-name (or user-name rcirc-default-user-name)) | |
0ffab1eb | 457 | (full-name (or full-name rcirc-default-full-name)) |
a2524d26 | 458 | (startup-channels startup-channels) |
8216fbaf | 459 | (process (make-network-process :name server :host server :service port-number))) |
bd43c990 RS |
460 | ;; set up process |
461 | (set-process-coding-system process 'raw-text 'raw-text) | |
adf794e4 | 462 | (switch-to-buffer (rcirc-generate-new-buffer-name process nil)) |
bd43c990 | 463 | (set-process-buffer process (current-buffer)) |
bd43c990 | 464 | (rcirc-mode process nil) |
a2524d26 EZ |
465 | (set-process-sentinel process 'rcirc-sentinel) |
466 | (set-process-filter process 'rcirc-filter) | |
8216fbaf EZ |
467 | (make-local-variable 'rcirc-process) |
468 | (setq rcirc-process process) | |
a2524d26 EZ |
469 | (make-local-variable 'rcirc-server) |
470 | (setq rcirc-server server) | |
8216fbaf EZ |
471 | (make-local-variable 'rcirc-server-name) |
472 | (setq rcirc-server-name server) ; update when we get 001 response | |
adf794e4 EZ |
473 | (make-local-variable 'rcirc-buffer-alist) |
474 | (setq rcirc-buffer-alist nil) | |
bd43c990 RS |
475 | (make-local-variable 'rcirc-nick-table) |
476 | (setq rcirc-nick-table (make-hash-table :test 'equal)) | |
bd43c990 RS |
477 | (make-local-variable 'rcirc-nick) |
478 | (setq rcirc-nick nick) | |
479 | (make-local-variable 'rcirc-process-output) | |
480 | (setq rcirc-process-output nil) | |
bd43c990 RS |
481 | (make-local-variable 'rcirc-startup-channels) |
482 | (setq rcirc-startup-channels startup-channels) | |
ad8121fe EZ |
483 | (make-local-variable 'rcirc-last-server-message-time) |
484 | (setq rcirc-last-server-message-time (current-time)) | |
8216fbaf EZ |
485 | (make-local-variable 'rcirc-timeout-timer) |
486 | (setq rcirc-timeout-timer nil) | |
487 | (make-local-variable 'rcirc-user-disconnect) | |
488 | (setq rcirc-user-disconnect nil) | |
489 | (make-local-variable 'rcirc-connecting) | |
490 | (setq rcirc-connecting t) | |
bd43c990 | 491 | |
195eca78 SM |
492 | (add-hook 'auto-save-hook 'rcirc-log-write) |
493 | ||
bd43c990 RS |
494 | ;; identify |
495 | (rcirc-send-string process (concat "NICK " nick)) | |
496 | (rcirc-send-string process (concat "USER " user-name | |
497 | " hostname servername :" | |
498 | full-name)) | |
499 | ||
500 | ;; setup ping timer if necessary | |
8216fbaf EZ |
501 | (unless rcirc-keepalive-timer |
502 | (setq rcirc-keepalive-timer | |
503 | (run-at-time 0 (/ rcirc-timeout-seconds 2) 'rcirc-keepalive))) | |
bd43c990 RS |
504 | |
505 | (message "Connecting to %s...done" server) | |
506 | ||
507 | ;; return process object | |
508 | process))) | |
509 | ||
adf794e4 EZ |
510 | (defmacro with-rcirc-process-buffer (process &rest body) |
511 | (declare (indent 1) (debug t)) | |
512 | `(with-current-buffer (process-buffer ,process) | |
513 | ,@body)) | |
514 | ||
a2524d26 EZ |
515 | (defmacro with-rcirc-server-buffer (&rest body) |
516 | (declare (indent 0) (debug t)) | |
517 | `(with-current-buffer rcirc-server-buffer | |
518 | ,@body)) | |
519 | ||
bd43c990 | 520 | (defun rcirc-keepalive () |
ad8121fe EZ |
521 | "Send keep alive pings to active rcirc processes. |
522 | Kill processes that have not received a server message since the | |
523 | last ping." | |
bd43c990 RS |
524 | (if (rcirc-process-list) |
525 | (mapc (lambda (process) | |
8216fbaf EZ |
526 | (with-rcirc-process-buffer process |
527 | (when (not rcirc-connecting) | |
0ffab1eb | 528 | (rcirc-send-string process |
195eca78 SM |
529 | (format "PRIVMSG %s :\C-aKEEPALIVE %f\C-a" |
530 | rcirc-nick | |
531 | (time-to-seconds | |
532 | (current-time))))))) | |
bd43c990 | 533 | (rcirc-process-list)) |
8216fbaf | 534 | ;; no processes, clean up timer |
bd43c990 RS |
535 | (cancel-timer rcirc-keepalive-timer) |
536 | (setq rcirc-keepalive-timer nil))) | |
537 | ||
195eca78 SM |
538 | (defun rcirc-handler-ctcp-KEEPALIVE (process target sender message) |
539 | (with-rcirc-process-buffer process | |
540 | (setq header-line-format (format "%f" (- (time-to-seconds (current-time)) | |
541 | (string-to-number message)))))) | |
542 | ||
adf794e4 EZ |
543 | (defvar rcirc-debug-buffer " *rcirc debug*") |
544 | (defvar rcirc-debug-flag nil | |
545 | "If non-nil, write information to `rcirc-debug-buffer'.") | |
546 | (defun rcirc-debug (process text) | |
bd43c990 | 547 | "Add an entry to the debug log including PROCESS and TEXT. |
2e398771 | 548 | Debug text is written to `rcirc-debug-buffer' if `rcirc-debug-flag' |
adf794e4 EZ |
549 | is non-nil." |
550 | (when rcirc-debug-flag | |
bd43c990 | 551 | (save-excursion |
195eca78 SM |
552 | (set-buffer (get-buffer-create rcirc-debug-buffer)) |
553 | (goto-char (point-max)) | |
554 | (insert (concat | |
555 | "[" | |
556 | (format-time-string "%Y-%m-%dT%T ") (process-name process) | |
557 | "] " | |
558 | text))))) | |
adf794e4 | 559 | |
bd43c990 RS |
560 | (defvar rcirc-sentinel-hooks nil |
561 | "Hook functions called when the process sentinel is called. | |
562 | Functions are called with PROCESS and SENTINEL arguments.") | |
563 | ||
564 | (defun rcirc-sentinel (process sentinel) | |
565 | "Called when PROCESS receives SENTINEL." | |
566 | (let ((sentinel (replace-regexp-in-string "\n" "" sentinel))) | |
adf794e4 EZ |
567 | (rcirc-debug process (format "SENTINEL: %S %S\n" process sentinel)) |
568 | (with-rcirc-process-buffer process | |
569 | (dolist (buffer (cons nil (mapcar 'cdr rcirc-buffer-alist))) | |
adf794e4 | 570 | (with-current-buffer (or buffer (current-buffer)) |
db58efbf EZ |
571 | (rcirc-print process "rcirc.el" "ERROR" rcirc-target |
572 | (format "%s: %s (%S)" | |
573 | (process-name process) | |
574 | sentinel | |
8216fbaf | 575 | (process-status process)) (not rcirc-target)) |
195eca78 | 576 | (rcirc-disconnect-buffer))) |
8216fbaf | 577 | (run-hook-with-args 'rcirc-sentinel-hooks process sentinel)))) |
bd43c990 | 578 | |
195eca78 SM |
579 | (defun rcirc-disconnect-buffer (&optional buffer) |
580 | (with-current-buffer (or buffer (current-buffer)) | |
581 | ;; set rcirc-target to nil for each channel so cleanup | |
582 | ;; doesnt happen when we reconnect | |
583 | (setq rcirc-target nil) | |
0ffab1eb | 584 | (setq mode-line-process ":disconnected"))) |
195eca78 | 585 | |
bd43c990 RS |
586 | (defun rcirc-process-list () |
587 | "Return a list of rcirc processes." | |
588 | (let (ps) | |
589 | (mapc (lambda (p) | |
18aa2c90 | 590 | (when (buffer-live-p (process-buffer p)) |
adf794e4 | 591 | (with-rcirc-process-buffer p |
bd43c990 RS |
592 | (when (eq major-mode 'rcirc-mode) |
593 | (setq ps (cons p ps)))))) | |
594 | (process-list)) | |
595 | ps)) | |
596 | ||
597 | (defvar rcirc-receive-message-hooks nil | |
2e398771 JB |
598 | "Hook functions run when a message is received from server. |
599 | Function is called with PROCESS, COMMAND, SENDER, ARGS and LINE.") | |
bd43c990 RS |
600 | (defun rcirc-filter (process output) |
601 | "Called when PROCESS receives OUTPUT." | |
adf794e4 | 602 | (rcirc-debug process output) |
8216fbaf | 603 | (rcirc-reschedule-timeout process) |
adf794e4 | 604 | (with-rcirc-process-buffer process |
ad8121fe | 605 | (setq rcirc-last-server-message-time (current-time)) |
bd43c990 RS |
606 | (setq rcirc-process-output (concat rcirc-process-output output)) |
607 | (when (= (aref rcirc-process-output | |
608 | (1- (length rcirc-process-output))) ?\n) | |
609 | (mapc (lambda (line) | |
610 | (rcirc-process-server-response process line)) | |
adf794e4 | 611 | (split-string rcirc-process-output "[\n\r]" t)) |
bd43c990 RS |
612 | (setq rcirc-process-output nil)))) |
613 | ||
8216fbaf EZ |
614 | (defun rcirc-reschedule-timeout (process) |
615 | (with-rcirc-process-buffer process | |
616 | (when (not rcirc-connecting) | |
617 | (with-rcirc-process-buffer process | |
618 | (when rcirc-timeout-timer (cancel-timer rcirc-timeout-timer)) | |
619 | (setq rcirc-timeout-timer (run-at-time rcirc-timeout-seconds nil | |
620 | 'rcirc-delete-process | |
621 | process)))))) | |
622 | ||
623 | (defun rcirc-delete-process (process) | |
8216fbaf EZ |
624 | (delete-process process)) |
625 | ||
adf794e4 | 626 | (defvar rcirc-trap-errors-flag t) |
bd43c990 | 627 | (defun rcirc-process-server-response (process text) |
adf794e4 | 628 | (if rcirc-trap-errors-flag |
bd43c990 RS |
629 | (condition-case err |
630 | (rcirc-process-server-response-1 process text) | |
631 | (error | |
632 | (rcirc-print process "RCIRC" "ERROR" nil | |
adf794e4 | 633 | (format "\"%s\" %s" text err) t))) |
bd43c990 RS |
634 | (rcirc-process-server-response-1 process text))) |
635 | ||
636 | (defun rcirc-process-server-response-1 (process text) | |
637 | (if (string-match "^\\(:\\([^ ]+\\) \\)?\\([^ ]+\\) \\(.+\\)$" text) | |
db58efbf EZ |
638 | (let* ((user (match-string 2 text)) |
639 | (sender (rcirc-user-nick user)) | |
bd43c990 RS |
640 | (cmd (match-string 3 text)) |
641 | (args (match-string 4 text)) | |
642 | (handler (intern-soft (concat "rcirc-handler-" cmd)))) | |
643 | (string-match "^\\([^:]*\\):?\\(.+\\)?$" args) | |
644 | (let* ((args1 (match-string 1 args)) | |
645 | (args2 (match-string 2 args)) | |
adf794e4 EZ |
646 | (args (delq nil (append (split-string args1 " " t) |
647 | (list args2))))) | |
bd43c990 RS |
648 | (if (not (fboundp handler)) |
649 | (rcirc-handler-generic process cmd sender args text) | |
650 | (funcall handler process sender args text)) | |
651 | (run-hook-with-args 'rcirc-receive-message-hooks | |
652 | process cmd sender args text))) | |
653 | (message "UNHANDLED: %s" text))) | |
654 | ||
f8db61b2 EZ |
655 | (defvar rcirc-responses-no-activity '("305" "306") |
656 | "Responses that don't trigger activity in the mode-line indicator.") | |
657 | ||
658 | (defun rcirc-handler-generic (process response sender args text) | |
bd43c990 | 659 | "Generic server response handler." |
f8db61b2 EZ |
660 | (rcirc-print process sender response nil |
661 | (mapconcat 'identity (cdr args) " ") | |
662 | (not (member response rcirc-responses-no-activity)))) | |
bd43c990 RS |
663 | |
664 | (defun rcirc-send-string (process string) | |
665 | "Send PROCESS a STRING plus a newline." | |
a2524d26 | 666 | (let ((string (concat (encode-coding-string string rcirc-encode-coding-system) |
bd43c990 | 667 | "\n"))) |
a2524d26 | 668 | (unless (eq (process-status process) 'open) |
53f831f3 | 669 | (error "Network connection to %s is not open" |
a2524d26 | 670 | (process-name process))) |
adf794e4 | 671 | (rcirc-debug process string) |
bd43c990 RS |
672 | (process-send-string process string))) |
673 | ||
a2524d26 EZ |
674 | (defun rcirc-buffer-process (&optional buffer) |
675 | "Return the process associated with channel BUFFER. | |
676 | With no argument or nil as argument, use the current buffer." | |
8216fbaf EZ |
677 | (or (get-buffer-process (if buffer |
678 | (with-current-buffer buffer | |
679 | rcirc-server-buffer) | |
680 | rcirc-server-buffer)) | |
681 | rcirc-process)) | |
a2524d26 EZ |
682 | |
683 | (defun rcirc-server-name (process) | |
684 | "Return PROCESS server name, given by the 001 response." | |
adf794e4 | 685 | (with-rcirc-process-buffer process |
195eca78 SM |
686 | (or rcirc-server-name |
687 | (warn "server name for process %S unknown" process)))) | |
bd43c990 RS |
688 | |
689 | (defun rcirc-nick (process) | |
690 | "Return PROCESS nick." | |
92c4adc1 | 691 | (with-rcirc-process-buffer process |
a2524d26 EZ |
692 | (or rcirc-nick rcirc-default-nick))) |
693 | ||
694 | (defun rcirc-buffer-nick (&optional buffer) | |
695 | "Return the nick associated with BUFFER. | |
696 | With no argument or nil as argument, use the current buffer." | |
697 | (with-current-buffer (or buffer (current-buffer)) | |
698 | (with-current-buffer rcirc-server-buffer | |
699 | (or rcirc-nick rcirc-default-nick)))) | |
bd43c990 | 700 | |
02f47e86 | 701 | (defvar rcirc-max-message-length 420 |
bd43c990 RS |
702 | "Messages longer than this value will be split.") |
703 | ||
195eca78 | 704 | (defun rcirc-send-message (process target message &optional noticep silent) |
bd43c990 | 705 | "Send TARGET associated with PROCESS a privmsg with text MESSAGE. |
195eca78 SM |
706 | If NOTICEP is non-nil, send a notice instead of privmsg. |
707 | If SILENT is non-nil, do not print the message in any irc buffer." | |
bd43c990 RS |
708 | ;; max message length is 512 including CRLF |
709 | (let* ((response (if noticep "NOTICE" "PRIVMSG")) | |
710 | (oversize (> (length message) rcirc-max-message-length)) | |
711 | (text (if oversize | |
712 | (substring message 0 rcirc-max-message-length) | |
713 | message)) | |
714 | (text (if (string= text "") | |
715 | " " | |
716 | text)) | |
717 | (more (if oversize | |
718 | (substring message rcirc-max-message-length)))) | |
db58efbf | 719 | (rcirc-get-buffer-create process target) |
bd43c990 | 720 | (rcirc-send-string process (concat response " " target " :" text)) |
195eca78 SM |
721 | (unless silent |
722 | (rcirc-print process (rcirc-nick process) response target text)) | |
db58efbf | 723 | (when more (rcirc-send-message process target more noticep)))) |
bd43c990 RS |
724 | |
725 | (defvar rcirc-input-ring nil) | |
726 | (defvar rcirc-input-ring-index 0) | |
727 | (defun rcirc-prev-input-string (arg) | |
728 | (ring-ref rcirc-input-ring (+ rcirc-input-ring-index arg))) | |
729 | ||
730 | (defun rcirc-insert-prev-input (arg) | |
731 | (interactive "p") | |
732 | (when (<= rcirc-prompt-end-marker (point)) | |
733 | (delete-region rcirc-prompt-end-marker (point-max)) | |
734 | (insert (rcirc-prev-input-string 0)) | |
735 | (setq rcirc-input-ring-index (1+ rcirc-input-ring-index)))) | |
736 | ||
737 | (defun rcirc-insert-next-input (arg) | |
738 | (interactive "p") | |
739 | (when (<= rcirc-prompt-end-marker (point)) | |
740 | (delete-region rcirc-prompt-end-marker (point-max)) | |
741 | (setq rcirc-input-ring-index (1- rcirc-input-ring-index)) | |
742 | (insert (rcirc-prev-input-string -1)))) | |
743 | ||
744 | (defvar rcirc-nick-completions nil) | |
745 | (defvar rcirc-nick-completion-start-offset nil) | |
7faa3f8c | 746 | |
bd43c990 RS |
747 | (defun rcirc-complete-nick () |
748 | "Cycle through nick completions from list of nicks in channel." | |
749 | (interactive) | |
7faa3f8c | 750 | (if (eq last-command this-command) |
bd43c990 RS |
751 | (setq rcirc-nick-completions |
752 | (append (cdr rcirc-nick-completions) | |
753 | (list (car rcirc-nick-completions)))) | |
754 | (setq rcirc-nick-completion-start-offset | |
755 | (- (save-excursion | |
756 | (if (re-search-backward " " rcirc-prompt-end-marker t) | |
757 | (1+ (point)) | |
758 | rcirc-prompt-end-marker)) | |
759 | rcirc-prompt-end-marker)) | |
760 | (setq rcirc-nick-completions | |
761 | (let ((completion-ignore-case t)) | |
adf794e4 EZ |
762 | (all-completions |
763 | (buffer-substring | |
bd43c990 RS |
764 | (+ rcirc-prompt-end-marker |
765 | rcirc-nick-completion-start-offset) | |
766 | (point)) | |
767 | (mapcar (lambda (x) (cons x nil)) | |
a2524d26 EZ |
768 | (rcirc-channel-nicks (rcirc-buffer-process) |
769 | rcirc-target)))))) | |
bd43c990 RS |
770 | (let ((completion (car rcirc-nick-completions))) |
771 | (when completion | |
adf794e4 | 772 | (delete-region (+ rcirc-prompt-end-marker |
7faa3f8c MB |
773 | rcirc-nick-completion-start-offset) |
774 | (point)) | |
bd43c990 | 775 | (insert (concat completion |
adf794e4 | 776 | (if (= (+ rcirc-prompt-end-marker |
bd43c990 RS |
777 | rcirc-nick-completion-start-offset) |
778 | rcirc-prompt-end-marker) | |
779 | ": ")))))) | |
780 | ||
a2524d26 EZ |
781 | (defun set-rcirc-decode-coding-system (coding-system) |
782 | "Set the decode coding system used in this channel." | |
783 | (interactive "zCoding system for incoming messages: ") | |
784 | (setq rcirc-decode-coding-system coding-system)) | |
785 | ||
786 | (defun set-rcirc-encode-coding-system (coding-system) | |
787 | "Set the encode coding system used in this channel." | |
788 | (interactive "zCoding system for outgoing messages: ") | |
789 | (setq rcirc-encode-coding-system coding-system)) | |
bd43c990 RS |
790 | |
791 | (defvar rcirc-mode-map (make-sparse-keymap) | |
792 | "Keymap for rcirc mode.") | |
793 | ||
794 | (define-key rcirc-mode-map (kbd "RET") 'rcirc-send-input) | |
795 | (define-key rcirc-mode-map (kbd "M-p") 'rcirc-insert-prev-input) | |
796 | (define-key rcirc-mode-map (kbd "M-n") 'rcirc-insert-next-input) | |
797 | (define-key rcirc-mode-map (kbd "TAB") 'rcirc-complete-nick) | |
798 | (define-key rcirc-mode-map (kbd "C-c C-b") 'rcirc-browse-url) | |
799 | (define-key rcirc-mode-map (kbd "C-c C-c") 'rcirc-edit-multiline) | |
800 | (define-key rcirc-mode-map (kbd "C-c C-j") 'rcirc-cmd-join) | |
801 | (define-key rcirc-mode-map (kbd "C-c C-k") 'rcirc-cmd-kick) | |
a2524d26 | 802 | (define-key rcirc-mode-map (kbd "C-c C-l") 'rcirc-toggle-low-priority) |
bd43c990 RS |
803 | (define-key rcirc-mode-map (kbd "C-c C-d") 'rcirc-cmd-mode) |
804 | (define-key rcirc-mode-map (kbd "C-c C-m") 'rcirc-cmd-msg) | |
805 | (define-key rcirc-mode-map (kbd "C-c C-r") 'rcirc-cmd-nick) ; rename | |
195eca78 | 806 | (define-key rcirc-mode-map (kbd "C-c C-o") 'rcirc-omit-mode) |
a0a5c583 | 807 | (define-key rcirc-mode-map (kbd "M-o") 'rcirc-omit-mode) |
bd43c990 RS |
808 | (define-key rcirc-mode-map (kbd "C-c C-p") 'rcirc-cmd-part) |
809 | (define-key rcirc-mode-map (kbd "C-c C-q") 'rcirc-cmd-query) | |
810 | (define-key rcirc-mode-map (kbd "C-c C-t") 'rcirc-cmd-topic) | |
811 | (define-key rcirc-mode-map (kbd "C-c C-n") 'rcirc-cmd-names) | |
812 | (define-key rcirc-mode-map (kbd "C-c C-w") 'rcirc-cmd-whois) | |
813 | (define-key rcirc-mode-map (kbd "C-c C-x") 'rcirc-cmd-quit) | |
814 | (define-key rcirc-mode-map (kbd "C-c TAB") ; C-i | |
adf794e4 | 815 | 'rcirc-toggle-ignore-buffer-activity) |
bd43c990 RS |
816 | (define-key rcirc-mode-map (kbd "C-c C-s") 'rcirc-switch-to-server-buffer) |
817 | (define-key rcirc-mode-map (kbd "C-c C-a") 'rcirc-jump-to-first-unread-line) | |
818 | ||
adf794e4 | 819 | (defvar rcirc-browse-url-map (make-sparse-keymap) |
2e398771 | 820 | "Keymap used for browsing URLs in `rcirc-mode'.") |
adf794e4 EZ |
821 | |
822 | (define-key rcirc-browse-url-map (kbd "RET") 'rcirc-browse-url-at-point) | |
823 | (define-key rcirc-browse-url-map (kbd "<mouse-2>") 'rcirc-browse-url-at-mouse) | |
824 | ||
825 | (defvar rcirc-short-buffer-name nil | |
826 | "Generated abbreviation to use to indicate buffer activity.") | |
827 | ||
bd43c990 RS |
828 | (defvar rcirc-mode-hook nil |
829 | "Hook run when setting up rcirc buffer.") | |
830 | ||
a2524d26 EZ |
831 | (defvar rcirc-last-post-time nil) |
832 | ||
195eca78 SM |
833 | (defvar rcirc-log-alist nil |
834 | "Alist of lines to log to disk when `rcirc-log-flag' is non-nil. | |
835 | Each element looks like (FILENAME . TEXT).") | |
836 | ||
a0a5c583 GM |
837 | (defvar rcirc-current-line 0 |
838 | "The current number of responses printed in this channel. | |
839 | This number is independent of the number of lines in the buffer.") | |
840 | ||
bd43c990 | 841 | (defun rcirc-mode (process target) |
2e398771 | 842 | "Major mode for IRC channel buffers. |
bd43c990 RS |
843 | |
844 | \\{rcirc-mode-map}" | |
845 | (kill-all-local-variables) | |
846 | (use-local-map rcirc-mode-map) | |
847 | (setq mode-name "rcirc") | |
848 | (setq major-mode 'rcirc-mode) | |
195eca78 | 849 | (setq mode-line-process nil) |
bd43c990 RS |
850 | |
851 | (make-local-variable 'rcirc-input-ring) | |
852 | (setq rcirc-input-ring (make-ring rcirc-input-ring-size)) | |
a2524d26 EZ |
853 | (make-local-variable 'rcirc-server-buffer) |
854 | (setq rcirc-server-buffer (process-buffer process)) | |
bd43c990 RS |
855 | (make-local-variable 'rcirc-target) |
856 | (setq rcirc-target target) | |
ad8121fe EZ |
857 | (make-local-variable 'rcirc-topic) |
858 | (setq rcirc-topic nil) | |
a2524d26 EZ |
859 | (make-local-variable 'rcirc-last-post-time) |
860 | (setq rcirc-last-post-time (current-time)) | |
195eca78 SM |
861 | (make-local-variable 'fill-paragraph-function) |
862 | (setq fill-paragraph-function 'rcirc-fill-paragraph) | |
a0a5c583 GM |
863 | (make-local-variable 'rcirc-recent-quit-alist) |
864 | (setq rcirc-recent-quit-alist nil) | |
865 | (make-local-variable 'rcirc-current-line) | |
866 | (setq rcirc-current-line 0) | |
adf794e4 EZ |
867 | |
868 | (make-local-variable 'rcirc-short-buffer-name) | |
869 | (setq rcirc-short-buffer-name nil) | |
bd43c990 | 870 | (make-local-variable 'rcirc-urls) |
bd43c990 | 871 | (setq use-hard-newlines t) |
bd43c990 | 872 | |
a0a5c583 GM |
873 | ;; setup for omitting responses |
874 | (setq buffer-invisibility-spec '()) | |
875 | (setq buffer-display-table (make-display-table)) | |
876 | (set-display-table-slot buffer-display-table 4 | |
877 | (let ((glyph (make-glyph-code | |
878 | ?. 'font-lock-keyword-face))) | |
879 | (make-vector 3 glyph))) | |
880 | ||
a2524d26 EZ |
881 | (make-local-variable 'rcirc-decode-coding-system) |
882 | (make-local-variable 'rcirc-encode-coding-system) | |
883 | (dolist (i rcirc-coding-system-alist) | |
884 | (let ((chan (if (consp (car i)) (caar i) (car i))) | |
885 | (serv (if (consp (car i)) (cdar i) ""))) | |
886 | (when (and (string-match chan (or target "")) | |
887 | (string-match serv (rcirc-server-name process))) | |
aac5d1fd EZ |
888 | (setq rcirc-decode-coding-system (if (consp (cdr i)) (cadr i) (cdr i)) |
889 | rcirc-encode-coding-system (if (consp (cdr i)) (cddr i) (cdr i)))))) | |
a2524d26 | 890 | |
bd43c990 RS |
891 | ;; setup the prompt and markers |
892 | (make-local-variable 'rcirc-prompt-start-marker) | |
893 | (setq rcirc-prompt-start-marker (make-marker)) | |
894 | (set-marker rcirc-prompt-start-marker (point-max)) | |
895 | (make-local-variable 'rcirc-prompt-end-marker) | |
896 | (setq rcirc-prompt-end-marker (make-marker)) | |
897 | (set-marker rcirc-prompt-end-marker (point-max)) | |
898 | (rcirc-update-prompt) | |
899 | (goto-char rcirc-prompt-end-marker) | |
900 | (make-local-variable 'overlay-arrow-position) | |
901 | (setq overlay-arrow-position (make-marker)) | |
902 | (set-marker overlay-arrow-position nil) | |
903 | ||
a2524d26 EZ |
904 | ;; if the user changes the major mode or kills the buffer, there is |
905 | ;; cleanup work to do | |
f8db61b2 EZ |
906 | (add-hook 'change-major-mode-hook 'rcirc-change-major-mode-hook nil t) |
907 | (add-hook 'kill-buffer-hook 'rcirc-kill-buffer-hook nil t) | |
a2524d26 | 908 | |
adf794e4 EZ |
909 | ;; add to buffer list, and update buffer abbrevs |
910 | (when target ; skip server buffer | |
911 | (let ((buffer (current-buffer))) | |
912 | (with-rcirc-process-buffer process | |
913 | (setq rcirc-buffer-alist (cons (cons target buffer) | |
914 | rcirc-buffer-alist)))) | |
915 | (rcirc-update-short-buffer-names)) | |
916 | ||
bd43c990 RS |
917 | (run-hooks 'rcirc-mode-hook)) |
918 | ||
adf794e4 EZ |
919 | (defun rcirc-update-prompt (&optional all) |
920 | "Reset the prompt string in the current buffer. | |
c18a54de | 921 | |
adf794e4 EZ |
922 | If ALL is non-nil, update prompts in all IRC buffers." |
923 | (if all | |
924 | (mapc (lambda (process) | |
925 | (mapc (lambda (buffer) | |
926 | (with-current-buffer buffer | |
927 | (rcirc-update-prompt))) | |
928 | (with-rcirc-process-buffer process | |
929 | (mapcar 'cdr rcirc-buffer-alist)))) | |
930 | (rcirc-process-list)) | |
931 | (let ((inhibit-read-only t) | |
932 | (prompt (or rcirc-prompt ""))) | |
933 | (mapc (lambda (rep) | |
934 | (setq prompt | |
a2524d26 EZ |
935 | (replace-regexp-in-string (car rep) (cdr rep) prompt))) |
936 | (list (cons "%n" (rcirc-buffer-nick)) | |
8216fbaf | 937 | (cons "%s" (with-rcirc-server-buffer rcirc-server-name)) |
adf794e4 EZ |
938 | (cons "%t" (or rcirc-target "")))) |
939 | (save-excursion | |
940 | (delete-region rcirc-prompt-start-marker rcirc-prompt-end-marker) | |
941 | (goto-char rcirc-prompt-start-marker) | |
942 | (let ((start (point))) | |
943 | (insert-before-markers prompt) | |
944 | (set-marker rcirc-prompt-start-marker start) | |
945 | (when (not (zerop (- rcirc-prompt-end-marker | |
946 | rcirc-prompt-start-marker))) | |
947 | (add-text-properties rcirc-prompt-start-marker | |
948 | rcirc-prompt-end-marker | |
949 | (list 'face 'rcirc-prompt | |
950 | 'read-only t 'field t | |
951 | 'front-sticky t 'rear-nonsticky t)))))))) | |
952 | ||
953 | (defun rcirc-set-changed (option value) | |
954 | "Set OPTION to VALUE and do updates after a customization change." | |
955 | (set-default option value) | |
956 | (cond ((eq option 'rcirc-prompt) | |
957 | (rcirc-update-prompt 'all)) | |
958 | (t | |
959 | (error "Bad option %s" option)))) | |
bd43c990 RS |
960 | |
961 | (defun rcirc-channel-p (target) | |
962 | "Return t if TARGET is a channel name." | |
963 | (and target | |
964 | (not (zerop (length target))) | |
965 | (or (eq (aref target 0) ?#) | |
966 | (eq (aref target 0) ?&)))) | |
967 | ||
968 | (defun rcirc-kill-buffer-hook () | |
969 | "Part the channel when killing an rcirc buffer." | |
970 | (when (eq major-mode 'rcirc-mode) | |
a2524d26 EZ |
971 | (rcirc-clean-up-buffer "Killed buffer"))) |
972 | ||
973 | (defun rcirc-change-major-mode-hook () | |
974 | "Part the channel when changing the major-mode." | |
975 | (rcirc-clean-up-buffer "Changed major mode")) | |
976 | ||
977 | (defun rcirc-clean-up-buffer (reason) | |
adf794e4 EZ |
978 | (let ((buffer (current-buffer))) |
979 | (rcirc-clear-activity buffer) | |
a2524d26 EZ |
980 | (when (and (rcirc-buffer-process) |
981 | (eq (process-status (rcirc-buffer-process)) 'open)) | |
982 | (with-rcirc-server-buffer | |
983 | (setq rcirc-buffer-alist | |
984 | (rassq-delete-all buffer rcirc-buffer-alist))) | |
adf794e4 | 985 | (rcirc-update-short-buffer-names) |
bd43c990 | 986 | (if (rcirc-channel-p rcirc-target) |
a2524d26 EZ |
987 | (rcirc-send-string (rcirc-buffer-process) |
988 | (concat "PART " rcirc-target " :" reason)) | |
adf794e4 | 989 | (when rcirc-target |
a2524d26 EZ |
990 | (rcirc-remove-nick-channel (rcirc-buffer-process) |
991 | (rcirc-buffer-nick) | |
195eca78 SM |
992 | rcirc-target)))) |
993 | (setq rcirc-target nil))) | |
adf794e4 | 994 | |
adf794e4 EZ |
995 | (defun rcirc-generate-new-buffer-name (process target) |
996 | "Return a buffer name based on PROCESS and TARGET. | |
2e398771 | 997 | This is used for the initial name given to IRC buffers." |
195eca78 SM |
998 | (substring-no-properties |
999 | (if target | |
1000 | (concat target "@" (process-name process)) | |
1001 | (concat "*" (process-name process) "*")))) | |
bd43c990 | 1002 | |
adf794e4 | 1003 | (defun rcirc-get-buffer (process target &optional server) |
bd43c990 | 1004 | "Return the buffer associated with the PROCESS and TARGET. |
adf794e4 | 1005 | |
adf794e4 EZ |
1006 | If optional argument SERVER is non-nil, return the server buffer |
1007 | if there is no existing buffer for TARGET, otherwise return nil." | |
1008 | (with-rcirc-process-buffer process | |
1009 | (if (null target) | |
1010 | (current-buffer) | |
1011 | (let ((buffer (cdr (assoc-string target rcirc-buffer-alist t)))) | |
1012 | (or buffer (when server (current-buffer))))))) | |
bd43c990 RS |
1013 | |
1014 | (defun rcirc-get-buffer-create (process target) | |
adf794e4 EZ |
1015 | "Return the buffer associated with the PROCESS and TARGET. |
1016 | Create the buffer if it doesn't exist." | |
1017 | (let ((buffer (rcirc-get-buffer process target))) | |
a2524d26 | 1018 | (if (and buffer (buffer-live-p buffer)) |
2fbed782 | 1019 | (with-current-buffer buffer |
db58efbf | 1020 | (when (not rcirc-target) |
2fbed782 | 1021 | (setq rcirc-target target)) |
db58efbf | 1022 | buffer) |
195eca78 SM |
1023 | ;; create the buffer |
1024 | (with-rcirc-process-buffer process | |
1025 | (let ((new-buffer (get-buffer-create | |
1026 | (rcirc-generate-new-buffer-name process target)))) | |
1027 | (with-current-buffer new-buffer | |
a0a5c583 GM |
1028 | (rcirc-mode process target) |
1029 | (rcirc-put-nick-channel process (rcirc-nick process) target | |
1030 | rcirc-current-line)) | |
195eca78 | 1031 | new-buffer))))) |
bd43c990 RS |
1032 | |
1033 | (defun rcirc-send-input () | |
1034 | "Send input to target associated with the current buffer." | |
1035 | (interactive) | |
53f831f3 AS |
1036 | (if (< (point) rcirc-prompt-end-marker) |
1037 | ;; copy the line down to the input area | |
1038 | (progn | |
1039 | (forward-line 0) | |
1040 | (let ((start (if (eq (point) (point-min)) | |
1041 | (point) | |
1042 | (if (get-text-property (1- (point)) 'hard) | |
1043 | (point) | |
1044 | (previous-single-property-change (point) 'hard)))) | |
1045 | (end (next-single-property-change (1+ (point)) 'hard))) | |
1046 | (goto-char (point-max)) | |
1047 | (insert (replace-regexp-in-string | |
1048 | "\n\\s-+" " " | |
1049 | (buffer-substring-no-properties start end))))) | |
1050 | ;; process input | |
1051 | (goto-char (point-max)) | |
a2524d26 EZ |
1052 | (when (not (equal 0 (- (point) rcirc-prompt-end-marker))) |
1053 | ;; delete a trailing newline | |
1054 | (when (eq (point) (point-at-bol)) | |
1055 | (delete-backward-char 1)) | |
1056 | (let ((input (buffer-substring-no-properties | |
1057 | rcirc-prompt-end-marker (point)))) | |
1058 | (dolist (line (split-string input "\n")) | |
1059 | (rcirc-process-input-line line)) | |
1060 | ;; add to input-ring | |
1061 | (save-excursion | |
1062 | (ring-insert rcirc-input-ring input) | |
1063 | (setq rcirc-input-ring-index 0)))))) | |
1064 | ||
195eca78 SM |
1065 | (defun rcirc-fill-paragraph (&optional arg) |
1066 | (interactive "p") | |
1067 | (when (> (point) rcirc-prompt-end-marker) | |
1068 | (save-restriction | |
1069 | (narrow-to-region rcirc-prompt-end-marker (point-max)) | |
1070 | (let ((fill-column rcirc-max-message-length)) | |
1071 | (fill-region (point-min) (point-max)))))) | |
1072 | ||
a2524d26 | 1073 | (defun rcirc-process-input-line (line) |
db58efbf EZ |
1074 | (if (string-match "^/\\([^ ]+\\) ?\\(.*\\)$" line) |
1075 | (rcirc-process-command (match-string 1 line) | |
1076 | (match-string 2 line) | |
1077 | line) | |
1078 | (rcirc-process-message line))) | |
1079 | ||
1080 | (defun rcirc-process-message (line) | |
1081 | (if (not rcirc-target) | |
a2524d26 | 1082 | (message "Not joined (no target)") |
db58efbf | 1083 | (delete-region rcirc-prompt-end-marker (point)) |
a2524d26 EZ |
1084 | (rcirc-send-message (rcirc-buffer-process) rcirc-target line) |
1085 | (setq rcirc-last-post-time (current-time)))) | |
db58efbf EZ |
1086 | |
1087 | (defun rcirc-process-command (command args line) | |
1088 | (if (eq (aref command 0) ?/) | |
1089 | ;; "//text" will send "/text" as a message | |
1090 | (rcirc-process-message (substring line 1)) | |
a2524d26 EZ |
1091 | (let ((fun (intern-soft (concat "rcirc-cmd-" command))) |
1092 | (process (rcirc-buffer-process))) | |
db58efbf EZ |
1093 | (newline) |
1094 | (with-current-buffer (current-buffer) | |
1095 | (delete-region rcirc-prompt-end-marker (point)) | |
1096 | (if (string= command "me") | |
a2524d26 | 1097 | (rcirc-print process (rcirc-buffer-nick) |
db58efbf | 1098 | "ACTION" rcirc-target args) |
a2524d26 | 1099 | (rcirc-print process (rcirc-buffer-nick) |
db58efbf EZ |
1100 | "COMMAND" rcirc-target line)) |
1101 | (set-marker rcirc-prompt-end-marker (point)) | |
1102 | (if (fboundp fun) | |
a2524d26 EZ |
1103 | (funcall fun args process rcirc-target) |
1104 | (rcirc-send-string process | |
f8db61b2 | 1105 | (concat command " :" args))))))) |
db58efbf | 1106 | |
bd43c990 RS |
1107 | (defvar rcirc-parent-buffer nil) |
1108 | (defvar rcirc-window-configuration nil) | |
1109 | (defun rcirc-edit-multiline () | |
1110 | "Move current edit to a dedicated buffer." | |
1111 | (interactive) | |
1112 | (let ((pos (1+ (- (point) rcirc-prompt-end-marker)))) | |
1113 | (goto-char (point-max)) | |
a0a5c583 GM |
1114 | (let ((text (buffer-substring-no-properties rcirc-prompt-end-marker |
1115 | (point))) | |
a2524d26 | 1116 | (parent (buffer-name))) |
bd43c990 RS |
1117 | (delete-region rcirc-prompt-end-marker (point)) |
1118 | (setq rcirc-window-configuration (current-window-configuration)) | |
1119 | (pop-to-buffer (concat "*multiline " parent "*")) | |
a2524d26 EZ |
1120 | (funcall rcirc-multiline-major-mode) |
1121 | (rcirc-multiline-minor-mode 1) | |
bd43c990 | 1122 | (setq rcirc-parent-buffer parent) |
bd43c990 | 1123 | (insert text) |
db58efbf EZ |
1124 | (and (> pos 0) (goto-char pos)) |
1125 | (message "Type C-c C-c to return text to %s, or C-c C-k to cancel" parent)))) | |
bd43c990 | 1126 | |
a2524d26 EZ |
1127 | (defvar rcirc-multiline-minor-mode-map (make-sparse-keymap) |
1128 | "Keymap for multiline mode in rcirc.") | |
92c4adc1 | 1129 | (define-key rcirc-multiline-minor-mode-map |
a2524d26 EZ |
1130 | (kbd "C-c C-c") 'rcirc-multiline-minor-submit) |
1131 | (define-key rcirc-multiline-minor-mode-map | |
1132 | (kbd "C-x C-s") 'rcirc-multiline-minor-submit) | |
1133 | (define-key rcirc-multiline-minor-mode-map | |
1134 | (kbd "C-c C-k") 'rcirc-multiline-minor-cancel) | |
1135 | (define-key rcirc-multiline-minor-mode-map | |
1136 | (kbd "ESC ESC ESC") 'rcirc-multiline-minor-cancel) | |
1137 | ||
1138 | (define-minor-mode rcirc-multiline-minor-mode | |
1139 | "Minor mode for editing multiple lines in rcirc." | |
1140 | :init-value nil | |
1141 | :lighter " rcirc-mline" | |
1142 | :keymap rcirc-multiline-minor-mode-map | |
1143 | :global nil | |
1144 | :group 'rcirc | |
bd43c990 | 1145 | (make-local-variable 'rcirc-parent-buffer) |
02f47e86 MB |
1146 | (put 'rcirc-parent-buffer 'permanent-local t) |
1147 | (setq fill-column rcirc-max-message-length)) | |
a2524d26 EZ |
1148 | |
1149 | (defun rcirc-multiline-minor-submit () | |
bd43c990 RS |
1150 | "Send the text in buffer back to parent buffer." |
1151 | (interactive) | |
adf794e4 | 1152 | (untabify (point-min) (point-max)) |
bd43c990 RS |
1153 | (let ((text (buffer-substring (point-min) (point-max))) |
1154 | (buffer (current-buffer)) | |
1155 | (pos (point))) | |
1156 | (set-buffer rcirc-parent-buffer) | |
1157 | (goto-char (point-max)) | |
1158 | (insert text) | |
bd43c990 | 1159 | (kill-buffer buffer) |
adf794e4 EZ |
1160 | (set-window-configuration rcirc-window-configuration) |
1161 | (goto-char (+ rcirc-prompt-end-marker (1- pos))))) | |
bd43c990 | 1162 | |
a2524d26 | 1163 | (defun rcirc-multiline-minor-cancel () |
bd43c990 RS |
1164 | "Cancel the multiline edit." |
1165 | (interactive) | |
bd43c990 RS |
1166 | (kill-buffer (current-buffer)) |
1167 | (set-window-configuration rcirc-window-configuration)) | |
1168 | ||
2fbed782 | 1169 | (defun rcirc-any-buffer (process) |
adf794e4 | 1170 | "Return a buffer for PROCESS, either the one selected or the process buffer." |
2fbed782 EZ |
1171 | (if rcirc-always-use-server-buffer-flag |
1172 | (process-buffer process) | |
1173 | (let ((buffer (window-buffer (selected-window)))) | |
1174 | (if (and buffer | |
1175 | (with-current-buffer buffer | |
1176 | (and (eq major-mode 'rcirc-mode) | |
a2524d26 | 1177 | (eq (rcirc-buffer-process) process)))) |
2fbed782 EZ |
1178 | buffer |
1179 | (process-buffer process))))) | |
bd43c990 | 1180 | |
324e4da7 | 1181 | (defcustom rcirc-response-formats |
195eca78 SM |
1182 | '(("PRIVMSG" . "<%N> %m") |
1183 | ("NOTICE" . "-%N- %m") | |
1184 | ("ACTION" . "[%N %m]") | |
1185 | ("COMMAND" . "%m") | |
1186 | ("ERROR" . "%fw!!! %m") | |
1187 | (t . "%fp*** %fs%n %r %m")) | |
324e4da7 MB |
1188 | "An alist of formats used for printing responses. |
1189 | The format is looked up using the response-type as a key; | |
1190 | if no match is found, the default entry (with a key of `t') is used. | |
1191 | ||
1192 | The entry's value part should be a string, which is inserted with | |
1193 | the of the following escape sequences replaced by the described values: | |
1194 | ||
1195 | %m The message text | |
2fbed782 EZ |
1196 | %n The sender's nick |
1197 | %N The sender's nick (with face `rcirc-my-nick' or `rcirc-other-nick') | |
324e4da7 | 1198 | %r The response-type |
324e4da7 MB |
1199 | %t The target |
1200 | %fw Following text uses the face `font-lock-warning-face' | |
1201 | %fp Following text uses the face `rcirc-server-prefix' | |
1202 | %fs Following text uses the face `rcirc-server' | |
1203 | %f[FACE] Following text uses the face FACE | |
3715419e | 1204 | %f- Following text uses the default face |
a2524d26 | 1205 | %% A literal `%' character" |
324e4da7 MB |
1206 | :type '(alist :key-type (choice (string :tag "Type") |
1207 | (const :tag "Default" t)) | |
1208 | :value-type string) | |
1209 | :group 'rcirc) | |
1210 | ||
0ffab1eb | 1211 | (defcustom rcirc-omit-responses |
a0a5c583 | 1212 | '("JOIN" "PART" "QUIT" "NICK") |
195eca78 SM |
1213 | "Responses which will be hidden when `rcirc-omit-mode' is enabled." |
1214 | :type '(repeat string) | |
1215 | :group 'rcirc) | |
1216 | ||
bd43c990 | 1217 | (defun rcirc-format-response-string (process sender response target text) |
324e4da7 MB |
1218 | "Return a nicely-formatted response string, incorporating TEXT |
1219 | \(and perhaps other arguments). The specific formatting used | |
1220 | is found by looking up RESPONSE in `rcirc-response-formats'." | |
195eca78 SM |
1221 | (with-temp-buffer |
1222 | (insert (or (cdr (assoc response rcirc-response-formats)) | |
1223 | (cdr (assq t rcirc-response-formats)))) | |
1224 | (goto-char (point-min)) | |
1225 | (let ((start (point-min)) | |
1226 | (sender (if (or (not sender) | |
1227 | (string= (rcirc-server-name process) sender)) | |
1228 | "" | |
1229 | sender)) | |
1230 | face) | |
1231 | (while (re-search-forward "%\\(\\(f\\(.\\)\\)\\|\\(.\\)\\)" nil t) | |
1232 | (rcirc-add-face start (match-beginning 0) face) | |
1233 | (setq start (match-beginning 0)) | |
1234 | (replace-match | |
1235 | (case (aref (match-string 1) 0) | |
1236 | (?f (setq face | |
1237 | (case (string-to-char (match-string 3)) | |
1238 | (?w 'font-lock-warning-face) | |
1239 | (?p 'rcirc-server-prefix) | |
1240 | (?s 'rcirc-server) | |
1241 | (t nil))) | |
1242 | "") | |
1243 | (?n sender) | |
1244 | (?N (let ((my-nick (rcirc-nick process))) | |
1245 | (save-match-data | |
1246 | (with-syntax-table rcirc-nick-syntax-table | |
1247 | (rcirc-facify sender | |
1248 | (cond ((string= sender my-nick) | |
1249 | 'rcirc-my-nick) | |
1250 | ((and rcirc-bright-nicks | |
0ffab1eb | 1251 | (string-match |
195eca78 SM |
1252 | (regexp-opt rcirc-bright-nicks |
1253 | 'words) | |
1254 | sender)) | |
1255 | 'rcirc-bright-nick) | |
1256 | ((and rcirc-dim-nicks | |
1257 | (string-match | |
1258 | (regexp-opt rcirc-dim-nicks | |
1259 | 'words) | |
1260 | sender)) | |
1261 | 'rcirc-dim-nick) | |
1262 | (t | |
1263 | 'rcirc-other-nick))))))) | |
1264 | (?m (propertize text 'rcirc-text text)) | |
1265 | (?r response) | |
1266 | (?t (or target "")) | |
1267 | (t (concat "UNKNOWN CODE:" (match-string 0)))) | |
1268 | t t nil 0) | |
1269 | (rcirc-add-face (match-beginning 0) (match-end 0) face)) | |
1270 | (rcirc-add-face start (match-beginning 0) face)) | |
1271 | (buffer-substring (point-min) (point-max)))) | |
bd43c990 | 1272 | |
db58efbf EZ |
1273 | (defun rcirc-target-buffer (process sender response target text) |
1274 | "Return a buffer to print the server response." | |
1275 | (assert (not (bufferp target))) | |
1276 | (with-rcirc-process-buffer process | |
1277 | (cond ((not target) | |
2fbed782 | 1278 | (rcirc-any-buffer process)) |
db58efbf EZ |
1279 | ((not (rcirc-channel-p target)) |
1280 | ;; message from another user | |
195eca78 SM |
1281 | (if (or (string= response "PRIVMSG") |
1282 | (string= response "ACTION")) | |
db58efbf EZ |
1283 | (rcirc-get-buffer-create process (if (string= sender rcirc-nick) |
1284 | target | |
1285 | sender)) | |
1286 | (rcirc-get-buffer process target t))) | |
1287 | ((or (rcirc-get-buffer process target) | |
2fbed782 | 1288 | (rcirc-any-buffer process)))))) |
db58efbf | 1289 | |
f8db61b2 EZ |
1290 | (defvar rcirc-activity-types nil) |
1291 | (make-variable-buffer-local 'rcirc-activity-types) | |
a2524d26 EZ |
1292 | (defvar rcirc-last-sender nil) |
1293 | (make-variable-buffer-local 'rcirc-last-sender) | |
7faa3f8c | 1294 | |
195eca78 SM |
1295 | (defcustom rcirc-log-directory "~/.emacs.d/rcirc-log" |
1296 | "Directory to keep IRC logfiles." | |
1297 | :type 'directory | |
1298 | :group 'rcirc) | |
1299 | ||
1300 | (defcustom rcirc-log-flag nil | |
1301 | "Non-nil means log IRC activity to disk. | |
1302 | Logfiles are kept in `rcirc-log-directory'." | |
1303 | :type 'boolean | |
1304 | :group 'rcirc) | |
1305 | ||
a0a5c583 GM |
1306 | (defcustom rcirc-omit-threshold 100 |
1307 | "Number of lines since last activity from a nick before `rcirc-omit-responses' are omitted." | |
1308 | :type 'integer | |
1309 | :group 'rcirc) | |
1310 | ||
1311 | (defun rcirc-last-quit-line (nick target) | |
1312 | "Return the line number where NICK left TARGET. | |
1313 | Returns nil if the information is not recorded." | |
1314 | (let ((chanbuf (rcirc-get-buffer (rcirc-buffer-process) target))) | |
1315 | (when chanbuf | |
1316 | (cdr (assoc-string nick (with-current-buffer chanbuf | |
1317 | rcirc-recent-quit-alist)))))) | |
1318 | ||
1319 | (defun rcirc-last-line (nick target) | |
1320 | "Return the line from the last activity from NICK in TARGET." | |
1321 | (let* ((chanbuf (rcirc-get-buffer (rcirc-buffer-process) target)) | |
1322 | (line (or (cdr (assoc-string target | |
1323 | (gethash nick (with-rcirc-server-buffer | |
1324 | rcirc-nick-table)) t)) | |
1325 | (rcirc-last-quit-line nick target)))) | |
1326 | (if line | |
1327 | line | |
1328 | ;;(message "line is nil for %s in %s" nick target) | |
1329 | nil))) | |
1330 | ||
1331 | (defun rcirc-elapsed-lines (nick target) | |
1332 | "Return the number of lines since activity from NICK in TARGET." | |
1333 | (let ((last-activity-line (rcirc-last-line nick target))) | |
1334 | (when (and last-activity-line | |
1335 | (> last-activity-line 0)) | |
1336 | (- rcirc-current-line last-activity-line)))) | |
1337 | ||
729f1525 DN |
1338 | (defvar rcirc-markup-text-functions |
1339 | '(rcirc-markup-attributes | |
1340 | rcirc-markup-my-nick | |
1341 | rcirc-markup-urls | |
1342 | rcirc-markup-keywords | |
1343 | rcirc-markup-bright-nicks | |
1344 | rcirc-markup-fill) | |
1345 | ||
1346 | "List of functions used to manipulate text before it is printed. | |
1347 | ||
1348 | Each function takes two arguments, SENDER, RESPONSE. The buffer | |
1349 | is narrowed with the text to be printed and the point is at the | |
1350 | beginning of the `rcirc-text' propertized text.") | |
1351 | ||
bd43c990 RS |
1352 | (defun rcirc-print (process sender response target text &optional activity) |
1353 | "Print TEXT in the buffer associated with TARGET. | |
1354 | Format based on SENDER and RESPONSE. If ACTIVITY is non-nil, | |
1355 | record activity." | |
a2524d26 | 1356 | (or text (setq text "")) |
0ffab1eb TTN |
1357 | (unless (and (or (member sender rcirc-ignore-list) |
1358 | (member (with-syntax-table rcirc-nick-syntax-table | |
1359 | (when (string-match "^\\([^/]\\w*\\)[:,]" text) | |
1360 | (match-string 1 text))) | |
1361 | rcirc-ignore-list)) | |
a0a5c583 GM |
1362 | ;; do not ignore if we sent the message |
1363 | (not (string= sender (rcirc-nick process)))) | |
db58efbf | 1364 | (let* ((buffer (rcirc-target-buffer process sender response target text)) |
2c8abe90 AS |
1365 | (inhibit-read-only t)) |
1366 | (with-current-buffer buffer | |
1367 | (let ((moving (= (point) rcirc-prompt-end-marker)) | |
1368 | (old-point (point-marker)) | |
1369 | (fill-start (marker-position rcirc-prompt-start-marker))) | |
1370 | ||
1371 | (unless (string= sender (rcirc-nick process)) | |
1372 | ;; only decode text from other senders, not ours | |
a2524d26 | 1373 | (setq text (decode-coding-string text rcirc-decode-coding-system)) |
2c8abe90 AS |
1374 | ;; mark the line with overlay arrow |
1375 | (unless (or (marker-position overlay-arrow-position) | |
195eca78 SM |
1376 | (get-buffer-window (current-buffer)) |
1377 | (member response rcirc-omit-responses)) | |
2c8abe90 AS |
1378 | (set-marker overlay-arrow-position |
1379 | (marker-position rcirc-prompt-start-marker)))) | |
1380 | ||
1381 | ;; temporarily set the marker insertion-type because | |
1382 | ;; insert-before-markers results in hidden text in new buffers | |
1383 | (goto-char rcirc-prompt-start-marker) | |
1384 | (set-marker-insertion-type rcirc-prompt-start-marker t) | |
1385 | (set-marker-insertion-type rcirc-prompt-end-marker t) | |
324e4da7 | 1386 | |
195eca78 | 1387 | (let ((start (point))) |
0ffab1eb | 1388 | (insert (rcirc-format-response-string process sender response nil |
195eca78 SM |
1389 | text) |
1390 | (propertize "\n" 'hard t)) | |
1391 | ||
1392 | ;; squeeze spaces out of text before rcirc-text | |
0ffab1eb | 1393 | (fill-region fill-start |
195eca78 SM |
1394 | (1- (or (next-single-property-change fill-start |
1395 | 'rcirc-text) | |
1396 | rcirc-prompt-end-marker))) | |
1397 | ||
a0a5c583 GM |
1398 | ;; increment the line count |
1399 | (setq rcirc-current-line (1+ rcirc-current-line)) | |
1400 | ||
195eca78 SM |
1401 | ;; run markup functions |
1402 | (save-excursion | |
1403 | (save-restriction | |
1404 | (narrow-to-region start rcirc-prompt-start-marker) | |
1405 | (goto-char (or (next-single-property-change start 'rcirc-text) | |
1406 | (point))) | |
1407 | (when (rcirc-buffer-process) | |
1408 | (save-excursion (rcirc-markup-timestamp sender response)) | |
1409 | (dolist (fn rcirc-markup-text-functions) | |
1410 | (save-excursion (funcall fn sender response))) | |
a0a5c583 GM |
1411 | (when rcirc-fill-flag |
1412 | (save-excursion (rcirc-markup-fill sender response)))) | |
195eca78 SM |
1413 | |
1414 | (when rcirc-read-only-flag | |
1415 | (add-text-properties (point-min) (point-max) | |
1416 | '(read-only t front-sticky t)))) | |
1417 | ;; make text omittable | |
a0a5c583 GM |
1418 | (let ((last-activity-lines (rcirc-elapsed-lines sender target))) |
1419 | (when (and (not (string= (rcirc-nick process) sender)) | |
1420 | (member response rcirc-omit-responses) | |
1421 | (or (not last-activity-lines) | |
1422 | (< rcirc-omit-threshold last-activity-lines))) | |
1423 | (put-text-property (1- start) (1- rcirc-prompt-start-marker) | |
1424 | 'invisible 'rcirc-omit))))) | |
195eca78 SM |
1425 | |
1426 | (set-marker-insertion-type rcirc-prompt-start-marker nil) | |
1427 | (set-marker-insertion-type rcirc-prompt-end-marker nil) | |
2c8abe90 AS |
1428 | |
1429 | ;; truncate buffer if it is very long | |
1430 | (save-excursion | |
1431 | (when (and rcirc-buffer-maximum-lines | |
1432 | (> rcirc-buffer-maximum-lines 0) | |
1433 | (= (forward-line (- rcirc-buffer-maximum-lines)) 0)) | |
1434 | (delete-region (point-min) (point)))) | |
1435 | ||
1436 | ;; set the window point for buffers show in windows | |
1437 | (walk-windows (lambda (w) | |
d40ac716 CY |
1438 | (when (and (not (eq (selected-window) w)) |
1439 | (eq (current-buffer) | |
1440 | (window-buffer w)) | |
1441 | (>= (window-point w) | |
1442 | rcirc-prompt-end-marker)) | |
195eca78 | 1443 | (set-window-point w (point-max)))) |
2c8abe90 AS |
1444 | nil t) |
1445 | ||
1446 | ;; restore the point | |
1447 | (goto-char (if moving rcirc-prompt-end-marker old-point)) | |
1448 | ||
195eca78 | 1449 | ;; keep window on bottom line if it was already there |
d40ac716 CY |
1450 | (when rcirc-scroll-show-maximum-output |
1451 | (walk-windows (lambda (w) | |
1452 | (when (eq (window-buffer w) (current-buffer)) | |
1453 | (with-current-buffer (window-buffer w) | |
1454 | (when (eq major-mode 'rcirc-mode) | |
1455 | (with-selected-window w | |
195eca78 SM |
1456 | (when (<= (- (window-height) |
1457 | (count-screen-lines (window-point) | |
1458 | (window-start)) | |
d40ac716 CY |
1459 | 1) |
1460 | 0) | |
1461 | (recenter -1))))))) | |
195eca78 | 1462 | nil t)) |
d40ac716 | 1463 | |
2c8abe90 AS |
1464 | ;; flush undo (can we do something smarter here?) |
1465 | (buffer-disable-undo) | |
1466 | (buffer-enable-undo)) | |
1467 | ||
1468 | ;; record modeline activity | |
f8db61b2 EZ |
1469 | (when (and activity |
1470 | (not rcirc-ignore-buffer-activity-flag) | |
1471 | (not (and rcirc-dim-nicks sender | |
195eca78 SM |
1472 | (string-match (regexp-opt rcirc-dim-nicks) sender) |
1473 | (rcirc-channel-p target)))) | |
f8db61b2 EZ |
1474 | (rcirc-record-activity (current-buffer) |
1475 | (when (not (rcirc-channel-p rcirc-target)) | |
1476 | 'nick))) | |
2c8abe90 | 1477 | |
195eca78 SM |
1478 | (when rcirc-log-flag |
1479 | (rcirc-log process sender response target text)) | |
1480 | ||
2c8abe90 AS |
1481 | (sit-for 0) ; displayed text before hook |
1482 | (run-hook-with-args 'rcirc-print-hooks | |
1483 | process sender response target text))))) | |
bd43c990 | 1484 | |
195eca78 SM |
1485 | (defun rcirc-log (process sender response target text) |
1486 | "Record line in `rcirc-log', to be later written to disk." | |
1487 | (let* ((filename (rcirc-generate-new-buffer-name process target)) | |
1488 | (cell (assoc-string filename rcirc-log-alist)) | |
1489 | (line (concat (format-time-string rcirc-time-format) | |
1490 | (substring-no-properties | |
1491 | (rcirc-format-response-string process sender | |
1492 | response target text)) | |
1493 | "\n"))) | |
1494 | (if cell | |
1495 | (setcdr cell (concat (cdr cell) line)) | |
1496 | (setq rcirc-log-alist | |
1497 | (cons (cons filename line) rcirc-log-alist))))) | |
1498 | ||
1499 | (defun rcirc-log-write () | |
1500 | "Flush `rcirc-log-alist' data to disk. | |
1501 | ||
1502 | Log data is written to `rcirc-log-directory'." | |
1503 | (make-directory rcirc-log-directory t) | |
1504 | (dolist (cell rcirc-log-alist) | |
1505 | (with-temp-buffer | |
1506 | (insert (cdr cell)) | |
1507 | (write-region (point-min) (point-max) | |
1508 | (concat rcirc-log-directory "/" (car cell)) | |
1509 | t 'quiet))) | |
1510 | (setq rcirc-log-alist nil)) | |
bd43c990 RS |
1511 | |
1512 | (defun rcirc-join-channels (process channels) | |
1513 | "Join CHANNELS." | |
1514 | (save-window-excursion | |
db58efbf EZ |
1515 | (dolist (channel channels) |
1516 | (with-rcirc-process-buffer process | |
1517 | (rcirc-cmd-join channel process))))) | |
bd43c990 RS |
1518 | \f |
1519 | ;;; nick management | |
8216fbaf | 1520 | (defvar rcirc-nick-prefix-chars "~&@%+") |
bd43c990 RS |
1521 | (defun rcirc-user-nick (user) |
1522 | "Return the nick from USER. Remove any non-nick junk." | |
db58efbf | 1523 | (save-match-data |
8216fbaf EZ |
1524 | (if (string-match (concat "^[" rcirc-nick-prefix-chars |
1525 | "]?\\([^! ]+\\)!?") (or user "")) | |
db58efbf EZ |
1526 | (match-string 1 user) |
1527 | user))) | |
bd43c990 | 1528 | |
bd43c990 RS |
1529 | (defun rcirc-nick-channels (process nick) |
1530 | "Return list of channels for NICK." | |
db58efbf EZ |
1531 | (with-rcirc-process-buffer process |
1532 | (mapcar (lambda (x) (car x)) | |
1533 | (gethash nick rcirc-nick-table)))) | |
bd43c990 | 1534 | |
a0a5c583 GM |
1535 | (defun rcirc-put-nick-channel (process nick channel &optional line) |
1536 | "Add CHANNEL to list associated with NICK. | |
1537 | Update the associated linestamp if LINE is non-nil. | |
1538 | ||
1539 | If the record doesn't exist, and LINE is nil, set the linestamp | |
1540 | to zero." | |
1541 | ;;(message "rcirc-put-nick-channel: %S %S %S" nick channel line) | |
2fbed782 EZ |
1542 | (let ((nick (rcirc-user-nick nick))) |
1543 | (with-rcirc-process-buffer process | |
1544 | (let* ((chans (gethash nick rcirc-nick-table)) | |
1545 | (record (assoc-string channel chans t))) | |
1546 | (if record | |
a0a5c583 GM |
1547 | (when line (setcdr record line)) |
1548 | (puthash nick (cons (cons channel (or line 0)) | |
2fbed782 EZ |
1549 | chans) |
1550 | rcirc-nick-table)))))) | |
bd43c990 RS |
1551 | |
1552 | (defun rcirc-nick-remove (process nick) | |
1553 | "Remove NICK from table." | |
adf794e4 | 1554 | (with-rcirc-process-buffer process |
bd43c990 RS |
1555 | (remhash nick rcirc-nick-table))) |
1556 | ||
1557 | (defun rcirc-remove-nick-channel (process nick channel) | |
1558 | "Remove the CHANNEL from list associated with NICK." | |
adf794e4 | 1559 | (with-rcirc-process-buffer process |
db58efbf | 1560 | (let* ((chans (gethash nick rcirc-nick-table)) |
adf794e4 EZ |
1561 | (newchans |
1562 | ;; instead of assoc-string-delete-all: | |
1563 | (let ((record (assoc-string channel chans t))) | |
1564 | (when record | |
1565 | (setcar record 'delete) | |
1566 | (assq-delete-all 'delete chans))))) | |
bd43c990 RS |
1567 | (if newchans |
1568 | (puthash nick newchans rcirc-nick-table) | |
1569 | (remhash nick rcirc-nick-table))))) | |
1570 | ||
a2524d26 EZ |
1571 | (defun rcirc-channel-nicks (process target) |
1572 | "Return the list of nicks associated with TARGET sorted by last activity." | |
1573 | (when target | |
1574 | (if (rcirc-channel-p target) | |
1575 | (with-rcirc-process-buffer process | |
1576 | (let (nicks) | |
1577 | (maphash | |
1578 | (lambda (k v) | |
1579 | (let ((record (assoc-string target v t))) | |
1580 | (if record | |
1581 | (setq nicks (cons (cons k (cdr record)) nicks))))) | |
1582 | rcirc-nick-table) | |
1583 | (mapcar (lambda (x) (car x)) | |
a0a5c583 GM |
1584 | (sort nicks (lambda (x y) |
1585 | (let ((lx (or (cdr x) 0)) | |
1586 | (ly (or (cdr y) 0))) | |
1587 | (< ly lx))))))) | |
a2524d26 | 1588 | (list target)))) |
2c8abe90 AS |
1589 | |
1590 | (defun rcirc-ignore-update-automatic (nick) | |
2e398771 JB |
1591 | "Remove NICK from `rcirc-ignore-list' |
1592 | if NICK is also on `rcirc-ignore-list-automatic'." | |
2c8abe90 AS |
1593 | (when (member nick rcirc-ignore-list-automatic) |
1594 | (setq rcirc-ignore-list-automatic | |
1595 | (delete nick rcirc-ignore-list-automatic) | |
1596 | rcirc-ignore-list | |
1597 | (delete nick rcirc-ignore-list)))) | |
bd43c990 RS |
1598 | \f |
1599 | ;;; activity tracking | |
db58efbf EZ |
1600 | (defvar rcirc-track-minor-mode-map (make-sparse-keymap) |
1601 | "Keymap for rcirc track minor mode.") | |
1602 | ||
1603 | (define-key rcirc-track-minor-mode-map (kbd "C-c `") 'rcirc-next-active-buffer) | |
1604 | (define-key rcirc-track-minor-mode-map (kbd "C-c C-@") 'rcirc-next-active-buffer) | |
1605 | (define-key rcirc-track-minor-mode-map (kbd "C-c C-SPC") 'rcirc-next-active-buffer) | |
1606 | ||
e8f10ddb | 1607 | ;;;###autoload |
db58efbf EZ |
1608 | (define-minor-mode rcirc-track-minor-mode |
1609 | "Global minor mode for tracking activity in rcirc buffers." | |
1610 | :init-value nil | |
1611 | :lighter "" | |
1612 | :keymap rcirc-track-minor-mode-map | |
1613 | :global t | |
1614 | :group 'rcirc | |
1615 | (or global-mode-string (setq global-mode-string '(""))) | |
1616 | ;; toggle the mode-line channel indicator | |
1617 | (if rcirc-track-minor-mode | |
a2524d26 EZ |
1618 | (progn |
1619 | (and (not (memq 'rcirc-activity-string global-mode-string)) | |
1620 | (setq global-mode-string | |
1621 | (append global-mode-string '(rcirc-activity-string)))) | |
1622 | (add-hook 'window-configuration-change-hook | |
1623 | 'rcirc-window-configuration-change)) | |
92c4adc1 | 1624 | (setq global-mode-string |
a2524d26 EZ |
1625 | (delete 'rcirc-activity-string global-mode-string)) |
1626 | (remove-hook 'window-configuration-change-hook | |
1627 | 'rcirc-window-configuration-change))) | |
db58efbf | 1628 | |
adf794e4 | 1629 | (or (assq 'rcirc-ignore-buffer-activity-flag minor-mode-alist) |
bd43c990 | 1630 | (setq minor-mode-alist |
adf794e4 | 1631 | (cons '(rcirc-ignore-buffer-activity-flag " Ignore") minor-mode-alist))) |
a2524d26 EZ |
1632 | (or (assq 'rcirc-low-priority-flag minor-mode-alist) |
1633 | (setq minor-mode-alist | |
1634 | (cons '(rcirc-low-priority-flag " LowPri") minor-mode-alist))) | |
195eca78 SM |
1635 | (or (assq 'rcirc-omit-mode minor-mode-alist) |
1636 | (setq minor-mode-alist | |
1637 | (cons '(rcirc-omit-mode " Omit") minor-mode-alist))) | |
bd43c990 | 1638 | |
db58efbf EZ |
1639 | (defun rcirc-toggle-ignore-buffer-activity () |
1640 | "Toggle the value of `rcirc-ignore-buffer-activity-flag'." | |
1641 | (interactive) | |
1642 | (setq rcirc-ignore-buffer-activity-flag | |
1643 | (not rcirc-ignore-buffer-activity-flag)) | |
1644 | (message (if rcirc-ignore-buffer-activity-flag | |
1645 | "Ignore activity in this buffer" | |
1646 | "Notice activity in this buffer")) | |
bd43c990 RS |
1647 | (force-mode-line-update)) |
1648 | ||
a2524d26 | 1649 | (defun rcirc-toggle-low-priority () |
02f47e86 | 1650 | "Toggle the value of `rcirc-low-priority-flag'." |
a2524d26 EZ |
1651 | (interactive) |
1652 | (setq rcirc-low-priority-flag | |
1653 | (not rcirc-low-priority-flag)) | |
1654 | (message (if rcirc-low-priority-flag | |
1655 | "Activity in this buffer is low priority" | |
1656 | "Activity in this buffer is normal priority")) | |
1657 | (force-mode-line-update)) | |
1658 | ||
195eca78 SM |
1659 | (defun rcirc-omit-mode () |
1660 | "Toggle the Rcirc-Omit mode. | |
0ffab1eb | 1661 | If enabled, \"uninteresting\" lines are not shown. |
195eca78 SM |
1662 | Uninteresting lines are those whose responses are listed in |
1663 | `rcirc-omit-responses'." | |
1664 | (interactive) | |
1665 | (setq rcirc-omit-mode (not rcirc-omit-mode)) | |
a0a5c583 GM |
1666 | (if rcirc-omit-mode |
1667 | (progn | |
1668 | (add-to-invisibility-spec '(rcirc-omit . t)) | |
1669 | (message "Rcirc-Omit mode enabled")) | |
1670 | (remove-from-invisibility-spec '(rcirc-omit . t)) | |
1671 | (message "Rcirc-Omit mode disabled")) | |
1672 | (recenter (when (> (point) rcirc-prompt-start-marker) -1))) | |
bd43c990 RS |
1673 | |
1674 | (defun rcirc-switch-to-server-buffer () | |
1675 | "Switch to the server buffer associated with current channel buffer." | |
1676 | (interactive) | |
195eca78 | 1677 | (switch-to-buffer rcirc-server-buffer)) |
bd43c990 RS |
1678 | |
1679 | (defun rcirc-jump-to-first-unread-line () | |
1680 | "Move the point to the first unread line in this buffer." | |
1681 | (interactive) | |
195eca78 SM |
1682 | (if (marker-position overlay-arrow-position) |
1683 | (goto-char overlay-arrow-position) | |
1684 | (message "No unread messages"))) | |
1685 | ||
1686 | (defun rcirc-non-irc-buffer () | |
1687 | (let ((buflist (buffer-list)) | |
1688 | buffer) | |
1689 | (while (and buflist (not buffer)) | |
1690 | (with-current-buffer (car buflist) | |
1691 | (unless (or (eq major-mode 'rcirc-mode) | |
1692 | (= ?\s (aref (buffer-name) 0)) ; internal buffers | |
1693 | (get-buffer-window (current-buffer))) | |
1694 | (setq buffer (current-buffer)))) | |
1695 | (setq buflist (cdr buflist))) | |
1696 | buffer)) | |
bd43c990 RS |
1697 | |
1698 | (defun rcirc-next-active-buffer (arg) | |
195eca78 SM |
1699 | "Switch to the next rcirc buffer with activity. |
1700 | With prefix ARG, go to the next low priority buffer with activity." | |
a2524d26 EZ |
1701 | (interactive "P") |
1702 | (let* ((pair (rcirc-split-activity rcirc-activity)) | |
1703 | (lopri (car pair)) | |
92c4adc1 | 1704 | (hipri (cdr pair))) |
a2524d26 EZ |
1705 | (if (or (and (not arg) hipri) |
1706 | (and arg lopri)) | |
a0a5c583 GM |
1707 | (progn |
1708 | (switch-to-buffer (car (if arg lopri hipri))) | |
1709 | (when (> (point) rcirc-prompt-start-marker) | |
1710 | (recenter -1))) | |
a2524d26 | 1711 | (if (eq major-mode 'rcirc-mode) |
195eca78 | 1712 | (switch-to-buffer (rcirc-non-irc-buffer)) |
92c4adc1 | 1713 | (message (concat |
a2524d26 EZ |
1714 | "No IRC activity." |
1715 | (when lopri | |
92c4adc1 | 1716 | (concat |
a2524d26 EZ |
1717 | " Type C-u " |
1718 | (key-description (this-command-keys)) | |
1719 | " for low priority activity.")))))))) | |
bd43c990 RS |
1720 | |
1721 | (defvar rcirc-activity-hooks nil | |
1722 | "Hook to be run when there is channel activity. | |
1723 | ||
1724 | Functions are called with a single argument, the buffer with the | |
1725 | activity. Only run if the buffer is not visible and | |
adf794e4 | 1726 | `rcirc-ignore-buffer-activity-flag' is non-nil.") |
bd43c990 | 1727 | |
a2524d26 | 1728 | (defun rcirc-record-activity (buffer &optional type) |
bd43c990 RS |
1729 | "Record BUFFER activity with TYPE." |
1730 | (with-current-buffer buffer | |
195eca78 SM |
1731 | (let ((old-activity rcirc-activity) |
1732 | (old-types rcirc-activity-types)) | |
1733 | (when (not (get-buffer-window (current-buffer) t)) | |
1734 | (setq rcirc-activity | |
1735 | (sort (add-to-list 'rcirc-activity (current-buffer)) | |
1736 | (lambda (b1 b2) | |
1737 | (let ((t1 (with-current-buffer b1 rcirc-last-post-time)) | |
1738 | (t2 (with-current-buffer b2 rcirc-last-post-time))) | |
1739 | (time-less-p t2 t1))))) | |
1740 | (pushnew type rcirc-activity-types) | |
1741 | (unless (and (equal rcirc-activity old-activity) | |
1742 | (member type old-types)) | |
1743 | (rcirc-update-activity-string))))) | |
bd43c990 RS |
1744 | (run-hook-with-args 'rcirc-activity-hooks buffer)) |
1745 | ||
1746 | (defun rcirc-clear-activity (buffer) | |
1747 | "Clear the BUFFER activity." | |
0ffab1eb | 1748 | (setq rcirc-activity (remove buffer rcirc-activity)) |
bd43c990 | 1749 | (with-current-buffer buffer |
f8db61b2 | 1750 | (setq rcirc-activity-types nil))) |
bd43c990 | 1751 | |
195eca78 SM |
1752 | (defun rcirc-clear-unread (buffer) |
1753 | "Erase the last read message arrow from BUFFER." | |
1754 | (when (buffer-live-p buffer) | |
1755 | (with-current-buffer buffer | |
1756 | (set-marker overlay-arrow-position nil)))) | |
1757 | ||
a2524d26 EZ |
1758 | (defun rcirc-split-activity (activity) |
1759 | "Return a cons cell with ACTIVITY split into (lopri . hipri)." | |
1760 | (let (lopri hipri) | |
1761 | (dolist (buf rcirc-activity) | |
1762 | (with-current-buffer buf | |
1763 | (if (and rcirc-low-priority-flag | |
f8db61b2 | 1764 | (not (member 'nick rcirc-activity-types))) |
a2524d26 EZ |
1765 | (add-to-list 'lopri buf t) |
1766 | (add-to-list 'hipri buf t)))) | |
1767 | (cons lopri hipri))) | |
1768 | ||
195eca78 SM |
1769 | (defvar rcirc-update-activity-string-hook nil |
1770 | "Hook run whenever the activity string is updated.") | |
1771 | ||
adf794e4 | 1772 | ;; TODO: add mouse properties |
bd43c990 RS |
1773 | (defun rcirc-update-activity-string () |
1774 | "Update mode-line string." | |
a2524d26 EZ |
1775 | (let* ((pair (rcirc-split-activity rcirc-activity)) |
1776 | (lopri (car pair)) | |
1777 | (hipri (cdr pair))) | |
1778 | (setq rcirc-activity-string | |
7faa3f8c | 1779 | (cond ((or hipri lopri) |
195eca78 | 1780 | (concat (and hipri "[") |
7faa3f8c MB |
1781 | (rcirc-activity-string hipri) |
1782 | (and hipri lopri ",") | |
1783 | (and lopri | |
1784 | (concat "(" | |
1785 | (rcirc-activity-string lopri) | |
1786 | ")")) | |
195eca78 | 1787 | (and hipri "]"))) |
7faa3f8c | 1788 | ((not (null (rcirc-process-list))) |
195eca78 SM |
1789 | "[]") |
1790 | (t "[]"))) | |
1791 | (run-hooks 'rcirc-update-activity-string-hook))) | |
a2524d26 EZ |
1792 | |
1793 | (defun rcirc-activity-string (buffers) | |
1794 | (mapconcat (lambda (b) | |
f8db61b2 | 1795 | (let ((s (substring-no-properties (rcirc-short-buffer-name b)))) |
a2524d26 | 1796 | (with-current-buffer b |
f8db61b2 EZ |
1797 | (dolist (type rcirc-activity-types) |
1798 | (rcirc-add-face 0 (length s) | |
1799 | (case type | |
82741a5e CY |
1800 | (nick 'rcirc-track-nick) |
1801 | (keyword 'rcirc-track-keyword)) | |
f8db61b2 EZ |
1802 | s))) |
1803 | s)) | |
a2524d26 | 1804 | buffers ",")) |
bd43c990 RS |
1805 | |
1806 | (defun rcirc-short-buffer-name (buffer) | |
1807 | "Return a short name for BUFFER to use in the modeline indicator." | |
1808 | (with-current-buffer buffer | |
adf794e4 EZ |
1809 | (or rcirc-short-buffer-name (buffer-name)))) |
1810 | ||
195eca78 SM |
1811 | (defun rcirc-visible-buffers () |
1812 | "Return a list of the visible buffers that are in rcirc-mode." | |
1813 | (let (acc) | |
adf794e4 | 1814 | (walk-windows (lambda (w) |
195eca78 SM |
1815 | (with-current-buffer (window-buffer w) |
1816 | (when (eq major-mode 'rcirc-mode) | |
1817 | (push (current-buffer) acc))))) | |
1818 | acc)) | |
1819 | ||
1820 | (defvar rcirc-visible-buffers nil) | |
1821 | (defun rcirc-window-configuration-change () | |
1822 | (unless (minibuffer-window-active-p (minibuffer-window)) | |
1823 | ;; delay this until command has finished to make sure window is | |
1824 | ;; actually visible before clearing activity | |
1825 | (add-hook 'post-command-hook 'rcirc-window-configuration-change-1))) | |
1826 | ||
1827 | (defun rcirc-window-configuration-change-1 () | |
1828 | ;; clear activity and overlay arrows | |
1829 | (let* ((old-activity rcirc-activity) | |
1830 | (hidden-buffers rcirc-visible-buffers)) | |
1831 | ||
1832 | (setq rcirc-visible-buffers (rcirc-visible-buffers)) | |
1833 | ||
1834 | (dolist (vbuf rcirc-visible-buffers) | |
1835 | (setq hidden-buffers (delq vbuf hidden-buffers)) | |
1836 | ;; clear activity for all visible buffers | |
1837 | (rcirc-clear-activity vbuf)) | |
1838 | ||
1839 | ;; clear unread arrow from recently hidden buffers | |
1840 | (dolist (hbuf hidden-buffers) | |
1841 | (rcirc-clear-unread hbuf)) | |
1842 | ||
1843 | ;; remove any killed buffers from list | |
1844 | (setq rcirc-activity | |
1845 | (delq nil (mapcar (lambda (buf) (when (buffer-live-p buf) buf)) | |
1846 | rcirc-activity))) | |
1847 | ;; update the mode-line string | |
1848 | (unless (equal old-activity rcirc-activity) | |
1849 | (rcirc-update-activity-string))) | |
1850 | ||
1851 | (remove-hook 'post-command-hook 'rcirc-window-configuration-change-1)) | |
bd43c990 RS |
1852 | |
1853 | \f | |
adf794e4 EZ |
1854 | ;;; buffer name abbreviation |
1855 | (defun rcirc-update-short-buffer-names () | |
1856 | (let ((bufalist | |
1857 | (apply 'append (mapcar (lambda (process) | |
1858 | (with-rcirc-process-buffer process | |
1859 | rcirc-buffer-alist)) | |
1860 | (rcirc-process-list))))) | |
1861 | (dolist (i (rcirc-abbreviate bufalist)) | |
a2524d26 EZ |
1862 | (when (buffer-live-p (cdr i)) |
1863 | (with-current-buffer (cdr i) | |
1864 | (setq rcirc-short-buffer-name (car i))))))) | |
adf794e4 EZ |
1865 | |
1866 | (defun rcirc-abbreviate (pairs) | |
1867 | (apply 'append (mapcar 'rcirc-rebuild-tree (rcirc-make-trees pairs)))) | |
1868 | ||
1869 | (defun rcirc-rebuild-tree (tree &optional acc) | |
1870 | (let ((ch (char-to-string (car tree)))) | |
1871 | (dolist (x (cdr tree)) | |
1872 | (if (listp x) | |
1873 | (setq acc (append acc | |
1874 | (mapcar (lambda (y) | |
1875 | (cons (concat ch (car y)) | |
1876 | (cdr y))) | |
1877 | (rcirc-rebuild-tree x)))) | |
1878 | (setq acc (cons (cons ch x) acc)))) | |
1879 | acc)) | |
1880 | ||
1881 | (defun rcirc-make-trees (pairs) | |
1882 | (let (alist) | |
1883 | (mapc (lambda (pair) | |
1884 | (if (consp pair) | |
1885 | (let* ((str (car pair)) | |
1886 | (data (cdr pair)) | |
1887 | (char (unless (zerop (length str)) | |
1888 | (aref str 0))) | |
1889 | (rest (unless (zerop (length str)) | |
1890 | (substring str 1))) | |
1891 | (part (if char (assq char alist)))) | |
1892 | (if part | |
1893 | ;; existing partition | |
1894 | (setcdr part (cons (cons rest data) (cdr part))) | |
1895 | ;; new partition | |
1896 | (setq alist (cons (if char | |
1897 | (list char (cons rest data)) | |
1898 | data) | |
1899 | alist)))) | |
1900 | (setq alist (cons pair alist)))) | |
1901 | pairs) | |
1902 | ;; recurse into cdrs of alist | |
1903 | (mapc (lambda (x) | |
1904 | (when (and (listp x) (listp (cadr x))) | |
1905 | (setcdr x (if (> (length (cdr x)) 1) | |
1906 | (rcirc-make-trees (cdr x)) | |
1907 | (setcdr x (list (cdadr x))))))) | |
1908 | alist))) | |
1909 | \f | |
bd43c990 RS |
1910 | ;;; /commands these are called with 3 args: PROCESS, TARGET, which is |
1911 | ;; the current buffer/channel/user, and ARGS, which is a string | |
1912 | ;; containing the text following the /cmd. | |
1913 | ||
adf794e4 | 1914 | (defmacro defun-rcirc-command (command argument docstring interactive-form |
bd43c990 RS |
1915 | &rest body) |
1916 | "Define a command." | |
1917 | `(defun ,(intern (concat "rcirc-cmd-" (symbol-name command))) | |
1918 | (,@argument &optional process target) | |
a2524d26 EZ |
1919 | ,(concat docstring "\n\nNote: If PROCESS or TARGET are nil, the values given" |
1920 | "\nby `rcirc-buffer-process' and `rcirc-target' will be used.") | |
bd43c990 | 1921 | ,interactive-form |
a2524d26 | 1922 | (let ((process (or process (rcirc-buffer-process))) |
bd43c990 RS |
1923 | (target (or target rcirc-target))) |
1924 | ,@body))) | |
1925 | ||
1926 | (defun-rcirc-command msg (message) | |
1927 | "Send private MESSAGE to TARGET." | |
1928 | (interactive "i") | |
1929 | (if (null message) | |
1930 | (progn | |
1931 | (setq target (completing-read "Message nick: " | |
92c4adc1 | 1932 | (with-rcirc-server-buffer |
a2524d26 | 1933 | rcirc-nick-table))) |
bd43c990 RS |
1934 | (when (> (length target) 0) |
1935 | (setq message (read-string (format "Message %s: " target))) | |
1936 | (when (> (length message) 0) | |
1937 | (rcirc-send-message process target message)))) | |
1938 | (if (not (string-match "\\([^ ]+\\) \\(.+\\)" message)) | |
1939 | (message "Not enough args, or something.") | |
1940 | (setq target (match-string 1 message) | |
1941 | message (match-string 2 message)) | |
1942 | (rcirc-send-message process target message)))) | |
1943 | ||
1944 | (defun-rcirc-command query (nick) | |
1945 | "Open a private chat buffer to NICK." | |
1946 | (interactive (list (completing-read "Query nick: " | |
a2524d26 | 1947 | (with-rcirc-server-buffer rcirc-nick-table)))) |
adf794e4 EZ |
1948 | (let ((existing-buffer (rcirc-get-buffer process nick))) |
1949 | (switch-to-buffer (or existing-buffer | |
1950 | (rcirc-get-buffer-create process nick))) | |
1951 | (when (not existing-buffer) | |
bd43c990 RS |
1952 | (rcirc-cmd-whois nick)))) |
1953 | ||
f161b079 | 1954 | (defun-rcirc-command join (channel) |
bd43c990 RS |
1955 | "Join CHANNEL." |
1956 | (interactive "sJoin channel: ") | |
f161b079 JB |
1957 | (let ((buffer (rcirc-get-buffer-create process |
1958 | (car (split-string channel))))) | |
a2524d26 | 1959 | (rcirc-send-string process (concat "JOIN " channel)) |
bd43c990 | 1960 | (when (not (eq (selected-window) (minibuffer-window))) |
195eca78 | 1961 | (switch-to-buffer buffer)))) |
bd43c990 | 1962 | |
195eca78 | 1963 | ;; TODO: /part #channel reason, or consider removing #channel altogether |
bd43c990 RS |
1964 | (defun-rcirc-command part (channel) |
1965 | "Part CHANNEL." | |
1966 | (interactive "sPart channel: ") | |
1967 | (let ((channel (if (> (length channel) 0) channel target))) | |
adf794e4 | 1968 | (rcirc-send-string process (concat "PART " channel " :" rcirc-id-string)))) |
bd43c990 RS |
1969 | |
1970 | (defun-rcirc-command quit (reason) | |
1971 | "Send a quit message to server with REASON." | |
1972 | (interactive "sQuit reason: ") | |
adf794e4 EZ |
1973 | (rcirc-send-string process (concat "QUIT :" |
1974 | (if (not (zerop (length reason))) | |
1975 | reason | |
1976 | rcirc-id-string)))) | |
bd43c990 RS |
1977 | |
1978 | (defun-rcirc-command nick (nick) | |
1979 | "Change nick to NICK." | |
1980 | (interactive "i") | |
1981 | (when (null nick) | |
1982 | (setq nick (read-string "New nick: " (rcirc-nick process)))) | |
1983 | (rcirc-send-string process (concat "NICK " nick))) | |
1984 | ||
1985 | (defun-rcirc-command names (channel) | |
1986 | "Display list of names in CHANNEL or in current channel if CHANNEL is nil. | |
1987 | If called interactively, prompt for a channel when prefix arg is supplied." | |
1988 | (interactive "P") | |
1989 | (if (interactive-p) | |
1990 | (if channel | |
1991 | (setq channel (read-string "List names in channel: " target)))) | |
1992 | (let ((channel (if (> (length channel) 0) | |
1993 | channel | |
1994 | target))) | |
1995 | (rcirc-send-string process (concat "NAMES " channel)))) | |
1996 | ||
1997 | (defun-rcirc-command topic (topic) | |
1998 | "List TOPIC for the TARGET channel. | |
1999 | With a prefix arg, prompt for new topic." | |
2000 | (interactive "P") | |
2001 | (if (and (interactive-p) topic) | |
2002 | (setq topic (read-string "New Topic: " rcirc-topic))) | |
2003 | (rcirc-send-string process (concat "TOPIC " target | |
2004 | (when (> (length topic) 0) | |
2005 | (concat " :" topic))))) | |
2006 | ||
2007 | (defun-rcirc-command whois (nick) | |
2008 | "Request information from server about NICK." | |
2009 | (interactive (list | |
2010 | (completing-read "Whois: " | |
a2524d26 | 2011 | (with-rcirc-server-buffer rcirc-nick-table)))) |
bd43c990 RS |
2012 | (rcirc-send-string process (concat "WHOIS " nick))) |
2013 | ||
2014 | (defun-rcirc-command mode (args) | |
2015 | "Set mode with ARGS." | |
2016 | (interactive (list (concat (read-string "Mode nick or channel: ") | |
2017 | " " (read-string "Mode: ")))) | |
2018 | (rcirc-send-string process (concat "MODE " args))) | |
2019 | ||
2020 | (defun-rcirc-command list (channels) | |
2021 | "Request information on CHANNELS from server." | |
2022 | (interactive "sList Channels: ") | |
2023 | (rcirc-send-string process (concat "LIST " channels))) | |
2024 | ||
2025 | (defun-rcirc-command oper (args) | |
2026 | "Send operator command to server." | |
2027 | (interactive "sOper args: ") | |
2028 | (rcirc-send-string process (concat "OPER " args))) | |
2029 | ||
2030 | (defun-rcirc-command quote (message) | |
2031 | "Send MESSAGE literally to server." | |
2032 | (interactive "sServer message: ") | |
2033 | (rcirc-send-string process message)) | |
2034 | ||
2035 | (defun-rcirc-command kick (arg) | |
2036 | "Kick NICK from current channel." | |
2037 | (interactive (list | |
2038 | (concat (completing-read "Kick nick: " | |
92c4adc1 | 2039 | (rcirc-channel-nicks |
a2524d26 EZ |
2040 | (rcirc-buffer-process) |
2041 | rcirc-target)) | |
bd43c990 RS |
2042 | (read-from-minibuffer "Kick reason: ")))) |
2043 | (let* ((arglist (split-string arg)) | |
adf794e4 | 2044 | (argstring (concat (car arglist) " :" |
bd43c990 RS |
2045 | (mapconcat 'identity (cdr arglist) " ")))) |
2046 | (rcirc-send-string process (concat "KICK " target " " argstring)))) | |
2047 | ||
2048 | (defun rcirc-cmd-ctcp (args &optional process target) | |
2049 | (if (string-match "^\\([^ ]+\\)\\s-+\\(.+\\)$" args) | |
2050 | (let ((target (match-string 1 args)) | |
2051 | (request (match-string 2 args))) | |
adf794e4 EZ |
2052 | (rcirc-send-string process |
2053 | (format "PRIVMSG %s \C-a%s\C-a" | |
2054 | target (upcase request)))) | |
2055 | (rcirc-print process (rcirc-nick process) "ERROR" nil | |
bd43c990 RS |
2056 | "usage: /ctcp NICK REQUEST"))) |
2057 | ||
2058 | (defun rcirc-cmd-me (args &optional process target) | |
2059 | (rcirc-send-string process (format "PRIVMSG %s :\C-aACTION %s\C-a" | |
2060 | target args))) | |
2c8abe90 | 2061 | |
f8db61b2 EZ |
2062 | (defun rcirc-add-or-remove (set &optional elt) |
2063 | (if (and elt (not (string= "" elt))) | |
2064 | (if (member-ignore-case elt set) | |
2065 | (delete elt set) | |
2066 | (cons elt set)) | |
2067 | set)) | |
2068 | ||
2c8abe90 AS |
2069 | (defun-rcirc-command ignore (nick) |
2070 | "Manage the ignore list. | |
2071 | Ignore NICK, unignore NICK if already ignored, or list ignored | |
2072 | nicks when no NICK is given. When listing ignored nicks, the | |
2e398771 | 2073 | ones added to the list automatically are marked with an asterisk." |
2c8abe90 | 2074 | (interactive "sToggle ignoring of nick: ") |
f8db61b2 | 2075 | (setq rcirc-ignore-list (rcirc-add-or-remove rcirc-ignore-list nick)) |
92c4adc1 | 2076 | (rcirc-print process nil "IGNORE" target |
db58efbf EZ |
2077 | (mapconcat |
2078 | (lambda (nick) | |
2079 | (concat nick | |
2080 | (if (member nick rcirc-ignore-list-automatic) | |
2081 | "*" ""))) | |
2082 | rcirc-ignore-list " "))) | |
2c8abe90 | 2083 | |
f8db61b2 EZ |
2084 | (defun-rcirc-command bright (nick) |
2085 | "Manage the bright nick list." | |
2086 | (interactive "sToggle emphasis of nick: ") | |
2087 | (setq rcirc-bright-nicks (rcirc-add-or-remove rcirc-bright-nicks nick)) | |
92c4adc1 | 2088 | (rcirc-print process nil "BRIGHT" target |
f8db61b2 EZ |
2089 | (mapconcat 'identity rcirc-bright-nicks " "))) |
2090 | ||
2091 | (defun-rcirc-command dim (nick) | |
2092 | "Manage the dim nick list." | |
2093 | (interactive "sToggle deemphasis of nick: ") | |
2094 | (setq rcirc-dim-nicks (rcirc-add-or-remove rcirc-dim-nicks nick)) | |
92c4adc1 | 2095 | (rcirc-print process nil "DIM" target |
f8db61b2 EZ |
2096 | (mapconcat 'identity rcirc-dim-nicks " "))) |
2097 | ||
2098 | (defun-rcirc-command keyword (keyword) | |
2099 | "Manage the keyword list. | |
2100 | Mark KEYWORD, unmark KEYWORD if already marked, or list marked | |
2101 | keywords when no KEYWORD is given." | |
2102 | (interactive "sToggle highlighting of keyword: ") | |
2103 | (setq rcirc-keywords (rcirc-add-or-remove rcirc-keywords keyword)) | |
92c4adc1 | 2104 | (rcirc-print process nil "KEYWORD" target |
f8db61b2 EZ |
2105 | (mapconcat 'identity rcirc-keywords " "))) |
2106 | ||
bd43c990 | 2107 | \f |
f8db61b2 EZ |
2108 | (defun rcirc-add-face (start end name &optional object) |
2109 | "Add face NAME to the face text property of the text from START to END." | |
2110 | (when name | |
2111 | (let ((pos start) | |
2112 | next prop) | |
2113 | (while (< pos end) | |
2114 | (setq prop (get-text-property pos 'face object) | |
2115 | next (next-single-property-change pos 'face object end)) | |
2116 | (unless (member name (get-text-property pos 'face object)) | |
2117 | (add-text-properties pos next (list 'face (cons name prop)) object)) | |
2118 | (setq pos next))))) | |
adf794e4 | 2119 | |
bd43c990 RS |
2120 | (defun rcirc-facify (string face) |
2121 | "Return a copy of STRING with FACE property added." | |
f8db61b2 EZ |
2122 | (let ((string (or string ""))) |
2123 | (rcirc-add-face 0 (length string) face string) | |
2124 | string)) | |
bd43c990 | 2125 | |
bd43c990 | 2126 | (defvar rcirc-url-regexp |
2fbed782 EZ |
2127 | (rx-to-string |
2128 | `(and word-boundary | |
92c4adc1 JB |
2129 | (or (and |
2130 | (or (and (or "http" "https" "ftp" "file" "gopher" "news" | |
019ed9c7 EZ |
2131 | "telnet" "wais" "mailto") |
2132 | "://") | |
2133 | "www.") | |
2134 | (1+ (char "-a-zA-Z0-9_.")) | |
7faa3f8c | 2135 | (1+ (char "-a-zA-Z0-9_")) |
019ed9c7 | 2136 | (optional ":" (1+ (char "0-9")))) |
2fbed782 EZ |
2137 | (and (1+ (char "-a-zA-Z0-9_.")) |
2138 | (or ".com" ".net" ".org") | |
2139 | word-boundary)) | |
92c4adc1 | 2140 | (optional |
2fbed782 | 2141 | (and "/" |
195eca78 | 2142 | (1+ (char "-a-zA-Z0-9_='!?#$\@~`%&*+|\\/:;.,{}[]()")) |
f8db61b2 | 2143 | (char "-a-zA-Z0-9_=#$\@~`%&*+|\\/:;{}[]()"))))) |
2e398771 | 2144 | "Regexp matching URLs. Set to nil to disable URL features in rcirc.") |
bd43c990 RS |
2145 | |
2146 | (defun rcirc-browse-url (&optional arg) | |
2e398771 | 2147 | "Prompt for URL to browse based on URLs in buffer." |
02f47e86 | 2148 | (interactive "P") |
bd43c990 RS |
2149 | (let ((completions (mapcar (lambda (x) (cons x nil)) rcirc-urls)) |
2150 | (initial-input (car rcirc-urls)) | |
2151 | (history (cdr rcirc-urls))) | |
2152 | (browse-url (completing-read "rcirc browse-url: " | |
2153 | completions nil nil initial-input 'history) | |
2154 | arg))) | |
2155 | ||
adf794e4 EZ |
2156 | (defun rcirc-browse-url-at-point (point) |
2157 | "Send URL at point to `browse-url'." | |
2158 | (interactive "d") | |
7faa3f8c | 2159 | (let ((beg (previous-single-property-change (1+ point) 'mouse-face)) |
adf794e4 EZ |
2160 | (end (next-single-property-change point 'mouse-face))) |
2161 | (browse-url (buffer-substring-no-properties beg end)))) | |
2162 | ||
2163 | (defun rcirc-browse-url-at-mouse (event) | |
2164 | "Send URL at mouse click to `browse-url'." | |
2165 | (interactive "e") | |
2166 | (let ((position (event-end event))) | |
2167 | (with-current-buffer (window-buffer (posn-window position)) | |
2168 | (rcirc-browse-url-at-point (posn-point position))))) | |
2169 | ||
f8db61b2 | 2170 | \f |
195eca78 SM |
2171 | (defun rcirc-markup-timestamp (sender response) |
2172 | (goto-char (point-min)) | |
0ffab1eb | 2173 | (insert (rcirc-facify (format-time-string rcirc-time-format) |
195eca78 | 2174 | 'rcirc-timestamp))) |
f8db61b2 | 2175 | |
195eca78 | 2176 | (defun rcirc-markup-attributes (sender response) |
f8db61b2 EZ |
2177 | (while (re-search-forward "\\([\C-b\C-_\C-v]\\).*?\\(\\1\\|\C-o\\)" nil t) |
2178 | (rcirc-add-face (match-beginning 0) (match-end 0) | |
2179 | (case (char-after (match-beginning 1)) | |
2180 | (?\C-b 'bold) | |
2181 | (?\C-v 'italic) | |
2182 | (?\C-_ 'underline))) | |
2183 | ;; keep the ^O since it could terminate other attributes | |
2184 | (when (not (eq ?\C-o (char-before (match-end 2)))) | |
2185 | (delete-region (match-beginning 2) (match-end 2))) | |
2186 | (delete-region (match-beginning 1) (match-end 1)) | |
2187 | (goto-char (1+ (match-beginning 1)))) | |
2188 | ;; remove the ^O characters now | |
2189 | (while (re-search-forward "\C-o+" nil t) | |
2190 | (delete-region (match-beginning 0) (match-end 0)))) | |
2191 | ||
195eca78 | 2192 | (defun rcirc-markup-my-nick (sender response) |
f8db61b2 | 2193 | (with-syntax-table rcirc-nick-syntax-table |
0ffab1eb TTN |
2194 | (while (re-search-forward (concat "\\b" |
2195 | (regexp-quote (rcirc-nick | |
195eca78 | 2196 | (rcirc-buffer-process))) |
f8db61b2 EZ |
2197 | "\\b") |
2198 | nil t) | |
92c4adc1 | 2199 | (rcirc-add-face (match-beginning 0) (match-end 0) |
f8db61b2 EZ |
2200 | 'rcirc-nick-in-message) |
2201 | (when (string= response "PRIVMSG") | |
0ffab1eb | 2202 | (rcirc-add-face (point-min) (point-max) |
195eca78 SM |
2203 | 'rcirc-nick-in-message-full-line) |
2204 | (rcirc-record-activity (current-buffer) 'nick))))) | |
f8db61b2 | 2205 | |
195eca78 | 2206 | (defun rcirc-markup-urls (sender response) |
f8db61b2 EZ |
2207 | (while (re-search-forward rcirc-url-regexp nil t) |
2208 | (let ((start (match-beginning 0)) | |
2209 | (end (match-end 0))) | |
2210 | (rcirc-add-face start end 'rcirc-url) | |
2211 | (add-text-properties start end (list 'mouse-face 'highlight | |
2212 | 'keymap rcirc-browse-url-map)) | |
2213 | ;; record the url | |
195eca78 SM |
2214 | (push (buffer-substring-no-properties start end) rcirc-urls)))) |
2215 | ||
2216 | (defun rcirc-markup-keywords (sender response) | |
2217 | (when (and (string= response "PRIVMSG") | |
2218 | (not (string= sender (rcirc-nick (rcirc-buffer-process))))) | |
2219 | (let* ((target (or rcirc-target "")) | |
2220 | (keywords (delq nil (mapcar (lambda (keyword) | |
2221 | (when (not (string-match keyword | |
2222 | target)) | |
2223 | keyword)) | |
2224 | rcirc-keywords)))) | |
2225 | (when keywords | |
2226 | (while (re-search-forward (regexp-opt keywords 'words) nil t) | |
2227 | (rcirc-add-face (match-beginning 0) (match-end 0) 'rcirc-keyword) | |
2228 | (rcirc-record-activity (current-buffer) 'keyword)))))) | |
2229 | ||
2230 | (defun rcirc-markup-bright-nicks (sender response) | |
f8db61b2 EZ |
2231 | (when (and rcirc-bright-nicks |
2232 | (string= response "NAMES")) | |
2233 | (with-syntax-table rcirc-nick-syntax-table | |
2234 | (while (re-search-forward (regexp-opt rcirc-bright-nicks 'words) nil t) | |
2235 | (rcirc-add-face (match-beginning 0) (match-end 0) | |
2236 | 'rcirc-bright-nick))))) | |
195eca78 SM |
2237 | |
2238 | (defun rcirc-markup-fill (sender response) | |
2239 | (when (not (string= response "372")) ; /motd | |
2240 | (let ((fill-prefix | |
2241 | (or rcirc-fill-prefix | |
2242 | (make-string (- (point) (line-beginning-position)) ?\s))) | |
2243 | (fill-column (cond ((eq rcirc-fill-column 'frame-width) | |
2244 | (1- (frame-width))) | |
2245 | (rcirc-fill-column | |
2246 | rcirc-fill-column) | |
2247 | (t fill-column)))) | |
2248 | (fill-region (point) (point-max) nil t)))) | |
bd43c990 RS |
2249 | \f |
2250 | ;;; handlers | |
2251 | ;; these are called with the server PROCESS, the SENDER, which is a | |
2252 | ;; server or a user, depending on the command, the ARGS, which is a | |
2253 | ;; list of strings, and the TEXT, which is the original server text, | |
2254 | ;; verbatim | |
2255 | (defun rcirc-handler-001 (process sender args text) | |
2256 | (rcirc-handler-generic process "001" sender args text) | |
2257 | ;; set the real server name | |
adf794e4 | 2258 | (with-rcirc-process-buffer process |
8216fbaf EZ |
2259 | (setq rcirc-connecting nil) |
2260 | (rcirc-reschedule-timeout process) | |
2261 | (setq rcirc-server-name sender) | |
bd43c990 RS |
2262 | (setq rcirc-nick (car args)) |
2263 | (rcirc-update-prompt) | |
2264 | (when rcirc-auto-authenticate-flag (rcirc-authenticate)) | |
adf794e4 | 2265 | (rcirc-join-channels process rcirc-startup-channels))) |
bd43c990 RS |
2266 | |
2267 | (defun rcirc-handler-PRIVMSG (process sender args text) | |
2268 | (let ((target (if (rcirc-channel-p (car args)) | |
2269 | (car args) | |
db58efbf | 2270 | sender)) |
bd43c990 RS |
2271 | (message (or (cadr args) ""))) |
2272 | (if (string-match "^\C-a\\(.*\\)\C-a$" message) | |
2273 | (rcirc-handler-CTCP process target sender (match-string 1 message)) | |
2274 | (rcirc-print process sender "PRIVMSG" target message t)) | |
a0a5c583 GM |
2275 | ;; update nick linestamp |
2276 | (with-current-buffer (rcirc-get-buffer process target t) | |
2277 | (rcirc-put-nick-channel process sender target rcirc-current-line)))) | |
bd43c990 RS |
2278 | |
2279 | (defun rcirc-handler-NOTICE (process sender args text) | |
2280 | (let ((target (car args)) | |
2281 | (message (cadr args))) | |
adf794e4 EZ |
2282 | (if (string-match "^\C-a\\(.*\\)\C-a$" message) |
2283 | (rcirc-handler-CTCP-response process target sender | |
2284 | (match-string 1 message)) | |
2285 | (rcirc-print process sender "NOTICE" | |
2286 | (cond ((rcirc-channel-p target) | |
2287 | target) | |
2288 | ;;; -ChanServ- [#gnu] Welcome... | |
02f47e86 | 2289 | ((string-match "\\[\\(#[^\] ]+\\)\\]" message) |
adf794e4 EZ |
2290 | (match-string 1 message)) |
2291 | (sender | |
a2524d26 | 2292 | (if (string= sender (rcirc-server-name process)) |
db58efbf EZ |
2293 | nil ; server notice |
2294 | sender))) | |
adf794e4 | 2295 | message t)))) |
bd43c990 RS |
2296 | |
2297 | (defun rcirc-handler-WALLOPS (process sender args text) | |
db58efbf | 2298 | (rcirc-print process sender "WALLOPS" sender (car args) t)) |
bd43c990 RS |
2299 | |
2300 | (defun rcirc-handler-JOIN (process sender args text) | |
db58efbf | 2301 | (let ((channel (car args))) |
a0a5c583 GM |
2302 | (with-current-buffer (rcirc-get-buffer-create process channel) |
2303 | ;; when recently rejoining, restore the linestamp | |
2304 | (rcirc-put-nick-channel process sender channel | |
2305 | (let ((last-activity-lines | |
2306 | (rcirc-elapsed-lines sender channel))) | |
2307 | (when (and last-activity-lines | |
2308 | (< last-activity-lines rcirc-omit-threshold)) | |
2309 | (rcirc-last-line sender channel))))) | |
2310 | ||
bd43c990 RS |
2311 | (rcirc-print process sender "JOIN" channel "") |
2312 | ||
2313 | ;; print in private chat buffer if it exists | |
a2524d26 | 2314 | (when (rcirc-get-buffer (rcirc-buffer-process) sender) |
a0a5c583 | 2315 | (rcirc-print process sender "JOIN" sender channel)))) |
bd43c990 RS |
2316 | |
2317 | ;; PART and KICK are handled the same way | |
2318 | (defun rcirc-handler-PART-or-KICK (process response channel sender nick args) | |
a2524d26 | 2319 | (rcirc-ignore-update-automatic nick) |
bd43c990 RS |
2320 | (if (not (string= nick (rcirc-nick process))) |
2321 | ;; this is someone else leaving | |
a0a5c583 GM |
2322 | (progn |
2323 | (rcirc-maybe-remember-nick-quit process nick channel) | |
2324 | (rcirc-remove-nick-channel process nick channel)) | |
adf794e4 EZ |
2325 | ;; this is us leaving |
2326 | (mapc (lambda (n) | |
2327 | (rcirc-remove-nick-channel process n channel)) | |
2328 | (rcirc-channel-nicks process channel)) | |
2329 | ||
2330 | ;; if the buffer is still around, make it inactive | |
2331 | (let ((buffer (rcirc-get-buffer process channel))) | |
2332 | (when buffer | |
195eca78 | 2333 | (rcirc-disconnect-buffer buffer))))) |
bd43c990 RS |
2334 | |
2335 | (defun rcirc-handler-PART (process sender args text) | |
a2524d26 EZ |
2336 | (let* ((channel (car args)) |
2337 | (reason (cadr args)) | |
2338 | (message (concat channel " " reason))) | |
2339 | (rcirc-print process sender "PART" channel message) | |
2340 | ;; print in private chat buffer if it exists | |
2341 | (when (rcirc-get-buffer (rcirc-buffer-process) sender) | |
2342 | (rcirc-print process sender "PART" sender message)) | |
2343 | ||
2344 | (rcirc-handler-PART-or-KICK process "PART" channel sender sender reason))) | |
bd43c990 RS |
2345 | |
2346 | (defun rcirc-handler-KICK (process sender args text) | |
a2524d26 EZ |
2347 | (let* ((channel (car args)) |
2348 | (nick (cadr args)) | |
2349 | (reason (caddr args)) | |
2350 | (message (concat nick " " channel " " reason))) | |
2351 | (rcirc-print process sender "KICK" channel message t) | |
2352 | ;; print in private chat buffer if it exists | |
2353 | (when (rcirc-get-buffer (rcirc-buffer-process) nick) | |
2354 | (rcirc-print process sender "KICK" nick message)) | |
2355 | ||
2356 | (rcirc-handler-PART-or-KICK process "KICK" channel sender nick reason))) | |
bd43c990 | 2357 | |
a0a5c583 GM |
2358 | (defun rcirc-maybe-remember-nick-quit (process nick channel) |
2359 | "Remember NICK as leaving CHANNEL if they recently spoke." | |
2360 | (let ((elapsed-lines (rcirc-elapsed-lines nick channel))) | |
2361 | (when (and elapsed-lines | |
2362 | (< elapsed-lines rcirc-omit-threshold)) | |
2363 | (let ((buffer (rcirc-get-buffer process channel))) | |
2364 | (when buffer | |
2365 | (with-current-buffer buffer | |
2366 | (let ((record (assoc-string nick rcirc-recent-quit-alist | |
2367 | t)) | |
2368 | (line (rcirc-last-line nick channel))) | |
2369 | (if record | |
2370 | (setcdr record line) | |
2371 | (setq rcirc-recent-quit-alist | |
2372 | (cons (cons nick line) | |
2373 | rcirc-recent-quit-alist)))))))))) | |
2374 | ||
bd43c990 | 2375 | (defun rcirc-handler-QUIT (process sender args text) |
db58efbf EZ |
2376 | (rcirc-ignore-update-automatic sender) |
2377 | (mapc (lambda (channel) | |
a0a5c583 GM |
2378 | ;; broadcast quit message each channel |
2379 | (rcirc-print process sender "QUIT" channel (apply 'concat args)) | |
2380 | ;; record nick in quit table if they recently spoke | |
2381 | (rcirc-maybe-remember-nick-quit process sender channel)) | |
db58efbf | 2382 | (rcirc-nick-channels process sender)) |
db58efbf | 2383 | (rcirc-nick-remove process sender)) |
bd43c990 RS |
2384 | |
2385 | (defun rcirc-handler-NICK (process sender args text) | |
db58efbf | 2386 | (let* ((old-nick sender) |
bd43c990 RS |
2387 | (new-nick (car args)) |
2388 | (channels (rcirc-nick-channels process old-nick))) | |
2c8abe90 AS |
2389 | ;; update list of ignored nicks |
2390 | (rcirc-ignore-update-automatic old-nick) | |
2391 | (when (member old-nick rcirc-ignore-list) | |
2392 | (add-to-list 'rcirc-ignore-list new-nick) | |
2393 | (add-to-list 'rcirc-ignore-list-automatic new-nick)) | |
bd43c990 RS |
2394 | ;; print message to nick's channels |
2395 | (dolist (target channels) | |
2396 | (rcirc-print process sender "NICK" target new-nick)) | |
2397 | ;; update private chat buffer, if it exists | |
adf794e4 EZ |
2398 | (let ((chat-buffer (rcirc-get-buffer process old-nick))) |
2399 | (when chat-buffer | |
2400 | (with-current-buffer chat-buffer | |
2401 | (rcirc-print process sender "NICK" old-nick new-nick) | |
2402 | (setq rcirc-target new-nick) | |
2403 | (rename-buffer (rcirc-generate-new-buffer-name process new-nick))))) | |
bd43c990 | 2404 | ;; remove old nick and add new one |
adf794e4 | 2405 | (with-rcirc-process-buffer process |
bd43c990 RS |
2406 | (let ((v (gethash old-nick rcirc-nick-table))) |
2407 | (remhash old-nick rcirc-nick-table) | |
2408 | (puthash new-nick v rcirc-nick-table)) | |
2409 | ;; if this is our nick... | |
2410 | (when (string= old-nick rcirc-nick) | |
2411 | (setq rcirc-nick new-nick) | |
adf794e4 | 2412 | (rcirc-update-prompt t) |
bd43c990 RS |
2413 | ;; reauthenticate |
2414 | (when rcirc-auto-authenticate-flag (rcirc-authenticate)))))) | |
2415 | ||
2416 | (defun rcirc-handler-PING (process sender args text) | |
195eca78 | 2417 | (rcirc-send-string process (concat "PONG :" (car args)))) |
bd43c990 RS |
2418 | |
2419 | (defun rcirc-handler-PONG (process sender args text) | |
2420 | ;; do nothing | |
2421 | ) | |
2422 | ||
2423 | (defun rcirc-handler-TOPIC (process sender args text) | |
2424 | (let ((topic (cadr args))) | |
2425 | (rcirc-print process sender "TOPIC" (car args) topic) | |
2426 | (with-current-buffer (rcirc-get-buffer process (car args)) | |
2427 | (setq rcirc-topic topic)))) | |
2428 | ||
a2524d26 EZ |
2429 | (defvar rcirc-nick-away-alist nil) |
2430 | (defun rcirc-handler-301 (process sender args text) | |
2431 | "RPL_AWAY" | |
2432 | (let* ((nick (cadr args)) | |
2433 | (rec (assoc-string nick rcirc-nick-away-alist)) | |
2434 | (away-message (caddr args))) | |
2435 | (when (or (not rec) | |
2436 | (not (string= (cdr rec) away-message))) | |
2437 | ;; away message has changed | |
2438 | (rcirc-handler-generic process "AWAY" nick (cdr args) text) | |
2439 | (if rec | |
2440 | (setcdr rec away-message) | |
2441 | (setq rcirc-nick-away-alist (cons (cons nick away-message) | |
2442 | rcirc-nick-away-alist)))))) | |
2443 | ||
bd43c990 RS |
2444 | (defun rcirc-handler-332 (process sender args text) |
2445 | "RPL_TOPIC" | |
adf794e4 EZ |
2446 | (let ((buffer (or (rcirc-get-buffer process (cadr args)) |
2447 | (rcirc-get-temp-buffer-create process (cadr args))))) | |
2448 | (with-current-buffer buffer | |
2449 | (setq rcirc-topic (caddr args))))) | |
bd43c990 RS |
2450 | |
2451 | (defun rcirc-handler-333 (process sender args text) | |
2452 | "Not in rfc1459.txt" | |
adf794e4 EZ |
2453 | (let ((buffer (or (rcirc-get-buffer process (cadr args)) |
2454 | (rcirc-get-temp-buffer-create process (cadr args))))) | |
2455 | (with-current-buffer buffer | |
2456 | (let ((setter (caddr args)) | |
2457 | (time (current-time-string | |
2458 | (seconds-to-time | |
2459 | (string-to-number (cadddr args)))))) | |
2460 | (rcirc-print process sender "TOPIC" (cadr args) | |
2461 | (format "%s (%s on %s)" rcirc-topic setter time)))))) | |
bd43c990 RS |
2462 | |
2463 | (defun rcirc-handler-477 (process sender args text) | |
2464 | "ERR_NOCHANMODES" | |
2465 | (rcirc-print process sender "477" (cadr args) (caddr args))) | |
2466 | ||
2467 | (defun rcirc-handler-MODE (process sender args text) | |
2468 | (let ((target (car args)) | |
2469 | (msg (mapconcat 'identity (cdr args) " "))) | |
2470 | (rcirc-print process sender "MODE" | |
2471 | (if (string= target (rcirc-nick process)) | |
2472 | nil | |
2473 | target) | |
2474 | msg) | |
2475 | ||
2476 | ;; print in private chat buffers if they exist | |
2477 | (mapc (lambda (nick) | |
db58efbf EZ |
2478 | (when (rcirc-get-buffer process nick) |
2479 | (rcirc-print process sender "MODE" nick msg))) | |
adf794e4 | 2480 | (cddr args)))) |
bd43c990 RS |
2481 | |
2482 | (defun rcirc-get-temp-buffer-create (process channel) | |
2483 | "Return a buffer based on PROCESS and CHANNEL." | |
2484 | (let ((tmpnam (concat " " (downcase channel) "TMP" (process-name process)))) | |
2485 | (get-buffer-create tmpnam))) | |
2486 | ||
2487 | (defun rcirc-handler-353 (process sender args text) | |
2488 | "RPL_NAMREPLY" | |
adf794e4 | 2489 | (let ((channel (caddr args))) |
bd43c990 RS |
2490 | (mapc (lambda (nick) |
2491 | (rcirc-put-nick-channel process nick channel)) | |
adf794e4 | 2492 | (split-string (cadddr args) " " t)) |
bd43c990 RS |
2493 | (with-current-buffer (rcirc-get-temp-buffer-create process channel) |
2494 | (goto-char (point-max)) | |
2495 | (insert (car (last args)) " ")))) | |
2496 | ||
2497 | (defun rcirc-handler-366 (process sender args text) | |
2498 | "RPL_ENDOFNAMES" | |
2499 | (let* ((channel (cadr args)) | |
2500 | (buffer (rcirc-get-temp-buffer-create process channel))) | |
2501 | (with-current-buffer buffer | |
2502 | (rcirc-print process sender "NAMES" channel | |
2503 | (buffer-substring (point-min) (point-max)))) | |
2504 | (kill-buffer buffer))) | |
2505 | ||
2506 | (defun rcirc-handler-433 (process sender args text) | |
2507 | "ERR_NICKNAMEINUSE" | |
2508 | (rcirc-handler-generic process "433" sender args text) | |
2509 | (let* ((new-nick (concat (cadr args) "`"))) | |
adf794e4 | 2510 | (with-rcirc-process-buffer process |
bd43c990 RS |
2511 | (rcirc-cmd-nick new-nick nil process)))) |
2512 | ||
2513 | (defun rcirc-authenticate () | |
2514 | "Send authentication to process associated with current buffer. | |
db58efbf | 2515 | Passwords are stored in `rcirc-authinfo' (which see)." |
bd43c990 | 2516 | (interactive) |
a2524d26 | 2517 | (with-rcirc-server-buffer |
db58efbf | 2518 | (dolist (i rcirc-authinfo) |
a2524d26 EZ |
2519 | (let ((process (rcirc-buffer-process)) |
2520 | (server (car i)) | |
db58efbf EZ |
2521 | (nick (caddr i)) |
2522 | (method (cadr i)) | |
2523 | (args (cdddr i))) | |
2524 | (when (and (string-match server rcirc-server) | |
2525 | (string-match nick rcirc-nick)) | |
2526 | (cond ((equal method 'nickserv) | |
2527 | (rcirc-send-string | |
a2524d26 | 2528 | process |
db58efbf EZ |
2529 | (concat |
2530 | "PRIVMSG nickserv :identify " | |
2531 | (car args)))) | |
2532 | ((equal method 'chanserv) | |
2533 | (rcirc-send-string | |
a2524d26 | 2534 | process |
db58efbf EZ |
2535 | (concat |
2536 | "PRIVMSG chanserv :identify " | |
195eca78 | 2537 | (car args) " " (cadr args)))) |
db58efbf EZ |
2538 | ((equal method 'bitlbee) |
2539 | (rcirc-send-string | |
a2524d26 | 2540 | process |
db58efbf EZ |
2541 | (concat "PRIVMSG &bitlbee :identify " (car args)))) |
2542 | (t | |
2543 | (message "No %S authentication method defined" | |
2544 | method)))))))) | |
adf794e4 | 2545 | |
bd43c990 RS |
2546 | (defun rcirc-handler-INVITE (process sender args text) |
2547 | (rcirc-print process sender "INVITE" nil (mapconcat 'identity args " ") t)) | |
2548 | ||
2549 | (defun rcirc-handler-ERROR (process sender args text) | |
2550 | (rcirc-print process sender "ERROR" nil (mapconcat 'identity args " "))) | |
2551 | ||
2552 | (defun rcirc-handler-CTCP (process target sender text) | |
2553 | (if (string-match "^\\([^ ]+\\) *\\(.*\\)$" text) | |
2554 | (let* ((request (upcase (match-string 1 text))) | |
2555 | (args (match-string 2 text)) | |
bd43c990 RS |
2556 | (handler (intern-soft (concat "rcirc-handler-ctcp-" request)))) |
2557 | (if (not (fboundp handler)) | |
db58efbf EZ |
2558 | (rcirc-print process sender "ERROR" target |
2559 | (format "%s sent unsupported ctcp: %s" sender text) | |
adf794e4 | 2560 | t) |
bd43c990 | 2561 | (funcall handler process target sender args) |
195eca78 SM |
2562 | (unless (or (string= request "ACTION") |
2563 | (string= request "KEEPALIVE")) | |
db58efbf | 2564 | (rcirc-print process sender "CTCP" target |
adf794e4 | 2565 | (format "%s" text) t)))))) |
bd43c990 RS |
2566 | |
2567 | (defun rcirc-handler-ctcp-VERSION (process target sender args) | |
2568 | (rcirc-send-string process | |
db58efbf | 2569 | (concat "NOTICE " sender |
adf794e4 | 2570 | " :\C-aVERSION " rcirc-id-string |
bd43c990 RS |
2571 | "\C-a"))) |
2572 | ||
2573 | (defun rcirc-handler-ctcp-ACTION (process target sender args) | |
2574 | (rcirc-print process sender "ACTION" target args t)) | |
2575 | ||
2576 | (defun rcirc-handler-ctcp-TIME (process target sender args) | |
2577 | (rcirc-send-string process | |
db58efbf | 2578 | (concat "NOTICE " sender |
bd43c990 | 2579 | " :\C-aTIME " (current-time-string) "\C-a"))) |
adf794e4 EZ |
2580 | |
2581 | (defun rcirc-handler-CTCP-response (process target sender message) | |
2582 | (rcirc-print process sender "CTCP" nil message t)) | |
bd43c990 | 2583 | \f |
adf794e4 EZ |
2584 | (defgroup rcirc-faces nil |
2585 | "Faces for rcirc." | |
2586 | :group 'rcirc | |
2587 | :group 'faces) | |
2588 | ||
ad8121fe EZ |
2589 | (defface rcirc-my-nick ; font-lock-function-name-face |
2590 | '((((class color) (min-colors 88) (background light)) (:foreground "Blue1")) | |
2591 | (((class color) (min-colors 88) (background dark)) (:foreground "LightSkyBlue")) | |
2592 | (((class color) (min-colors 16) (background light)) (:foreground "Blue")) | |
2593 | (((class color) (min-colors 16) (background dark)) (:foreground "LightSkyBlue")) | |
2594 | (((class color) (min-colors 8)) (:foreground "blue" :weight bold)) | |
2595 | (t (:inverse-video t :weight bold))) | |
adf794e4 EZ |
2596 | "The face used to highlight my messages." |
2597 | :group 'rcirc-faces) | |
bd43c990 | 2598 | |
ad8121fe EZ |
2599 | (defface rcirc-other-nick ; font-lock-variable-name-face |
2600 | '((((class grayscale) (background light)) | |
2601 | (:foreground "Gray90" :weight bold :slant italic)) | |
bd43c990 | 2602 | (((class grayscale) (background dark)) |
ad8121fe EZ |
2603 | (:foreground "DimGray" :weight bold :slant italic)) |
2604 | (((class color) (min-colors 88) (background light)) (:foreground "DarkGoldenrod")) | |
2605 | (((class color) (min-colors 88) (background dark)) (:foreground "LightGoldenrod")) | |
2606 | (((class color) (min-colors 16) (background light)) (:foreground "DarkGoldenrod")) | |
2607 | (((class color) (min-colors 16) (background dark)) (:foreground "LightGoldenrod")) | |
2608 | (((class color) (min-colors 8)) (:foreground "yellow" :weight light)) | |
2609 | (t (:weight bold :slant italic))) | |
adf794e4 EZ |
2610 | "The face used to highlight other messages." |
2611 | :group 'rcirc-faces) | |
bd43c990 | 2612 | |
02f47e86 MB |
2613 | (defface rcirc-bright-nick |
2614 | '((((class grayscale) (background light)) | |
2615 | (:foreground "LightGray" :weight bold :underline t)) | |
2616 | (((class grayscale) (background dark)) | |
2617 | (:foreground "Gray50" :weight bold :underline t)) | |
2618 | (((class color) (min-colors 88) (background light)) (:foreground "CadetBlue")) | |
2619 | (((class color) (min-colors 88) (background dark)) (:foreground "Aquamarine")) | |
2620 | (((class color) (min-colors 16) (background light)) (:foreground "CadetBlue")) | |
2621 | (((class color) (min-colors 16) (background dark)) (:foreground "Aquamarine")) | |
2622 | (((class color) (min-colors 8)) (:foreground "magenta")) | |
2623 | (t (:weight bold :underline t))) | |
f8db61b2 | 2624 | "Face used for nicks matched by `rcirc-bright-nicks'." |
02f47e86 MB |
2625 | :group 'rcirc-faces) |
2626 | ||
2627 | (defface rcirc-dim-nick | |
2628 | '((t :inherit default)) | |
f8db61b2 | 2629 | "Face used for nicks in `rcirc-dim-nicks'." |
02f47e86 MB |
2630 | :group 'rcirc-faces) |
2631 | ||
ad8121fe EZ |
2632 | (defface rcirc-server ; font-lock-comment-face |
2633 | '((((class grayscale) (background light)) | |
2634 | (:foreground "DimGray" :weight bold :slant italic)) | |
bd43c990 | 2635 | (((class grayscale) (background dark)) |
ad8121fe EZ |
2636 | (:foreground "LightGray" :weight bold :slant italic)) |
2637 | (((class color) (min-colors 88) (background light)) | |
2638 | (:foreground "Firebrick")) | |
2639 | (((class color) (min-colors 88) (background dark)) | |
2640 | (:foreground "chocolate1")) | |
2641 | (((class color) (min-colors 16) (background light)) | |
2642 | (:foreground "red")) | |
2643 | (((class color) (min-colors 16) (background dark)) | |
2644 | (:foreground "red1")) | |
2645 | (((class color) (min-colors 8) (background light)) | |
2646 | ) | |
2647 | (((class color) (min-colors 8) (background dark)) | |
2648 | ) | |
2649 | (t (:weight bold :slant italic))) | |
adf794e4 EZ |
2650 | "The face used to highlight server messages." |
2651 | :group 'rcirc-faces) | |
bd43c990 | 2652 | |
ad8121fe | 2653 | (defface rcirc-server-prefix ; font-lock-comment-delimiter-face |
db58efbf | 2654 | '((default :inherit rcirc-server) |
ad8121fe EZ |
2655 | (((class grayscale))) |
2656 | (((class color) (min-colors 16))) | |
2657 | (((class color) (min-colors 8) (background light)) | |
2658 | :foreground "red") | |
2659 | (((class color) (min-colors 8) (background dark)) | |
2660 | :foreground "red1")) | |
2661 | "The face used to highlight server prefixes." | |
2662 | :group 'rcirc-faces) | |
2663 | ||
2664 | (defface rcirc-timestamp | |
2665 | '((t (:inherit default))) | |
2666 | "The face used to highlight timestamps." | |
2667 | :group 'rcirc-faces) | |
2668 | ||
2669 | (defface rcirc-nick-in-message ; font-lock-keyword-face | |
2670 | '((((class grayscale) (background light)) (:foreground "LightGray" :weight bold)) | |
2671 | (((class grayscale) (background dark)) (:foreground "DimGray" :weight bold)) | |
2672 | (((class color) (min-colors 88) (background light)) (:foreground "Purple")) | |
2673 | (((class color) (min-colors 88) (background dark)) (:foreground "Cyan1")) | |
2674 | (((class color) (min-colors 16) (background light)) (:foreground "Purple")) | |
2675 | (((class color) (min-colors 16) (background dark)) (:foreground "Cyan")) | |
2676 | (((class color) (min-colors 8)) (:foreground "cyan" :weight bold)) | |
2677 | (t (:weight bold))) | |
f8db61b2 | 2678 | "The face used to highlight instances of your nick within messages." |
adf794e4 | 2679 | :group 'rcirc-faces) |
bd43c990 | 2680 | |
f8db61b2 EZ |
2681 | (defface rcirc-nick-in-message-full-line |
2682 | '((t (:bold t))) | |
2683 | "The face used emphasize the entire message when your nick is mentioned." | |
92c4adc1 | 2684 | :group 'rcirc-faces) |
f8db61b2 | 2685 | |
ad8121fe EZ |
2686 | (defface rcirc-prompt ; comint-highlight-prompt |
2687 | '((((min-colors 88) (background dark)) (:foreground "cyan1")) | |
2688 | (((background dark)) (:foreground "cyan")) | |
bd43c990 | 2689 | (t (:foreground "dark blue"))) |
2e398771 | 2690 | "The face used to highlight prompts." |
adf794e4 | 2691 | :group 'rcirc-faces) |
bd43c990 | 2692 | |
f8db61b2 | 2693 | (defface rcirc-track-nick |
8216fbaf EZ |
2694 | '((((type tty)) (:inherit default)) |
2695 | (t (:inverse-video t))) | |
f8db61b2 EZ |
2696 | "The face used in the mode-line when your nick is mentioned." |
2697 | :group 'rcirc-faces) | |
2698 | ||
2699 | (defface rcirc-track-keyword | |
2700 | '((t (:bold t ))) | |
2701 | "The face used in the mode-line when keywords are mentioned." | |
2702 | :group 'rcirc-faces) | |
2703 | ||
2704 | (defface rcirc-url | |
bd43c990 | 2705 | '((t (:bold t))) |
f8db61b2 EZ |
2706 | "The face used to highlight urls." |
2707 | :group 'rcirc-faces) | |
2708 | ||
2709 | (defface rcirc-keyword | |
2710 | '((t (:inherit highlight))) | |
2711 | "The face used to highlight keywords." | |
adf794e4 | 2712 | :group 'rcirc-faces) |
a2524d26 | 2713 | |
bd43c990 | 2714 | \f |
adf794e4 | 2715 | ;; When using M-x flyspell-mode, only check words after the prompt |
bd43c990 RS |
2716 | (put 'rcirc-mode 'flyspell-mode-predicate 'rcirc-looking-at-input) |
2717 | (defun rcirc-looking-at-input () | |
2718 | "Returns true if point is past the input marker." | |
2719 | (>= (point) rcirc-prompt-end-marker)) | |
2720 | \f | |
2721 | ||
2722 | (provide 'rcirc) | |
e636ae15 MB |
2723 | |
2724 | ;; arch-tag: b471b7e8-6b5a-4399-b2c6-a3c78dfc8ffb | |
bd43c990 | 2725 | ;;; rcirc.el ends here |