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