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