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