* lread.c (invalid_syntax): Omit length argument.
[emacs.git] / lisp / net / rcirc.el
blob70190867e89cfd4b5f6240e56ffe38ed4f426377
1 ;;; rcirc.el --- default, simple IRC client.
3 ;; Copyright (C) 2005-2011 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 (when server
476 (let (connected)
477 (dolist (p (rcirc-process-list))
478 (when (string= server (process-name p))
479 (setq connected p)))
480 (if (not connected)
481 (condition-case e
482 (rcirc-connect server port nick user-name
483 full-name channels password encryption)
484 (quit (message "Quit connecting to %s" server)))
485 (with-current-buffer (process-buffer connected)
486 (setq connected-servers
487 (cons (process-contact (get-buffer-process
488 (current-buffer)) :host)
489 connected-servers))))))))
490 (when connected-servers
491 (message "Already connected to %s"
492 (if (cdr connected-servers)
493 (concat (mapconcat 'identity (butlast connected-servers) ", ")
494 ", and "
495 (car (last connected-servers)))
496 (car connected-servers)))))))
498 ;;;###autoload
499 (defalias 'irc 'rcirc)
502 (defvar rcirc-process-output nil)
503 (defvar rcirc-topic nil)
504 (defvar rcirc-keepalive-timer nil)
505 (defvar rcirc-last-server-message-time nil)
506 (defvar rcirc-server nil) ; server provided by server
507 (defvar rcirc-server-name nil) ; server name given by 001 response
508 (defvar rcirc-timeout-timer nil)
509 (defvar rcirc-user-authenticated nil)
510 (defvar rcirc-user-disconnect nil)
511 (defvar rcirc-connecting nil)
512 (defvar rcirc-process nil)
514 ;;;###autoload
515 (defun rcirc-connect (server &optional port nick user-name
516 full-name startup-channels password encryption)
517 (save-excursion
518 (message "Connecting to %s..." server)
519 (let* ((inhibit-eol-conversion)
520 (port-number (if port
521 (if (stringp port)
522 (string-to-number port)
523 port)
524 rcirc-default-port))
525 (nick (or nick rcirc-default-nick))
526 (user-name (or user-name rcirc-default-user-name))
527 (full-name (or full-name rcirc-default-full-name))
528 (startup-channels startup-channels)
529 (process (open-network-stream
530 server nil server port-number
531 :type (or encryption 'plain))))
532 ;; set up process
533 (set-process-coding-system process 'raw-text 'raw-text)
534 (switch-to-buffer (rcirc-generate-new-buffer-name process nil))
535 (set-process-buffer process (current-buffer))
536 (rcirc-mode process nil)
537 (set-process-sentinel process 'rcirc-sentinel)
538 (set-process-filter process 'rcirc-filter)
540 (set (make-local-variable 'rcirc-process) process)
541 (set (make-local-variable 'rcirc-server) server)
542 (set (make-local-variable 'rcirc-server-name) server) ; Update when we get 001 response.
543 (set (make-local-variable 'rcirc-buffer-alist) nil)
544 (set (make-local-variable 'rcirc-nick-table)
545 (make-hash-table :test 'equal))
546 (set (make-local-variable 'rcirc-nick) nick)
547 (set (make-local-variable 'rcirc-process-output) nil)
548 (set (make-local-variable 'rcirc-startup-channels) startup-channels)
549 (set (make-local-variable 'rcirc-last-server-message-time)
550 (current-time))
552 (set (make-local-variable 'rcirc-timeout-timer) nil)
553 (set (make-local-variable 'rcirc-user-disconnect) nil)
554 (set (make-local-variable 'rcirc-user-authenticated) nil)
555 (set (make-local-variable 'rcirc-connecting) t)
557 (add-hook 'auto-save-hook 'rcirc-log-write)
559 ;; identify
560 (unless (zerop (length password))
561 (rcirc-send-string process (concat "PASS " password)))
562 (rcirc-send-string process (concat "NICK " nick))
563 (rcirc-send-string process (concat "USER " user-name
564 " 0 * :" full-name))
566 ;; setup ping timer if necessary
567 (unless rcirc-keepalive-timer
568 (setq rcirc-keepalive-timer
569 (run-at-time 0 (/ rcirc-timeout-seconds 2) 'rcirc-keepalive)))
571 (message "Connecting to %s...done" server)
573 ;; return process object
574 process)))
576 (defmacro with-rcirc-process-buffer (process &rest body)
577 (declare (indent 1) (debug t))
578 `(with-current-buffer (process-buffer ,process)
579 ,@body))
581 (defmacro with-rcirc-server-buffer (&rest body)
582 (declare (indent 0) (debug t))
583 `(with-current-buffer rcirc-server-buffer
584 ,@body))
586 (defun rcirc-float-time ()
587 (if (featurep 'xemacs)
588 (time-to-seconds (current-time))
589 (float-time)))
591 (defun rcirc-prompt-for-encryption (server-plist)
592 "Prompt the user for the encryption method to use.
593 SERVER-PLIST is the property list for the server."
594 (let ((msg "Encryption (default %s): ")
595 (choices '("plain" "tls"))
596 (default (or (plist-get server-plist :encryption)
597 'plain)))
598 (intern
599 (completing-read (format msg default)
600 choices nil t nil nil (symbol-name default)))))
602 (defun rcirc-keepalive ()
603 "Send keep alive pings to active rcirc processes.
604 Kill processes that have not received a server message since the
605 last ping."
606 (if (rcirc-process-list)
607 (mapc (lambda (process)
608 (with-rcirc-process-buffer process
609 (when (not rcirc-connecting)
610 (rcirc-send-ctcp process
611 rcirc-nick
612 (format "KEEPALIVE %f"
613 (rcirc-float-time))))))
614 (rcirc-process-list))
615 ;; no processes, clean up timer
616 (cancel-timer rcirc-keepalive-timer)
617 (setq rcirc-keepalive-timer nil)))
619 (defun rcirc-handler-ctcp-KEEPALIVE (process target sender message)
620 (with-rcirc-process-buffer process
621 (setq header-line-format (format "%f" (- (rcirc-float-time)
622 (string-to-number message))))))
624 (defvar rcirc-debug-buffer "*rcirc debug*")
625 (defvar rcirc-debug-flag nil
626 "If non-nil, write information to `rcirc-debug-buffer'.")
627 (defun rcirc-debug (process text)
628 "Add an entry to the debug log including PROCESS and TEXT.
629 Debug text is written to `rcirc-debug-buffer' if `rcirc-debug-flag'
630 is non-nil."
631 (when rcirc-debug-flag
632 (with-current-buffer (get-buffer-create rcirc-debug-buffer)
633 (goto-char (point-max))
634 (insert (concat
636 (format-time-string "%Y-%m-%dT%T ") (process-name process)
637 "] "
638 text)))))
640 (defvar rcirc-sentinel-hooks nil
641 "Hook functions called when the process sentinel is called.
642 Functions are called with PROCESS and SENTINEL arguments.")
644 (defun rcirc-sentinel (process sentinel)
645 "Called when PROCESS receives SENTINEL."
646 (let ((sentinel (replace-regexp-in-string "\n" "" sentinel)))
647 (rcirc-debug process (format "SENTINEL: %S %S\n" process sentinel))
648 (with-rcirc-process-buffer process
649 (dolist (buffer (cons nil (mapcar 'cdr rcirc-buffer-alist)))
650 (with-current-buffer (or buffer (current-buffer))
651 (rcirc-print process "rcirc.el" "ERROR" rcirc-target
652 (format "%s: %s (%S)"
653 (process-name process)
654 sentinel
655 (process-status process)) (not rcirc-target))
656 (rcirc-disconnect-buffer)))
657 (run-hook-with-args 'rcirc-sentinel-hooks process sentinel))))
659 (defun rcirc-disconnect-buffer (&optional buffer)
660 (with-current-buffer (or buffer (current-buffer))
661 ;; set rcirc-target to nil for each channel so cleanup
662 ;; doesnt happen when we reconnect
663 (setq rcirc-target nil)
664 (setq mode-line-process ":disconnected")))
666 (defun rcirc-process-list ()
667 "Return a list of rcirc processes."
668 (let (ps)
669 (mapc (lambda (p)
670 (when (buffer-live-p (process-buffer p))
671 (with-rcirc-process-buffer p
672 (when (eq major-mode 'rcirc-mode)
673 (setq ps (cons p ps))))))
674 (process-list))
675 ps))
677 (defvar rcirc-receive-message-hooks nil
678 "Hook functions run when a message is received from server.
679 Function is called with PROCESS, COMMAND, SENDER, ARGS and LINE.")
680 (defun rcirc-filter (process output)
681 "Called when PROCESS receives OUTPUT."
682 (rcirc-debug process output)
683 (rcirc-reschedule-timeout process)
684 (with-rcirc-process-buffer process
685 (setq rcirc-last-server-message-time (current-time))
686 (setq rcirc-process-output (concat rcirc-process-output output))
687 (when (= (aref rcirc-process-output
688 (1- (length rcirc-process-output))) ?\n)
689 (mapc (lambda (line)
690 (rcirc-process-server-response process line))
691 (split-string rcirc-process-output "[\n\r]" t))
692 (setq rcirc-process-output nil))))
694 (defun rcirc-reschedule-timeout (process)
695 (with-rcirc-process-buffer process
696 (when (not rcirc-connecting)
697 (with-rcirc-process-buffer process
698 (when rcirc-timeout-timer (cancel-timer rcirc-timeout-timer))
699 (setq rcirc-timeout-timer (run-at-time rcirc-timeout-seconds nil
700 'rcirc-delete-process
701 process))))))
703 (defun rcirc-delete-process (process)
704 (delete-process process))
706 (defvar rcirc-trap-errors-flag t)
707 (defun rcirc-process-server-response (process text)
708 (if rcirc-trap-errors-flag
709 (condition-case err
710 (rcirc-process-server-response-1 process text)
711 (error
712 (rcirc-print process "RCIRC" "ERROR" nil
713 (format "\"%s\" %s" text err) t)))
714 (rcirc-process-server-response-1 process text)))
716 (defun rcirc-process-server-response-1 (process text)
717 (if (string-match "^\\(:\\([^ ]+\\) \\)?\\([^ ]+\\) \\(.+\\)$" text)
718 (let* ((user (match-string 2 text))
719 (sender (rcirc-user-nick user))
720 (cmd (match-string 3 text))
721 (args (match-string 4 text))
722 (handler (intern-soft (concat "rcirc-handler-" cmd))))
723 (string-match "^\\([^:]*\\):?\\(.+\\)?$" args)
724 (let* ((args1 (match-string 1 args))
725 (args2 (match-string 2 args))
726 (args (delq nil (append (split-string args1 " " t)
727 (list args2)))))
728 (if (not (fboundp handler))
729 (rcirc-handler-generic process cmd sender args text)
730 (funcall handler process sender args text))
731 (run-hook-with-args 'rcirc-receive-message-hooks
732 process cmd sender args text)))
733 (message "UNHANDLED: %s" text)))
735 (defvar rcirc-responses-no-activity '("305" "306")
736 "Responses that don't trigger activity in the mode-line indicator.")
738 (defun rcirc-handler-generic (process response sender args text)
739 "Generic server response handler."
740 (rcirc-print process sender response nil
741 (mapconcat 'identity (cdr args) " ")
742 (not (member response rcirc-responses-no-activity))))
744 (defun rcirc--connection-open-p (process)
745 (memq (process-status process) '(run open)))
747 (defun rcirc-send-string (process string)
748 "Send PROCESS a STRING plus a newline."
749 (let ((string (concat (encode-coding-string string rcirc-encode-coding-system)
750 "\n")))
751 (unless (rcirc--connection-open-p process)
752 (error "Network connection to %s is not open"
753 (process-name process)))
754 (rcirc-debug process string)
755 (process-send-string process string)))
757 (defun rcirc-send-privmsg (process target string)
758 (rcirc-send-string process (format "PRIVMSG %s :%s" target string)))
760 (defun rcirc-send-ctcp (process target request &optional args)
761 (let ((args (if args (concat " " args) "")))
762 (rcirc-send-privmsg process target
763 (format "\C-a%s%s\C-a" request args))))
765 (defun rcirc-buffer-process (&optional buffer)
766 "Return the process associated with channel BUFFER.
767 With no argument or nil as argument, use the current buffer."
768 (or (get-buffer-process (if buffer
769 (with-current-buffer buffer
770 rcirc-server-buffer)
771 rcirc-server-buffer))
772 rcirc-process))
774 (defun rcirc-server-name (process)
775 "Return PROCESS server name, given by the 001 response."
776 (with-rcirc-process-buffer process
777 (or rcirc-server-name
778 (warn "server name for process %S unknown" process))))
780 (defun rcirc-nick (process)
781 "Return PROCESS nick."
782 (with-rcirc-process-buffer process
783 (or rcirc-nick rcirc-default-nick)))
785 (defun rcirc-buffer-nick (&optional buffer)
786 "Return the nick associated with BUFFER.
787 With no argument or nil as argument, use the current buffer."
788 (with-current-buffer (or buffer (current-buffer))
789 (with-current-buffer rcirc-server-buffer
790 (or rcirc-nick rcirc-default-nick))))
792 (defvar rcirc-max-message-length 420
793 "Messages longer than this value will be split.")
795 (defun rcirc-send-message (process target message &optional noticep silent)
796 "Send TARGET associated with PROCESS a privmsg with text MESSAGE.
797 If NOTICEP is non-nil, send a notice instead of privmsg.
798 If SILENT is non-nil, do not print the message in any irc buffer."
799 ;; max message length is 512 including CRLF
800 (let* ((response (if noticep "NOTICE" "PRIVMSG"))
801 (oversize (> (length message) rcirc-max-message-length))
802 (text (if oversize
803 (substring message 0 rcirc-max-message-length)
804 message))
805 (text (if (string= text "")
807 text))
808 (more (if oversize
809 (substring message rcirc-max-message-length))))
810 (rcirc-get-buffer-create process target)
811 (rcirc-send-string process (concat response " " target " :" text))
812 (unless silent
813 (rcirc-print process (rcirc-nick process) response target text))
814 (when more (rcirc-send-message process target more noticep))))
816 (defvar rcirc-input-ring nil)
817 (defvar rcirc-input-ring-index 0)
818 (defun rcirc-prev-input-string (arg)
819 (ring-ref rcirc-input-ring (+ rcirc-input-ring-index arg)))
821 (defun rcirc-insert-prev-input (arg)
822 (interactive "p")
823 (when (<= rcirc-prompt-end-marker (point))
824 (delete-region rcirc-prompt-end-marker (point-max))
825 (insert (rcirc-prev-input-string 0))
826 (setq rcirc-input-ring-index (1+ rcirc-input-ring-index))))
828 (defun rcirc-insert-next-input (arg)
829 (interactive "p")
830 (when (<= rcirc-prompt-end-marker (point))
831 (delete-region rcirc-prompt-end-marker (point-max))
832 (setq rcirc-input-ring-index (1- rcirc-input-ring-index))
833 (insert (rcirc-prev-input-string -1))))
835 (defvar rcirc-server-commands
836 '("/admin" "/away" "/connect" "/die" "/error" "/info"
837 "/invite" "/ison" "/join" "/kick" "/kill" "/links"
838 "/list" "/lusers" "/mode" "/motd" "/names" "/nick"
839 "/notice" "/oper" "/part" "/pass" "/ping" "/pong"
840 "/privmsg" "/quit" "/rehash" "/restart" "/service" "/servlist"
841 "/server" "/squery" "/squit" "/stats" "/summon" "/time"
842 "/topic" "/trace" "/user" "/userhost" "/users" "/version"
843 "/wallops" "/who" "/whois" "/whowas")
844 "A list of user commands by IRC server.
845 The value defaults to RFCs 1459 and 2812.")
847 ;; /me and /ctcp are not defined by `defun-rcirc-command'.
848 (defvar rcirc-client-commands '("/me" "/ctcp")
849 "A list of user commands defined by IRC client rcirc.
850 The list is updated automatically by `defun-rcirc-command'.")
852 (defun rcirc-completion-at-point ()
853 "Function used for `completion-at-point-functions' in `rcirc-mode'."
854 (and (rcirc-looking-at-input)
855 (let* ((beg (save-excursion
856 (if (re-search-backward " " rcirc-prompt-end-marker t)
857 (1+ (point))
858 rcirc-prompt-end-marker)))
859 (table (if (and (= beg rcirc-prompt-end-marker)
860 (eq (char-after beg) ?/))
861 (delete-dups
862 (nconc (sort (copy-sequence rcirc-client-commands)
863 'string-lessp)
864 (sort (copy-sequence rcirc-server-commands)
865 'string-lessp)))
866 (rcirc-channel-nicks (rcirc-buffer-process)
867 rcirc-target))))
868 (list beg (point) table))))
870 (defvar rcirc-completions nil)
871 (defvar rcirc-completion-start nil)
873 (defun rcirc-complete ()
874 "Cycle through completions from list of nicks in channel or IRC commands.
875 IRC command completion is performed only if '/' is the first input char."
876 (interactive)
877 (unless (rcirc-looking-at-input)
878 (error "Point not located after rcirc prompt"))
879 (if (eq last-command this-command)
880 (setq rcirc-completions
881 (append (cdr rcirc-completions) (list (car rcirc-completions))))
882 (let ((completion-ignore-case t)
883 (table (rcirc-completion-at-point)))
884 (setq rcirc-completion-start (car table))
885 (setq rcirc-completions
886 (and rcirc-completion-start
887 (all-completions (buffer-substring rcirc-completion-start
888 (cadr table))
889 (nth 2 table))))))
890 (let ((completion (car rcirc-completions)))
891 (when completion
892 (delete-region rcirc-completion-start (point))
893 (insert
894 (cond
895 ((= (aref completion 0) ?/) (concat completion " "))
896 ((= rcirc-completion-start rcirc-prompt-end-marker)
897 (format rcirc-nick-completion-format completion))
898 (t completion))))))
900 (defun set-rcirc-decode-coding-system (coding-system)
901 "Set the decode coding system used in this channel."
902 (interactive "zCoding system for incoming messages: ")
903 (set (make-local-variable 'rcirc-decode-coding-system) coding-system))
905 (defun set-rcirc-encode-coding-system (coding-system)
906 "Set the encode coding system used in this channel."
907 (interactive "zCoding system for outgoing messages: ")
908 (set (make-local-variable 'rcirc-encode-coding-system) coding-system))
910 (defvar rcirc-mode-map
911 (let ((map (make-sparse-keymap)))
912 (define-key map (kbd "RET") 'rcirc-send-input)
913 (define-key map (kbd "M-p") 'rcirc-insert-prev-input)
914 (define-key map (kbd "M-n") 'rcirc-insert-next-input)
915 (define-key map (kbd "TAB") 'rcirc-complete)
916 (define-key map (kbd "C-c C-b") 'rcirc-browse-url)
917 (define-key map (kbd "C-c C-c") 'rcirc-edit-multiline)
918 (define-key map (kbd "C-c C-j") 'rcirc-cmd-join)
919 (define-key map (kbd "C-c C-k") 'rcirc-cmd-kick)
920 (define-key map (kbd "C-c C-l") 'rcirc-toggle-low-priority)
921 (define-key map (kbd "C-c C-d") 'rcirc-cmd-mode)
922 (define-key map (kbd "C-c C-m") 'rcirc-cmd-msg)
923 (define-key map (kbd "C-c C-r") 'rcirc-cmd-nick) ; rename
924 (define-key map (kbd "C-c C-o") 'rcirc-omit-mode)
925 (define-key map (kbd "C-c C-p") 'rcirc-cmd-part)
926 (define-key map (kbd "C-c C-q") 'rcirc-cmd-query)
927 (define-key map (kbd "C-c C-t") 'rcirc-cmd-topic)
928 (define-key map (kbd "C-c C-n") 'rcirc-cmd-names)
929 (define-key map (kbd "C-c C-w") 'rcirc-cmd-whois)
930 (define-key map (kbd "C-c C-x") 'rcirc-cmd-quit)
931 (define-key map (kbd "C-c TAB") ; C-i
932 'rcirc-toggle-ignore-buffer-activity)
933 (define-key map (kbd "C-c C-s") 'rcirc-switch-to-server-buffer)
934 (define-key map (kbd "C-c C-a") 'rcirc-jump-to-first-unread-line)
935 map)
936 "Keymap for rcirc mode.")
938 (defvar rcirc-browse-url-map
939 (let ((map (make-sparse-keymap)))
940 (define-key map (kbd "RET") 'rcirc-browse-url-at-point)
941 (define-key map (kbd "<mouse-2>") 'rcirc-browse-url-at-mouse)
942 (define-key map [follow-link] 'mouse-face)
943 map)
944 "Keymap used for browsing URLs in `rcirc-mode'.")
946 (defvar rcirc-short-buffer-name nil
947 "Generated abbreviation to use to indicate buffer activity.")
949 (defvar rcirc-mode-hook nil
950 "Hook run when setting up rcirc buffer.")
952 (defvar rcirc-last-post-time nil)
954 (defvar rcirc-log-alist nil
955 "Alist of lines to log to disk when `rcirc-log-flag' is non-nil.
956 Each element looks like (FILENAME . TEXT).")
958 (defvar rcirc-current-line 0
959 "The current number of responses printed in this channel.
960 This number is independent of the number of lines in the buffer.")
962 (defun rcirc-mode (process target)
963 ;; FIXME: Use define-derived-mode.
964 "Major mode for IRC channel buffers.
966 \\{rcirc-mode-map}"
967 (kill-all-local-variables)
968 (use-local-map rcirc-mode-map)
969 (setq mode-name "rcirc")
970 (setq major-mode 'rcirc-mode)
971 (setq mode-line-process nil)
973 (set (make-local-variable 'rcirc-input-ring)
974 (make-ring rcirc-input-ring-size))
975 (set (make-local-variable 'rcirc-server-buffer) (process-buffer process))
976 (set (make-local-variable 'rcirc-target) target)
977 (set (make-local-variable 'rcirc-topic) nil)
978 (set (make-local-variable 'rcirc-last-post-time) (current-time))
979 (set (make-local-variable 'fill-paragraph-function) 'rcirc-fill-paragraph)
980 (set (make-local-variable 'rcirc-recent-quit-alist) nil)
981 (set (make-local-variable 'rcirc-current-line) 0)
983 (set (make-local-variable 'rcirc-short-buffer-name) nil)
984 (set (make-local-variable 'rcirc-urls) nil)
986 ;; setup for omitting responses
987 (setq buffer-invisibility-spec '())
988 (setq buffer-display-table (make-display-table))
989 (set-display-table-slot buffer-display-table 4
990 (let ((glyph (make-glyph-code
991 ?. 'font-lock-keyword-face)))
992 (make-vector 3 glyph)))
994 (dolist (i rcirc-coding-system-alist)
995 (let ((chan (if (consp (car i)) (caar i) (car i)))
996 (serv (if (consp (car i)) (cdar i) "")))
997 (when (and (string-match chan (or target ""))
998 (string-match serv (rcirc-server-name process)))
999 (set (make-local-variable 'rcirc-decode-coding-system)
1000 (if (consp (cdr i)) (cadr i) (cdr i)))
1001 (set (make-local-variable 'rcirc-encode-coding-system)
1002 (if (consp (cdr i)) (cddr i) (cdr i))))))
1004 ;; setup the prompt and markers
1005 (set (make-local-variable 'rcirc-prompt-start-marker) (point-max-marker))
1006 (set (make-local-variable 'rcirc-prompt-end-marker) (point-max-marker))
1007 (rcirc-update-prompt)
1008 (goto-char rcirc-prompt-end-marker)
1010 (set (make-local-variable 'overlay-arrow-position) (make-marker))
1012 ;; if the user changes the major mode or kills the buffer, there is
1013 ;; cleanup work to do
1014 (add-hook 'change-major-mode-hook 'rcirc-change-major-mode-hook nil t)
1015 (add-hook 'kill-buffer-hook 'rcirc-kill-buffer-hook nil t)
1017 ;; add to buffer list, and update buffer abbrevs
1018 (when target ; skip server buffer
1019 (let ((buffer (current-buffer)))
1020 (with-rcirc-process-buffer process
1021 (setq rcirc-buffer-alist (cons (cons target buffer)
1022 rcirc-buffer-alist))))
1023 (rcirc-update-short-buffer-names))
1025 (add-hook 'completion-at-point-functions
1026 'rcirc-completion-at-point nil 'local)
1028 (run-mode-hooks 'rcirc-mode-hook))
1030 (defun rcirc-update-prompt (&optional all)
1031 "Reset the prompt string in the current buffer.
1033 If ALL is non-nil, update prompts in all IRC buffers."
1034 (if all
1035 (mapc (lambda (process)
1036 (mapc (lambda (buffer)
1037 (with-current-buffer buffer
1038 (rcirc-update-prompt)))
1039 (with-rcirc-process-buffer process
1040 (mapcar 'cdr rcirc-buffer-alist))))
1041 (rcirc-process-list))
1042 (let ((inhibit-read-only t)
1043 (prompt (or rcirc-prompt "")))
1044 (mapc (lambda (rep)
1045 (setq prompt
1046 (replace-regexp-in-string (car rep) (cdr rep) prompt)))
1047 (list (cons "%n" (rcirc-buffer-nick))
1048 (cons "%s" (with-rcirc-server-buffer rcirc-server-name))
1049 (cons "%t" (or rcirc-target ""))))
1050 (save-excursion
1051 (delete-region rcirc-prompt-start-marker rcirc-prompt-end-marker)
1052 (goto-char rcirc-prompt-start-marker)
1053 (let ((start (point)))
1054 (insert-before-markers prompt)
1055 (set-marker rcirc-prompt-start-marker start)
1056 (when (not (zerop (- rcirc-prompt-end-marker
1057 rcirc-prompt-start-marker)))
1058 (add-text-properties rcirc-prompt-start-marker
1059 rcirc-prompt-end-marker
1060 (list 'face 'rcirc-prompt
1061 'read-only t 'field t
1062 'front-sticky t 'rear-nonsticky t))))))))
1064 (defun rcirc-set-changed (option value)
1065 "Set OPTION to VALUE and do updates after a customization change."
1066 (set-default option value)
1067 (cond ((eq option 'rcirc-prompt)
1068 (rcirc-update-prompt 'all))
1070 (error "Bad option %s" option))))
1072 (defun rcirc-channel-p (target)
1073 "Return t if TARGET is a channel name."
1074 (and target
1075 (not (zerop (length target)))
1076 (or (eq (aref target 0) ?#)
1077 (eq (aref target 0) ?&))))
1079 (defcustom rcirc-log-directory "~/.emacs.d/rcirc-log"
1080 "Directory to keep IRC logfiles."
1081 :type 'directory
1082 :group 'rcirc)
1084 (defcustom rcirc-log-flag nil
1085 "Non-nil means log IRC activity to disk.
1086 Logfiles are kept in `rcirc-log-directory'."
1087 :type 'boolean
1088 :group 'rcirc)
1090 (defun rcirc-kill-buffer-hook ()
1091 "Part the channel when killing an rcirc buffer."
1092 (when (eq major-mode 'rcirc-mode)
1093 (when (and rcirc-log-flag
1094 rcirc-log-directory)
1095 (rcirc-log-write))
1096 (rcirc-clean-up-buffer "Killed buffer")))
1098 (defun rcirc-change-major-mode-hook ()
1099 "Part the channel when changing the major-mode."
1100 (rcirc-clean-up-buffer "Changed major mode"))
1102 (defun rcirc-clean-up-buffer (reason)
1103 (let ((buffer (current-buffer)))
1104 (rcirc-clear-activity buffer)
1105 (when (and (rcirc-buffer-process)
1106 (rcirc--connection-open-p (rcirc-buffer-process)))
1107 (with-rcirc-server-buffer
1108 (setq rcirc-buffer-alist
1109 (rassq-delete-all buffer rcirc-buffer-alist)))
1110 (rcirc-update-short-buffer-names)
1111 (if (rcirc-channel-p rcirc-target)
1112 (rcirc-send-string (rcirc-buffer-process)
1113 (concat "PART " rcirc-target " :" reason))
1114 (when rcirc-target
1115 (rcirc-remove-nick-channel (rcirc-buffer-process)
1116 (rcirc-buffer-nick)
1117 rcirc-target))))
1118 (setq rcirc-target nil)))
1120 (defun rcirc-generate-new-buffer-name (process target)
1121 "Return a buffer name based on PROCESS and TARGET.
1122 This is used for the initial name given to IRC buffers."
1123 (substring-no-properties
1124 (if target
1125 (concat target "@" (process-name process))
1126 (concat "*" (process-name process) "*"))))
1128 (defun rcirc-get-buffer (process target &optional server)
1129 "Return the buffer associated with the PROCESS and TARGET.
1131 If optional argument SERVER is non-nil, return the server buffer
1132 if there is no existing buffer for TARGET, otherwise return nil."
1133 (with-rcirc-process-buffer process
1134 (if (null target)
1135 (current-buffer)
1136 (let ((buffer (cdr (assoc-string target rcirc-buffer-alist t))))
1137 (or buffer (when server (current-buffer)))))))
1139 (defun rcirc-get-buffer-create (process target)
1140 "Return the buffer associated with the PROCESS and TARGET.
1141 Create the buffer if it doesn't exist."
1142 (let ((buffer (rcirc-get-buffer process target)))
1143 (if (and buffer (buffer-live-p buffer))
1144 (with-current-buffer buffer
1145 (when (not rcirc-target)
1146 (setq rcirc-target target))
1147 buffer)
1148 ;; create the buffer
1149 (with-rcirc-process-buffer process
1150 (let ((new-buffer (get-buffer-create
1151 (rcirc-generate-new-buffer-name process target))))
1152 (with-current-buffer new-buffer
1153 (rcirc-mode process target)
1154 (rcirc-put-nick-channel process (rcirc-nick process) target
1155 rcirc-current-line))
1156 new-buffer)))))
1158 (defun rcirc-send-input ()
1159 "Send input to target associated with the current buffer."
1160 (interactive)
1161 (if (< (point) rcirc-prompt-end-marker)
1162 ;; copy the line down to the input area
1163 (progn
1164 (forward-line 0)
1165 (let ((start (if (eq (point) (point-min))
1166 (point)
1167 (if (get-text-property (1- (point)) 'hard)
1168 (point)
1169 (previous-single-property-change (point) 'hard))))
1170 (end (next-single-property-change (1+ (point)) 'hard)))
1171 (goto-char (point-max))
1172 (insert (replace-regexp-in-string
1173 "\n\\s-+" " "
1174 (buffer-substring-no-properties start end)))))
1175 ;; process input
1176 (goto-char (point-max))
1177 (when (not (equal 0 (- (point) rcirc-prompt-end-marker)))
1178 ;; delete a trailing newline
1179 (when (eq (point) (point-at-bol))
1180 (delete-char -1))
1181 (let ((input (buffer-substring-no-properties
1182 rcirc-prompt-end-marker (point))))
1183 (dolist (line (split-string input "\n"))
1184 (rcirc-process-input-line line))
1185 ;; add to input-ring
1186 (save-excursion
1187 (ring-insert rcirc-input-ring input)
1188 (setq rcirc-input-ring-index 0))))))
1190 (defun rcirc-fill-paragraph (&optional arg)
1191 (interactive "p")
1192 (when (> (point) rcirc-prompt-end-marker)
1193 (save-restriction
1194 (narrow-to-region rcirc-prompt-end-marker (point-max))
1195 (let ((fill-column rcirc-max-message-length))
1196 (fill-region (point-min) (point-max))))))
1198 (defun rcirc-process-input-line (line)
1199 (if (string-match "^/\\([^ ]+\\) ?\\(.*\\)$" line)
1200 (rcirc-process-command (match-string 1 line)
1201 (match-string 2 line)
1202 line)
1203 (rcirc-process-message line)))
1205 (defun rcirc-process-message (line)
1206 (if (not rcirc-target)
1207 (message "Not joined (no target)")
1208 (delete-region rcirc-prompt-end-marker (point))
1209 (rcirc-send-message (rcirc-buffer-process) rcirc-target line)
1210 (setq rcirc-last-post-time (current-time))))
1212 (defun rcirc-process-command (command args line)
1213 (if (eq (aref command 0) ?/)
1214 ;; "//text" will send "/text" as a message
1215 (rcirc-process-message (substring line 1))
1216 (let ((fun (intern-soft (concat "rcirc-cmd-" command)))
1217 (process (rcirc-buffer-process)))
1218 (newline)
1219 (with-current-buffer (current-buffer)
1220 (delete-region rcirc-prompt-end-marker (point))
1221 (if (string= command "me")
1222 (rcirc-print process (rcirc-buffer-nick)
1223 "ACTION" rcirc-target args)
1224 (rcirc-print process (rcirc-buffer-nick)
1225 "COMMAND" rcirc-target line))
1226 (set-marker rcirc-prompt-end-marker (point))
1227 (if (fboundp fun)
1228 (funcall fun args process rcirc-target)
1229 (rcirc-send-string process
1230 (concat command " :" args)))))))
1232 (defvar rcirc-parent-buffer nil)
1233 (make-variable-buffer-local 'rcirc-parent-buffer)
1234 (put 'rcirc-parent-buffer 'permanent-local t)
1235 (defvar rcirc-window-configuration nil)
1236 (defun rcirc-edit-multiline ()
1237 "Move current edit to a dedicated buffer."
1238 (interactive)
1239 (let ((pos (1+ (- (point) rcirc-prompt-end-marker))))
1240 (goto-char (point-max))
1241 (let ((text (buffer-substring-no-properties rcirc-prompt-end-marker
1242 (point)))
1243 (parent (buffer-name)))
1244 (delete-region rcirc-prompt-end-marker (point))
1245 (setq rcirc-window-configuration (current-window-configuration))
1246 (pop-to-buffer (concat "*multiline " parent "*"))
1247 (funcall rcirc-multiline-major-mode)
1248 (rcirc-multiline-minor-mode 1)
1249 (setq rcirc-parent-buffer parent)
1250 (insert text)
1251 (and (> pos 0) (goto-char pos))
1252 (message "Type C-c C-c to return text to %s, or C-c C-k to cancel" parent))))
1254 (defvar rcirc-multiline-minor-mode-map
1255 (let ((map (make-sparse-keymap)))
1256 (define-key map (kbd "C-c C-c") 'rcirc-multiline-minor-submit)
1257 (define-key map (kbd "C-x C-s") 'rcirc-multiline-minor-submit)
1258 (define-key map (kbd "C-c C-k") 'rcirc-multiline-minor-cancel)
1259 (define-key map (kbd "ESC ESC ESC") 'rcirc-multiline-minor-cancel)
1260 map)
1261 "Keymap for multiline mode in rcirc.")
1263 (define-minor-mode rcirc-multiline-minor-mode
1264 "Minor mode for editing multiple lines in rcirc."
1265 :init-value nil
1266 :lighter " rcirc-mline"
1267 :keymap rcirc-multiline-minor-mode-map
1268 :global nil
1269 :group 'rcirc
1270 (setq fill-column rcirc-max-message-length))
1272 (defun rcirc-multiline-minor-submit ()
1273 "Send the text in buffer back to parent buffer."
1274 (interactive)
1275 (untabify (point-min) (point-max))
1276 (let ((text (buffer-substring (point-min) (point-max)))
1277 (buffer (current-buffer))
1278 (pos (point)))
1279 (set-buffer rcirc-parent-buffer)
1280 (goto-char (point-max))
1281 (insert text)
1282 (kill-buffer buffer)
1283 (set-window-configuration rcirc-window-configuration)
1284 (goto-char (+ rcirc-prompt-end-marker (1- pos)))))
1286 (defun rcirc-multiline-minor-cancel ()
1287 "Cancel the multiline edit."
1288 (interactive)
1289 (kill-buffer (current-buffer))
1290 (set-window-configuration rcirc-window-configuration))
1292 (defun rcirc-any-buffer (process)
1293 "Return a buffer for PROCESS, either the one selected or the process buffer."
1294 (if rcirc-always-use-server-buffer-flag
1295 (process-buffer process)
1296 (let ((buffer (window-buffer (selected-window))))
1297 (if (and buffer
1298 (with-current-buffer buffer
1299 (and (eq major-mode 'rcirc-mode)
1300 (eq (rcirc-buffer-process) process))))
1301 buffer
1302 (process-buffer process)))))
1304 (defcustom rcirc-response-formats
1305 '(("PRIVMSG" . "<%N> %m")
1306 ("NOTICE" . "-%N- %m")
1307 ("ACTION" . "[%N %m]")
1308 ("COMMAND" . "%m")
1309 ("ERROR" . "%fw!!! %m")
1310 (t . "%fp*** %fs%n %r %m"))
1311 "An alist of formats used for printing responses.
1312 The format is looked up using the response-type as a key;
1313 if no match is found, the default entry (with a key of `t') is used.
1315 The entry's value part should be a string, which is inserted with
1316 the of the following escape sequences replaced by the described values:
1318 %m The message text
1319 %n The sender's nick
1320 %N The sender's nick (with face `rcirc-my-nick' or `rcirc-other-nick')
1321 %r The response-type
1322 %t The target
1323 %fw Following text uses the face `font-lock-warning-face'
1324 %fp Following text uses the face `rcirc-server-prefix'
1325 %fs Following text uses the face `rcirc-server'
1326 %f[FACE] Following text uses the face FACE
1327 %f- Following text uses the default face
1328 %% A literal `%' character"
1329 :type '(alist :key-type (choice (string :tag "Type")
1330 (const :tag "Default" t))
1331 :value-type string)
1332 :group 'rcirc)
1334 (defcustom rcirc-omit-responses
1335 '("JOIN" "PART" "QUIT" "NICK")
1336 "Responses which will be hidden when `rcirc-omit-mode' is enabled."
1337 :type '(repeat string)
1338 :group 'rcirc)
1340 (defun rcirc-format-response-string (process sender response target text)
1341 "Return a nicely-formatted response string, incorporating TEXT
1342 \(and perhaps other arguments). The specific formatting used
1343 is found by looking up RESPONSE in `rcirc-response-formats'."
1344 (with-temp-buffer
1345 (insert (or (cdr (assoc response rcirc-response-formats))
1346 (cdr (assq t rcirc-response-formats))))
1347 (goto-char (point-min))
1348 (let ((start (point-min))
1349 (sender (if (or (not sender)
1350 (string= (rcirc-server-name process) sender))
1352 sender))
1353 face)
1354 (while (re-search-forward "%\\(\\(f\\(.\\)\\)\\|\\(.\\)\\)" nil t)
1355 (rcirc-add-face start (match-beginning 0) face)
1356 (setq start (match-beginning 0))
1357 (replace-match
1358 (case (aref (match-string 1) 0)
1359 (?f (setq face
1360 (case (string-to-char (match-string 3))
1361 (?w 'font-lock-warning-face)
1362 (?p 'rcirc-server-prefix)
1363 (?s 'rcirc-server)
1364 (t nil)))
1366 (?n sender)
1367 (?N (let ((my-nick (rcirc-nick process)))
1368 (save-match-data
1369 (with-syntax-table rcirc-nick-syntax-table
1370 (rcirc-facify sender
1371 (cond ((string= sender my-nick)
1372 'rcirc-my-nick)
1373 ((and rcirc-bright-nicks
1374 (string-match
1375 (regexp-opt rcirc-bright-nicks
1376 'words)
1377 sender))
1378 'rcirc-bright-nick)
1379 ((and rcirc-dim-nicks
1380 (string-match
1381 (regexp-opt rcirc-dim-nicks
1382 'words)
1383 sender))
1384 'rcirc-dim-nick)
1386 'rcirc-other-nick)))))))
1387 (?m (propertize text 'rcirc-text text))
1388 (?r response)
1389 (?t (or target ""))
1390 (t (concat "UNKNOWN CODE:" (match-string 0))))
1391 t t nil 0)
1392 (rcirc-add-face (match-beginning 0) (match-end 0) face))
1393 (rcirc-add-face start (match-beginning 0) face))
1394 (buffer-substring (point-min) (point-max))))
1396 (defun rcirc-target-buffer (process sender response target text)
1397 "Return a buffer to print the server response."
1398 (assert (not (bufferp target)))
1399 (with-rcirc-process-buffer process
1400 (cond ((not target)
1401 (rcirc-any-buffer process))
1402 ((not (rcirc-channel-p target))
1403 ;; message from another user
1404 (if (or (string= response "PRIVMSG")
1405 (string= response "ACTION"))
1406 (rcirc-get-buffer-create process (if (string= sender rcirc-nick)
1407 target
1408 sender))
1409 (rcirc-get-buffer process target t)))
1410 ((or (rcirc-get-buffer process target)
1411 (rcirc-any-buffer process))))))
1413 (defvar rcirc-activity-types nil)
1414 (make-variable-buffer-local 'rcirc-activity-types)
1415 (defvar rcirc-last-sender nil)
1416 (make-variable-buffer-local 'rcirc-last-sender)
1418 (defcustom rcirc-omit-threshold 100
1419 "Number of lines since last activity from a nick before `rcirc-omit-responses' are omitted."
1420 :type 'integer
1421 :group 'rcirc)
1423 (defcustom rcirc-log-process-buffers nil
1424 "Non-nil if rcirc process buffers should be logged to disk."
1425 :group 'rcirc
1426 :type 'boolean
1427 :version "24.1")
1429 (defun rcirc-last-quit-line (process nick target)
1430 "Return the line number where NICK left TARGET.
1431 Returns nil if the information is not recorded."
1432 (let ((chanbuf (rcirc-get-buffer process target)))
1433 (when chanbuf
1434 (cdr (assoc-string nick (with-current-buffer chanbuf
1435 rcirc-recent-quit-alist))))))
1437 (defun rcirc-last-line (process nick target)
1438 "Return the line from the last activity from NICK in TARGET."
1439 (let* ((chanbuf (rcirc-get-buffer process target))
1440 (line (or (cdr (assoc-string target
1441 (gethash nick (with-rcirc-server-buffer
1442 rcirc-nick-table)) t))
1443 (rcirc-last-quit-line process nick target))))
1444 (if line
1445 line
1446 ;;(message "line is nil for %s in %s" nick target)
1447 nil)))
1449 (defun rcirc-elapsed-lines (process nick target)
1450 "Return the number of lines since activity from NICK in TARGET."
1451 (let ((last-activity-line (rcirc-last-line process nick target)))
1452 (when (and last-activity-line
1453 (> last-activity-line 0))
1454 (- rcirc-current-line last-activity-line))))
1456 (defvar rcirc-markup-text-functions
1457 '(rcirc-markup-attributes
1458 rcirc-markup-my-nick
1459 rcirc-markup-urls
1460 rcirc-markup-keywords
1461 rcirc-markup-bright-nicks)
1463 "List of functions used to manipulate text before it is printed.
1465 Each function takes two arguments, SENDER, and RESPONSE. The
1466 buffer is narrowed with the text to be printed and the point is
1467 at the beginning of the `rcirc-text' propertized text.")
1469 (defun rcirc-print (process sender response target text &optional activity)
1470 "Print TEXT in the buffer associated with TARGET.
1471 Format based on SENDER and RESPONSE. If ACTIVITY is non-nil,
1472 record activity."
1473 (or text (setq text ""))
1474 (unless (and (or (member sender rcirc-ignore-list)
1475 (member (with-syntax-table rcirc-nick-syntax-table
1476 (when (string-match "^\\([^/]\\w*\\)[:,]" text)
1477 (match-string 1 text)))
1478 rcirc-ignore-list))
1479 ;; do not ignore if we sent the message
1480 (not (string= sender (rcirc-nick process))))
1481 (let* ((buffer (rcirc-target-buffer process sender response target text))
1482 (inhibit-read-only t))
1483 (with-current-buffer buffer
1484 (let ((moving (= (point) rcirc-prompt-end-marker))
1485 (old-point (point-marker))
1486 (fill-start (marker-position rcirc-prompt-start-marker)))
1488 (setq text (decode-coding-string text rcirc-decode-coding-system))
1489 (unless (string= sender (rcirc-nick process))
1490 ;; mark the line with overlay arrow
1491 (unless (or (marker-position overlay-arrow-position)
1492 (get-buffer-window (current-buffer))
1493 (member response rcirc-omit-responses))
1494 (set-marker overlay-arrow-position
1495 (marker-position rcirc-prompt-start-marker))))
1497 ;; temporarily set the marker insertion-type because
1498 ;; insert-before-markers results in hidden text in new buffers
1499 (goto-char rcirc-prompt-start-marker)
1500 (set-marker-insertion-type rcirc-prompt-start-marker t)
1501 (set-marker-insertion-type rcirc-prompt-end-marker t)
1503 (let ((start (point)))
1504 (insert (rcirc-format-response-string process sender response nil
1505 text)
1506 (propertize "\n" 'hard t))
1508 ;; squeeze spaces out of text before rcirc-text
1509 (fill-region fill-start
1510 (1- (or (next-single-property-change fill-start
1511 'rcirc-text)
1512 rcirc-prompt-end-marker)))
1514 ;; run markup functions
1515 (save-excursion
1516 (save-restriction
1517 (narrow-to-region start rcirc-prompt-start-marker)
1518 (goto-char (or (next-single-property-change start 'rcirc-text)
1519 (point)))
1520 (when (rcirc-buffer-process)
1521 (save-excursion (rcirc-markup-timestamp sender response))
1522 (dolist (fn rcirc-markup-text-functions)
1523 (save-excursion (funcall fn sender response)))
1524 (when rcirc-fill-flag
1525 (save-excursion (rcirc-markup-fill sender response))))
1527 (when rcirc-read-only-flag
1528 (add-text-properties (point-min) (point-max)
1529 '(read-only t front-sticky t))))
1530 ;; make text omittable
1531 (let ((last-activity-lines (rcirc-elapsed-lines process sender target)))
1532 (if (and (not (string= (rcirc-nick process) sender))
1533 (member response rcirc-omit-responses)
1534 (or (not last-activity-lines)
1535 (< rcirc-omit-threshold last-activity-lines)))
1536 (put-text-property (1- start) (1- rcirc-prompt-start-marker)
1537 'invisible 'rcirc-omit)
1538 ;; otherwise increment the line count
1539 (setq rcirc-current-line (1+ rcirc-current-line))))))
1541 (set-marker-insertion-type rcirc-prompt-start-marker nil)
1542 (set-marker-insertion-type rcirc-prompt-end-marker nil)
1544 ;; truncate buffer if it is very long
1545 (save-excursion
1546 (when (and rcirc-buffer-maximum-lines
1547 (> rcirc-buffer-maximum-lines 0)
1548 (= (forward-line (- rcirc-buffer-maximum-lines)) 0))
1549 (delete-region (point-min) (point))))
1551 ;; set the window point for buffers show in windows
1552 (walk-windows (lambda (w)
1553 (when (and (not (eq (selected-window) w))
1554 (eq (current-buffer)
1555 (window-buffer w))
1556 (>= (window-point w)
1557 rcirc-prompt-end-marker))
1558 (set-window-point w (point-max))))
1559 nil t)
1561 ;; restore the point
1562 (goto-char (if moving rcirc-prompt-end-marker old-point))
1564 ;; keep window on bottom line if it was already there
1565 (when rcirc-scroll-show-maximum-output
1566 (walk-windows (lambda (w)
1567 (when (eq (window-buffer w) (current-buffer))
1568 (with-current-buffer (window-buffer w)
1569 (when (eq major-mode 'rcirc-mode)
1570 (with-selected-window w
1571 (when (<= (- (window-height)
1572 (count-screen-lines (window-point)
1573 (window-start))
1576 (recenter -1)))))))
1577 nil t))
1579 ;; flush undo (can we do something smarter here?)
1580 (buffer-disable-undo)
1581 (buffer-enable-undo))
1583 ;; record modeline activity
1584 (when (and activity
1585 (not rcirc-ignore-buffer-activity-flag)
1586 (not (and rcirc-dim-nicks sender
1587 (string-match (regexp-opt rcirc-dim-nicks) sender)
1588 (rcirc-channel-p target))))
1589 (rcirc-record-activity (current-buffer)
1590 (when (not (rcirc-channel-p rcirc-target))
1591 'nick)))
1593 (when (and rcirc-log-flag
1594 (or target
1595 rcirc-log-process-buffers))
1596 (rcirc-log process sender response target text))
1598 (sit-for 0) ; displayed text before hook
1599 (run-hook-with-args 'rcirc-print-hooks
1600 process sender response target text)))))
1602 (defun rcirc-generate-log-filename (process target)
1603 (if target
1604 (rcirc-generate-new-buffer-name process target)
1605 (process-name process)))
1607 (defcustom rcirc-log-filename-function 'rcirc-generate-log-filename
1608 "A function to generate the filename used by rcirc's logging facility.
1610 It is called with two arguments, PROCESS and TARGET (see
1611 `rcirc-generate-new-buffer-name' for their meaning), and should
1612 return the filename, or nil if no logging is desired for this
1613 session.
1615 If the returned filename is absolute (`file-name-absolute-p'
1616 returns t), then it is used as-is, otherwise the resulting file
1617 is put into `rcirc-log-directory'.
1619 The filename is then cleaned using `convert-standard-filename' to
1620 guarantee valid filenames for the current OS."
1621 :group 'rcirc
1622 :type 'function)
1624 (defun rcirc-log (process sender response target text)
1625 "Record line in `rcirc-log', to be later written to disk."
1626 (let ((filename (funcall rcirc-log-filename-function process target)))
1627 (unless (null filename)
1628 (let ((cell (assoc-string filename rcirc-log-alist))
1629 (line (concat (format-time-string rcirc-time-format)
1630 (substring-no-properties
1631 (rcirc-format-response-string process sender
1632 response target text))
1633 "\n")))
1634 (if cell
1635 (setcdr cell (concat (cdr cell) line))
1636 (setq rcirc-log-alist
1637 (cons (cons filename line) rcirc-log-alist)))))))
1639 (defun rcirc-log-write ()
1640 "Flush `rcirc-log-alist' data to disk.
1642 Log data is written to `rcirc-log-directory', except for
1643 log-files with absolute names (see `rcirc-log-filename-function')."
1644 (dolist (cell rcirc-log-alist)
1645 (let ((filename (convert-standard-filename
1646 (expand-file-name (car cell)
1647 rcirc-log-directory)))
1648 (coding-system-for-write 'utf-8))
1649 (make-directory (file-name-directory filename) t)
1650 (with-temp-buffer
1651 (insert (cdr cell))
1652 (write-region (point-min) (point-max) filename t 'quiet))))
1653 (setq rcirc-log-alist nil))
1655 (defun rcirc-view-log-file ()
1656 "View logfile corresponding to the current buffer."
1657 (interactive)
1658 (find-file-other-window
1659 (expand-file-name (funcall rcirc-log-filename-function
1660 (rcirc-buffer-process) rcirc-target)
1661 rcirc-log-directory)))
1663 (defun rcirc-join-channels (process channels)
1664 "Join CHANNELS."
1665 (save-window-excursion
1666 (dolist (channel channels)
1667 (with-rcirc-process-buffer process
1668 (rcirc-cmd-join channel process)))))
1670 ;;; nick management
1671 (defvar rcirc-nick-prefix-chars "~&@%+")
1672 (defun rcirc-user-nick (user)
1673 "Return the nick from USER. Remove any non-nick junk."
1674 (save-match-data
1675 (if (string-match (concat "^[" rcirc-nick-prefix-chars
1676 "]?\\([^! ]+\\)!?") (or user ""))
1677 (match-string 1 user)
1678 user)))
1680 (defun rcirc-nick-channels (process nick)
1681 "Return list of channels for NICK."
1682 (with-rcirc-process-buffer process
1683 (mapcar (lambda (x) (car x))
1684 (gethash nick rcirc-nick-table))))
1686 (defun rcirc-put-nick-channel (process nick channel &optional line)
1687 "Add CHANNEL to list associated with NICK.
1688 Update the associated linestamp if LINE is non-nil.
1690 If the record doesn't exist, and LINE is nil, set the linestamp
1691 to zero."
1692 (let ((nick (rcirc-user-nick nick)))
1693 (with-rcirc-process-buffer process
1694 (let* ((chans (gethash nick rcirc-nick-table))
1695 (record (assoc-string channel chans t)))
1696 (if record
1697 (when line (setcdr record line))
1698 (puthash nick (cons (cons channel (or line 0))
1699 chans)
1700 rcirc-nick-table))))))
1702 (defun rcirc-nick-remove (process nick)
1703 "Remove NICK from table."
1704 (with-rcirc-process-buffer process
1705 (remhash nick rcirc-nick-table)))
1707 (defun rcirc-remove-nick-channel (process nick channel)
1708 "Remove the CHANNEL from list associated with NICK."
1709 (with-rcirc-process-buffer process
1710 (let* ((chans (gethash nick rcirc-nick-table))
1711 (newchans
1712 ;; instead of assoc-string-delete-all:
1713 (let ((record (assoc-string channel chans t)))
1714 (when record
1715 (setcar record 'delete)
1716 (assq-delete-all 'delete chans)))))
1717 (if newchans
1718 (puthash nick newchans rcirc-nick-table)
1719 (remhash nick rcirc-nick-table)))))
1721 (defun rcirc-channel-nicks (process target)
1722 "Return the list of nicks associated with TARGET sorted by last activity."
1723 (when target
1724 (if (rcirc-channel-p target)
1725 (with-rcirc-process-buffer process
1726 (let (nicks)
1727 (maphash
1728 (lambda (k v)
1729 (let ((record (assoc-string target v t)))
1730 (if record
1731 (setq nicks (cons (cons k (cdr record)) nicks)))))
1732 rcirc-nick-table)
1733 (mapcar (lambda (x) (car x))
1734 (sort nicks (lambda (x y)
1735 (let ((lx (or (cdr x) 0))
1736 (ly (or (cdr y) 0)))
1737 (< ly lx)))))))
1738 (list target))))
1740 (defun rcirc-ignore-update-automatic (nick)
1741 "Remove NICK from `rcirc-ignore-list'
1742 if NICK is also on `rcirc-ignore-list-automatic'."
1743 (when (member nick rcirc-ignore-list-automatic)
1744 (setq rcirc-ignore-list-automatic
1745 (delete nick rcirc-ignore-list-automatic)
1746 rcirc-ignore-list
1747 (delete nick rcirc-ignore-list))))
1749 (defun rcirc-nickname< (s1 s2)
1750 "Return t if IRC nickname S1 is less than S2, and nil otherwise.
1751 Operator nicknames (@) are considered less than voiced
1752 nicknames (+). Any other nicknames are greater than voiced
1753 nicknames. The comparison is case-insensitive."
1754 (setq s1 (downcase s1)
1755 s2 (downcase s2))
1756 (let* ((s1-op (eq ?@ (string-to-char s1)))
1757 (s2-op (eq ?@ (string-to-char s2))))
1758 (if s1-op
1759 (if s2-op
1760 (string< (substring s1 1) (substring s2 1))
1762 (if s2-op
1764 (string< s1 s2)))))
1766 (defun rcirc-sort-nicknames-join (input sep)
1767 "Return a string of sorted nicknames.
1768 INPUT is a string containing nicknames separated by SEP.
1769 This function does not alter the INPUT string."
1770 (let* ((parts (split-string input sep t))
1771 (sorted (sort parts 'rcirc-nickname<)))
1772 (mapconcat 'identity sorted sep)))
1774 ;;; activity tracking
1775 (defvar rcirc-track-minor-mode-map
1776 (let ((map (make-sparse-keymap)))
1777 (define-key map (kbd "C-c C-@") 'rcirc-next-active-buffer)
1778 (define-key map (kbd "C-c C-SPC") 'rcirc-next-active-buffer)
1779 map)
1780 "Keymap for rcirc track minor mode.")
1782 ;;;###autoload
1783 (define-minor-mode rcirc-track-minor-mode
1784 "Global minor mode for tracking activity in rcirc buffers."
1785 :init-value nil
1786 :lighter ""
1787 :keymap rcirc-track-minor-mode-map
1788 :global t
1789 :group 'rcirc
1790 (or global-mode-string (setq global-mode-string '("")))
1791 ;; toggle the mode-line channel indicator
1792 (if rcirc-track-minor-mode
1793 (progn
1794 (and (not (memq 'rcirc-activity-string global-mode-string))
1795 (setq global-mode-string
1796 (append global-mode-string '(rcirc-activity-string))))
1797 (add-hook 'window-configuration-change-hook
1798 'rcirc-window-configuration-change))
1799 (setq global-mode-string
1800 (delete 'rcirc-activity-string global-mode-string))
1801 (remove-hook 'window-configuration-change-hook
1802 'rcirc-window-configuration-change)))
1804 (or (assq 'rcirc-ignore-buffer-activity-flag minor-mode-alist)
1805 (setq minor-mode-alist
1806 (cons '(rcirc-ignore-buffer-activity-flag " Ignore") minor-mode-alist)))
1807 (or (assq 'rcirc-low-priority-flag minor-mode-alist)
1808 (setq minor-mode-alist
1809 (cons '(rcirc-low-priority-flag " LowPri") minor-mode-alist)))
1810 (or (assq 'rcirc-omit-mode minor-mode-alist)
1811 (setq minor-mode-alist
1812 (cons '(rcirc-omit-mode " Omit") minor-mode-alist)))
1814 (defun rcirc-toggle-ignore-buffer-activity ()
1815 "Toggle the value of `rcirc-ignore-buffer-activity-flag'."
1816 (interactive)
1817 (setq rcirc-ignore-buffer-activity-flag
1818 (not rcirc-ignore-buffer-activity-flag))
1819 (message (if rcirc-ignore-buffer-activity-flag
1820 "Ignore activity in this buffer"
1821 "Notice activity in this buffer"))
1822 (force-mode-line-update))
1824 (defun rcirc-toggle-low-priority ()
1825 "Toggle the value of `rcirc-low-priority-flag'."
1826 (interactive)
1827 (setq rcirc-low-priority-flag
1828 (not rcirc-low-priority-flag))
1829 (message (if rcirc-low-priority-flag
1830 "Activity in this buffer is low priority"
1831 "Activity in this buffer is normal priority"))
1832 (force-mode-line-update))
1834 (defun rcirc-omit-mode ()
1835 "Toggle the Rcirc-Omit mode.
1836 If enabled, \"uninteresting\" lines are not shown.
1837 Uninteresting lines are those whose responses are listed in
1838 `rcirc-omit-responses'."
1839 (interactive)
1840 (setq rcirc-omit-mode (not rcirc-omit-mode))
1841 (if rcirc-omit-mode
1842 (progn
1843 (add-to-invisibility-spec '(rcirc-omit . nil))
1844 (message "Rcirc-Omit mode enabled"))
1845 (remove-from-invisibility-spec '(rcirc-omit . nil))
1846 (message "Rcirc-Omit mode disabled"))
1847 (recenter (when (> (point) rcirc-prompt-start-marker) -1)))
1849 (defun rcirc-switch-to-server-buffer ()
1850 "Switch to the server buffer associated with current channel buffer."
1851 (interactive)
1852 (unless (buffer-live-p rcirc-server-buffer)
1853 (error "No such buffer"))
1854 (switch-to-buffer rcirc-server-buffer))
1856 (defun rcirc-jump-to-first-unread-line ()
1857 "Move the point to the first unread line in this buffer."
1858 (interactive)
1859 (if (marker-position overlay-arrow-position)
1860 (goto-char overlay-arrow-position)
1861 (message "No unread messages")))
1863 (defun rcirc-non-irc-buffer ()
1864 (let ((buflist (buffer-list))
1865 buffer)
1866 (while (and buflist (not buffer))
1867 (with-current-buffer (car buflist)
1868 (unless (or (eq major-mode 'rcirc-mode)
1869 (= ?\s (aref (buffer-name) 0)) ; internal buffers
1870 (get-buffer-window (current-buffer)))
1871 (setq buffer (current-buffer))))
1872 (setq buflist (cdr buflist)))
1873 buffer))
1875 (defun rcirc-next-active-buffer (arg)
1876 "Switch to the next rcirc buffer with activity.
1877 With prefix ARG, go to the next low priority buffer with activity."
1878 (interactive "P")
1879 (let* ((pair (rcirc-split-activity rcirc-activity))
1880 (lopri (car pair))
1881 (hipri (cdr pair)))
1882 (if (or (and (not arg) hipri)
1883 (and arg lopri))
1884 (progn
1885 (switch-to-buffer (car (if arg lopri hipri)))
1886 (when (> (point) rcirc-prompt-start-marker)
1887 (recenter -1)))
1888 (if (eq major-mode 'rcirc-mode)
1889 (switch-to-buffer (rcirc-non-irc-buffer))
1890 (message "%s" (concat
1891 "No IRC activity."
1892 (when lopri
1893 (concat
1894 " Type C-u "
1895 (key-description (this-command-keys))
1896 " for low priority activity."))))))))
1898 (defvar rcirc-activity-hooks nil
1899 "Hook to be run when there is channel activity.
1901 Functions are called with a single argument, the buffer with the
1902 activity. Only run if the buffer is not visible and
1903 `rcirc-ignore-buffer-activity-flag' is non-nil.")
1905 (defun rcirc-record-activity (buffer &optional type)
1906 "Record BUFFER activity with TYPE."
1907 (with-current-buffer buffer
1908 (let ((old-activity rcirc-activity)
1909 (old-types rcirc-activity-types))
1910 (when (not (get-buffer-window (current-buffer) t))
1911 (setq rcirc-activity
1912 (sort (add-to-list 'rcirc-activity (current-buffer))
1913 (lambda (b1 b2)
1914 (let ((t1 (with-current-buffer b1 rcirc-last-post-time))
1915 (t2 (with-current-buffer b2 rcirc-last-post-time)))
1916 (time-less-p t2 t1)))))
1917 (pushnew type rcirc-activity-types)
1918 (unless (and (equal rcirc-activity old-activity)
1919 (member type old-types))
1920 (rcirc-update-activity-string)))))
1921 (run-hook-with-args 'rcirc-activity-hooks buffer))
1923 (defun rcirc-clear-activity (buffer)
1924 "Clear the BUFFER activity."
1925 (setq rcirc-activity (remove buffer rcirc-activity))
1926 (with-current-buffer buffer
1927 (setq rcirc-activity-types nil)))
1929 (defun rcirc-clear-unread (buffer)
1930 "Erase the last read message arrow from BUFFER."
1931 (when (buffer-live-p buffer)
1932 (with-current-buffer buffer
1933 (set-marker overlay-arrow-position nil))))
1935 (defun rcirc-split-activity (activity)
1936 "Return a cons cell with ACTIVITY split into (lopri . hipri)."
1937 (let (lopri hipri)
1938 (dolist (buf rcirc-activity)
1939 (with-current-buffer buf
1940 (if (and rcirc-low-priority-flag
1941 (not (member 'nick rcirc-activity-types)))
1942 (add-to-list 'lopri buf t)
1943 (add-to-list 'hipri buf t))))
1944 (cons lopri hipri)))
1946 (defvar rcirc-update-activity-string-hook nil
1947 "Hook run whenever the activity string is updated.")
1949 ;; TODO: add mouse properties
1950 (defun rcirc-update-activity-string ()
1951 "Update mode-line string."
1952 (let* ((pair (rcirc-split-activity rcirc-activity))
1953 (lopri (car pair))
1954 (hipri (cdr pair)))
1955 (setq rcirc-activity-string
1956 (cond ((or hipri lopri)
1957 (concat (and hipri "[")
1958 (rcirc-activity-string hipri)
1959 (and hipri lopri ",")
1960 (and lopri
1961 (concat "("
1962 (rcirc-activity-string lopri)
1963 ")"))
1964 (and hipri "]")))
1965 ((not (null (rcirc-process-list)))
1966 "[]")
1967 (t "[]")))
1968 (run-hooks 'rcirc-update-activity-string-hook)))
1970 (defun rcirc-activity-string (buffers)
1971 (mapconcat (lambda (b)
1972 (let ((s (substring-no-properties (rcirc-short-buffer-name b))))
1973 (with-current-buffer b
1974 (dolist (type rcirc-activity-types)
1975 (rcirc-add-face 0 (length s)
1976 (case type
1977 (nick 'rcirc-track-nick)
1978 (keyword 'rcirc-track-keyword))
1979 s)))
1981 buffers ","))
1983 (defun rcirc-short-buffer-name (buffer)
1984 "Return a short name for BUFFER to use in the modeline indicator."
1985 (with-current-buffer buffer
1986 (or rcirc-short-buffer-name (buffer-name))))
1988 (defun rcirc-visible-buffers ()
1989 "Return a list of the visible buffers that are in rcirc-mode."
1990 (let (acc)
1991 (walk-windows (lambda (w)
1992 (with-current-buffer (window-buffer w)
1993 (when (eq major-mode 'rcirc-mode)
1994 (push (current-buffer) acc)))))
1995 acc))
1997 (defvar rcirc-visible-buffers nil)
1998 (defun rcirc-window-configuration-change ()
1999 (unless (minibuffer-window-active-p (minibuffer-window))
2000 ;; delay this until command has finished to make sure window is
2001 ;; actually visible before clearing activity
2002 (add-hook 'post-command-hook 'rcirc-window-configuration-change-1)))
2004 (defun rcirc-window-configuration-change-1 ()
2005 ;; clear activity and overlay arrows
2006 (let* ((old-activity rcirc-activity)
2007 (hidden-buffers rcirc-visible-buffers))
2009 (setq rcirc-visible-buffers (rcirc-visible-buffers))
2011 (dolist (vbuf rcirc-visible-buffers)
2012 (setq hidden-buffers (delq vbuf hidden-buffers))
2013 ;; clear activity for all visible buffers
2014 (rcirc-clear-activity vbuf))
2016 ;; clear unread arrow from recently hidden buffers
2017 (dolist (hbuf hidden-buffers)
2018 (rcirc-clear-unread hbuf))
2020 ;; remove any killed buffers from list
2021 (setq rcirc-activity
2022 (delq nil (mapcar (lambda (buf) (when (buffer-live-p buf) buf))
2023 rcirc-activity)))
2024 ;; update the mode-line string
2025 (unless (equal old-activity rcirc-activity)
2026 (rcirc-update-activity-string)))
2028 (remove-hook 'post-command-hook 'rcirc-window-configuration-change-1))
2031 ;;; buffer name abbreviation
2032 (defun rcirc-update-short-buffer-names ()
2033 (let ((bufalist
2034 (apply 'append (mapcar (lambda (process)
2035 (with-rcirc-process-buffer process
2036 rcirc-buffer-alist))
2037 (rcirc-process-list)))))
2038 (dolist (i (rcirc-abbreviate bufalist))
2039 (when (buffer-live-p (cdr i))
2040 (with-current-buffer (cdr i)
2041 (setq rcirc-short-buffer-name (car i)))))))
2043 (defun rcirc-abbreviate (pairs)
2044 (apply 'append (mapcar 'rcirc-rebuild-tree (rcirc-make-trees pairs))))
2046 (defun rcirc-rebuild-tree (tree &optional acc)
2047 (let ((ch (char-to-string (car tree))))
2048 (dolist (x (cdr tree))
2049 (if (listp x)
2050 (setq acc (append acc
2051 (mapcar (lambda (y)
2052 (cons (concat ch (car y))
2053 (cdr y)))
2054 (rcirc-rebuild-tree x))))
2055 (setq acc (cons (cons ch x) acc))))
2056 acc))
2058 (defun rcirc-make-trees (pairs)
2059 (let (alist)
2060 (mapc (lambda (pair)
2061 (if (consp pair)
2062 (let* ((str (car pair))
2063 (data (cdr pair))
2064 (char (unless (zerop (length str))
2065 (aref str 0)))
2066 (rest (unless (zerop (length str))
2067 (substring str 1)))
2068 (part (if char (assq char alist))))
2069 (if part
2070 ;; existing partition
2071 (setcdr part (cons (cons rest data) (cdr part)))
2072 ;; new partition
2073 (setq alist (cons (if char
2074 (list char (cons rest data))
2075 data)
2076 alist))))
2077 (setq alist (cons pair alist))))
2078 pairs)
2079 ;; recurse into cdrs of alist
2080 (mapc (lambda (x)
2081 (when (and (listp x) (listp (cadr x)))
2082 (setcdr x (if (> (length (cdr x)) 1)
2083 (rcirc-make-trees (cdr x))
2084 (setcdr x (list (cdadr x)))))))
2085 alist)))
2087 ;;; /commands these are called with 3 args: PROCESS, TARGET, which is
2088 ;; the current buffer/channel/user, and ARGS, which is a string
2089 ;; containing the text following the /cmd.
2091 (defmacro defun-rcirc-command (command argument docstring interactive-form
2092 &rest body)
2093 "Define a command."
2094 `(progn
2095 (add-to-list 'rcirc-client-commands ,(concat "/" (symbol-name command)))
2096 (defun ,(intern (concat "rcirc-cmd-" (symbol-name command)))
2097 (,@argument &optional process target)
2098 ,(concat docstring "\n\nNote: If PROCESS or TARGET are nil, the values given"
2099 "\nby `rcirc-buffer-process' and `rcirc-target' will be used.")
2100 ,interactive-form
2101 (let ((process (or process (rcirc-buffer-process)))
2102 (target (or target rcirc-target)))
2103 ,@body))))
2105 (defun-rcirc-command msg (message)
2106 "Send private MESSAGE to TARGET."
2107 (interactive "i")
2108 (if (null message)
2109 (progn
2110 (setq target (completing-read "Message nick: "
2111 (with-rcirc-server-buffer
2112 rcirc-nick-table)))
2113 (when (> (length target) 0)
2114 (setq message (read-string (format "Message %s: " target)))
2115 (when (> (length message) 0)
2116 (rcirc-send-message process target message))))
2117 (if (not (string-match "\\([^ ]+\\) \\(.+\\)" message))
2118 (message "Not enough args, or something.")
2119 (setq target (match-string 1 message)
2120 message (match-string 2 message))
2121 (rcirc-send-message process target message))))
2123 (defun-rcirc-command query (nick)
2124 "Open a private chat buffer to NICK."
2125 (interactive (list (completing-read "Query nick: "
2126 (with-rcirc-server-buffer rcirc-nick-table))))
2127 (let ((existing-buffer (rcirc-get-buffer process nick)))
2128 (switch-to-buffer (or existing-buffer
2129 (rcirc-get-buffer-create process nick)))
2130 (when (not existing-buffer)
2131 (rcirc-cmd-whois nick))))
2133 (defun-rcirc-command join (channels)
2134 "Join CHANNELS.
2135 CHANNELS is a comma- or space-separated string of channel names."
2136 (interactive "sJoin channels: ")
2137 (let* ((split-channels (split-string channels "[ ,]" t))
2138 (buffers (mapcar (lambda (ch)
2139 (rcirc-get-buffer-create process ch))
2140 split-channels))
2141 (channels (mapconcat 'identity split-channels ",")))
2142 (rcirc-send-string process (concat "JOIN " channels))
2143 (when (not (eq (selected-window) (minibuffer-window)))
2144 (dolist (b buffers) ;; order the new channel buffers in the buffer list
2145 (switch-to-buffer b)))))
2147 ;; TODO: /part #channel reason, or consider removing #channel altogether
2148 (defun-rcirc-command part (channel)
2149 "Part CHANNEL."
2150 (interactive "sPart channel: ")
2151 (let ((channel (if (> (length channel) 0) channel target)))
2152 (rcirc-send-string process (concat "PART " channel " :" rcirc-id-string))))
2154 (defun-rcirc-command quit (reason)
2155 "Send a quit message to server with REASON."
2156 (interactive "sQuit reason: ")
2157 (rcirc-send-string process (concat "QUIT :"
2158 (if (not (zerop (length reason)))
2159 reason
2160 rcirc-id-string))))
2162 (defun-rcirc-command nick (nick)
2163 "Change nick to NICK."
2164 (interactive "i")
2165 (when (null nick)
2166 (setq nick (read-string "New nick: " (rcirc-nick process))))
2167 (rcirc-send-string process (concat "NICK " nick)))
2169 (defun-rcirc-command names (channel)
2170 "Display list of names in CHANNEL or in current channel if CHANNEL is nil.
2171 If called interactively, prompt for a channel when prefix arg is supplied."
2172 (interactive "P")
2173 (if (called-interactively-p 'interactive)
2174 (if channel
2175 (setq channel (read-string "List names in channel: " target))))
2176 (let ((channel (if (> (length channel) 0)
2177 channel
2178 target)))
2179 (rcirc-send-string process (concat "NAMES " channel))))
2181 (defun-rcirc-command topic (topic)
2182 "List TOPIC for the TARGET channel.
2183 With a prefix arg, prompt for new topic."
2184 (interactive "P")
2185 (if (and (called-interactively-p 'interactive) topic)
2186 (setq topic (read-string "New Topic: " rcirc-topic)))
2187 (rcirc-send-string process (concat "TOPIC " target
2188 (when (> (length topic) 0)
2189 (concat " :" topic)))))
2191 (defun-rcirc-command whois (nick)
2192 "Request information from server about NICK."
2193 (interactive (list
2194 (completing-read "Whois: "
2195 (with-rcirc-server-buffer rcirc-nick-table))))
2196 (rcirc-send-string process (concat "WHOIS " nick)))
2198 (defun-rcirc-command mode (args)
2199 "Set mode with ARGS."
2200 (interactive (list (concat (read-string "Mode nick or channel: ")
2201 " " (read-string "Mode: "))))
2202 (rcirc-send-string process (concat "MODE " args)))
2204 (defun-rcirc-command list (channels)
2205 "Request information on CHANNELS from server."
2206 (interactive "sList Channels: ")
2207 (rcirc-send-string process (concat "LIST " channels)))
2209 (defun-rcirc-command oper (args)
2210 "Send operator command to server."
2211 (interactive "sOper args: ")
2212 (rcirc-send-string process (concat "OPER " args)))
2214 (defun-rcirc-command quote (message)
2215 "Send MESSAGE literally to server."
2216 (interactive "sServer message: ")
2217 (rcirc-send-string process message))
2219 (defun-rcirc-command kick (arg)
2220 "Kick NICK from current channel."
2221 (interactive (list
2222 (concat (completing-read "Kick nick: "
2223 (rcirc-channel-nicks
2224 (rcirc-buffer-process)
2225 rcirc-target))
2226 (read-from-minibuffer "Kick reason: "))))
2227 (let* ((arglist (split-string arg))
2228 (argstring (concat (car arglist) " :"
2229 (mapconcat 'identity (cdr arglist) " "))))
2230 (rcirc-send-string process (concat "KICK " target " " argstring))))
2232 (defun rcirc-cmd-ctcp (args &optional process target)
2233 (if (string-match "^\\([^ ]+\\)\\s-+\\(.+\\)$" args)
2234 (let* ((target (match-string 1 args))
2235 (request (upcase (match-string 2 args)))
2236 (function (intern-soft (concat "rcirc-ctcp-sender-" request))))
2237 (if (fboundp function) ;; use special function if available
2238 (funcall function process target request)
2239 (rcirc-send-ctcp process target request)))
2240 (rcirc-print process (rcirc-nick process) "ERROR" nil
2241 "usage: /ctcp NICK REQUEST")))
2243 (defun rcirc-ctcp-sender-PING (process target request)
2244 "Send a CTCP PING message to TARGET."
2245 (let ((timestamp (format "%.0f" (rcirc-float-time))))
2246 (rcirc-send-ctcp process target "PING" timestamp)))
2248 (defun rcirc-cmd-me (args &optional process target)
2249 (rcirc-send-ctcp process target "ACTION" args))
2251 (defun rcirc-add-or-remove (set &rest elements)
2252 (dolist (elt elements)
2253 (if (and elt (not (string= "" elt)))
2254 (setq set (if (member-ignore-case elt set)
2255 (delete elt set)
2256 (cons elt set)))))
2257 set)
2259 (defun-rcirc-command ignore (nick)
2260 "Manage the ignore list.
2261 Ignore NICK, unignore NICK if already ignored, or list ignored
2262 nicks when no NICK is given. When listing ignored nicks, the
2263 ones added to the list automatically are marked with an asterisk."
2264 (interactive "sToggle ignoring of nick: ")
2265 (setq rcirc-ignore-list
2266 (apply #'rcirc-add-or-remove rcirc-ignore-list
2267 (split-string nick nil t)))
2268 (rcirc-print process nil "IGNORE" target
2269 (mapconcat
2270 (lambda (nick)
2271 (concat nick
2272 (if (member nick rcirc-ignore-list-automatic)
2273 "*" "")))
2274 rcirc-ignore-list " ")))
2276 (defun-rcirc-command bright (nick)
2277 "Manage the bright nick list."
2278 (interactive "sToggle emphasis of nick: ")
2279 (setq rcirc-bright-nicks
2280 (apply #'rcirc-add-or-remove rcirc-bright-nicks
2281 (split-string nick nil t)))
2282 (rcirc-print process nil "BRIGHT" target
2283 (mapconcat 'identity rcirc-bright-nicks " ")))
2285 (defun-rcirc-command dim (nick)
2286 "Manage the dim nick list."
2287 (interactive "sToggle deemphasis of nick: ")
2288 (setq rcirc-dim-nicks
2289 (apply #'rcirc-add-or-remove rcirc-dim-nicks
2290 (split-string nick nil t)))
2291 (rcirc-print process nil "DIM" target
2292 (mapconcat 'identity rcirc-dim-nicks " ")))
2294 (defun-rcirc-command keyword (keyword)
2295 "Manage the keyword list.
2296 Mark KEYWORD, unmark KEYWORD if already marked, or list marked
2297 keywords when no KEYWORD is given."
2298 (interactive "sToggle highlighting of keyword: ")
2299 (setq rcirc-keywords
2300 (apply #'rcirc-add-or-remove rcirc-keywords
2301 (split-string keyword nil t)))
2302 (rcirc-print process nil "KEYWORD" target
2303 (mapconcat 'identity rcirc-keywords " ")))
2306 (defun rcirc-add-face (start end name &optional object)
2307 "Add face NAME to the face text property of the text from START to END."
2308 (when name
2309 (let ((pos start)
2310 next prop)
2311 (while (< pos end)
2312 (setq prop (get-text-property pos 'face object)
2313 next (next-single-property-change pos 'face object end))
2314 (unless (member name (get-text-property pos 'face object))
2315 (add-text-properties pos next (list 'face (cons name prop)) object))
2316 (setq pos next)))))
2318 (defun rcirc-facify (string face)
2319 "Return a copy of STRING with FACE property added."
2320 (let ((string (or string "")))
2321 (rcirc-add-face 0 (length string) face string)
2322 string))
2324 (defvar rcirc-url-regexp
2325 (concat
2326 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
2327 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
2328 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
2329 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
2330 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
2331 (punct "!?:;.,"))
2332 (concat
2333 "\\(?:"
2334 ;; Match paired parentheses, e.g. in Wikipedia URLs:
2335 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)" "[" chars "]"
2336 "\\|"
2337 "[" chars punct "]+" "[" chars "]"
2338 "\\)"))
2339 (concat ;; XEmacs 21.4 doesn't support POSIX.
2340 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
2341 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
2342 "\\)")
2343 "Regexp matching URLs. Set to nil to disable URL features in rcirc.")
2345 (defun rcirc-browse-url (&optional arg)
2346 "Prompt for URL to browse based on URLs in buffer."
2347 (interactive "P")
2348 (let ((completions (mapcar (lambda (x) (cons x nil)) rcirc-urls))
2349 (initial-input (car rcirc-urls))
2350 (history (cdr rcirc-urls)))
2351 (browse-url (completing-read "rcirc browse-url: "
2352 completions nil nil initial-input 'history)
2353 arg)))
2355 (defun rcirc-browse-url-at-point (point)
2356 "Send URL at point to `browse-url'."
2357 (interactive "d")
2358 (let ((beg (previous-single-property-change (1+ point) 'mouse-face))
2359 (end (next-single-property-change point 'mouse-face)))
2360 (browse-url (buffer-substring-no-properties beg end))))
2362 (defun rcirc-browse-url-at-mouse (event)
2363 "Send URL at mouse click to `browse-url'."
2364 (interactive "e")
2365 (let ((position (event-end event)))
2366 (with-current-buffer (window-buffer (posn-window position))
2367 (rcirc-browse-url-at-point (posn-point position)))))
2370 (defun rcirc-markup-timestamp (sender response)
2371 (goto-char (point-min))
2372 (insert (rcirc-facify (format-time-string rcirc-time-format)
2373 'rcirc-timestamp)))
2375 (defun rcirc-markup-attributes (sender response)
2376 (while (re-search-forward "\\([\C-b\C-_\C-v]\\).*?\\(\\1\\|\C-o\\)" nil t)
2377 (rcirc-add-face (match-beginning 0) (match-end 0)
2378 (case (char-after (match-beginning 1))
2379 (?\C-b 'bold)
2380 (?\C-v 'italic)
2381 (?\C-_ 'underline)))
2382 ;; keep the ^O since it could terminate other attributes
2383 (when (not (eq ?\C-o (char-before (match-end 2))))
2384 (delete-region (match-beginning 2) (match-end 2)))
2385 (delete-region (match-beginning 1) (match-end 1))
2386 (goto-char (match-beginning 1)))
2387 ;; remove the ^O characters now
2388 (while (re-search-forward "\C-o+" nil t)
2389 (delete-region (match-beginning 0) (match-end 0))))
2391 (defun rcirc-markup-my-nick (sender response)
2392 (with-syntax-table rcirc-nick-syntax-table
2393 (while (re-search-forward (concat "\\b"
2394 (regexp-quote (rcirc-nick
2395 (rcirc-buffer-process)))
2396 "\\b")
2397 nil t)
2398 (rcirc-add-face (match-beginning 0) (match-end 0)
2399 'rcirc-nick-in-message)
2400 (when (string= response "PRIVMSG")
2401 (rcirc-add-face (point-min) (point-max)
2402 'rcirc-nick-in-message-full-line)
2403 (rcirc-record-activity (current-buffer) 'nick)))))
2405 (defun rcirc-markup-urls (sender response)
2406 (while (and rcirc-url-regexp ;; nil means disable URL catching
2407 (re-search-forward rcirc-url-regexp nil t))
2408 (let ((start (match-beginning 0))
2409 (end (match-end 0)))
2410 (rcirc-add-face start end 'rcirc-url)
2411 (add-text-properties start end (list 'mouse-face 'highlight
2412 'keymap rcirc-browse-url-map))
2413 ;; record the url
2414 (push (buffer-substring-no-properties start end) rcirc-urls))))
2416 (defun rcirc-markup-keywords (sender response)
2417 (when (and (string= response "PRIVMSG")
2418 (not (string= sender (rcirc-nick (rcirc-buffer-process)))))
2419 (let* ((target (or rcirc-target ""))
2420 (keywords (delq nil (mapcar (lambda (keyword)
2421 (when (not (string-match keyword
2422 target))
2423 keyword))
2424 rcirc-keywords))))
2425 (when keywords
2426 (while (re-search-forward (regexp-opt keywords 'words) nil t)
2427 (rcirc-add-face (match-beginning 0) (match-end 0) 'rcirc-keyword)
2428 (rcirc-record-activity (current-buffer) 'keyword))))))
2430 (defun rcirc-markup-bright-nicks (sender response)
2431 (when (and rcirc-bright-nicks
2432 (string= response "NAMES"))
2433 (with-syntax-table rcirc-nick-syntax-table
2434 (while (re-search-forward (regexp-opt rcirc-bright-nicks 'words) nil t)
2435 (rcirc-add-face (match-beginning 0) (match-end 0)
2436 'rcirc-bright-nick)))))
2438 (defun rcirc-markup-fill (sender response)
2439 (when (not (string= response "372")) ; /motd
2440 (let ((fill-prefix
2441 (or rcirc-fill-prefix
2442 (make-string (- (point) (line-beginning-position)) ?\s)))
2443 (fill-column (- (cond ((eq rcirc-fill-column 'frame-width)
2444 (1- (frame-width)))
2445 (rcirc-fill-column
2446 rcirc-fill-column)
2447 (t fill-column))
2448 ;; make sure ... doesn't cause line wrapping
2449 3)))
2450 (fill-region (point) (point-max) nil t))))
2452 ;;; handlers
2453 ;; these are called with the server PROCESS, the SENDER, which is a
2454 ;; server or a user, depending on the command, the ARGS, which is a
2455 ;; list of strings, and the TEXT, which is the original server text,
2456 ;; verbatim
2457 (defun rcirc-handler-001 (process sender args text)
2458 (rcirc-handler-generic process "001" sender args text)
2459 (with-rcirc-process-buffer process
2460 (setq rcirc-connecting nil)
2461 (rcirc-reschedule-timeout process)
2462 (setq rcirc-server-name sender)
2463 (setq rcirc-nick (car args))
2464 (rcirc-update-prompt)
2465 (if rcirc-auto-authenticate-flag
2466 (if (and rcirc-authenticate-before-join
2467 ;; We have to ensure that there's an authentication
2468 ;; entry for that server. Else,
2469 ;; rcirc-authenticated-hook won't be triggered, and
2470 ;; autojoin won't happen at all.
2471 (let (auth-required)
2472 (dolist (s rcirc-authinfo auth-required)
2473 (when (string-match (car s) rcirc-server-name)
2474 (setq auth-required t)))))
2475 (progn
2476 (add-hook 'rcirc-authenticated-hook 'rcirc-join-channels-post-auth t t)
2477 (rcirc-authenticate))
2478 (rcirc-authenticate)
2479 (rcirc-join-channels process rcirc-startup-channels))
2480 (rcirc-join-channels process rcirc-startup-channels))))
2482 (defun rcirc-join-channels-post-auth (process)
2483 "Join `rcirc-startup-channels' after authenticating."
2484 (with-rcirc-process-buffer process
2485 (rcirc-join-channels process rcirc-startup-channels)))
2487 (defun rcirc-handler-PRIVMSG (process sender args text)
2488 (rcirc-check-auth-status process sender args text)
2489 (let ((target (if (rcirc-channel-p (car args))
2490 (car args)
2491 sender))
2492 (message (or (cadr args) "")))
2493 (if (string-match "^\C-a\\(.*\\)\C-a$" message)
2494 (rcirc-handler-CTCP process target sender (match-string 1 message))
2495 (rcirc-print process sender "PRIVMSG" target message t))
2496 ;; update nick linestamp
2497 (with-current-buffer (rcirc-get-buffer process target t)
2498 (rcirc-put-nick-channel process sender target rcirc-current-line))))
2500 (defun rcirc-handler-NOTICE (process sender args text)
2501 (rcirc-check-auth-status process sender args text)
2502 (let ((target (car args))
2503 (message (cadr args)))
2504 (if (string-match "^\C-a\\(.*\\)\C-a$" message)
2505 (rcirc-handler-CTCP-response process target sender
2506 (match-string 1 message))
2507 (rcirc-print process sender "NOTICE"
2508 (cond ((rcirc-channel-p target)
2509 target)
2510 ;;; -ChanServ- [#gnu] Welcome...
2511 ((string-match "\\[\\(#[^\] ]+\\)\\]" message)
2512 (match-string 1 message))
2513 (sender
2514 (if (string= sender (rcirc-server-name process))
2515 nil ; server notice
2516 sender)))
2517 message t))))
2519 (defun rcirc-check-auth-status (process sender args text)
2520 "Check if the user just authenticated.
2521 If authenticated, runs `rcirc-authenticated-hook' with PROCESS as
2522 the only argument."
2523 (with-rcirc-process-buffer process
2524 (when (and (not rcirc-user-authenticated)
2525 rcirc-authenticate-before-join
2526 rcirc-auto-authenticate-flag)
2527 (let ((target (car args))
2528 (message (cadr args)))
2529 (when (or
2530 (and ;; nickserv
2531 (string= sender "NickServ")
2532 (string= target rcirc-nick)
2533 (member message
2534 (list
2535 (format "You are now identified for \C-b%s\C-b." rcirc-nick)
2536 "Password accepted - you are now recognized."
2538 (and ;; quakenet
2539 (string= sender "Q")
2540 (string= target rcirc-nick)
2541 (string-match "\\`You are now logged in as .+\\.\\'" message)))
2542 (setq rcirc-user-authenticated t)
2543 (run-hook-with-args 'rcirc-authenticated-hook process)
2544 (remove-hook 'rcirc-authenticated-hook 'rcirc-join-channels-post-auth t))))))
2546 (defun rcirc-handler-WALLOPS (process sender args text)
2547 (rcirc-print process sender "WALLOPS" sender (car args) t))
2549 (defun rcirc-handler-JOIN (process sender args text)
2550 (let ((channel (car args)))
2551 (with-current-buffer (rcirc-get-buffer-create process channel)
2552 ;; when recently rejoining, restore the linestamp
2553 (rcirc-put-nick-channel process sender channel
2554 (let ((last-activity-lines
2555 (rcirc-elapsed-lines process sender channel)))
2556 (when (and last-activity-lines
2557 (< last-activity-lines rcirc-omit-threshold))
2558 (rcirc-last-line process sender channel))))
2559 ;; reset mode-line-process in case joining a channel with an
2560 ;; already open buffer (after getting kicked e.g.)
2561 (setq mode-line-process nil))
2563 (rcirc-print process sender "JOIN" channel "")
2565 ;; print in private chat buffer if it exists
2566 (when (rcirc-get-buffer (rcirc-buffer-process) sender)
2567 (rcirc-print process sender "JOIN" sender channel))))
2569 ;; PART and KICK are handled the same way
2570 (defun rcirc-handler-PART-or-KICK (process response channel sender nick args)
2571 (rcirc-ignore-update-automatic nick)
2572 (if (not (string= nick (rcirc-nick process)))
2573 ;; this is someone else leaving
2574 (progn
2575 (rcirc-maybe-remember-nick-quit process nick channel)
2576 (rcirc-remove-nick-channel process nick channel))
2577 ;; this is us leaving
2578 (mapc (lambda (n)
2579 (rcirc-remove-nick-channel process n channel))
2580 (rcirc-channel-nicks process channel))
2582 ;; if the buffer is still around, make it inactive
2583 (let ((buffer (rcirc-get-buffer process channel)))
2584 (when buffer
2585 (rcirc-disconnect-buffer buffer)))))
2587 (defun rcirc-handler-PART (process sender args text)
2588 (let* ((channel (car args))
2589 (reason (cadr args))
2590 (message (concat channel " " reason)))
2591 (rcirc-print process sender "PART" channel message)
2592 ;; print in private chat buffer if it exists
2593 (when (rcirc-get-buffer (rcirc-buffer-process) sender)
2594 (rcirc-print process sender "PART" sender message))
2596 (rcirc-handler-PART-or-KICK process "PART" channel sender sender reason)))
2598 (defun rcirc-handler-KICK (process sender args text)
2599 (let* ((channel (car args))
2600 (nick (cadr args))
2601 (reason (caddr args))
2602 (message (concat nick " " channel " " reason)))
2603 (rcirc-print process sender "KICK" channel message t)
2604 ;; print in private chat buffer if it exists
2605 (when (rcirc-get-buffer (rcirc-buffer-process) nick)
2606 (rcirc-print process sender "KICK" nick message))
2608 (rcirc-handler-PART-or-KICK process "KICK" channel sender nick reason)))
2610 (defun rcirc-maybe-remember-nick-quit (process nick channel)
2611 "Remember NICK as leaving CHANNEL if they recently spoke."
2612 (let ((elapsed-lines (rcirc-elapsed-lines process nick channel)))
2613 (when (and elapsed-lines
2614 (< elapsed-lines rcirc-omit-threshold))
2615 (let ((buffer (rcirc-get-buffer process channel)))
2616 (when buffer
2617 (with-current-buffer buffer
2618 (let ((record (assoc-string nick rcirc-recent-quit-alist t))
2619 (line (rcirc-last-line process nick channel)))
2620 (if record
2621 (setcdr record line)
2622 (setq rcirc-recent-quit-alist
2623 (cons (cons nick line)
2624 rcirc-recent-quit-alist))))))))))
2626 (defun rcirc-handler-QUIT (process sender args text)
2627 (rcirc-ignore-update-automatic sender)
2628 (mapc (lambda (channel)
2629 ;; broadcast quit message each channel
2630 (rcirc-print process sender "QUIT" channel (apply 'concat args))
2631 ;; record nick in quit table if they recently spoke
2632 (rcirc-maybe-remember-nick-quit process sender channel))
2633 (rcirc-nick-channels process sender))
2634 (rcirc-nick-remove process sender))
2636 (defun rcirc-handler-NICK (process sender args text)
2637 (let* ((old-nick sender)
2638 (new-nick (car args))
2639 (channels (rcirc-nick-channels process old-nick)))
2640 ;; update list of ignored nicks
2641 (rcirc-ignore-update-automatic old-nick)
2642 (when (member old-nick rcirc-ignore-list)
2643 (add-to-list 'rcirc-ignore-list new-nick)
2644 (add-to-list 'rcirc-ignore-list-automatic new-nick))
2645 ;; print message to nick's channels
2646 (dolist (target channels)
2647 (rcirc-print process sender "NICK" target new-nick))
2648 ;; update private chat buffer, if it exists
2649 (let ((chat-buffer (rcirc-get-buffer process old-nick)))
2650 (when chat-buffer
2651 (with-current-buffer chat-buffer
2652 (rcirc-print process sender "NICK" old-nick new-nick)
2653 (setq rcirc-target new-nick)
2654 (rename-buffer (rcirc-generate-new-buffer-name process new-nick)))))
2655 ;; remove old nick and add new one
2656 (with-rcirc-process-buffer process
2657 (let ((v (gethash old-nick rcirc-nick-table)))
2658 (remhash old-nick rcirc-nick-table)
2659 (puthash new-nick v rcirc-nick-table))
2660 ;; if this is our nick...
2661 (when (string= old-nick rcirc-nick)
2662 (setq rcirc-nick new-nick)
2663 (rcirc-update-prompt t)
2664 ;; reauthenticate
2665 (when rcirc-auto-authenticate-flag (rcirc-authenticate))))))
2667 (defun rcirc-handler-PING (process sender args text)
2668 (rcirc-send-string process (concat "PONG :" (car args))))
2670 (defun rcirc-handler-PONG (process sender args text)
2671 ;; do nothing
2674 (defun rcirc-handler-TOPIC (process sender args text)
2675 (let ((topic (cadr args)))
2676 (rcirc-print process sender "TOPIC" (car args) topic)
2677 (with-current-buffer (rcirc-get-buffer process (car args))
2678 (setq rcirc-topic topic))))
2680 (defvar rcirc-nick-away-alist nil)
2681 (defun rcirc-handler-301 (process sender args text)
2682 "RPL_AWAY"
2683 (let* ((nick (cadr args))
2684 (rec (assoc-string nick rcirc-nick-away-alist))
2685 (away-message (caddr args)))
2686 (when (or (not rec)
2687 (not (string= (cdr rec) away-message)))
2688 ;; away message has changed
2689 (rcirc-handler-generic process "AWAY" nick (cdr args) text)
2690 (if rec
2691 (setcdr rec away-message)
2692 (setq rcirc-nick-away-alist (cons (cons nick away-message)
2693 rcirc-nick-away-alist))))))
2695 (defun rcirc-handler-317 (process sender args text)
2696 "RPL_WHOISIDLE"
2697 (let* ((nick (nth 1 args))
2698 (idle-secs (string-to-number (nth 2 args)))
2699 (idle-string
2700 (if (< idle-secs most-positive-fixnum)
2701 (format-seconds "%yy %dd %hh %mm %z%ss" idle-secs)
2702 "a very long time"))
2703 (signon-time (seconds-to-time (string-to-number (nth 3 args))))
2704 (signon-string (format-time-string "%c" signon-time))
2705 (message (format "%s idle for %s, signed on %s"
2706 nick idle-string signon-string)))
2707 (rcirc-print process sender "317" nil message t)))
2709 (defun rcirc-handler-332 (process sender args text)
2710 "RPL_TOPIC"
2711 (let ((buffer (or (rcirc-get-buffer process (cadr args))
2712 (rcirc-get-temp-buffer-create process (cadr args)))))
2713 (with-current-buffer buffer
2714 (setq rcirc-topic (caddr args)))))
2716 (defun rcirc-handler-333 (process sender args text)
2717 "Not in rfc1459.txt"
2718 (let ((buffer (or (rcirc-get-buffer process (cadr args))
2719 (rcirc-get-temp-buffer-create process (cadr args)))))
2720 (with-current-buffer buffer
2721 (let ((setter (caddr args))
2722 (time (current-time-string
2723 (seconds-to-time
2724 (string-to-number (cadddr args))))))
2725 (rcirc-print process sender "TOPIC" (cadr args)
2726 (format "%s (%s on %s)" rcirc-topic setter time))))))
2728 (defun rcirc-handler-477 (process sender args text)
2729 "ERR_NOCHANMODES"
2730 (rcirc-print process sender "477" (cadr args) (caddr args)))
2732 (defun rcirc-handler-MODE (process sender args text)
2733 (let ((target (car args))
2734 (msg (mapconcat 'identity (cdr args) " ")))
2735 (rcirc-print process sender "MODE"
2736 (if (string= target (rcirc-nick process))
2738 target)
2739 msg)
2741 ;; print in private chat buffers if they exist
2742 (mapc (lambda (nick)
2743 (when (rcirc-get-buffer process nick)
2744 (rcirc-print process sender "MODE" nick msg)))
2745 (cddr args))))
2747 (defun rcirc-get-temp-buffer-create (process channel)
2748 "Return a buffer based on PROCESS and CHANNEL."
2749 (let ((tmpnam (concat " " (downcase channel) "TMP" (process-name process))))
2750 (get-buffer-create tmpnam)))
2752 (defun rcirc-handler-353 (process sender args text)
2753 "RPL_NAMREPLY"
2754 (let ((channel (nth 2 args))
2755 (names (or (nth 3 args) "")))
2756 (mapc (lambda (nick)
2757 (rcirc-put-nick-channel process nick channel))
2758 (split-string names " " t))
2759 ;; create a temporary buffer to insert the names into
2760 ;; rcirc-handler-366 (RPL_ENDOFNAMES) will handle it
2761 (with-current-buffer (rcirc-get-temp-buffer-create process channel)
2762 (goto-char (point-max))
2763 (insert (car (last args)) " "))))
2765 (defun rcirc-handler-366 (process sender args text)
2766 "RPL_ENDOFNAMES"
2767 (let* ((channel (cadr args))
2768 (buffer (rcirc-get-temp-buffer-create process channel)))
2769 (with-current-buffer buffer
2770 (rcirc-print process sender "NAMES" channel
2771 (let ((content (buffer-substring (point-min) (point-max))))
2772 (rcirc-sort-nicknames-join content " "))))
2773 (kill-buffer buffer)))
2775 (defun rcirc-handler-433 (process sender args text)
2776 "ERR_NICKNAMEINUSE"
2777 (rcirc-handler-generic process "433" sender args text)
2778 (let* ((new-nick (concat (cadr args) "`")))
2779 (with-rcirc-process-buffer process
2780 (rcirc-cmd-nick new-nick nil process))))
2782 (defun rcirc-authenticate ()
2783 "Send authentication to process associated with current buffer.
2784 Passwords are stored in `rcirc-authinfo' (which see)."
2785 (interactive)
2786 (with-rcirc-server-buffer
2787 (dolist (i rcirc-authinfo)
2788 (let ((process (rcirc-buffer-process))
2789 (server (car i))
2790 (nick (caddr i))
2791 (method (cadr i))
2792 (args (cdddr i)))
2793 (when (and (string-match server rcirc-server))
2794 (if (and (memq method '(nickserv chanserv bitlbee))
2795 (string-match nick rcirc-nick))
2796 ;; the following methods rely on the user's nickname.
2797 (case method
2798 (nickserv
2799 (rcirc-send-privmsg
2800 process
2801 (or (cadr args) "NickServ")
2802 (concat "IDENTIFY " (car args))))
2803 (chanserv
2804 (rcirc-send-privmsg
2805 process
2806 "ChanServ"
2807 (format "IDENTIFY %s %s" (car args) (cadr args))))
2808 (bitlbee
2809 (rcirc-send-privmsg
2810 process
2811 "&bitlbee"
2812 (concat "IDENTIFY " (car args)))))
2813 ;; quakenet authentication doesn't rely on the user's nickname.
2814 ;; the variable `nick' here represents the Q account name.
2815 (when (eq method 'quakenet)
2816 (rcirc-send-privmsg
2817 process
2818 "Q@CServe.quakenet.org"
2819 (format "AUTH %s %s" nick (car args))))))))))
2821 (defun rcirc-handler-INVITE (process sender args text)
2822 (rcirc-print process sender "INVITE" nil (mapconcat 'identity args " ") t))
2824 (defun rcirc-handler-ERROR (process sender args text)
2825 (rcirc-print process sender "ERROR" nil (mapconcat 'identity args " ")))
2827 (defun rcirc-handler-CTCP (process target sender text)
2828 (if (string-match "^\\([^ ]+\\) *\\(.*\\)$" text)
2829 (let* ((request (upcase (match-string 1 text)))
2830 (args (match-string 2 text))
2831 (handler (intern-soft (concat "rcirc-handler-ctcp-" request))))
2832 (if (not (fboundp handler))
2833 (rcirc-print process sender "ERROR" target
2834 (format "%s sent unsupported ctcp: %s" sender text)
2836 (funcall handler process target sender args)
2837 (unless (or (string= request "ACTION")
2838 (string= request "KEEPALIVE"))
2839 (rcirc-print process sender "CTCP" target
2840 (format "%s" text) t))))))
2842 (defun rcirc-handler-ctcp-VERSION (process target sender args)
2843 (rcirc-send-string process
2844 (concat "NOTICE " sender
2845 " :\C-aVERSION " rcirc-id-string
2846 "\C-a")))
2848 (defun rcirc-handler-ctcp-ACTION (process target sender args)
2849 (rcirc-print process sender "ACTION" target args t))
2851 (defun rcirc-handler-ctcp-TIME (process target sender args)
2852 (rcirc-send-string process
2853 (concat "NOTICE " sender
2854 " :\C-aTIME " (current-time-string) "\C-a")))
2856 (defun rcirc-handler-CTCP-response (process target sender message)
2857 (rcirc-print process sender "CTCP" nil message t))
2859 (defgroup rcirc-faces nil
2860 "Faces for rcirc."
2861 :group 'rcirc
2862 :group 'faces)
2864 (defface rcirc-my-nick ; font-lock-function-name-face
2865 '((((class color) (min-colors 88) (background light)) (:foreground "Blue1"))
2866 (((class color) (min-colors 88) (background dark)) (:foreground "LightSkyBlue"))
2867 (((class color) (min-colors 16) (background light)) (:foreground "Blue"))
2868 (((class color) (min-colors 16) (background dark)) (:foreground "LightSkyBlue"))
2869 (((class color) (min-colors 8)) (:foreground "blue" :weight bold))
2870 (t (:inverse-video t :weight bold)))
2871 "The face used to highlight my messages."
2872 :group 'rcirc-faces)
2874 (defface rcirc-other-nick ; font-lock-variable-name-face
2875 '((((class grayscale) (background light))
2876 (:foreground "Gray90" :weight bold :slant italic))
2877 (((class grayscale) (background dark))
2878 (:foreground "DimGray" :weight bold :slant italic))
2879 (((class color) (min-colors 88) (background light)) (:foreground "DarkGoldenrod"))
2880 (((class color) (min-colors 88) (background dark)) (:foreground "LightGoldenrod"))
2881 (((class color) (min-colors 16) (background light)) (:foreground "DarkGoldenrod"))
2882 (((class color) (min-colors 16) (background dark)) (:foreground "LightGoldenrod"))
2883 (((class color) (min-colors 8)) (:foreground "yellow" :weight light))
2884 (t (:weight bold :slant italic)))
2885 "The face used to highlight other messages."
2886 :group 'rcirc-faces)
2888 (defface rcirc-bright-nick
2889 '((((class grayscale) (background light))
2890 (:foreground "LightGray" :weight bold :underline t))
2891 (((class grayscale) (background dark))
2892 (:foreground "Gray50" :weight bold :underline t))
2893 (((class color) (min-colors 88) (background light)) (:foreground "CadetBlue"))
2894 (((class color) (min-colors 88) (background dark)) (:foreground "Aquamarine"))
2895 (((class color) (min-colors 16) (background light)) (:foreground "CadetBlue"))
2896 (((class color) (min-colors 16) (background dark)) (:foreground "Aquamarine"))
2897 (((class color) (min-colors 8)) (:foreground "magenta"))
2898 (t (:weight bold :underline t)))
2899 "Face used for nicks matched by `rcirc-bright-nicks'."
2900 :group 'rcirc-faces)
2902 (defface rcirc-dim-nick
2903 '((t :inherit default))
2904 "Face used for nicks in `rcirc-dim-nicks'."
2905 :group 'rcirc-faces)
2907 (defface rcirc-server ; font-lock-comment-face
2908 '((((class grayscale) (background light))
2909 (:foreground "DimGray" :weight bold :slant italic))
2910 (((class grayscale) (background dark))
2911 (:foreground "LightGray" :weight bold :slant italic))
2912 (((class color) (min-colors 88) (background light))
2913 (:foreground "Firebrick"))
2914 (((class color) (min-colors 88) (background dark))
2915 (:foreground "chocolate1"))
2916 (((class color) (min-colors 16) (background light))
2917 (:foreground "red"))
2918 (((class color) (min-colors 16) (background dark))
2919 (:foreground "red1"))
2920 (((class color) (min-colors 8) (background light))
2922 (((class color) (min-colors 8) (background dark))
2924 (t (:weight bold :slant italic)))
2925 "The face used to highlight server messages."
2926 :group 'rcirc-faces)
2928 (defface rcirc-server-prefix ; font-lock-comment-delimiter-face
2929 '((default :inherit rcirc-server)
2930 (((class grayscale)))
2931 (((class color) (min-colors 16)))
2932 (((class color) (min-colors 8) (background light))
2933 :foreground "red")
2934 (((class color) (min-colors 8) (background dark))
2935 :foreground "red1"))
2936 "The face used to highlight server prefixes."
2937 :group 'rcirc-faces)
2939 (defface rcirc-timestamp
2940 '((t (:inherit default)))
2941 "The face used to highlight timestamps."
2942 :group 'rcirc-faces)
2944 (defface rcirc-nick-in-message ; font-lock-keyword-face
2945 '((((class grayscale) (background light)) (:foreground "LightGray" :weight bold))
2946 (((class grayscale) (background dark)) (:foreground "DimGray" :weight bold))
2947 (((class color) (min-colors 88) (background light)) (:foreground "Purple"))
2948 (((class color) (min-colors 88) (background dark)) (:foreground "Cyan1"))
2949 (((class color) (min-colors 16) (background light)) (:foreground "Purple"))
2950 (((class color) (min-colors 16) (background dark)) (:foreground "Cyan"))
2951 (((class color) (min-colors 8)) (:foreground "cyan" :weight bold))
2952 (t (:weight bold)))
2953 "The face used to highlight instances of your nick within messages."
2954 :group 'rcirc-faces)
2956 (defface rcirc-nick-in-message-full-line
2957 '((t (:bold t)))
2958 "The face used emphasize the entire message when your nick is mentioned."
2959 :group 'rcirc-faces)
2961 (defface rcirc-prompt ; comint-highlight-prompt
2962 '((((min-colors 88) (background dark)) (:foreground "cyan1"))
2963 (((background dark)) (:foreground "cyan"))
2964 (t (:foreground "dark blue")))
2965 "The face used to highlight prompts."
2966 :group 'rcirc-faces)
2968 (defface rcirc-track-nick
2969 '((((type tty)) (:inherit default))
2970 (t (:inverse-video t)))
2971 "The face used in the mode-line when your nick is mentioned."
2972 :group 'rcirc-faces)
2974 (defface rcirc-track-keyword
2975 '((t (:bold t )))
2976 "The face used in the mode-line when keywords are mentioned."
2977 :group 'rcirc-faces)
2979 (defface rcirc-url
2980 '((t (:bold t)))
2981 "The face used to highlight urls."
2982 :group 'rcirc-faces)
2984 (defface rcirc-keyword
2985 '((t (:inherit highlight)))
2986 "The face used to highlight keywords."
2987 :group 'rcirc-faces)
2990 ;; When using M-x flyspell-mode, only check words after the prompt
2991 (put 'rcirc-mode 'flyspell-mode-predicate 'rcirc-looking-at-input)
2992 (defun rcirc-looking-at-input ()
2993 "Returns true if point is past the input marker."
2994 (>= (point) rcirc-prompt-end-marker))
2997 (provide 'rcirc)
2999 ;;; rcirc.el ends here