1 ;; erc.el --- An Emacs Internet Relay Chat client
3 ;; Copyright (C) 1997-2012 Free Software Foundation, Inc.
5 ;; Author: Alexander L. Belikoff (alexander@belikoff.net)
6 ;; Contributors: Sergey Berezin (sergey.berezin@cs.cmu.edu),
7 ;; Mario Lang (mlang@delysid.org),
8 ;; Alex Schroeder (alex@gnu.org)
9 ;; Andreas Fuchs (afs@void.at)
10 ;; Gergely Nagy (algernon@midgard.debian.net)
11 ;; David Edmondson (dme@dme.org)
12 ;; Maintainer: Michael Olson (mwolson@gnu.org)
13 ;; Keywords: IRC, chat, client, Internet
16 ;; This file is part of GNU Emacs.
18 ;; GNU Emacs is free software: you can redistribute it and/or modify
19 ;; it under the terms of the GNU General Public License as published by
20 ;; the Free Software Foundation, either version 3 of the License, or
21 ;; (at your option) any later version.
23 ;; GNU Emacs is distributed in the hope that it will be useful,
24 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
25 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 ;; GNU General Public License for more details.
28 ;; You should have received a copy of the GNU General Public License
29 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
33 ;; ERC is a powerful, modular, and extensible IRC client for Emacs.
35 ;; For more information, see the following URLs:
36 ;; * http://sv.gnu.org/projects/erc/
37 ;; * http://www.emacswiki.org/cgi-bin/wiki/ERC
39 ;; As of 2006-06-13, ERC development is now hosted on Savannah
40 ;; (http://sv.gnu.org/projects/erc). I invite everyone who wants to
41 ;; hack on it to contact me <mwolson@gnu.org> in order to get write
42 ;; access to the shared Arch archive.
46 ;; Put erc.el in your load-path, and put (require 'erc) in your .emacs.
50 ;; Use M-x customize-group RET erc RET to get an overview
51 ;; of all the variables you can tweak.
55 ;; To connect to an IRC server, do
59 ;; After you are connected to a server, you can use C-h m or have a look at
67 (defconst erc-version-string
"Version 5.3"
68 "ERC version. This is used by function `erc-version'.")
70 (eval-when-compile (require 'cl
))
76 (defvar erc-official-location
77 "http://emacswiki.org/cgi-bin/wiki/ERC (mailing list: erc-discuss@gnu.org)"
78 "Location of the ERC client on the Internet.")
81 "Emacs Internet Relay Chat client."
82 :link
'(url-link "http://www.emacswiki.org/cgi-bin/wiki/ERC")
86 (defgroup erc-buffers nil
87 "Creating new ERC buffers"
90 (defgroup erc-display nil
91 "Settings for how various things are displayed"
94 (defgroup erc-mode-line-and-header nil
95 "Displaying information in the mode-line and header"
98 (defgroup erc-ignore nil
99 "Ignoring certain messages"
102 (defgroup erc-query nil
103 "Using separate buffers for private discussions"
106 (defgroup erc-quit-and-part nil
107 "Quitting and parting channels"
110 (defgroup erc-paranoia nil
111 "Know what is sent and received; control the display of sensitive data."
114 (defgroup erc-scripts nil
115 "Running scripts at startup and with /LOAD"
118 (require 'erc-backend
)
120 ;; compatibility with older ERC releases
122 (if (fboundp 'defvaralias
)
124 (defvaralias 'erc-announced-server-name
'erc-server-announced-name
)
125 (erc-make-obsolete-variable 'erc-announced-server-name
126 'erc-server-announced-name
128 (defvaralias 'erc-process
'erc-server-process
)
129 (erc-make-obsolete-variable 'erc-process
'erc-server-process
"ERC 5.1")
130 (defvaralias 'erc-default-coding-system
'erc-server-coding-system
)
131 (erc-make-obsolete-variable 'erc-default-coding-system
132 'erc-server-coding-system
134 (message (concat "ERC: The function `defvaralias' is not bound. See the "
135 "NEWS file for variable name changes since ERC 5.0.4.")))
137 (defalias 'erc-send-command
'erc-server-send
)
138 (erc-make-obsolete 'erc-send-command
'erc-server-send
"ERC 5.1")
140 ;; tunable connection and authentication parameters
142 (defcustom erc-server nil
143 "IRC server to use if one is not provided.
144 See function `erc-compute-server' for more details on connection
145 parameters and authentication."
147 :type
'(choice (const :tag
"None" nil
)
148 (string :tag
"Server")))
150 (defcustom erc-port nil
151 "IRC port to use if not specified.
153 This can be either a string or a number."
155 :type
'(choice (const :tag
"None" nil
)
156 (integer :tag
"Port number")
157 (string :tag
"Port string")))
159 (defcustom erc-nick nil
160 "Nickname to use if one is not provided.
162 This can be either a string, or a list of strings.
163 In the latter case, if the first nick in the list is already in use,
164 other nicks are tried in the list order.
166 See function `erc-compute-nick' for more details on connection
167 parameters and authentication."
169 :type
'(choice (const :tag
"None" nil
)
170 (string :tag
"Nickname")
171 (repeat (string :tag
"Nickname"))))
173 (defcustom erc-nick-uniquifier
"`"
174 "The string to append to the nick if it is already in use."
178 (defcustom erc-try-new-nick-p t
179 "If the nickname you chose isn't available, and this option is non-nil,
180 ERC should automatically attempt to connect with another nickname.
182 You can manually set another nickname with the /NICK command."
186 (defcustom erc-user-full-name nil
189 This can be either a string or a function to call.
191 See function `erc-compute-full-name' for more details on connection
192 parameters and authentication."
194 :type
'(choice (const :tag
"No name" nil
)
196 (function :tag
"Get from function"))
197 :set
(lambda (sym val
)
199 (set sym
(funcall val
))
202 (defvar erc-password nil
203 "Password to use when authenticating to an IRC server.
204 It is not strictly necessary to provide this, since ERC will
207 (defcustom erc-user-mode nil
208 "Initial user modes to be set after a connection is established."
210 :type
'(choice (const nil
) string function
))
213 (defcustom erc-prompt-for-password t
214 "Asks before using the default password, or whether to enter a new one."
218 (defcustom erc-warn-about-blank-lines t
219 "Warn the user if they attempt to send a blank line."
223 (defcustom erc-send-whitespace-lines nil
224 "If set to non-nil, send lines consisting of only whitespace."
228 (defcustom erc-hide-prompt nil
229 "If non-nil, do not display the prompt for commands.
231 \(A command is any input starting with a '/').
233 See also the variables `erc-prompt' and `erc-command-indicator'."
239 (defcustom erc-show-my-nick t
240 "If non-nil, display one's own nickname when sending a message.
242 If non-nil, \"<nickname>\" will be shown.
243 If nil, only \"> \" will be shown."
247 (define-widget 'erc-message-type
'set
248 "A set of standard IRC Message types."
249 :args
'((const "JOIN")
255 (repeat :inline t
:tag
"Others" (string :tag
"IRC Message Type"))))
257 (defcustom erc-hide-list nil
258 "List of IRC type messages to hide.
259 A typical value would be '(\"JOIN\" \"PART\" \"QUIT\")."
261 :type
'erc-message-type
)
263 (defvar erc-session-password nil
264 "The password used for the current session.")
265 (make-variable-buffer-local 'erc-session-password
)
267 (defcustom erc-disconnected-hook nil
268 "Run this hook with arguments (NICK IP REASON) when disconnected.
269 This happens before automatic reconnection. Note, that
270 `erc-server-QUIT-functions' might not be run when we disconnect,
271 simply because we do not necessarily receive the QUIT event."
275 (defcustom erc-complete-functions nil
276 "These functions get called when the user hits TAB in ERC.
277 Each function in turn is called until one returns non-nil to
278 indicate it has handled the input."
282 (defcustom erc-join-hook nil
283 "Hook run when we join a channel. Hook functions are called
284 without arguments, with the current buffer set to the buffer of
287 See also `erc-server-JOIN-functions', `erc-part-hook'."
291 (defcustom erc-quit-hook nil
292 "Hook run when processing a quit command directed at our nick.
294 The hook receives one argument, the current PROCESS.
295 See also `erc-server-QUIT-functions' and `erc-disconnected-hook'."
299 (defcustom erc-part-hook nil
300 "Hook run when processing a PART message directed at our nick.
302 The hook receives one argument, the current BUFFER.
303 See also `erc-server-QUIT-functions', `erc-quit-hook' and
304 `erc-disconnected-hook'."
308 (defcustom erc-kick-hook nil
309 "Hook run when processing a KICK message directed at our nick.
311 The hook receives one argument, the current BUFFER.
312 See also `erc-server-PART-functions' and `erc-part-hook'."
316 (defcustom erc-nick-changed-functions nil
317 "List of functions run when your nick was successfully changed.
319 Each function should accept two arguments, NEW-NICK and OLD-NICK."
323 (defcustom erc-connect-pre-hook
'(erc-initialize-log-marker)
324 "Hook called just before `erc' calls `erc-connect'.
325 Functions are passed a buffer as the first argument."
330 (defvar erc-channel-users nil
331 "A hash table of members in the current channel, which
332 associates nicknames with cons cells of the form:
333 \(USER . MEMBER-DATA) where USER is a pointer to an
334 erc-server-user struct, and MEMBER-DATA is a pointer to an
335 erc-channel-user struct.")
336 (make-variable-buffer-local 'erc-channel-users
)
338 (defvar erc-server-users nil
339 "A hash table of users on the current server, which associates
340 nicknames with erc-server-user struct instances.")
341 (make-variable-buffer-local 'erc-server-users
)
343 (defun erc-downcase (string)
344 "Convert STRING to IRC standard conforming downcase."
345 (let ((s (downcase string
))
351 (while (string-match "[]\\[~]" s
)
352 (aset s
(match-beginning 0)
353 (cdr (assq (aref s
(match-beginning 0)) c
)))))
356 (defmacro erc-with-server-buffer
(&rest body
)
357 "Execute BODY in the current ERC server buffer.
358 If no server buffer exists, return nil."
359 (let ((buffer (make-symbol "buffer")))
360 `(let ((,buffer
(erc-server-buffer)))
361 (when (buffer-live-p ,buffer
)
362 (with-current-buffer ,buffer
364 (put 'erc-with-server-buffer
'lisp-indent-function
0)
365 (put 'erc-with-server-buffer
'edebug-form-spec
'(body))
367 (defstruct (erc-server-user (:type vector
) :named
)
369 nickname host login full-name info
372 ;; This is an alist of the form (BUFFER . CHANNEL-DATA), where
373 ;; CHANNEL-DATA is either nil or an erc-channel-user struct.
377 (defstruct (erc-channel-user (:type vector
) :named
)
379 ;; Last message time (in the form of the return value of
382 ;; This is useful for ordered name completion.
383 (last-message-time nil
))
385 (defsubst erc-get-channel-user
(nick)
386 "Finds the (USER . CHANNEL-DATA) element corresponding to NICK
387 in the current buffer's `erc-channel-users' hash table."
388 (gethash (erc-downcase nick
) erc-channel-users
))
390 (defsubst erc-get-server-user
(nick)
391 "Finds the USER corresponding to NICK in the current server's
392 `erc-server-users' hash table."
393 (erc-with-server-buffer
394 (gethash (erc-downcase nick
) erc-server-users
)))
396 (defsubst erc-add-server-user
(nick user
)
397 "This function is for internal use only.
399 Adds USER with nickname NICK to the `erc-server-users' hash table."
400 (erc-with-server-buffer
401 (puthash (erc-downcase nick
) user erc-server-users
)))
403 (defsubst erc-remove-server-user
(nick)
404 "This function is for internal use only.
406 Removes the user with nickname NICK from the `erc-server-users'
407 hash table. This user is not removed from the
408 `erc-channel-users' lists of other buffers.
410 See also: `erc-remove-user'."
411 (erc-with-server-buffer
412 (remhash (erc-downcase nick
) erc-server-users
)))
414 (defun erc-change-user-nickname (user new-nick
)
415 "This function is for internal use only.
417 Changes the nickname of USER to NEW-NICK in the
418 `erc-server-users' hash table. The `erc-channel-users' lists of
419 other buffers are also changed."
420 (let ((nick (erc-server-user-nickname user
)))
421 (setf (erc-server-user-nickname user
) new-nick
)
422 (erc-with-server-buffer
423 (remhash (erc-downcase nick
) erc-server-users
)
424 (puthash (erc-downcase new-nick
) user erc-server-users
))
425 (dolist (buf (erc-server-user-buffers user
))
426 (if (buffer-live-p buf
)
427 (with-current-buffer buf
428 (let ((cdata (erc-get-channel-user nick
)))
429 (remhash (erc-downcase nick
) erc-channel-users
)
430 (puthash (erc-downcase new-nick
) cdata
431 erc-channel-users
)))))))
433 (defun erc-remove-channel-user (nick)
434 "This function is for internal use only.
436 Removes the user with nickname NICK from the `erc-channel-users'
437 list for this channel. If this user is not in the
438 `erc-channel-users' list of any other buffers, the user is also
439 removed from the server's `erc-server-users' list.
441 See also: `erc-remove-server-user' and `erc-remove-user'."
442 (let ((channel-data (erc-get-channel-user nick
)))
444 (let ((user (car channel-data
)))
445 (setf (erc-server-user-buffers user
)
446 (delq (current-buffer)
447 (erc-server-user-buffers user
)))
448 (remhash (erc-downcase nick
) erc-channel-users
)
449 (if (null (erc-server-user-buffers user
))
450 (erc-remove-server-user nick
))))))
452 (defun erc-remove-user (nick)
453 "This function is for internal use only.
455 Removes the user with nickname NICK from the `erc-server-users'
456 list as well as from all `erc-channel-users' lists.
458 See also: `erc-remove-server-user' and
459 `erc-remove-channel-user'."
460 (let ((user (erc-get-server-user nick
)))
462 (let ((buffers (erc-server-user-buffers user
)))
463 (dolist (buf buffers
)
464 (if (buffer-live-p buf
)
465 (with-current-buffer buf
466 (remhash (erc-downcase nick
) erc-channel-users
)
467 (run-hooks 'erc-channel-members-changed-hook
)))))
468 (erc-remove-server-user nick
))))
470 (defun erc-remove-channel-users ()
471 "This function is for internal use only.
473 Removes all users in the current channel. This is called by
474 `erc-server-PART' and `erc-server-QUIT'."
475 (when (and erc-server-connected
476 (erc-server-process-alive)
477 (hash-table-p erc-channel-users
))
478 (maphash (lambda (nick cdata
)
479 (erc-remove-channel-user nick
))
481 (clrhash erc-channel-users
)))
483 (defsubst erc-channel-user-op-p
(nick)
484 "Return t if NICK is an operator in the current channel."
486 (hash-table-p erc-channel-users
)
487 (let ((cdata (erc-get-channel-user nick
)))
488 (and cdata
(cdr cdata
)
489 (erc-channel-user-op (cdr cdata
))))))
491 (defsubst erc-channel-user-voice-p
(nick)
492 "Return t if NICK has voice in the current channel."
494 (hash-table-p erc-channel-users
)
495 (let ((cdata (erc-get-channel-user nick
)))
496 (and cdata
(cdr cdata
)
497 (erc-channel-user-voice (cdr cdata
))))))
499 (defun erc-get-channel-user-list ()
500 "Returns a list of users in the current channel. Each element
501 of the list is of the form (USER . CHANNEL-DATA), where USER is
502 an erc-server-user struct, and CHANNEL-DATA is either `nil' or an
503 erc-channel-user struct.
505 See also: `erc-sort-channel-users-by-activity'"
507 (if (hash-table-p erc-channel-users
)
508 (maphash (lambda (nick cdata
)
509 (setq users
(cons cdata users
)))
513 (defun erc-get-server-nickname-list ()
514 "Returns a list of known nicknames on the current server."
515 (erc-with-server-buffer
517 (when (hash-table-p erc-server-users
)
518 (maphash (lambda (n user
)
520 (cons (erc-server-user-nickname user
)
525 (defun erc-get-channel-nickname-list ()
526 "Returns a list of known nicknames on the current channel."
528 (when (hash-table-p erc-channel-users
)
529 (maphash (lambda (n cdata
)
531 (cons (erc-server-user-nickname (car cdata
))
536 (defun erc-get-server-nickname-alist ()
537 "Returns an alist of known nicknames on the current server."
538 (erc-with-server-buffer
540 (when (hash-table-p erc-server-users
)
541 (maphash (lambda (n user
)
543 (cons (cons (erc-server-user-nickname user
) nil
)
548 (defun erc-get-channel-nickname-alist ()
549 "Returns an alist of known nicknames on the current channel."
551 (when (hash-table-p erc-channel-users
)
552 (maphash (lambda (n cdata
)
554 (cons (cons (erc-server-user-nickname (car cdata
)) nil
)
559 (defun erc-sort-channel-users-by-activity (list)
560 "Sorts LIST such that users which have spoken most recently are
561 listed first. LIST must be of the form (USER . CHANNEL-DATA).
563 See also: `erc-get-channel-user-list'."
568 (let ((tx (erc-channel-user-last-message-time (cdr x
)))
569 (ty (erc-channel-user-last-message-time (cdr y
))))
576 (defun erc-sort-channel-users-alphabetically (list)
577 "Sort LIST so that users' nicknames are in alphabetical order.
578 LIST must be of the form (USER . CHANNEL-DATA).
580 See also: `erc-get-channel-user-list'."
585 (let ((nickx (downcase (erc-server-user-nickname (car x
))))
586 (nicky (downcase (erc-server-user-nickname (car y
)))))
589 (string-lessp nickx nicky
)
593 (defvar erc-channel-topic nil
594 "A topic string for the channel. Should only be used in channel-buffers.")
595 (make-variable-buffer-local 'erc-channel-topic
)
597 (defvar erc-channel-modes nil
598 "List of strings representing channel modes.
599 E.g. '(\"i\" \"m\" \"s\" \"b Quake!*@*\")
600 \(not sure the ban list will be here, but why not)")
601 (make-variable-buffer-local 'erc-channel-modes
)
603 (defvar erc-insert-marker nil
604 "The place where insertion of new text in erc buffers should happen.")
605 (make-variable-buffer-local 'erc-insert-marker
)
607 (defvar erc-input-marker nil
608 "The marker where input should be inserted.")
609 (make-variable-buffer-local 'erc-input-marker
)
611 (defun erc-string-no-properties (string)
612 "Return a copy of STRING will all text-properties removed."
613 (let ((newstring (copy-sequence string
)))
614 (set-text-properties 0 (length newstring
) nil newstring
)
617 (defcustom erc-prompt
"ERC>"
618 "Prompt used by ERC. Trailing whitespace is not required."
620 :type
'(choice string function
))
623 "Return the input prompt as a string.
625 See also the variable `erc-prompt'."
626 (let ((prompt (if (functionp erc-prompt
)
629 (if (> (length prompt
) 0)
633 (defcustom erc-command-indicator nil
634 "Indicator used by ERC for showing commands.
636 If non-nil, this will be used in the ERC buffer to indicate
637 commands (i.e., input starting with a '/').
639 If nil, the prompt will be constructed from the variable `erc-prompt'."
641 :type
'(choice (const nil
) string function
))
643 (defun erc-command-indicator ()
644 "Return the command indicator prompt as a string.
646 This only has any meaning if the variable `erc-command-indicator' is non-nil."
647 (and erc-command-indicator
648 (let ((prompt (if (functionp erc-command-indicator
)
649 (funcall erc-command-indicator
)
650 erc-command-indicator
)))
651 (if (> (length prompt
) 0)
655 (defcustom erc-notice-prefix
"*** "
656 "Prefix for all notices."
660 (defcustom erc-notice-highlight-type
'all
661 "Determines how to highlight notices.
662 See `erc-notice-prefix'.
664 The following values are allowed:
666 'prefix - highlight notice prefix only
667 'all - highlight the entire notice
669 Any other value disables notice's highlighting altogether."
671 :type
'(choice (const :tag
"highlight notice prefix only" prefix
)
672 (const :tag
"highlight the entire notice" all
)
673 (const :tag
"don't highlight notices at all" nil
)))
675 (defcustom erc-echo-notice-hook nil
676 "Specifies a list of functions to call to echo a private
677 notice. Each function is called with four arguments, the string
678 to display, the parsed server message, the target buffer (or
679 nil), and the sender. The functions are called in order, until a
680 function evaluates to non-nil. These hooks are called after
681 those specified in `erc-echo-notice-always-hook'.
683 See also: `erc-echo-notice-always-hook',
684 `erc-echo-notice-in-default-buffer',
685 `erc-echo-notice-in-target-buffer',
686 `erc-echo-notice-in-minibuffer',
687 `erc-echo-notice-in-server-buffer',
688 `erc-echo-notice-in-active-non-server-buffer',
689 `erc-echo-notice-in-active-buffer',
690 `erc-echo-notice-in-user-buffers',
691 `erc-echo-notice-in-user-and-target-buffers',
692 `erc-echo-notice-in-first-user-buffer'"
695 :options
'(erc-echo-notice-in-default-buffer
696 erc-echo-notice-in-target-buffer
697 erc-echo-notice-in-minibuffer
698 erc-echo-notice-in-server-buffer
699 erc-echo-notice-in-active-non-server-buffer
700 erc-echo-notice-in-active-buffer
701 erc-echo-notice-in-user-buffers
702 erc-echo-notice-in-user-and-target-buffers
703 erc-echo-notice-in-first-user-buffer
))
705 (defcustom erc-echo-notice-always-hook
706 '(erc-echo-notice-in-default-buffer)
707 "Specifies a list of functions to call to echo a private
708 notice. Each function is called with four arguments, the string
709 to display, the parsed server message, the target buffer (or
710 nil), and the sender. The functions are called in order, and all
711 functions are called. These hooks are called before those
712 specified in `erc-echo-notice-hook'.
714 See also: `erc-echo-notice-hook',
715 `erc-echo-notice-in-default-buffer',
716 `erc-echo-notice-in-target-buffer',
717 `erc-echo-notice-in-minibuffer',
718 `erc-echo-notice-in-server-buffer',
719 `erc-echo-notice-in-active-non-server-buffer',
720 `erc-echo-notice-in-active-buffer',
721 `erc-echo-notice-in-user-buffers',
722 `erc-echo-notice-in-user-and-target-buffers',
723 `erc-echo-notice-in-first-user-buffer'"
726 :options
'(erc-echo-notice-in-default-buffer
727 erc-echo-notice-in-target-buffer
728 erc-echo-notice-in-minibuffer
729 erc-echo-notice-in-server-buffer
730 erc-echo-notice-in-active-non-server-buffer
731 erc-echo-notice-in-active-buffer
732 erc-echo-notice-in-user-buffers
733 erc-echo-notice-in-user-and-target-buffers
734 erc-echo-notice-in-first-user-buffer
))
736 ;; other tunable parameters
738 (defcustom erc-whowas-on-nosuchnick nil
739 "If non-nil, do a whowas on a nick if no such nick."
743 (defcustom erc-verbose-server-ping nil
744 "If non-nil, show every time you get a PING or PONG from the server."
748 (defcustom erc-public-away-p nil
749 "Let others know you are back when you are no longer marked away.
750 This happens in this form:
751 * <nick> is back (gone for <time>)
753 Many consider it impolite to do so automatically."
757 (defcustom erc-away-nickname nil
758 "The nickname to take when you are marked as being away."
760 :type
'(choice (const nil
)
763 (defcustom erc-paranoid nil
764 "If non-nil, then all incoming CTCP requests will be shown."
768 (defcustom erc-disable-ctcp-replies nil
769 "Disable replies to CTCP requests that require a reply.
770 If non-nil, then all incoming CTCP requests that normally require
771 an automatic reply (like VERSION or PING) will be ignored. Good to
772 set if some hacker is trying to flood you away."
776 (defcustom erc-anonymous-login t
777 "Be paranoid, don't give away your machine name."
781 (defcustom erc-prompt-for-channel-key nil
782 "Prompt for channel key when using `erc-join-channel' interactively."
786 (defcustom erc-email-userid
"user"
787 "Use this as your email user ID."
791 (defcustom erc-system-name nil
792 "Use this as the name of your system.
793 If nil, ERC will call `system-name' to get this information."
795 :type
'(choice (const :tag
"Default system name" nil
)
798 (defcustom erc-ignore-list nil
799 "List of regexps matching user identifiers to ignore.
801 A user identifier has the form \"nick!login@host\". If an
802 identifier matches, the message from the person will not be
805 :type
'(repeat regexp
))
806 (make-variable-buffer-local 'erc-ignore-list
)
808 (defcustom erc-ignore-reply-list nil
809 "List of regexps matching user identifiers to ignore completely.
811 This differs from `erc-ignore-list' in that it also ignores any
812 messages directed at the user.
814 A user identifier has the form \"nick!login@host\".
816 If an identifier matches, or a message is addressed to a nick
817 whose identifier matches, the message will not be processed.
819 CAVEAT: ERC doesn't know about the user and host of anyone who
820 was already in the channel when you joined, but never said
821 anything, so it won't be able to match the user and host of those
822 people. You can update the ERC internal info using /WHO *."
824 :type
'(repeat regexp
))
826 (defvar erc-flood-protect t
827 "If non-nil, flood protection is enabled.
828 Flooding is sending too much information to the server in too
829 short of an interval, which may cause the server to terminate the
832 See `erc-server-flood-margin' for other flood-related parameters.")
836 (defcustom erc-startup-file-list
837 (list (concat erc-user-emacs-directory
".ercrc.el")
838 (concat erc-user-emacs-directory
".ercrc")
839 "~/.ercrc.el" "~/.ercrc" ".ercrc.el" ".ercrc")
840 "List of files to try for a startup script.
841 The first existent and readable one will get executed.
843 If the filename ends with `.el' it is presumed to be an Emacs Lisp
844 script and it gets (load)ed. Otherwise it is treated as a bunch of
845 regular IRC commands."
847 :type
'(repeat file
))
849 (defcustom erc-script-path nil
850 "List of directories to look for a script in /load command.
851 The script is first searched in the current directory, then in each
852 directory in the list."
854 :type
'(repeat directory
))
856 (defcustom erc-script-echo t
857 "If non-nil, echo the IRC script commands locally."
861 (defvar erc-last-saved-position nil
862 "A marker containing the position the current buffer was last saved at.")
863 (make-variable-buffer-local 'erc-last-saved-position
)
865 (defcustom erc-kill-buffer-on-part nil
866 "Kill the channel buffer on PART.
867 This variable should probably stay nil, as ERC can reuse buffers if
868 you rejoin them later."
869 :group
'erc-quit-and-part
872 (defcustom erc-kill-queries-on-quit nil
873 "Kill all query (also channel) buffers of this server on QUIT.
874 See the variable `erc-kill-buffer-on-part' for details."
875 :group
'erc-quit-and-part
878 (defcustom erc-kill-server-buffer-on-quit nil
879 "Kill the server buffer of the process on QUIT."
880 :group
'erc-quit-and-part
883 (defcustom erc-quit-reason-various-alist nil
884 "Alist of possible arguments to the /quit command.
886 Each element has the form:
889 If REGEXP matches the argument to /quit, then its relevant RESULT
890 will be used. RESULT may be either a string, or a function. If
891 a function, it should return the quit message as a string.
893 If no elements match, then the empty string is used.
896 (setq erc-quit-reason-various-alist
897 '((\"zippy\" erc-quit-reason-zippy)
898 (\"xmms\" dme:now-playing)
899 (\"version\" erc-quit-reason-normal)
900 (\"home\" \"Gone home !\")
901 (\"^$\" \"Default Reason\")))
902 If the user types \"/quit zippy\", then a Zippy the Pinhead quotation
903 will be used as the quit message."
904 :group
'erc-quit-and-part
905 :type
'(repeat (list regexp
(choice (string) (function)))))
907 (defcustom erc-part-reason-various-alist nil
908 "Alist of possible arguments to the /part command.
910 Each element has the form:
913 If REGEXP matches the argument to /part, then its relevant RESULT
914 will be used. RESULT may be either a string, or a function. If
915 a function, it should return the part message as a string.
917 If no elements match, then the empty string is used.
920 (setq erc-part-reason-various-alist
921 '((\"zippy\" erc-part-reason-zippy)
922 (\"xmms\" dme:now-playing)
923 (\"version\" erc-part-reason-normal)
924 (\"home\" \"Gone home !\")
925 (\"^$\" \"Default Reason\")))
926 If the user types \"/part zippy\", then a Zippy the Pinhead quotation
927 will be used as the part message."
928 :group
'erc-quit-and-part
929 :type
'(repeat (list regexp
(choice (string) (function)))))
931 (defcustom erc-quit-reason
'erc-quit-reason-normal
932 "A function which returns the reason for quitting.
934 The function is passed a single argument, the string typed by the
935 user after \"/quit\"."
936 :group
'erc-quit-and-part
937 :type
'(choice (const erc-quit-reason-normal
)
938 (const erc-quit-reason-zippy
)
939 (const erc-quit-reason-various
)
942 (defcustom erc-part-reason
'erc-part-reason-normal
943 "A function which returns the reason for parting a channel.
945 The function is passed a single argument, the string typed by the
946 user after \"/PART\"."
947 :group
'erc-quit-and-part
948 :type
'(choice (const erc-part-reason-normal
)
949 (const erc-part-reason-zippy
)
950 (const erc-part-reason-various
)
953 (defvar erc-grab-buffer-name
"*erc-grab*"
954 "The name of the buffer created by `erc-grab-region'.")
956 ;; variables available for IRC scripts
958 (defvar erc-user-information
"ERC User"
959 "USER_INFORMATION IRC variable.")
963 (defgroup erc-hooks nil
964 "Hook variables for fancy customizations of ERC."
967 (defcustom erc-mode-hook nil
968 "Hook run after `erc-mode' setup is finished."
971 :options
'(erc-add-scroll-to-bottom))
973 (defcustom erc-timer-hook nil
974 "Put functions which should get called more or less periodically here.
975 The idea is that servers always play ping pong with the client, and so there
976 is no need for any idle-timer games with Emacs."
980 (defcustom erc-insert-pre-hook nil
981 "Hook called first when some text is inserted through `erc-display-line'.
982 It gets called with one argument, STRING.
983 To be able to modify the inserted text, use `erc-insert-modify-hook' instead.
984 Filtering functions can set `erc-insert-this' to nil to avoid
985 display of that particular string at all."
989 (defcustom erc-send-pre-hook nil
990 "Hook called first when some text is sent through `erc-send-current-line'.
991 It gets called with one argument, STRING.
993 To change the text that will be sent, set the variable STR which is
994 used in `erc-send-current-line'.
996 To change the text inserted into the buffer without changing the text
997 that will be sent, use `erc-send-modify-hook' instead.
999 Filtering functions can set `erc-send-this' to nil to avoid sending of
1000 that particular string at all and `erc-insert-this' to prevent
1001 inserting that particular string into the buffer.
1003 Note that it's useless to set `erc-send-this' to nil and
1004 `erc-insert-this' to t. ERC is sane enough to not insert the text
1009 (defvar erc-insert-this t
1010 "Insert the text into the target buffer or not.
1011 Functions on `erc-insert-pre-hook' can set this variable to nil
1012 if they wish to avoid insertion of a particular string.")
1014 (defvar erc-send-this t
1015 "Send the text to the target or not.
1016 Functions on `erc-send-pre-hook' can set this variable to nil
1017 if they wish to avoid sending of a particular string.")
1019 (defcustom erc-insert-modify-hook
()
1020 "Insertion hook for functions that will change the text's appearance.
1021 This hook is called just after `erc-insert-pre-hook' when the value
1022 of `erc-insert-this' is t.
1023 While this hook is run, narrowing is in effect and `current-buffer' is
1024 the buffer where the text got inserted. One possible value to add here
1029 (defcustom erc-insert-post-hook nil
1030 "This hook is called just after `erc-insert-modify-hook'.
1031 At this point, all modifications from prior hook functions are done."
1034 :options
'(erc-truncate-buffer
1036 erc-save-buffer-in-logs
))
1038 (defcustom erc-send-modify-hook nil
1039 "Sending hook for functions that will change the text's appearance.
1040 This hook is called just after `erc-send-pre-hook' when the values
1041 of `erc-send-this' and `erc-insert-this' are both t.
1042 While this hook is run, narrowing is in effect and `current-buffer' is
1043 the buffer where the text got inserted.
1045 Note that no function in this hook can change the appearance of the
1046 text that is sent. Only changing the sent text's appearance on the
1047 sending user's screen is possible. One possible value to add here
1052 (defcustom erc-send-post-hook nil
1053 "This hook is called just after `erc-send-modify-hook'.
1054 At this point, all modifications from prior hook functions are done.
1055 NOTE: The functions on this hook are called _before_ sending a command
1058 This function is called with narrowing, ala `erc-send-modify-hook'."
1061 :options
'(erc-make-read-only))
1063 (defcustom erc-send-completed-hook
1064 (when (featurep 'emacspeak
)
1067 (emacspeak-auditory-icon 'select-object
)))))
1068 "Hook called after a message has been parsed by ERC.
1070 The single argument to the functions is the unmodified string
1071 which the local user typed."
1074 ;; mode-specific tables
1076 (defvar erc-mode-syntax-table
1077 (let ((syntax-table (make-syntax-table)))
1078 (modify-syntax-entry ?
\" ". " syntax-table
)
1079 (modify-syntax-entry ?
\\ ". " syntax-table
)
1080 (modify-syntax-entry ?
' "w " syntax-table
)
1081 ;; Make dabbrev-expand useful for nick names
1082 (modify-syntax-entry ?
< "." syntax-table
)
1083 (modify-syntax-entry ?
> "." syntax-table
)
1085 "Syntax table used while in ERC mode.")
1087 (defvar erc-mode-abbrev-table nil
1088 "Abbrev table used while in ERC mode.")
1089 (define-abbrev-table 'erc-mode-abbrev-table
())
1091 (defvar erc-mode-map
1092 (let ((map (make-sparse-keymap)))
1093 (define-key map
"\C-m" 'erc-send-current-line
)
1094 (define-key map
"\C-a" 'erc-bol
)
1095 (define-key map
[home] 'erc-bol)
1096 (define-key map "\C-c\C-a" 'erc-bol)
1097 (define-key map "\C-c\C-b" 'erc-iswitchb)
1098 (define-key map "\C-c\C-c" 'erc-toggle-interpret-controls)
1099 (define-key map "\C-c\C-d" 'erc-input-action)
1100 (define-key map "\C-c\C-e" 'erc-toggle-ctcp-autoresponse)
1101 (define-key map "\C-c\C-f" 'erc-toggle-flood-control)
1102 (define-key map "\C-c\C-i" 'erc-invite-only-mode)
1103 (define-key map "\C-c\C-j" 'erc-join-channel)
1104 (define-key map "\C-c\C-n" 'erc-channel-names)
1105 (define-key map "\C-c\C-o" 'erc-get-channel-mode-from-keypress)
1106 (define-key map "\C-c\C-p" 'erc-part-from-channel)
1107 (define-key map "\C-c\C-q" 'erc-quit-server)
1108 (define-key map "\C-c\C-r" 'erc-remove-text-properties-region)
1109 (define-key map "\C-c\C-t" 'erc-set-topic)
1110 (define-key map "\C-c\C-u" 'erc-kill-input)
1111 (define-key map "\C-c\C-x" 'erc-quit-server)
1112 (define-key map "\M-\t" 'ispell-complete-word)
1113 (define-key map "\t" 'completion-at-point)
1115 ;; Suppress `font-lock-fontify-block' key binding since it
1116 ;; destroys face properties.
1117 (if (fboundp 'command-remapping)
1118 (define-key map [remap font-lock-fontify-block] 'undefined)
1119 (substitute-key-definition
1120 'font-lock-fontify-block 'undefined map global-map))
1127 ; Honestly, I have a horrible sense of color and the "defaults" below
1128 ; are supposed to be really bad. But colors ARE required in IRC to
1129 ; convey different parts of conversation. If you think you know better
1130 ; defaults - send them to me.
1132 ;; Now colors are a bit nicer, at least to my eyes.
1133 ;; You may still want to change them to better fit your background.-- S.B.
1135 (defgroup erc-faces nil
1139 (defface erc-default-face '((t))
1143 (defface erc-direct-msg-face '((t (:foreground "IndianRed")))
1144 "ERC face used for messages you receive in the main erc buffer."
1147 (defface erc-header-line
1148 '((t (:foreground "grey20" :background "grey90")))
1149 "ERC face used for the header line.
1151 This will only be used if `erc-header-line-face-method' is non-nil."
1154 (defface erc-input-face '((t (:foreground "brown")))
1155 "ERC face used for your input."
1158 (defface erc-prompt-face
1159 '((t (:bold t :foreground "Black" :background "lightBlue2")))
1160 "ERC face for the prompt."
1163 (defface erc-command-indicator-face
1165 "ERC face for the command indicator.
1166 See the variable `erc-command-indicator'."
1169 (defface erc-notice-face
1170 (if (or (featurep 'xemacs)
1171 (< emacs-major-version 22))
1172 '((t (:bold t :foreground "blue")))
1173 '((((class color) (min-colors 88))
1174 (:bold t :foreground "SlateBlue"))
1175 (t (:bold t :foreground "blue"))))
1176 "ERC face for notices."
1179 (defface erc-action-face '((t (:bold t)))
1180 "ERC face for actions generated by /ME."
1183 (defface erc-error-face '((t (:foreground "red")))
1184 "ERC face for errors."
1187 ;; same default color as `erc-input-face'
1188 (defface erc-my-nick-face '((t (:bold t :foreground "brown")))
1189 "ERC face for your current nickname in messages sent by you.
1190 See also `erc-show-my-nick'."
1193 (defface erc-nick-default-face '((t (:bold t)))
1194 "ERC nickname default face."
1197 (defface erc-nick-msg-face '((t (:bold t :foreground "IndianRed")))
1198 "ERC nickname face for private messages."
1201 ;; Debugging support
1203 (defvar erc-log-p nil
1204 "When set to t, generate debug messages in a separate debug buffer.")
1206 (defvar erc-debug-log-file (expand-file-name "ERC.debug")
1207 "Debug log file name.")
1209 (defvar erc-dbuf nil)
1210 (make-variable-buffer-local 'erc-dbuf)
1212 (defmacro define-erc-module (name alias doc enable-body disable-body
1214 "Define a new minor mode using ERC conventions.
1215 Symbol NAME is the name of the module.
1216 Symbol ALIAS is the alias to use, or nil.
1217 DOC is the documentation string to use for the minor mode.
1218 ENABLE-BODY is a list of expressions used to enable the mode.
1219 DISABLE-BODY is a list of expressions used to disable the mode.
1220 If LOCAL-P is non-nil, the mode will be created as a buffer-local
1221 mode, rather than a global one.
1223 This will define a minor mode called erc-NAME-mode, possibly
1224 an alias erc-ALIAS-mode, as well as the helper functions
1225 erc-NAME-enable, and erc-NAME-disable.
1229 ;;;###autoload (autoload 'erc-replace-mode \"erc-replace\")
1230 (define-erc-module replace nil
1231 \"This mode replaces incoming text according to `erc-replace-alist'.\"
1232 ((add-hook 'erc-insert-modify-hook
1233 'erc-replace-insert))
1234 ((remove-hook 'erc-insert-modify-hook
1235 'erc-replace-insert)))"
1236 (let* ((sn (symbol-name name))
1237 (mode (intern (format "erc-%s-mode" (downcase sn))))
1238 (group (intern (format "erc-%s" (downcase sn))))
1239 (enable (intern (format "erc-%s-enable" (downcase sn))))
1240 (disable (intern (format "erc-%s-disable" (downcase sn)))))
1242 (erc-define-minor-mode
1244 ,(format "Toggle ERC %S mode.
1245 With a prefix argument ARG, enable %s if ARG is positive,
1246 and disable it otherwise. If called from Lisp, enable the mode
1247 if ARG is omitted or nil.
1250 :global ,(not local-p) :group (quote ,group)
1255 ,(format "Enable ERC %S mode."
1258 (add-to-list 'erc-modules (quote ,name))
1262 ,(format "Disable ERC %S mode."
1265 (setq erc-modules (delq (quote ,name) erc-modules))
1268 ,(when (and alias (not (eq name alias)))
1272 (format "erc-%s-mode"
1273 (downcase (symbol-name alias)))))
1276 ;; For find-function and find-variable.
1277 (put ',mode 'definition-name ',name)
1278 (put ',enable 'definition-name ',name)
1279 (put ',disable 'definition-name ',name))))
1281 (put 'define-erc-module 'doc-string-elt 3)
1283 (defun erc-once-with-server-event (event &rest forms)
1284 "Execute FORMS the next time EVENT occurs in the `current-buffer'.
1286 You should make sure that `current-buffer' is a server buffer.
1288 This function temporarily adds a function to EVENT's hook to
1289 execute FORMS. After FORMS are run, the function is removed from
1290 EVENT's hook. The last expression of FORMS should be either nil
1291 or t, where nil indicates that the other functions on EVENT's hook
1292 should be run too, and t indicates that other functions should
1295 Please be sure to use this function in server-buffers. In
1296 channel-buffers it may not work at all, as it uses the LOCAL
1297 argument of `add-hook' and `remove-hook' to ensure multiserver
1299 (unless (erc-server-buffer-p)
1301 "You should only run `erc-once-with-server-event' in a server buffer"))
1302 (let ((fun (make-symbol "fun"))
1303 (hook (erc-get-hook event)))
1304 (put fun 'erc-original-buffer (current-buffer))
1305 (fset fun `(lambda (proc parsed)
1306 (with-current-buffer (get ',fun 'erc-original-buffer)
1307 (remove-hook ',hook ',fun t))
1310 (add-hook hook fun nil t)
1313 (defun erc-once-with-server-event-global (event &rest forms)
1314 "Execute FORMS the next time EVENT occurs in any server buffer.
1316 This function temporarily prepends a function to EVENT's hook to
1317 execute FORMS. After FORMS are run, the function is removed from
1318 EVENT's hook. The last expression of FORMS should be either nil
1319 or t, where nil indicates that the other functions on EVENT's hook
1320 should be run too, and t indicates that other functions should
1323 When FORMS execute, the current buffer is the server buffer associated with the
1324 connection over which the data was received that triggered EVENT."
1325 (let ((fun (make-symbol "fun"))
1326 (hook (erc-get-hook event)))
1327 (fset fun `(lambda (proc parsed)
1328 (remove-hook ',hook ',fun)
1331 (add-hook hook fun nil nil)
1334 (defmacro erc-log (string)
1335 "Logs STRING if logging is on (see `erc-log-p')."
1337 (erc-log-aux ,string)))
1339 (defun erc-server-buffer ()
1340 "Return the server buffer for the current buffer's process.
1341 The buffer-local variable `erc-server-process' is used to find
1342 the process buffer."
1343 (and (erc-server-buffer-live-p)
1344 (process-buffer erc-server-process)))
1346 (defun erc-server-buffer-live-p ()
1347 "Return t if the server buffer has not been killed."
1348 (and (processp erc-server-process)
1349 (buffer-live-p (process-buffer erc-server-process))))
1351 (defun erc-server-buffer-p (&optional buffer)
1352 "Return non-nil if argument BUFFER is an ERC server buffer.
1354 If BUFFER is nil, the current buffer is used."
1355 (with-current-buffer (or buffer (current-buffer))
1356 (and (eq major-mode 'erc-mode)
1357 (null (erc-default-target)))))
1359 (defun erc-open-server-buffer-p (&optional buffer)
1360 "Return non-nil if argument BUFFER is an ERC server buffer that
1361 has an open IRC process.
1363 If BUFFER is nil, the current buffer is used."
1364 (and (erc-server-buffer-p)
1365 (erc-server-process-alive)))
1367 (defun erc-query-buffer-p (&optional buffer)
1368 "Return non-nil if BUFFER is an ERC query buffer.
1369 If BUFFER is nil, the current buffer is used."
1370 (with-current-buffer (or buffer (current-buffer))
1371 (let ((target (erc-default-target)))
1372 (and (eq major-mode 'erc-mode)
1374 (not (memq (aref target 0) '(?# ?& ?+ ?!)))))))
1376 (defun erc-ison-p (nick)
1377 "Return non-nil if NICK is online."
1378 (interactive "sNick: ")
1379 (erc-with-server-buffer
1380 (let ((erc-online-p 'unknown))
1381 (erc-once-with-server-event
1383 `(let ((ison (split-string (aref parsed 3))))
1384 (setq erc-online-p (car (erc-member-ignore-case ,nick ison)))
1386 (erc-server-send (format "ISON %s" nick))
1387 (while (eq erc-online-p 'unknown) (accept-process-output))
1389 (message "%s is %sonline"
1390 (or erc-online-p nick)
1391 (if erc-online-p "" "not "))
1394 (defun erc-log-aux (string)
1395 "Do the debug logging of STRING."
1396 (let ((cb (current-buffer))
1399 (session-buffer (erc-server-buffer)))
1402 (set-buffer session-buffer)
1403 (if (not (and erc-dbuf (bufferp erc-dbuf) (buffer-live-p erc-dbuf)))
1405 (setq erc-dbuf (get-buffer-create
1406 (concat "*ERC-DEBUG: "
1407 erc-session-server "*")))))
1408 (set-buffer erc-dbuf)
1409 (setq point (point))
1410 (setq was-eob (eobp))
1411 (goto-char (point-max))
1412 (insert (concat "** " string "\n"))
1413 (if was-eob (goto-char (point-max))
1416 (message "ERC: ** %s" string))))
1418 ;; Last active buffer, to print server messages in the right place
1420 (defvar erc-active-buffer nil
1421 "The current active buffer, the one where the user typed the last command.
1422 Defaults to the server buffer, and should only be set in the
1424 (make-variable-buffer-local 'erc-active-buffer)
1426 (defun erc-active-buffer ()
1427 "Return the value of `erc-active-buffer' for the current server.
1428 Defaults to the server buffer."
1429 (erc-with-server-buffer
1430 (if (buffer-live-p erc-active-buffer)
1432 (setq erc-active-buffer (current-buffer)))))
1434 (defun erc-set-active-buffer (buffer)
1435 "Set the value of `erc-active-buffer' to BUFFER."
1436 (cond ((erc-server-buffer)
1437 (with-current-buffer (erc-server-buffer)
1438 (setq erc-active-buffer buffer)))
1439 (t (setq erc-active-buffer buffer))))
1441 ;; Mode activation routines
1443 (define-derived-mode erc-mode fundamental-mode "ERC"
1444 "Major mode for Emacs IRC."
1445 (setq local-abbrev-table erc-mode-abbrev-table)
1446 (when (boundp 'next-line-add-newlines)
1447 (set (make-local-variable 'next-line-add-newlines) nil))
1448 (setq line-move-ignore-invisible t)
1449 (set (make-local-variable 'paragraph-separate)
1450 (concat "\C-l\\|\\(^" (regexp-quote (erc-prompt)) "\\)"))
1451 (set (make-local-variable 'paragraph-start)
1452 (concat "\\(" (regexp-quote (erc-prompt)) "\\)"))
1453 (add-hook 'completion-at-point-functions 'erc-complete-word-at-point nil t))
1457 (defconst erc-default-server "irc.freenode.net"
1458 "IRC server to use if it cannot be detected otherwise.")
1460 (defconst erc-default-port 6667
1461 "IRC port to use if it cannot be detected otherwise.")
1463 (defcustom erc-join-buffer 'buffer
1464 "Determines how to display a newly created IRC buffer.
1466 The available choices are:
1468 'window - in another window,
1469 'window-noselect - in another window, but don't select that one,
1470 'frame - in another frame,
1471 'bury - bury it in a new buffer,
1472 'buffer - in place of the current buffer,
1473 any other value - in place of the current buffer."
1475 :type '(choice (const :tag "Split window and select" window)
1476 (const :tag "Split window, don't select" window-noselect)
1477 (const :tag "New frame" frame)
1478 (const :tag "Bury in new buffer" bury)
1479 (const :tag "Use current buffer" buffer)
1480 (const :tag "Use current buffer" t)))
1482 (defcustom erc-frame-alist nil
1483 "Alist of frame parameters for creating erc frames.
1484 A value of nil means to use `default-frame-alist'."
1486 :type '(repeat (cons :format "%v"
1487 (symbol :tag "Parameter")
1488 (sexp :tag "Value"))))
1490 (defcustom erc-frame-dedicated-flag nil
1491 "Non-nil means the erc frames are dedicated to that buffer.
1492 This only has effect when `erc-join-buffer' is set to `frame'."
1496 (defcustom erc-reuse-frames t
1497 "Determines whether new frames are always created.
1498 Non-nil means that a new frame is not created to display an ERC
1499 buffer if there is already a window displaying it. This only has
1500 effect when `erc-join-buffer' is set to `frame'."
1504 (defun erc-channel-p (channel)
1505 "Return non-nil if CHANNEL seems to be an IRC channel name."
1506 (cond ((stringp channel)
1507 (memq (aref channel 0) '(?# ?& ?+ ?!)))
1508 ((and (bufferp channel) (buffer-live-p channel))
1509 (with-current-buffer channel
1510 (erc-channel-p (erc-default-target))))
1513 (defcustom erc-reuse-buffers t
1514 "If nil, create new buffers on joining a channel/query.
1515 If non-nil, a new buffer will only be created when you join
1516 channels with same names on different servers, or have query buffers
1517 open with nicks of the same name on different servers. Otherwise,
1518 the existing buffers will be reused."
1522 (defun erc-normalize-port (port)
1523 "Normalize the port specification PORT to integer form.
1524 PORT may be an integer, a string or a symbol. If it is a string or a
1525 symbol, it may have these values:
1529 * ircd-dalnet -> 7000"
1532 (erc-normalize-port (symbol-name port)))
1534 (let ((port-nr (string-to-number port)))
1538 ((string-equal port "irc")
1540 ((string-equal port "ircs")
1542 ((string-equal port "ircd")
1544 ((string-equal port "ircd-dalnet")
1553 (defun erc-port-equal (a b)
1554 "Check whether ports A and B are equal."
1555 (= (erc-normalize-port a) (erc-normalize-port b)))
1557 (defun erc-generate-new-buffer-name (server port target &optional proc)
1558 "Create a new buffer name based on the arguments."
1559 (when (numberp port) (setq port (number-to-string port)))
1560 (let ((buf-name (or target
1561 (or (let ((name (concat server ":" port)))
1562 (when (> (length name) 1)
1564 ;; This fallback should in fact never happen
1565 "*erc-server-buffer*")))
1567 ;; Reuse existing buffers, but not if the buffer is a connected server
1568 ;; buffer and not if its associated with a different server than the
1569 ;; current ERC buffer.
1570 ;; if buf-name is taken by a different connection (or by something !erc)
1571 ;; then see if "buf-name/server" meets the same criteria
1572 (dolist (candidate (list buf-name (concat buf-name "/" server)))
1573 (if (and (not buffer-name)
1575 (get-buffer candidate)
1577 (with-current-buffer (get-buffer candidate)
1578 (and (erc-server-buffer-p)
1579 (not (erc-server-process-alive)))))
1580 (with-current-buffer (get-buffer candidate)
1581 (and (string= erc-session-server server)
1582 (erc-port-equal erc-session-port port))))
1583 (setq buffer-name candidate)))
1584 ;; if buffer-name is unset, neither candidate worked out for us,
1585 ;; fallback to the old <N> uniquification method:
1586 (or buffer-name (generate-new-buffer-name buf-name)) ))
1588 (defun erc-get-buffer-create (server port target &optional proc)
1589 "Create a new buffer based on the arguments."
1590 (get-buffer-create (erc-generate-new-buffer-name server port target proc)))
1593 (defun erc-member-ignore-case (string list)
1594 "Return non-nil if STRING is a member of LIST.
1596 All strings are compared according to IRC protocol case rules, see
1598 (setq string (erc-downcase string))
1601 (if (string= string (erc-downcase (car list)))
1602 (throw 'result list)
1603 (setq list (cdr list))))))
1605 (defmacro erc-with-buffer (spec &rest body)
1606 "Execute BODY in the buffer associated with SPEC.
1608 SPEC should have the form
1612 If TARGET is a buffer, use it. Otherwise, use the buffer
1613 matching TARGET in the process specified by PROCESS.
1615 If PROCESS is nil, use the current `erc-server-process'.
1616 See `erc-get-buffer' for details.
1618 See also `with-current-buffer'.
1620 \(fn (TARGET [PROCESS]) BODY...)"
1621 (let ((buf (make-symbol "buf"))
1622 (proc (make-symbol "proc"))
1623 (target (make-symbol "target"))
1624 (process (make-symbol "process")))
1625 `(let* ((,target ,(car spec))
1626 (,process ,(cadr spec))
1627 (,buf (if (bufferp ,target)
1629 (let ((,proc (or ,process
1630 (and (processp erc-server-process)
1631 erc-server-process))))
1632 (if (and ,target ,proc)
1633 (erc-get-buffer ,target ,proc))))))
1634 (when (buffer-live-p ,buf)
1635 (with-current-buffer ,buf
1637 (put 'erc-with-buffer 'lisp-indent-function 1)
1638 (put 'erc-with-buffer 'edebug-form-spec '((form &optional form) body))
1640 (defun erc-get-buffer (target &optional proc)
1641 "Return the buffer matching TARGET in the process PROC.
1642 If PROC is not supplied, all processes are searched."
1643 (let ((downcased-target (erc-downcase target)))
1647 (let ((current (erc-default-target)))
1648 (and (stringp current)
1649 (string-equal downcased-target (erc-downcase current))
1650 (throw 'buffer (current-buffer)))))
1653 (defun erc-buffer-filter (predicate &optional proc)
1654 "Return a list of `erc-mode' buffers matching certain criteria.
1655 PREDICATE is a function executed with each buffer, if it returns t, that buffer
1656 is considered a valid match.
1658 PROC is either an `erc-server-process', identifying a certain
1659 server connection, or nil which means all open connections."
1663 (mapcar (lambda (buf)
1664 (when (buffer-live-p buf)
1665 (with-current-buffer buf
1666 (and (eq major-mode 'erc-mode)
1668 (eq proc erc-server-process))
1673 (defun erc-buffer-list (&optional predicate proc)
1674 "Return a list of ERC buffers.
1675 PREDICATE is a function which executes with every buffer satisfying
1676 the predicate. If PREDICATE is passed as nil, return a list of all ERC
1677 buffers. If PROC is given, the buffers local variable `erc-server-process'
1678 needs to match PROC."
1680 (setq predicate (lambda () t)))
1681 (erc-buffer-filter predicate proc))
1683 (defmacro erc-with-all-buffers-of-server (process pred &rest forms)
1684 "Execute FORMS in all buffers which have same process as this server.
1685 FORMS will be evaluated in all buffers having the process PROCESS and
1686 where PRED matches or in all buffers of the server process if PRED is
1688 ;; Make the evaluation have the correct order
1689 (let ((pre (make-symbol "pre"))
1690 (pro (make-symbol "pro")))
1691 `(let* ((,pro ,process)
1693 (res (mapcar (lambda (buffer)
1694 (with-current-buffer buffer
1696 (erc-buffer-list ,pre
1698 ;; Silence the byte-compiler by binding the result of mapcar to
1701 (put 'erc-with-all-buffers-of-server 'lisp-indent-function 1)
1702 (put 'erc-with-all-buffers-of-server 'edebug-form-spec '(form form body))
1704 ;; (iswitchb-mode) will autoload iswitchb.el
1705 (defvar iswitchb-temp-buflist)
1706 (declare-function iswitchb-read-buffer "iswitchb"
1707 (prompt &optional default require-match start matches-set))
1709 (defun erc-iswitchb (&optional arg)
1710 "Use `iswitchb-read-buffer' to prompt for a ERC buffer to switch to.
1711 When invoked with prefix argument, use all erc buffers. Without prefix
1712 ARG, allow only buffers related to same session server.
1713 If `erc-track-mode' is in enabled, put the last element of
1714 `erc-modified-channels-alist' in front of the buffer list.
1716 Due to some yet unresolved reason, global function `iswitchb-mode'
1717 needs to be active for this function to work."
1719 (let ((enabled (bound-and-true-p iswitchb-mode)))
1720 (or enabled (iswitchb-mode 1))
1722 (let ((iswitchb-make-buflist-hook
1724 (setq iswitchb-temp-buflist
1725 (mapcar 'buffer-name
1728 (when arg erc-server-process)))))))
1730 (iswitchb-read-buffer
1732 (if (boundp 'erc-modified-channels-alist)
1733 (buffer-name (caar (last erc-modified-channels-alist)))
1736 (or enabled (iswitchb-mode -1)))))
1738 (defun erc-channel-list (proc)
1739 "Return a list of channel buffers.
1740 PROC is the process for the server connection. If PROC is nil, return
1741 all channel buffers on all servers."
1744 (and (erc-default-target)
1745 (erc-channel-p (erc-default-target))))
1748 (defun erc-buffer-list-with-nick (nick proc)
1749 "Return buffers containing NICK in the `erc-channel-users' list."
1750 (with-current-buffer (process-buffer proc)
1751 (let ((user (gethash (erc-downcase nick) erc-server-users)))
1753 (erc-server-user-buffers user)
1756 ;; Some local variables
1758 (defvar erc-default-recipients nil
1759 "List of default recipients of the current buffer.")
1760 (make-variable-buffer-local 'erc-default-recipients)
1762 (defvar erc-session-user-full-name nil
1763 "Full name of the user on the current server.")
1764 (make-variable-buffer-local 'erc-session-user-full-name)
1766 (defvar erc-channel-user-limit nil
1767 "Limit of users per channel.")
1768 (make-variable-buffer-local 'erc-channel-user-limit)
1770 (defvar erc-channel-key nil
1771 "Key needed to join channel.")
1772 (make-variable-buffer-local 'erc-channel-key)
1774 (defvar erc-invitation nil
1775 "Last invitation channel.")
1776 (make-variable-buffer-local 'erc-invitation)
1778 (defvar erc-away nil
1779 "Non-nil indicates that we are away.
1781 Use `erc-away-time' to access this if you might be in a channel
1782 buffer rather than a server buffer.")
1783 (make-variable-buffer-local 'erc-away)
1785 (defvar erc-channel-list nil
1786 "Server channel list.")
1787 (make-variable-buffer-local 'erc-channel-list)
1789 (defvar erc-bad-nick nil
1790 "Non-nil indicates that we got a `nick in use' error while connecting.")
1791 (make-variable-buffer-local 'erc-bad-nick)
1793 (defvar erc-logged-in nil
1794 "Non-nil indicates that we are logged in.")
1795 (make-variable-buffer-local 'erc-logged-in)
1797 (defvar erc-default-nicks nil
1798 "The local copy of `erc-nick' - the list of nicks to choose from.")
1799 (make-variable-buffer-local 'erc-default-nicks)
1801 (defvar erc-nick-change-attempt-count 0
1802 "Used to keep track of how many times an attempt at changing nick is made.")
1803 (make-variable-buffer-local 'erc-nick-change-attempt-count)
1805 (defun erc-migrate-modules (mods)
1806 "Migrate old names of ERC modules to new ones."
1807 ;; modify `transforms' to specify what needs to be changed
1808 ;; each item is in the format '(old . new)
1809 (let ((transforms '((pcomplete . completion))))
1811 (mapcar (lambda (m) (or (cdr (assoc m transforms)) m))
1814 (defcustom erc-modules '(netsplit fill button match track completion readonly
1815 networks ring autojoin noncommands irccontrols
1816 move-to-prompt stamp menu list)
1817 "A list of modules which ERC should enable.
1818 If you set the value of this without using `customize' remember to call
1819 \(erc-update-modules) after you change it. When using `customize', modules
1820 removed from the list will be disabled."
1822 ;; replace outdated names with their newer equivalents
1823 (erc-migrate-modules (symbol-value sym)))
1824 :set (lambda (sym val)
1825 ;; disable modules which have just been removed
1826 (when (and (boundp 'erc-modules) erc-modules val)
1827 (dolist (module erc-modules)
1828 (unless (member module val)
1829 (let ((f (intern-soft (format "erc-%s-mode" module))))
1830 (when (and (fboundp f) (boundp f) (symbol-value f))
1831 (message "Disabling `erc-%s'" module)
1834 ;; this test is for the case where erc hasn't been loaded yet
1835 (when (fboundp 'erc-update-modules)
1836 (erc-update-modules)))
1840 (const :tag "autoaway: Set away status automatically" autoaway)
1841 (const :tag "autojoin: Join channels automatically" autojoin)
1842 (const :tag "button: Buttonize URLs, nicknames, and other text" button)
1843 (const :tag "capab: Mark unidentified users on servers supporting CAPAB"
1845 (const :tag "completion: Complete nicknames and commands (programmable)"
1847 (const :tag "hecomplete: Complete nicknames and commands (old)" hecomplete)
1848 (const :tag "dcc: Provide Direct Client-to-Client support" dcc)
1849 (const :tag "fill: Wrap long lines" fill)
1850 (const :tag "identd: Launch an identd server on port 8113" identd)
1851 (const :tag "irccontrols: Highlight or remove IRC control characters"
1853 (const :tag "keep-place: Leave point above un-viewed text" keep-place)
1854 (const :tag "list: List channels in a separate buffer" list)
1855 (const :tag "log: Save buffers in logs" log)
1856 (const :tag "match: Highlight pals, fools, and other keywords" match)
1857 (const :tag "menu: Display a menu in ERC buffers" menu)
1858 (const :tag "move-to-prompt: Move to the prompt when typing text"
1860 (const :tag "netsplit: Detect netsplits" netsplit)
1861 (const :tag "networks: Provide data about IRC networks" networks)
1862 (const :tag "noncommands: Don't display non-IRC commands after evaluation"
1865 "notify: Notify when the online status of certain users changes"
1867 (const :tag "page: Process CTCP PAGE requests from IRC" page)
1868 (const :tag "readonly: Make displayed lines read-only" readonly)
1869 (const :tag "replace: Replace text in messages" replace)
1870 (const :tag "ring: Enable an input history" ring)
1871 (const :tag "scrolltobottom: Scroll to the bottom of the buffer"
1873 (const :tag "services: Identify to Nickserv (IRC Services) automatically"
1875 (const :tag "smiley: Convert smileys to pretty icons" smiley)
1876 (const :tag "sound: Play sounds when you receive CTCP SOUND requests"
1878 (const :tag "stamp: Add timestamps to messages" stamp)
1879 (const :tag "spelling: Check spelling" spelling)
1880 (const :tag "track: Track channel activity in the mode-line" track)
1881 (const :tag "truncate: Truncate buffers to a certain size" truncate)
1882 (const :tag "unmorse: Translate morse code in messages" unmorse)
1883 (const :tag "xdcc: Act as an XDCC file-server" xdcc)
1884 (repeat :tag "Others" :inline t symbol))
1887 (defun erc-update-modules ()
1888 "Run this to enable erc-foo-mode for all modules in `erc-modules'."
1890 (dolist (mod erc-modules)
1891 (setq req (concat "erc-" (symbol-name mod)))
1893 ;; yuck. perhaps we should bring the filenames into sync?
1894 ((string= req "erc-capab-identify")
1895 (setq req "erc-capab"))
1896 ((string= req "erc-completion")
1897 (setq req "erc-pcomplete"))
1898 ((string= req "erc-pcomplete")
1899 (setq mod 'completion))
1900 ((string= req "erc-autojoin")
1901 (setq req "erc-join")))
1903 (require (intern req))
1905 (let ((sym (intern-soft (concat "erc-" (symbol-name mod) "-mode"))))
1908 (error "`%s' is not a known ERC module" mod))))))
1910 (defun erc-setup-buffer (buffer)
1911 "Consults `erc-join-buffer' to find out how to display `BUFFER'."
1912 (cond ((eq erc-join-buffer 'window)
1913 (if (active-minibuffer-window)
1914 (display-buffer buffer)
1915 (switch-to-buffer-other-window buffer)))
1916 ((eq erc-join-buffer 'window-noselect)
1917 (display-buffer buffer))
1918 ((eq erc-join-buffer 'bury)
1920 ((eq erc-join-buffer 'frame)
1921 (when (or (not erc-reuse-frames)
1922 (not (get-buffer-window buffer t)))
1925 (select-frame frame))
1926 (make-frame (or erc-frame-alist
1927 default-frame-alist)))
1928 (switch-to-buffer buffer)
1929 (when erc-frame-dedicated-flag
1930 (set-window-dedicated-p (selected-window) t))))
1932 (if (active-minibuffer-window)
1933 (display-buffer buffer)
1934 (switch-to-buffer buffer)))))
1936 (defun erc-open (&optional server port nick full-name
1937 connect passwd tgt-list channel process)
1938 "Connect to SERVER on PORT as NICK with FULL-NAME.
1940 If CONNECT is non-nil, connect to the server. Otherwise assume
1941 already connected and just create a separate buffer for the new
1944 Use PASSWD as user password on the server. If TGT-LIST is
1945 non-nil, use it to initialize `erc-default-recipients'.
1947 Returns the buffer for the given server or channel."
1948 (let ((server-announced-name (when (and (boundp 'erc-session-server)
1949 (string= server erc-session-server))
1950 erc-server-announced-name))
1951 (connected-p (unless connect erc-server-connected))
1952 (buffer (erc-get-buffer-create server port channel))
1953 (old-buffer (current-buffer))
1956 (when connect (run-hook-with-args 'erc-before-connect server port nick))
1957 (erc-update-modules)
1959 (setq old-point (point))
1961 (setq erc-server-announced-name server-announced-name)
1962 (setq erc-server-connected connected-p)
1963 ;; connection parameters
1964 (setq erc-server-process process)
1965 (setq erc-insert-marker (make-marker))
1966 (setq erc-input-marker (make-marker))
1967 ;; go to the end of the buffer and open a new line
1968 ;; (the buffer may have existed)
1969 (goto-char (point-max))
1971 (when (get-text-property (point) 'erc-prompt)
1972 (setq continued-session t)
1973 (set-marker erc-input-marker
1974 (or (next-single-property-change (point) 'erc-prompt)
1976 (unless continued-session
1977 (goto-char (point-max))
1979 (set-marker erc-insert-marker (point))
1980 ;; stack of default recipients
1981 (setq erc-default-recipients tgt-list)
1982 (setq erc-server-current-nick nil)
1983 ;; Initialize erc-server-users and erc-channel-users
1985 (progn ;; server buffer
1986 (setq erc-server-users
1987 (make-hash-table :test 'equal))
1988 (setq erc-channel-users nil))
1989 (progn ;; target buffer
1990 (setq erc-server-users nil)
1991 (setq erc-channel-users
1992 (make-hash-table :test 'equal))))
1993 ;; clear last incomplete line read
1994 (setq erc-server-filter-data nil)
1995 (setq erc-channel-topic "")
1996 ;; limit on the number of users on the channel (mode +l)
1997 (setq erc-channel-user-limit nil)
1998 (setq erc-channel-key nil)
1999 ;; last active buffer, defaults to this one
2000 (erc-set-active-buffer buffer)
2001 ;; last invitation channel
2002 (setq erc-invitation nil)
2003 ;; Server channel list
2004 (setq erc-channel-list ())
2005 ;; login-time 'nick in use' error
2006 (setq erc-bad-nick nil)
2007 ;; whether we have logged in
2008 (setq erc-logged-in nil)
2009 ;; The local copy of `erc-nick' - the list of nicks to choose
2010 (setq erc-default-nicks (if (consp erc-nick) erc-nick (list erc-nick)))
2012 (setq erc-session-password passwd)
2013 ;; debug output buffer
2016 (get-buffer-create (concat "*ERC-DEBUG: " server "*"))))
2018 (unless continued-session
2019 (goto-char (point-max))
2021 (if continued-session
2022 (goto-char old-point)
2023 (set-marker erc-insert-marker (point))
2024 (erc-display-prompt)
2025 (goto-char (point-max)))
2027 (erc-determine-parameters server port nick full-name)
2029 ;; Saving log file on exit
2030 (run-hook-with-args 'erc-connect-pre-hook buffer)
2033 (erc-server-connect erc-session-server erc-session-port buffer))
2034 (erc-update-mode-line)
2036 ;; Now display the buffer in a window as per user wishes.
2037 (unless (eq buffer old-buffer)
2039 ;; we can't log to debug buffer, it may not exist yet
2040 (message "erc: old buffer %s, switching to %s"
2042 (erc-setup-buffer buffer))
2046 (defun erc-initialize-log-marker (buffer)
2047 "Initialize the `erc-last-saved-position' marker to a sensible position.
2048 BUFFER is the current buffer."
2049 (with-current-buffer buffer
2050 (setq erc-last-saved-position (make-marker))
2051 (move-marker erc-last-saved-position
2052 (1- (marker-position erc-insert-marker)))))
2054 ;; interactive startup
2056 (defvar erc-server-history-list nil
2057 "IRC server interactive selection history list.")
2059 (defvar erc-nick-history-list nil
2060 "Nickname interactive selection history list.")
2062 (defun erc-already-logged-in (server port nick)
2063 "Return the buffers corresponding to a NICK on PORT of a session SERVER.
2064 This is determined by looking for the appropriate buffer and checking
2065 whether the connection is still alive.
2066 If no buffer matches, return nil."
2069 (and (erc-server-process-alive)
2070 (string= erc-session-server server)
2071 (erc-port-equal erc-session-port port)
2072 (erc-current-nick-p nick)))))
2074 (if (not (fboundp 'read-passwd))
2075 (defun read-passwd (prompt)
2076 "Substitute for `read-passwd' in early emacsen."
2077 (read-from-minibuffer prompt)))
2079 (defcustom erc-before-connect nil
2080 "Hook called before connecting to a server.
2081 This hook gets executed before `erc' actually invokes `erc-mode'
2082 with your input data. The functions in here get called with three
2083 parameters, SERVER, PORT and NICK."
2087 (defcustom erc-after-connect nil
2088 "Hook called after connecting to a server.
2089 This hook gets executed when an end of MOTD has been received. All
2090 functions in here get called with the parameters SERVER and NICK."
2095 (defun erc-select-read-args ()
2096 "Prompt the user for values of nick, server, port, and password."
2097 (let (user-input server port nick passwd)
2098 (setq user-input (read-from-minibuffer
2100 (erc-compute-server) nil nil 'erc-server-history-list))
2102 (if (string-match "\\(.*\\):\\(.*\\)\\'" user-input)
2103 (setq port (erc-string-to-port (match-string 2 user-input))
2104 user-input (match-string 1 user-input))
2106 (erc-string-to-port (read-from-minibuffer
2107 "IRC port: " (erc-port-to-string
2108 (erc-compute-port))))))
2110 (if (string-match "\\`\\(.*\\)@\\(.*\\)" user-input)
2111 (setq nick (match-string 1 user-input)
2112 user-input (match-string 2 user-input))
2114 (if (erc-already-logged-in server port nick)
2115 (read-from-minibuffer
2116 (erc-format-message 'nick-in-use ?n nick)
2118 nil nil 'erc-nick-history-list)
2119 (read-from-minibuffer
2120 "Nickname: " (erc-compute-nick nick)
2121 nil nil 'erc-nick-history-list))))
2123 (setq server user-input)
2125 (setq passwd (if erc-prompt-for-password
2126 (if (and erc-password
2127 (y-or-n-p "Use the default password? "))
2129 (read-passwd "Password: "))
2131 (when (and passwd (string= "" passwd))
2134 (while (erc-already-logged-in server port nick)
2135 ;; hmm, this is a problem when using multiple connections to a bnc
2136 ;; with the same nick. Currently this code prevents using more than one
2137 ;; bnc with the same nick. actually it would be nice to have
2138 ;; bncs transparent, so that erc-compute-buffer-name displays
2139 ;; the server one is connected to.
2140 (setq nick (read-from-minibuffer
2141 (erc-format-message 'nick-in-use ?n nick)
2143 nil nil 'erc-nick-history-list)))
2144 (list :server server :port port :nick nick :password passwd)))
2147 (defun* erc (&key (server (erc-compute-server))
2148 (port (erc-compute-port))
2149 (nick (erc-compute-nick))
2151 (full-name (erc-compute-full-name)))
2152 "ERC is a powerful, modular, and extensible IRC client.
2153 This function is the main entry point for ERC.
2155 It permits you to select connection parameters, and then starts ERC.
2157 Non-interactively, it takes the keyword arguments
2158 (server (erc-compute-server))
2159 (port (erc-compute-port))
2160 (nick (erc-compute-nick))
2162 (full-name (erc-compute-full-name)))
2164 That is, if called with
2166 (erc :server \"irc.freenode.net\" :full-name \"Harry S Truman\")
2168 then the server and full-name will be set to those values, whereas
2169 `erc-compute-port', `erc-compute-nick' and `erc-compute-full-name' will
2170 be invoked for the values of the other parameters."
2171 (interactive (erc-select-read-args))
2172 (erc-open server port nick full-name t password))
2175 (defalias 'erc-select 'erc)
2176 (defalias 'erc-ssl 'erc-tls)
2179 (defun erc-tls (&rest r)
2180 "Interactively select TLS connection parameters and run ERC.
2181 Arguments are the same as for `erc'."
2182 (interactive (erc-select-read-args))
2183 (let ((erc-server-connect-function 'erc-open-tls-stream))
2186 (defun erc-open-tls-stream (name buffer host port)
2187 "Open an TLS stream to an IRC server.
2188 The process will be given the name NAME, its target buffer will be
2189 BUFFER. HOST and PORT specify the connection target."
2190 (open-network-stream name buffer host port
2193 ;;; Displaying error messages
2195 (defun erc-error (&rest args)
2196 "Pass ARGS to `format', and display the result as an error message.
2197 If `debug-on-error' is set to non-nil, then throw a real error with this
2198 message instead, to make debugging easier."
2200 (apply #'error args)
2201 (apply #'message args)
2204 ;;; Debugging the protocol
2206 (defvar erc-debug-irc-protocol nil
2207 "If non-nil, log all IRC protocol traffic to the buffer \"*erc-protocol*\".
2209 The buffer is created if it doesn't exist.
2211 NOTE: If this variable is non-nil, and you kill the only
2212 visible \"*erc-protocol*\" buffer, it will be recreated shortly,
2213 but you won't see it.
2215 WARNING: Do not set this variable directly! Instead, use the
2216 function `erc-toggle-debug-irc-protocol' to toggle its value.")
2218 (declare-function erc-network-name "erc-networks" ())
2220 (defun erc-log-irc-protocol (string &optional outbound)
2221 "Append STRING to the buffer *erc-protocol*.
2223 This only has any effect if `erc-debug-irc-protocol' is non-nil.
2225 The buffer is created if it doesn't exist.
2227 If OUTBOUND is non-nil, STRING is being sent to the IRC server
2228 and appears in face `erc-input-face' in the buffer."
2229 (when erc-debug-irc-protocol
2230 (let ((network-name (or (ignore-errors (erc-network-name))
2232 (with-current-buffer (get-buffer-create "*erc-protocol*")
2234 (goto-char (point-max))
2235 (let ((inhibit-read-only t))
2236 (insert (if (not outbound)
2237 ;; Cope with the fact that string might
2238 ;; contain multiple lines of text.
2239 (let ((lines (delete "" (split-string string
2242 (dolist (line lines)
2243 (setq result (concat result network-name
2247 (concat network-name " >> " string
2250 (1- (length string))))
2252 'face 'erc-input-face)))))
2253 (let ((orig-win (selected-window))
2254 (debug-buffer-window (get-buffer-window (current-buffer) t)))
2255 (when debug-buffer-window
2256 (select-window debug-buffer-window)
2257 (when (= 1 (count-lines (point) (point-max)))
2258 (goto-char (point-max))
2260 (select-window orig-win)))))))
2262 (defun erc-toggle-debug-irc-protocol (&optional arg)
2263 "Toggle the value of `erc-debug-irc-protocol'.
2265 If ARG is non-nil, show the *erc-protocol* buffer."
2267 (let* ((buf (get-buffer-create "*erc-protocol*")))
2268 (with-current-buffer buf
2269 (erc-view-mode-enter)
2270 (when (null (current-local-map))
2271 (let ((inhibit-read-only t))
2272 (insert (erc-make-notice "This buffer displays all IRC protocol traffic exchanged with each server.\n"))
2273 (insert (erc-make-notice "Kill this buffer to terminate protocol logging.\n\n")))
2274 (use-local-map (make-sparse-keymap))
2275 (local-set-key (kbd "t") 'erc-toggle-debug-irc-protocol))
2276 (add-hook 'kill-buffer-hook
2277 #'(lambda () (setq erc-debug-irc-protocol nil))
2279 (goto-char (point-max))
2280 (let ((inhibit-read-only t))
2281 (insert (erc-make-notice
2282 (format "IRC protocol logging %s at %s -- Press `t' to toggle logging.\n"
2283 (if erc-debug-irc-protocol "disabled" "enabled")
2284 (current-time-string))))))
2285 (setq erc-debug-irc-protocol (not erc-debug-irc-protocol))
2287 (not (get-buffer-window "*erc-protocol*" t)))
2288 (display-buffer buf t))
2289 (message "IRC protocol traffic logging %s (see buffer *erc-protocol*)."
2290 (if erc-debug-irc-protocol "enabled" "disabled"))))
2296 (defun erc-send-action (tgt str &optional force)
2297 "Send CTCP ACTION information described by STR to TGT."
2298 (erc-send-ctcp-message tgt (format "ACTION %s" str) force)
2299 (erc-display-message
2300 nil 'input (current-buffer)
2301 'ACTION ?n (erc-current-nick) ?a str ?u "" ?h ""))
2303 ;; Display interface
2305 (defun erc-string-invisible-p (string)
2306 "Check whether STRING is invisible or not.
2307 I.e. any char in it has the `invisible' property set."
2308 (text-property-any 0 (length string) 'invisible t string))
2310 (defcustom erc-remove-parsed-property t
2311 "Whether to remove the erc-parsed text property after displaying a message.
2313 The default is to remove it, since it causes ERC to take up extra
2314 memory. If you have code that relies on this property, then set
2315 this option to nil."
2319 (defun erc-display-line-1 (string buffer)
2320 "Display STRING in `erc-mode' BUFFER.
2321 Auxiliary function used in `erc-display-line'. The line gets filtered to
2322 interpret the control characters. Then, `erc-insert-pre-hook' gets called.
2323 If `erc-insert-this' is still t, STRING gets inserted into the buffer.
2324 Afterwards, `erc-insert-modify' and `erc-insert-post-hook' get called.
2325 If STRING is nil, the function does nothing."
2327 (with-current-buffer (or buffer (process-buffer erc-server-process))
2328 (let ((insert-position (or (marker-position erc-insert-marker)
2330 (let ((string string) ;; FIXME! Can this be removed?
2331 (buffer-undo-list t)
2332 (inhibit-read-only t))
2333 (unless (string-match "\n$" string)
2334 (setq string (concat string "\n"))
2335 (when (erc-string-invisible-p string)
2336 (erc-put-text-properties 0 (length string)
2337 '(invisible intangible) string)))
2338 (erc-log (concat "erc-display-line: " string
2339 (format "(%S)" string) " in buffer "
2340 (format "%s" buffer)))
2341 (setq erc-insert-this t)
2342 (run-hook-with-args 'erc-insert-pre-hook string)
2343 (if (null erc-insert-this)
2344 ;; Leave erc-insert-this set to t as much as possible. Fran
2345 ;; Litterio <franl> has seen erc-insert-this set to nil while
2346 ;; erc-send-pre-hook is running, which should never happen. This
2348 (setq erc-insert-this t)
2349 (save-excursion ;; to restore point in the new buffer
2352 (goto-char insert-position)
2353 (insert-before-markers string)
2354 ;; run insertion hook, with point at restored location
2356 (narrow-to-region insert-position (point))
2357 (run-hooks 'erc-insert-modify-hook)
2358 (run-hooks 'erc-insert-post-hook)
2359 (when erc-remove-parsed-property
2360 (remove-text-properties (point-min) (point-max)
2361 '(erc-parsed nil))))))))
2362 (erc-update-undo-list (- (or (marker-position erc-insert-marker)
2364 insert-position))))))
2366 (defun erc-update-undo-list (shift)
2367 ;; Translate buffer positions in buffer-undo-list by SHIFT.
2368 (unless (or (zerop shift) (atom buffer-undo-list))
2369 (let ((list buffer-undo-list) elt)
2371 (setq elt (car list))
2372 (cond ((integerp elt) ; POSITION
2373 (incf (car list) shift))
2374 ((or (atom elt) ; nil, EXTENT
2375 ;; (eq t (car elt)) ; (t . TIME)
2376 (markerp (car elt))) ; (MARKER . DISTANCE)
2378 ((integerp (car elt)) ; (BEGIN . END)
2379 (incf (car elt) shift)
2380 (incf (cdr elt) shift))
2381 ((stringp (car elt)) ; (TEXT . POSITION)
2382 (incf (cdr elt) (* (if (natnump (cdr elt)) 1 -1) shift)))
2383 ((null (car elt)) ; (nil PROPERTY VALUE BEG . END)
2384 (let ((cons (nthcdr 3 elt)))
2385 (incf (car cons) shift)
2386 (incf (cdr cons) shift)))
2387 ((and (featurep 'xemacs)
2388 (extentp (car elt))) ; (EXTENT START END)
2389 (incf (nth 1 elt) shift)
2390 (incf (nth 2 elt) shift)))
2391 (setq list (cdr list))))))
2393 (defvar erc-valid-nick-regexp "[]a-zA-Z^[;\\`_{}|][]^[;\\`_{}|a-zA-Z0-9-]*"
2394 "Regexp which matches all valid characters in a IRC nickname.")
2396 (defun erc-is-valid-nick-p (nick)
2397 "Check if NICK is a valid IRC nickname."
2398 (string-match (concat "^" erc-valid-nick-regexp "$") nick))
2400 (defun erc-display-line (string &optional buffer)
2401 "Display STRING in the ERC BUFFER.
2402 All screen output must be done through this function. If BUFFER is nil
2403 or omitted, the default ERC buffer for the `erc-session-server' is used.
2404 The BUFFER can be an actual buffer, a list of buffers, 'all or 'active.
2405 If BUFFER = 'all, the string is displayed in all the ERC buffers for the
2406 current session. 'active means the current active buffer
2407 \(`erc-active-buffer'). If the buffer can't be resolved, the current
2408 buffer is used. `erc-display-line-1' is used to display STRING.
2410 If STRING is nil, the function does nothing."
2411 (let ((inhibit-point-motion-hooks t)
2414 ((bufferp buffer) (list buffer))
2415 ((listp buffer) buffer)
2416 ((processp buffer) (list (process-buffer buffer)))
2418 ;; Hmm, or all of the same session server?
2419 (erc-buffer-list nil erc-server-process))
2420 ((and (eq 'active buffer) (erc-active-buffer))
2421 (list (erc-active-buffer)))
2422 ((erc-server-buffer-live-p)
2423 (list (process-buffer erc-server-process)))
2424 (t (list (current-buffer)))))
2425 (when (buffer-live-p buf)
2426 (erc-display-line-1 string buf)
2427 (add-to-list 'new-bufs buf)))
2428 (when (null new-bufs)
2429 (if (erc-server-buffer-live-p)
2430 (erc-display-line-1 string (process-buffer erc-server-process))
2431 (erc-display-line-1 string (current-buffer))))))
2433 (defun erc-display-message-highlight (type string)
2434 "Highlight STRING according to TYPE, where erc-TYPE-face is an ERC face.
2436 See also `erc-make-notice'."
2437 (cond ((eq type 'notice)
2438 (erc-make-notice string))
2440 (erc-put-text-property
2442 'face (or (intern-soft
2443 (concat "erc-" (symbol-name type) "-face"))
2448 (defun erc-display-message (parsed type buffer msg &rest args)
2449 "Display MSG in BUFFER.
2451 ARGS, PARSED, and TYPE are used to format MSG sensibly.
2453 See also `erc-format-message' and `erc-display-line'."
2454 (let ((string (if (symbolp msg)
2455 (apply 'erc-format-message msg args)
2462 (mapc (lambda (type)
2464 (erc-display-message-highlight type string)))
2468 (erc-display-message-highlight type string))))
2470 (if (not (erc-response-p parsed))
2471 (erc-display-line string buffer)
2472 (unless (member (erc-response.command parsed) erc-hide-list)
2473 (erc-put-text-property 0 (length string) 'erc-parsed parsed string)
2474 (erc-put-text-property 0 (length string) 'rear-sticky t string)
2475 (erc-display-line string buffer)))))
2477 (defun erc-message-type-member (position list)
2478 "Return non-nil if the erc-parsed text-property at POSITION is in LIST.
2480 This function relies on the erc-parsed text-property being
2482 (let ((prop-val (erc-get-parsed-vector position)))
2483 (and prop-val (member (erc-response.command prop-val) list))))
2485 (defvar erc-send-input-line-function 'erc-send-input-line)
2486 (make-variable-buffer-local 'erc-send-input-line-function)
2488 (defun erc-send-input-line (target line &optional force)
2489 "Send LINE to TARGET.
2491 See also `erc-server-send'."
2492 (setq line (format "PRIVMSG %s :%s"
2494 ;; If the line is empty, we still want to
2495 ;; send it - i.e. an empty pasted line.
2496 (if (string= line "\n")
2499 (erc-server-send line force target))
2501 (defun erc-get-arglist (fun)
2502 "Return the argument list of a function without the parens."
2503 (let ((arglist (format "%S" (erc-function-arglist fun))))
2504 (if (string-match "^(\\(.*\\))$" arglist)
2505 (match-string 1 arglist)
2508 (defun erc-command-no-process-p (str)
2509 "Return non-nil if STR is an ERC command that can be run when the process
2510 is not alive, nil otherwise."
2511 (let ((fun (erc-extract-command-from-line str)))
2514 (get (car fun) 'process-not-needed))))
2516 (defun erc-command-name (cmd)
2517 "For CMD being the function name of a ERC command, something like
2518 erc-cmd-FOO, this returns a string /FOO."
2519 (let ((command-name (symbol-name cmd)))
2520 (if (string-match "^erc-cmd-\\(.*\\)$" command-name)
2521 (concat "/" (match-string 1 command-name))
2524 (defun erc-process-input-line (line &optional force no-command)
2525 "Translate LINE to an RFC1459 command and send it based.
2526 Returns non-nil if the command is actually sent to the server, and nil
2529 If the command in the LINE is not bound as a function `erc-cmd-<COMMAND>',
2530 it is passed to `erc-cmd-default'. If LINE is not a command (i.e. doesn't
2531 start with /<COMMAND>) then it is sent as a message.
2533 An optional FORCE argument forces sending the line when flood
2534 protection is in effect. The optional NO-COMMAND argument prohibits
2535 this function from interpreting the line as a command."
2536 (let ((command-list (erc-extract-command-from-line line)))
2537 (if (and command-list
2539 (let* ((cmd (nth 0 command-list))
2540 (args (nth 1 command-list)))
2545 (wrong-number-of-arguments
2546 (erc-display-message nil 'error (current-buffer) 'incorrect-args
2547 ?c (erc-command-name cmd)
2548 ?u (or (erc-get-arglist cmd)
2551 (or (documentation cmd) "")))
2553 (let ((r (erc-default-target)))
2555 (funcall erc-send-input-line-function r line force)
2556 (erc-display-message nil 'error (current-buffer) 'no-target)
2559 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2560 ;; Input commands handlers
2561 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2563 (defun erc-cmd-AMSG (line)
2564 "Send LINE to all channels of the current server that you are on."
2565 (interactive "sSend to all channels you're on: ")
2566 (setq line (erc-trim-string line))
2567 (erc-with-all-buffers-of-server nil
2569 (erc-channel-p (erc-default-target)))
2570 (erc-send-message line)))
2571 (put 'erc-cmd-AMSG 'do-not-parse-args t)
2573 (defun erc-cmd-SAY (line)
2574 "Send LINE to the current query or channel as a message, not a command.
2576 Use this when you want to send a message with a leading '/'. Note
2577 that since multi-line messages are never a command, you don't
2578 need this when pasting multiple lines of text."
2579 (if (string-match "^\\s-*$" line)
2581 (string-match "^ ?\\(.*\\)" line)
2582 (erc-process-input-line (match-string 1 line) nil t)))
2583 (put 'erc-cmd-SAY 'do-not-parse-args t)
2585 (defun erc-cmd-SET (line)
2586 "Set the variable named by the first word in LINE to some VALUE.
2587 VALUE is computed by evaluating the rest of LINE in Lisp."
2589 ((string-match "^\\s-*\\(\\S-+\\)\\s-+\\(.*\\)$" line)
2590 (let ((var (read (concat "erc-" (match-string 1 line))))
2591 (val (read (match-string 2 line))))
2594 (set var (eval val))
2595 (erc-display-message
2596 nil nil 'active (format "Set %S to %S" var val))
2598 (setq var (read (match-string 1 line)))
2601 (set var (eval val))
2602 (erc-display-message
2603 nil nil 'active (format "Set %S to %S" var val))
2605 (erc-display-message nil 'error 'active 'variable-not-bound)
2607 ((string-match "^\\s-*$" line)
2609 (concat "Available user variables:\n"
2614 (let ((val (symbol-value var)))
2615 (concat (format "%S:" var)
2617 (concat "\n" (pp-to-string val))
2618 (format " %S\n" val)))))
2619 (apropos-internal "^erc-" 'custom-variable-p))))
2620 (current-buffer)) t)
2622 (defalias 'erc-cmd-VAR 'erc-cmd-SET)
2623 (defalias 'erc-cmd-VARIABLE 'erc-cmd-SET)
2624 (put 'erc-cmd-SET 'do-not-parse-args t)
2625 (put 'erc-cmd-SET 'process-not-needed t)
2627 (defun erc-cmd-default (line)
2630 Commands for which no erc-cmd-xxx exists, are tunneled through
2631 this function. LINE is sent to the server verbatim, and
2632 therefore has to contain the command itself as well."
2633 (erc-log (format "cmd: DEFAULT: %s" line))
2634 (erc-server-send (substring line 1))
2637 (defun erc-cmd-IGNORE (&optional user)
2638 "Ignore USER. This should be a regexp matching nick!user@host.
2639 If no USER argument is specified, list the contents of `erc-ignore-list'."
2641 (let ((quoted (regexp-quote user)))
2642 (when (and (not (string= user quoted))
2643 (y-or-n-p (format "Use regexp-quoted form (%s) instead? "
2647 (erc-make-notice (format "Now ignoring %s" user))
2649 (erc-with-server-buffer (add-to-list 'erc-ignore-list user)))
2650 (if (null (erc-with-server-buffer erc-ignore-list))
2651 (erc-display-line (erc-make-notice "Ignore list is empty") 'active)
2652 (erc-display-line (erc-make-notice "Ignore list:") 'active)
2653 (mapc #'(lambda (item)
2654 (erc-display-line (erc-make-notice item)
2656 (erc-with-server-buffer erc-ignore-list))))
2659 (defun erc-cmd-UNIGNORE (user)
2660 "Remove the user specified in USER from the ignore list."
2661 (let ((ignored-nick (car (erc-with-server-buffer
2662 (erc-member-ignore-case (regexp-quote user)
2663 erc-ignore-list)))))
2664 (unless ignored-nick
2665 (if (setq ignored-nick (erc-ignored-user-p user))
2666 (unless (y-or-n-p (format "Remove this regexp (%s)? "
2668 (setq ignored-nick nil))
2670 (erc-make-notice (format "%s is not currently ignored!" user))
2674 (erc-make-notice (format "No longer ignoring %s" user))
2676 (erc-with-server-buffer
2677 (setq erc-ignore-list (delete ignored-nick erc-ignore-list)))))
2680 (defun erc-cmd-CLEAR ()
2681 "Clear the window content."
2684 (put 'erc-cmd-CLEAR 'process-not-needed t)
2686 (defun erc-cmd-OPS ()
2687 "Show the ops in the current channel."
2690 (if erc-channel-users
2691 (maphash (lambda (nick user-data)
2692 (let ((cuser (cdr user-data)))
2694 (erc-channel-user-op cuser))
2695 (setq ops (cons (erc-server-user-nickname
2699 (setq ops (sort ops 'string-lessp))
2701 (erc-display-message
2702 nil 'notice (current-buffer) 'ops
2703 ?i (length ops) ?s (if (> (length ops) 1) "s" "")
2704 ?o (mapconcat 'identity ops " "))
2705 (erc-display-message nil 'notice (current-buffer) 'ops-none)))
2708 (defun erc-cmd-COUNTRY (tld)
2709 "Display the country associated with the top level domain TLD."
2710 (require 'mail-extr)
2711 (let ((co (ignore-errors (what-domain tld))))
2713 (erc-display-message
2714 nil 'notice 'active 'country ?c co ?d tld)
2715 (erc-display-message
2716 nil 'notice 'active 'country-unknown ?d tld))
2718 (put 'erc-cmd-COUNTRY 'process-not-needed t)
2720 (defun erc-cmd-AWAY (line)
2721 "Mark the user as being away, the reason being indicated by LINE.
2722 If no reason is given, unset away status."
2723 (when (string-match "^\\s-*\\(.*\\)$" line)
2724 (let ((reason (match-string 1 line)))
2725 (erc-log (format "cmd: AWAY: %s" reason))
2727 (if (string= reason "")
2729 (concat "AWAY :" reason))))
2731 (put 'erc-cmd-AWAY 'do-not-parse-args t)
2733 (defun erc-cmd-GAWAY (line)
2734 "Mark the user as being away everywhere, the reason being indicated by LINE."
2735 ;; on all server buffers.
2736 (erc-with-all-buffers-of-server nil
2737 #'erc-open-server-buffer-p
2738 (erc-cmd-AWAY line)))
2739 (put 'erc-cmd-GAWAY 'do-not-parse-args t)
2741 (defun erc-cmd-CTCP (nick cmd &rest args)
2742 "Send a Client To Client Protocol message to NICK.
2744 CMD is the CTCP command, possible values being ECHO, FINGER, CLIENTINFO, TIME,
2745 VERSION and so on. It is called with ARGS."
2746 (let ((str (concat cmd
2748 (concat " " (mapconcat #'identity args " "))))))
2749 (erc-log (format "cmd: CTCP [%s]: [%s]" nick str))
2750 (erc-send-ctcp-message nick str)
2753 (defun erc-cmd-HELP (&optional func)
2754 "Popup help information.
2756 If FUNC contains a valid function or variable, help about that
2757 will be displayed. If FUNC is empty, display an apropos about
2758 ERC commands. Otherwise, do `apropos' in the ERC namespace
2762 To find out about erc and bbdb, do
2765 For help about the WHOIS command, do:
2768 For a list of user commands (/join /part, ...):
2771 (let* ((sym (or (let ((sym (intern-soft
2772 (concat "erc-cmd-" (upcase func)))))
2773 (if (and sym (or (boundp sym) (fboundp sym)))
2776 (let ((sym (intern-soft func)))
2777 (if (and sym (or (boundp sym) (fboundp sym)))
2780 (let ((sym (intern-soft (concat "erc-" func))))
2781 (if (and sym (or (boundp sym) (fboundp sym)))
2786 ((boundp sym) (describe-variable sym))
2787 ((fboundp sym) (describe-function sym))
2789 (apropos-command (concat "erc-.*" func) nil
2792 (get x 'custom-type))))
2794 (apropos "erc-cmd-")
2795 (message "Type C-h m to get additional information about keybindings.")
2798 (defalias 'erc-cmd-H 'erc-cmd-HELP)
2799 (put 'erc-cmd-HELP 'process-not-needed t)
2801 (defun erc-cmd-JOIN (channel &optional key)
2802 "Join the channel given in CHANNEL, optionally with KEY.
2803 If CHANNEL is specified as \"-invite\", join the channel to which you
2804 were most recently invited. See also `invitation'."
2806 (if (string= (upcase channel) "-INVITE")
2808 (setq chnl erc-invitation)
2809 (erc-display-message nil 'error (current-buffer) 'no-invitation))
2810 (setq chnl (erc-ensure-channel-name channel)))
2812 ;; Prevent double joining of same channel on same server.
2813 (let ((joined-channels
2814 (mapcar #'(lambda (chanbuf)
2815 (with-current-buffer chanbuf (erc-default-target)))
2816 (erc-channel-list erc-server-process))))
2817 (if (erc-member-ignore-case chnl joined-channels)
2818 (switch-to-buffer (car (erc-member-ignore-case chnl
2820 (erc-log (format "cmd: JOIN: %s" chnl))
2822 (erc-server-send (format "JOIN %s %s" chnl key))
2823 (erc-server-send (format "JOIN %s" chnl)))))))
2826 (defalias 'erc-cmd-CHANNEL 'erc-cmd-JOIN)
2827 (defalias 'erc-cmd-J 'erc-cmd-JOIN)
2829 (defvar erc-channel-new-member-names nil
2830 "If non-nil, a names list is currently being received.
2832 If non-nil, this variable is a hash-table that associates
2833 received nicks with t.")
2834 (make-variable-buffer-local 'erc-channel-new-member-names)
2836 (defun erc-cmd-NAMES (&optional channel)
2837 "Display the users in CHANNEL.
2838 If CHANNEL is not specified, display the users in the current channel.
2839 This function clears the channel name list first, then sends the
2841 (let ((tgt (or (and (erc-channel-p channel) channel)
2842 (erc-default-target))))
2843 (if (and tgt (erc-channel-p tgt))
2845 (erc-log (format "cmd: DEFAULT: NAMES %s" tgt))
2848 (erc-channel-begin-receiving-names))
2849 (erc-server-send (concat "NAMES " tgt)))
2850 (erc-display-message nil 'error (current-buffer) 'no-default-channel)))
2852 (defalias 'erc-cmd-N 'erc-cmd-NAMES)
2854 (defun erc-cmd-KICK (target &optional reason-or-nick &rest reasonwords)
2855 "Kick the user indicated in LINE from the current channel.
2856 LINE has the format: \"#CHANNEL NICK REASON\" or \"NICK REASON\"."
2857 (let ((reasonstring (mapconcat 'identity reasonwords " ")))
2858 (if (string= "" reasonstring)
2859 (setq reasonstring (format "Kicked by %s" (erc-current-nick))))
2860 (if (erc-channel-p target)
2861 (let ((nick reason-or-nick))
2862 (erc-log (format "cmd: KICK: %s/%s: %s" nick target reasonstring))
2863 (erc-server-send (format "KICK %s %s :%s" target nick reasonstring)
2867 (let ((ch (erc-default-target)))
2868 (setq reasonstring (concat
2869 (if reason-or-nick (concat reason-or-nick " "))
2874 (format "cmd: KICK: %s/%s: %s" target ch reasonstring))
2876 (format "KICK %s %s :%s" ch target reasonstring) nil ch))
2877 (erc-display-message nil 'error (current-buffer)
2878 'no-default-channel))
2881 (defvar erc-script-args nil)
2883 (defun erc-cmd-LOAD (line)
2884 "Load the script provided in the LINE.
2885 If LINE continues beyond the file name, the rest of
2886 it is put in a (local) variable `erc-script-args',
2887 which can be used in Emacs Lisp scripts.
2889 The optional FORCE argument is ignored here - you can't force loading
2890 a script after exceeding the flood threshold."
2892 ((string-match "^\\s-*\\(\\S-+\\)\\(.*\\)$" line)
2893 (let* ((file-to-find (match-string 1 line))
2894 (erc-script-args (match-string 2 line))
2895 (file (erc-find-file file-to-find erc-script-path)))
2896 (erc-log (format "cmd: LOAD: %s" file-to-find))
2899 (erc-display-message nil 'error (current-buffer)
2900 'cannot-find-file ?f file-to-find))
2901 ((not (file-readable-p file))
2902 (erc-display-message nil 'error (current-buffer)
2903 'cannot-read-file ?f file))
2905 (message "Loading \'%s\'..." file)
2906 (erc-load-script file)
2907 (message "Loading \'%s\'...done" file))))
2911 (defun erc-cmd-WHOIS (user &optional server)
2912 "Display whois information for USER.
2914 If SERVER is non-nil, use that, rather than the current server."
2915 ;; FIXME: is the above docstring correct? -- Lawrence 2004-01-08
2916 (let ((send (if server
2917 (format "WHOIS %s %s" user server)
2918 (format "WHOIS %s" user))))
2919 (erc-log (format "cmd: %s" send))
2920 (erc-server-send send)
2922 (defalias 'erc-cmd-WI 'erc-cmd-WHOIS)
2924 (defun erc-cmd-WHOAMI ()
2925 "Display whois information about yourself."
2926 (erc-cmd-WHOIS (erc-current-nick))
2929 (defun erc-cmd-IDLE (nick)
2930 "Show the length of time NICK has been idle."
2931 (let ((origbuf (current-buffer))
2933 (erc-with-server-buffer
2934 (add-to-list 'symlist
2935 (cons (erc-once-with-server-event
2938 (erc-response.command-args parsed))))
2939 'erc-server-311-functions))
2940 (add-to-list 'symlist
2941 (cons (erc-once-with-server-event
2944 (erc-response.command-args parsed))))
2945 'erc-server-312-functions))
2946 (add-to-list 'symlist
2947 (cons (erc-once-with-server-event
2950 (erc-response.command-args parsed))))
2951 'erc-server-318-functions))
2952 (add-to-list 'symlist
2953 (cons (erc-once-with-server-event
2956 (erc-response.command-args parsed))))
2957 'erc-server-319-functions))
2958 (add-to-list 'symlist
2959 (cons (erc-once-with-server-event
2962 (erc-response.command-args parsed))))
2963 'erc-server-320-functions))
2964 (add-to-list 'symlist
2965 (cons (erc-once-with-server-event
2968 (erc-response.command-args parsed))))
2969 'erc-server-330-functions))
2970 (add-to-list 'symlist
2971 (cons (erc-once-with-server-event
2976 (erc-response.command-args parsed)))))
2979 (format "%s has been idle for %s."
2980 (erc-string-no-properties ,nick)
2981 (erc-seconds-to-string idleseconds)))
2984 'erc-server-317-functions))
2986 ;; Send the WHOIS command.
2987 (erc-cmd-WHOIS nick)
2989 ;; Remove the uninterned symbols from the server hooks that did not run.
2990 (run-at-time 20 nil `(lambda ()
2991 (with-current-buffer ,(current-buffer)
2992 (dolist (sym ',symlist)
2993 (let ((hooksym (cdr sym))
2994 (funcsym (car sym)))
2995 (remove-hook hooksym funcsym t))))))))
2998 (defun erc-cmd-DESCRIBE (line)
2999 "Pose some action to a certain user.
3000 LINE has the format \"USER ACTION\"."
3003 "^\\s-*\\(\\S-+\\)\\s-\\(.*\\)$" line)
3004 (let ((dst (match-string 1 line))
3005 (s (match-string 2 line)))
3006 (erc-log (format "cmd: DESCRIBE: [%s] %s" dst s))
3007 (erc-send-action dst s))
3010 (put 'erc-cmd-DESCRIBE 'do-not-parse-args t)
3012 (defun erc-cmd-ME (line)
3013 "Send LINE as an action."
3015 ((string-match "^\\s-\\(.*\\)$" line)
3016 (let ((s (match-string 1 line)))
3017 (erc-log (format "cmd: ME: %s" s))
3018 (erc-send-action (erc-default-target) s))
3021 (put 'erc-cmd-ME 'do-not-parse-args t)
3023 (defun erc-cmd-ME\'S (line)
3024 "Do a /ME command, but add the string \" 's\" to the beginning."
3025 (erc-cmd-ME (concat " 's" line)))
3026 (put 'erc-cmd-ME\'S 'do-not-parse-args t)
3028 (defun erc-cmd-LASTLOG (line)
3029 "Show all lines in the current buffer matching the regexp LINE.
3031 If a match spreads across multiple lines, all those lines are shown.
3033 The lines are shown in a buffer named `*Occur*'.
3034 It serves as a menu to find any of the occurrences in this buffer.
3035 \\[describe-mode] in that buffer will explain how.
3037 If LINE contains upper case characters (excluding those preceded by `\'),
3038 the matching is case-sensitive."
3041 (put 'erc-cmd-LASTLOG 'do-not-parse-args t)
3042 (put 'erc-cmd-LASTLOG 'process-not-needed t)
3044 (defun erc-send-message (line &optional force)
3045 "Send LINE to the current channel or user and display it.
3047 See also `erc-message' and `erc-display-line'."
3048 (erc-message "PRIVMSG" (concat (erc-default-target) " " line) force)
3050 (concat (erc-format-my-nick) line)
3052 ;; FIXME - treat multiline, run hooks, or remove me?
3055 (defun erc-cmd-MODE (line)
3056 "Change or display the mode value of a channel or user.
3057 The first word specifies the target. The rest is the mode string
3060 If only one word is given, display the mode of that target.
3062 A list of valid mode strings for Freenode may be found at
3063 URL `http://freenode.net/using_the_network.shtml'."
3065 ((string-match "^\\s-\\(.*\\)$" line)
3066 (let ((s (match-string 1 line)))
3067 (erc-log (format "cmd: MODE: %s" s))
3068 (erc-server-send (concat "MODE " line)))
3071 (put 'erc-cmd-MODE 'do-not-parse-args t)
3073 (defun erc-cmd-NOTICE (channel-or-user &rest message)
3074 "Send a notice to the channel or user given as the first word.
3075 The rest is the message to send."
3076 (erc-message "NOTICE" (concat channel-or-user " "
3077 (mapconcat #'identity message " "))))
3079 (defun erc-cmd-MSG (line)
3080 "Send a message to the channel or user given as the first word in LINE.
3082 The rest of LINE is the message to send."
3083 (erc-message "PRIVMSG" line))
3085 (defalias 'erc-cmd-M 'erc-cmd-MSG)
3086 (put 'erc-cmd-MSG 'do-not-parse-args t)
3088 (defun erc-cmd-SQUERY (line)
3089 "Send a Service Query to the service given as the first word in LINE.
3091 The rest of LINE is the message to send."
3092 (erc-message "SQUERY" line))
3094 (defun erc-cmd-NICK (nick)
3095 "Change current nickname to NICK."
3096 (erc-log (format "cmd: NICK: %s (erc-bad-nick: %S)" nick erc-bad-nick))
3097 (let ((nicklen (cdr (assoc "NICKLEN" (erc-with-server-buffer
3098 erc-server-parameters)))))
3099 (and nicklen (> (length nick) (string-to-number nicklen))
3100 (erc-display-message
3101 nil 'notice 'active 'nick-too-long
3102 ?i (length nick) ?l nicklen)))
3103 (erc-server-send (format "NICK %s" nick))
3105 (erc-set-current-nick nick)
3106 (erc-update-mode-line)
3107 (setq erc-bad-nick nil)))
3110 (defun erc-cmd-PART (line)
3111 "When LINE is an empty string, leave the current channel.
3112 Otherwise leave the channel indicated by LINE."
3114 ((string-match "^\\s-*\\([&#+!]\\S-+\\)\\s-?\\(.*\\)$" line)
3115 (let* ((ch (match-string 1 line))
3116 (msg (match-string 2 line))
3117 (reason (funcall erc-part-reason (if (equal msg "") nil msg))))
3118 (erc-log (format "cmd: PART: %s: %s" ch reason))
3119 (erc-server-send (if (string= reason "")
3120 (format "PART %s" ch)
3121 (format "PART %s :%s" ch reason))
3124 ((string-match "^\\s-*\\(.*\\)$" line)
3125 (let* ((ch (erc-default-target))
3126 (msg (match-string 1 line))
3127 (reason (funcall erc-part-reason (if (equal msg "") nil msg))))
3128 (if (and ch (erc-channel-p ch))
3130 (erc-log (format "cmd: PART: %s: %s" ch reason))
3131 (erc-server-send (if (string= reason "")
3132 (format "PART %s" ch)
3133 (format "PART %s :%s" ch reason))
3135 (erc-display-message nil 'error (current-buffer) 'no-target)))
3138 (put 'erc-cmd-PART 'do-not-parse-args t)
3140 (defalias 'erc-cmd-LEAVE 'erc-cmd-PART)
3142 (defun erc-cmd-PING (recipient)
3144 (let ((time (format "%f" (erc-current-time))))
3145 (erc-log (format "cmd: PING: %s" time))
3146 (erc-cmd-CTCP recipient "PING" time)))
3148 (defun erc-cmd-QUOTE (line)
3149 "Send LINE directly to the server.
3150 All the text given as argument is sent to the sever as unmodified,
3151 just as you provided it. Use this command with care!"
3153 ((string-match "^ ?\\(.+\\)$" line)
3154 (erc-server-send (match-string 1 line)))
3156 (put 'erc-cmd-QUOTE 'do-not-parse-args t)
3158 (defcustom erc-query-display 'window
3159 "Indicates how to display query buffers when using the /QUERY
3160 command to talk to someone.
3162 The default behavior is to display the message in a new window
3163 and bring it to the front. See the documentation for
3164 `erc-join-buffer' for a description of the available choices.
3166 See also `erc-auto-query' to decide how private messages from
3167 other people should be displayed."
3169 :type '(choice (const :tag "Split window and select" window)
3170 (const :tag "Split window, don't select" window-noselect)
3171 (const :tag "New frame" frame)
3172 (const :tag "Bury in new buffer" bury)
3173 (const :tag "Use current buffer" buffer)
3174 (const :tag "Use current buffer" t)))
3176 (defun erc-cmd-QUERY (&optional user)
3177 "Open a query with USER.
3178 The type of query window/frame/etc will depend on the value of
3179 `erc-query-display'.
3181 If USER is omitted, close the current query buffer if one exists
3182 - except this is broken now ;-)"
3184 (list (read-from-minibuffer "Start a query with: " nil)))
3185 (let ((session-buffer (erc-server-buffer))
3186 (erc-join-buffer erc-query-display))
3188 (erc-query user session-buffer)
3189 ;; currently broken, evil hack to display help anyway
3190 ;(erc-delete-query))))
3191 (signal 'wrong-number-of-arguments ""))))
3192 (defalias 'erc-cmd-Q 'erc-cmd-QUERY)
3194 (defun erc-quit-reason-normal (&optional s)
3195 "Normal quit message.
3197 If S is non-nil, it will be used as the quit reason."
3199 (format "\C-bERC\C-b %s (IRC client for Emacs)"; - \C-b%s\C-b"
3200 erc-version-string) ; erc-official-location)
3203 (defun erc-quit-reason-zippy (&optional s)
3204 "Zippy quit message.
3206 If S is non-nil, it will be used as the quit reason."
3208 (erc-replace-regexp-in-string "\n" "" (yow))))
3210 (defun erc-quit-reason-various (s)
3211 "Choose a quit reason based on S (a string)."
3212 (when (featurep 'xemacs) (require 'poe))
3213 (let ((res (car (assoc-default (or s "")
3214 erc-quit-reason-various-alist 'string-match))))
3216 ((functionp res) (funcall res))
3219 (t (erc-quit-reason-normal)))))
3221 (defun erc-part-reason-normal (&optional s)
3222 "Normal part message.
3224 If S is non-nil, it will be used as the quit reason."
3226 (format "\C-bERC\C-b %s (IRC client for Emacs)"; - \C-b%s\C-b"
3227 erc-version-string) ; erc-official-location)
3230 (defun erc-part-reason-zippy (&optional s)
3231 "Zippy part message.
3233 If S is non-nil, it will be used as the quit reason."
3235 (erc-replace-regexp-in-string "\n" "" (yow))))
3237 (defun erc-part-reason-various (s)
3238 "Choose a part reason based on S (a string)."
3239 (when (featurep 'xemacs) (require 'poe))
3240 (let ((res (car (assoc-default (or s "")
3241 erc-part-reason-various-alist 'string-match))))
3243 ((functionp res) (funcall res))
3246 (t (erc-part-reason-normal)))))
3248 (defun erc-cmd-QUIT (reason)
3249 "Disconnect from the current server.
3250 If REASON is omitted, display a default quit message, otherwise display
3251 the message given by REASON."
3255 ((string-match "^\\s-*\\(.*\\)$" reason)
3256 (let* ((s (match-string 1 reason))
3257 (buffer (erc-server-buffer))
3258 (reason (funcall erc-quit-reason (if (equal s "") nil s)))
3260 (with-current-buffer (if (and buffer
3264 (erc-log (format "cmd: QUIT: %s" reason))
3265 (setq erc-server-quitting t)
3266 (erc-set-active-buffer (erc-server-buffer))
3267 (setq server-proc erc-server-process)
3268 (erc-server-send (format "QUIT :%s" reason)))
3269 (run-hook-with-args 'erc-quit-hook server-proc)
3270 (when erc-kill-queries-on-quit
3271 (erc-kill-query-buffers server-proc))
3272 ;; if the process has not been killed within 4 seconds, kill it
3275 (when (and (processp proc)
3276 (memq (process-status proc) '(run open)))
3277 (delete-process proc)))
3282 (defalias 'erc-cmd-BYE 'erc-cmd-QUIT)
3283 (defalias 'erc-cmd-EXIT 'erc-cmd-QUIT)
3284 (defalias 'erc-cmd-SIGNOFF 'erc-cmd-QUIT)
3285 (put 'erc-cmd-QUIT 'do-not-parse-args t)
3286 (put 'erc-cmd-QUIT 'process-not-needed t)
3288 (defun erc-cmd-GQUIT (reason)
3289 "Disconnect from all servers at once with the same quit REASON."
3290 (erc-with-all-buffers-of-server nil #'erc-open-server-buffer-p
3291 (erc-cmd-QUIT reason))
3292 (when erc-kill-queries-on-quit
3293 ;; if the query buffers have not been killed within 4 seconds,
3298 (dolist (buffer (erc-buffer-list (lambda (buf)
3299 (not (erc-server-buffer-p buf)))))
3300 (kill-buffer buffer)))))
3303 (defalias 'erc-cmd-GQ 'erc-cmd-GQUIT)
3304 (put 'erc-cmd-GQUIT 'do-not-parse-args t)
3305 (put 'erc-cmd-GQUIT 'process-not-needed t)
3307 (defun erc-cmd-RECONNECT ()
3308 "Try to reconnect to the current IRC server."
3309 (let ((buffer (erc-server-buffer))
3311 (unless (buffer-live-p buffer)
3312 (setq buffer (current-buffer)))
3313 (with-current-buffer buffer
3314 (setq erc-server-quitting nil)
3315 (setq erc-server-reconnecting t)
3316 (setq erc-server-reconnect-count 0)
3317 (setq process (get-buffer-process (erc-server-buffer)))
3319 (delete-process process)
3320 (erc-server-reconnect))
3321 (setq erc-server-reconnecting nil)))
3323 (put 'erc-cmd-RECONNECT 'process-not-needed t)
3325 (defun erc-cmd-SERVER (server)
3326 "Connect to SERVER, leaving existing connection intact."
3327 (erc-log (format "cmd: SERVER: %s" server))
3329 (erc :server server :nick (erc-current-nick))
3331 (erc-error "Cannot find host %s." server)))
3333 (put 'erc-cmd-SERVER 'process-not-needed t)
3335 (defvar motif-version-string)
3336 (defvar gtk-version-string)
3338 (defun erc-cmd-SV ()
3339 "Say the current ERC and Emacs version into channel."
3340 (erc-send-message (format "I'm using ERC %s with %s %s (%s%s) of %s."
3342 (if (featurep 'xemacs) "XEmacs" "GNU Emacs")
3344 system-configuration
3346 (cond ((featurep 'motif)
3347 (concat ", " (substring
3348 motif-version-string 4)))
3350 (concat ", GTK+ Version "
3351 gtk-version-string))
3352 ((featurep 'x-toolkit) ", X toolkit")
3354 (if (and (boundp 'x-toolkit-scroll-bars)
3355 (memq x-toolkit-scroll-bars
3357 (format ", %s scroll bars"
3358 (capitalize (symbol-name
3359 x-toolkit-scroll-bars)))
3361 (if (featurep 'multi-tty) ", multi-tty" ""))
3362 erc-emacs-build-time))
3365 (defun erc-cmd-SM ()
3366 "Say the current ERC modes into channel."
3367 (erc-send-message (format "I'm using the following modules: %s!"
3371 (defun erc-cmd-DEOP (&rest people)
3372 "Remove the operator setting from user(s) given in PEOPLE."
3373 (when (> (length people) 0)
3374 (erc-server-send (concat "MODE " (erc-default-target)
3376 (make-string (length people) ?o)
3378 (mapconcat 'identity people " ")))
3381 (defun erc-cmd-OP (&rest people)
3382 "Add the operator setting to users(s) given in PEOPLE."
3383 (when (> (length people) 0)
3384 (erc-server-send (concat "MODE " (erc-default-target)
3386 (make-string (length people) ?o)
3388 (mapconcat 'identity people " ")))
3391 (defun erc-cmd-TIME (&optional line)
3392 "Request the current time and date from the current server."
3394 ((and line (string-match "^\\s-*\\(.*\\)$" line))
3395 (let ((args (match-string 1 line)))
3396 (erc-log (format "cmd: TIME: %s" args))
3397 (erc-server-send (concat "TIME " args)))
3399 (t (erc-server-send "TIME"))))
3400 (defalias 'erc-cmd-DATE 'erc-cmd-TIME)
3402 (defun erc-cmd-TOPIC (topic)
3403 "Set or request the topic for a channel.
3404 LINE has the format: \"#CHANNEL TOPIC\", \"#CHANNEL\", \"TOPIC\"
3405 or the empty string.
3407 If no #CHANNEL is given, the default channel is used. If TOPIC is
3408 given, the channel topic is modified, otherwise the current topic will
3411 ;; /topic #channel TOPIC
3412 ((string-match "^\\s-*\\([&#+!]\\S-+\\)\\s-\\(.*\\)$" topic)
3413 (let ((ch (match-string 1 topic))
3414 (topic (match-string 2 topic)))
3415 (erc-log (format "cmd: TOPIC [%s]: %s" ch topic))
3416 (erc-server-send (format "TOPIC %s :%s" ch topic) nil ch))
3419 ((string-match "^\\s-*\\([&#+!]\\S-+\\)" topic)
3420 (let ((ch (match-string 1 topic)))
3421 (erc-server-send (format "TOPIC %s" ch) nil ch)
3424 ((string-match "^\\s-*$" topic)
3425 (let ((ch (erc-default-target)))
3426 (erc-server-send (format "TOPIC %s" ch) nil ch)
3429 ((string-match "^\\s-*\\(.*\\)$" topic)
3430 (let ((ch (erc-default-target))
3431 (topic (match-string 1 topic)))
3432 (if (and ch (erc-channel-p ch))
3434 (erc-log (format "cmd: TOPIC [%s]: %s" ch topic))
3435 (erc-server-send (format "TOPIC %s :%s" ch topic) nil ch))
3436 (erc-display-message nil 'error (current-buffer) 'no-target)))
3439 (defalias 'erc-cmd-T 'erc-cmd-TOPIC)
3440 (put 'erc-cmd-TOPIC 'do-not-parse-args t)
3442 (defun erc-cmd-APPENDTOPIC (topic)
3443 "Append TOPIC to the current channel topic, separated by a space."
3444 (let ((oldtopic erc-channel-topic))
3445 ;; display help when given no arguments
3446 (when (string-match "^\\s-*$" topic)
3447 (signal 'wrong-number-of-arguments nil))
3448 ;; strip trailing ^O
3449 (when (string-match "\\(.*\\)\C-o" oldtopic)
3450 (erc-cmd-TOPIC (concat (match-string 1 oldtopic) topic)))))
3451 (defalias 'erc-cmd-AT 'erc-cmd-APPENDTOPIC)
3452 (put 'erc-cmd-APPENDTOPIC 'do-not-parse-args t)
3454 (defun erc-cmd-CLEARTOPIC (&optional channel)
3455 "Clear the topic for a CHANNEL.
3456 If CHANNEL is not specified, clear the topic for the default channel."
3457 (interactive "sClear topic of channel (RET is current channel): ")
3458 (let ((chnl (or (and (erc-channel-p channel) channel) (erc-default-target))))
3460 (erc-server-send (format "TOPIC %s :" chnl))
3465 (defvar erc-channel-banlist nil
3466 "A list of bans seen for the current channel.
3468 Each ban is an alist of the form:
3471 The property `received-from-server' indicates whether
3472 or not the ban list has been requested from the server.")
3473 (make-variable-buffer-local 'erc-channel-banlist)
3474 (put 'erc-channel-banlist 'received-from-server nil)
3476 (defun erc-cmd-BANLIST ()
3477 "Pretty-print the contents of `erc-channel-banlist'.
3479 The ban list is fetched from the server if necessary."
3480 (let ((chnl (erc-default-target))
3481 (chnl-name (buffer-name)))
3484 ((not (erc-channel-p chnl))
3485 (erc-display-line (erc-make-notice "You're not on a channel\n")
3488 ((not (get 'erc-channel-banlist 'received-from-server))
3489 (let ((old-367-hook erc-server-367-functions))
3490 (setq erc-server-367-functions 'erc-banlist-store
3491 erc-channel-banlist nil)
3492 ;; fetch the ban list then callback
3493 (erc-with-server-buffer
3494 (erc-once-with-server-event
3496 `(with-current-buffer ,chnl-name
3497 (put 'erc-channel-banlist 'received-from-server t)
3498 (setq erc-server-367-functions ',old-367-hook)
3501 (erc-server-send (format "MODE %s b" chnl)))))
3503 ((null erc-channel-banlist)
3504 (erc-display-line (erc-make-notice
3505 (format "No bans for channel: %s\n" chnl))
3507 (put 'erc-channel-banlist 'received-from-server nil))
3510 (let* ((erc-fill-column (or (and (boundp 'erc-fill-column)
3512 (and (boundp 'fill-column)
3514 (1- (window-width))))
3515 (separator (make-string erc-fill-column ?=))
3517 "%-" (number-to-string (/ erc-fill-column 2)) "s"
3518 "%" (number-to-string (/ erc-fill-column 2)) "s")))
3521 (erc-make-notice (format "Ban list for channel: %s\n"
3522 (erc-default-target)))
3525 (erc-display-line separator 'active)
3526 (erc-display-line (format fmt "Ban Mask" "Banned By") 'active)
3527 (erc-display-line separator 'active)
3533 (truncate-string-to-width (cdr x) (/ erc-fill-column 2))
3535 (truncate-string-to-width (car x) (/ erc-fill-column 2))
3538 erc-channel-banlist)
3540 (erc-display-line (erc-make-notice "End of Ban list")
3542 (put 'erc-channel-banlist 'received-from-server nil)))))
3545 (defalias 'erc-cmd-BL 'erc-cmd-BANLIST)
3547 (defun erc-cmd-MASSUNBAN ()
3550 Unban all currently banned users in the current channel."
3551 (let ((chnl (erc-default-target)))
3554 ((not (erc-channel-p chnl))
3556 (erc-make-notice "You're not on a channel\n")
3559 ((not (get 'erc-channel-banlist 'received-from-server))
3560 (let ((old-367-hook erc-server-367-functions))
3561 (setq erc-server-367-functions 'erc-banlist-store)
3562 ;; fetch the ban list then callback
3563 (erc-with-server-buffer
3564 (erc-once-with-server-event
3566 `(with-current-buffer ,chnl
3567 (put 'erc-channel-banlist 'received-from-server t)
3568 (setq erc-server-367-functions ,old-367-hook)
3571 (erc-server-send (format "MODE %s b" chnl)))))
3573 (t (let ((bans (mapcar 'cdr erc-channel-banlist)))
3575 ;; Glob the bans into groups of three, and carry out the unban.
3576 ;; eg. /mode #foo -bbb a*!*@* b*!*@* c*!*@*
3580 (format "MODE %s -%s %s" (erc-default-target)
3581 (make-string (length x) ?b)
3582 (mapconcat 'identity x " "))))
3583 (erc-group-list bans 3))))
3586 (defalias 'erc-cmd-MUB 'erc-cmd-MASSUNBAN)
3588 ;;;; End of IRC commands
3590 (defun erc-ensure-channel-name (channel)
3591 "Return CHANNEL if it is a valid channel name.
3592 Eventually add a # in front of it, if that turns it into a valid channel name."
3593 (if (erc-channel-p channel)
3595 (concat "#" channel)))
3597 (defun erc-grab-region (start end)
3598 "Copy the region between START and END in a recreatable format.
3600 Converts all the IRC text properties in each line of the region
3601 into control codes and writes them to a separate buffer. The
3602 resulting text may be used directly as a script to generate this
3605 (erc-set-active-buffer (current-buffer))
3607 (let* ((cb (current-buffer))
3608 (buf (generate-new-buffer erc-grab-buffer-name))
3609 (region (buffer-substring start end))
3610 (lines (erc-split-multiline-safe region)))
3612 (dolist (line lines)
3613 (insert (concat line "\n")))
3615 (switch-to-buffer-other-window buf)))
3616 (message "erc-grab-region doesn't grab colors etc. anymore. If you use this, please tell the maintainers.")
3619 (defun erc-display-prompt (&optional buffer pos prompt face)
3620 "Display PROMPT in BUFFER at position POS.
3621 Display an ERC prompt in BUFFER.
3623 If PROMPT is nil, one is constructed with the function `erc-prompt'.
3624 If BUFFER is nil, the `current-buffer' is used.
3625 If POS is nil, PROMPT will be displayed at `point'.
3626 If FACE is non-nil, it will be used to propertize the prompt. If it is nil,
3627 `erc-prompt-face' will be used."
3628 (let* ((prompt (or prompt (erc-prompt)))
3630 (ob (current-buffer)))
3631 ;; We cannot use save-excursion because we move point, therefore
3632 ;; we resort to the ol' ob trick to restore this.
3633 (when (and buffer (bufferp buffer))
3634 (set-buffer buffer))
3636 ;; now save excursion again to store where point and mark are
3637 ;; in the current buffer
3639 (setq pos (or pos (point)))
3642 ;; Do not extend the text properties when typing at the end
3643 ;; of the prompt, but stuff typed in front of the prompt
3644 ;; shall remain part of the prompt.
3645 (setq prompt (erc-propertize prompt
3646 'start-open t ; XEmacs
3647 'rear-nonsticky t ; Emacs
3652 (erc-put-text-property 0 (1- (length prompt))
3653 'face (or face 'erc-prompt-face)
3656 ;; Set the input marker
3657 (set-marker erc-input-marker (point)))
3659 ;; Now we are back at the old position. If the prompt was
3660 ;; inserted here or before us, advance point by the length of
3662 (when (or (not pos) (<= (point) pos))
3664 ;; Clear the undo buffer now, so the user can undo his stuff,
3665 ;; but not the stuff we did. Sneaky!
3666 (setq buffer-undo-list nil)
3669 ;; interactive operations
3671 (defun erc-input-message ()
3672 "Read input from the minibuffer."
3674 (let ((minibuffer-allow-text-properties t)
3675 (read-map minibuffer-local-map))
3676 (insert (read-from-minibuffer "Message: "
3677 (string (if (featurep 'xemacs)
3679 last-command-event)) read-map))
3680 (erc-send-current-line)))
3682 (defvar erc-action-history-list ()
3683 "History list for interactive action input.")
3685 (defun erc-input-action ()
3686 "Interactively input a user action and send it to IRC."
3688 (erc-set-active-buffer (current-buffer))
3689 (let ((action (read-from-minibuffer
3690 "Action: " nil nil nil 'erc-action-history-list)))
3691 (if (not (string-match "^\\s-*$" action))
3692 (erc-send-action (erc-default-target) action))))
3694 (defun erc-join-channel (channel &optional key)
3697 If `point' is at the beginning of a channel name, use that as default."
3700 (let ((chnl (if (looking-at "\\([&#+!][^ \n]+\\)") (match-string 1) ""))
3701 (table (when (erc-server-buffer-live-p)
3702 (set-buffer (process-buffer erc-server-process))
3704 (completing-read "Join channel: " table nil nil nil nil chnl))
3705 (when (or current-prefix-arg erc-prompt-for-channel-key)
3706 (read-from-minibuffer "Channel key (RET for none): " nil))))
3707 (erc-cmd-JOIN channel (when (>= (length key) 1) key)))
3709 (defun erc-part-from-channel (reason)
3710 "Part from the current channel and prompt for a REASON."
3713 (if (and (boundp 'reason) (stringp reason) (not (string= reason "")))
3715 (read-from-minibuffer (concat "Reason for leaving " (erc-default-target)
3717 (erc-cmd-PART (concat (erc-default-target)" " reason)))
3719 (defun erc-set-topic (topic)
3720 "Prompt for a TOPIC for the current channel."
3723 (read-from-minibuffer
3724 (concat "Set topic of " (erc-default-target) ": ")
3725 (when erc-channel-topic
3726 (let ((ss (split-string erc-channel-topic "\C-o")))
3727 (cons (apply 'concat (if (cdr ss) (butlast ss) ss))
3729 (let ((topic-list (split-string topic "\C-o"))) ; strip off the topic setter
3730 (erc-cmd-TOPIC (concat (erc-default-target) " " (car topic-list)))))
3732 (defun erc-set-channel-limit (&optional limit)
3733 "Set a LIMIT for the current channel. Remove limit if nil.
3734 Prompt for one if called interactively."
3735 (interactive (list (read-from-minibuffer
3736 (format "Limit for %s (RET to remove limit): "
3737 (erc-default-target)))))
3738 (let ((tgt (erc-default-target)))
3739 (if (and limit (>= (length limit) 1))
3740 (erc-server-send (format "MODE %s +l %s" tgt limit))
3741 (erc-server-send (format "MODE %s -l" tgt)))))
3743 (defun erc-set-channel-key (&optional key)
3744 "Set a KEY for the current channel. Remove key if nil.
3745 Prompt for one if called interactively."
3746 (interactive (list (read-from-minibuffer
3747 (format "Key for %s (RET to remove key): "
3748 (erc-default-target)))))
3749 (let ((tgt (erc-default-target)))
3750 (if (and key (>= (length key) 1))
3751 (erc-server-send (format "MODE %s +k %s" tgt key))
3752 (erc-server-send (format "MODE %s -k" tgt)))))
3754 (defun erc-quit-server (reason)
3755 "Disconnect from current server after prompting for REASON.
3756 `erc-quit-reason' works with this just like with `erc-cmd-QUIT'."
3757 (interactive (list (read-from-minibuffer
3758 (format "Reason for quitting %s: "
3759 (or erc-server-announced-name
3760 erc-session-server)))))
3761 (erc-cmd-QUIT reason))
3763 ;; Movement of point
3766 "Move `point' to the beginning of the current line.
3768 This places `point' just after the prompt, or at the beginning of the line."
3771 (when (get-text-property (point) 'erc-prompt)
3772 (goto-char erc-input-marker))
3775 (defun erc-kill-input ()
3776 "Kill current input line using `erc-bol' followed by `kill-line'."
3778 (when (and (erc-bol)
3779 (/= (point) (point-max))) ;; Prevent a (ding) and an error when
3780 ;; there's nothing to kill
3781 (if (boundp 'erc-input-ring-index)
3782 (setq erc-input-ring-index nil))
3785 (defun erc-complete-word-at-point ()
3786 (run-hook-with-args-until-success 'erc-complete-functions))
3788 (define-obsolete-function-alias 'erc-complete-word 'completion-at-point "24.1")
3790 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3792 ;; IRC SERVER INPUT HANDLING
3794 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3796 ;;;; New Input parsing
3798 ; Stolen from ZenIRC. I just wanna test this code, so here is
3801 (defcustom erc-default-server-hook '(erc-debug-missing-hooks
3802 erc-default-server-handler)
3803 "Default for server messages which aren't covered by `erc-server-hooks'."
3804 :group 'erc-server-hooks
3807 (defun erc-default-server-handler (proc parsed)
3808 "Default server handler.
3810 Displays PROC and PARSED appropriately using `erc-display-message'."
3811 (erc-display-message
3818 (setq res (append res (list x)))))
3823 (defvar erc-server-vectors
3824 '(["msgtype" "sender" "to" "arg1" "arg2" "arg3" "..."])
3825 "List of received server messages which ERC does not specifically handle.
3826 See `erc-debug-missing-hooks'.")
3827 ;(make-variable-buffer-local 'erc-server-vectors)
3829 (defun erc-debug-missing-hooks (proc parsed)
3830 "Add PARSED server message ERC does not yet handle to `erc-server-vectors'.
3831 These vectors can be helpful when adding new server message handlers to ERC.
3832 See `erc-default-server-hook'."
3833 (nconc erc-server-vectors (list parsed))
3836 (defun erc-query (target server)
3837 "Open a query buffer on TARGET, using SERVER.
3838 To change how this query window is displayed, use `let' to bind
3839 `erc-join-buffer' before calling this."
3841 (buffer-live-p server)
3842 (set-buffer server))
3843 (error "Couldn't switch to server buffer"))
3844 (let ((buf (erc-open erc-session-server
3847 erc-session-user-full-name
3852 erc-server-process)))
3854 (error "Couldn't open query window"))
3855 (erc-update-mode-line)
3858 (defcustom erc-auto-query 'window-noselect
3859 "If non-nil, create a query buffer each time you receive a private message.
3860 If the buffer doesn't already exist, it is created.
3862 This can be set to a symbol, to control how the new query window
3863 should appear. The default behavior is to display the buffer in
3864 a new window, but not to select it. See the documentation for
3865 `erc-join-buffer' for a description of the available choices."
3867 :type '(choice (const :tag "Don't create query window" nil)
3868 (const :tag "Split window and select" window)
3869 (const :tag "Split window, don't select" window-noselect)
3870 (const :tag "New frame" frame)
3871 (const :tag "Bury in new buffer" bury)
3872 (const :tag "Use current buffer" buffer)
3873 (const :tag "Use current buffer" t)))
3875 (defcustom erc-query-on-unjoined-chan-privmsg t
3876 "If non-nil create query buffer on receiving any PRIVMSG at all.
3877 This includes PRIVMSGs directed to channels. If you are using an IRC
3878 bouncer, such as dircproxy, to keep a log of channels when you are
3879 disconnected, you should set this option to t."
3883 (defcustom erc-format-query-as-channel-p t
3884 "If non-nil, format text from others in a query buffer like in a channel,
3885 otherwise format like a private message."
3889 (defcustom erc-minibuffer-notice nil
3890 "If non-nil, print ERC notices for the user in the minibuffer.
3891 Only happens when the session buffer isn't visible."
3895 (defcustom erc-minibuffer-ignored nil
3896 "If non-nil, print a message in the minibuffer if we ignored something."
3900 (defun erc-wash-quit-reason (reason nick login host)
3901 "Remove duplicate text from quit REASON.
3902 Specifically in relation to NICK (user@host) information. Returns REASON
3903 unmodified if nothing can be removed.
3904 E.g. \"Read error to Nick [user@some.host]: 110\" would be shortened to
3905 \"Read error: 110\". The same applies for \"Ping Timeout\"."
3906 (setq nick (regexp-quote nick)
3907 login (regexp-quote login)
3908 host (regexp-quote host))
3909 (or (when (string-match (concat "^\\(Read error\\) to "
3910 nick "\\[" host "\\]: "
3911 "\\(.+\\)$") reason)
3912 (concat (match-string 1 reason) ": " (match-string 2 reason)))
3913 (when (string-match (concat "^\\(Ping timeout\\) for "
3914 nick "\\[" host "\\]$") reason)
3915 (match-string 1 reason))
3918 (defun erc-nickname-in-use (nick reason)
3919 "If NICK is unavailable, tell the user the REASON.
3921 See also `erc-display-error-notice'."
3922 (if (or (not erc-try-new-nick-p)
3923 ;; how many default-nicks are left + one more try...
3924 (eq erc-nick-change-attempt-count
3925 (if (consp erc-nick)
3926 (+ (length erc-nick) 1)
3928 (erc-display-error-notice
3930 (format "Nickname %s is %s, try another." nick reason))
3931 (setq erc-nick-change-attempt-count (+ erc-nick-change-attempt-count 1))
3932 (let ((newnick (nth 1 erc-default-nicks))
3933 (nicklen (cdr (assoc "NICKLEN"
3934 (erc-with-server-buffer
3935 erc-server-parameters)))))
3936 (setq erc-bad-nick t)
3937 ;; try to use a different nick
3938 (if erc-default-nicks
3939 (setq erc-default-nicks (cdr erc-default-nicks)))
3941 (setq newnick (concat (truncate-string-to-width
3943 (if (and erc-server-connected nicklen)
3944 (- (string-to-number nicklen)
3945 (length erc-nick-uniquifier))
3946 ;; rfc2812 max nick length = 9
3947 ;; we must assume this is the
3948 ;; server's setting if we haven't
3949 ;; established a connection yet
3950 (- 9 (length erc-nick-uniquifier))))
3951 erc-nick-uniquifier)))
3952 (erc-cmd-NICK newnick)
3953 (erc-display-error-notice
3955 (format "Nickname %s is %s, trying %s"
3956 nick reason newnick)))))
3960 (defgroup erc-server-hooks nil
3961 "Server event callbacks.
3962 Every server event - like numeric replies - has its own hook.
3963 Those hooks are all called using `run-hook-with-args-until-success'.
3964 They receive as first argument the process object from where the event
3966 and as second argument the event parsed as a vector."
3969 (defun erc-display-server-message (proc parsed)
3970 "Display the message sent by the server as a notice."
3971 (erc-display-message
3972 parsed 'notice 'active (erc-response.contents parsed)))
3974 (defun erc-auto-query (proc parsed)
3975 ;; FIXME: This needs more documentation, unless it's not a user function --
3976 ;; Lawrence 2004-01-08
3977 "Put this on `erc-server-PRIVMSG-functions'."
3978 (when erc-auto-query
3979 (let* ((nick (car (erc-parse-user (erc-response.sender parsed))))
3980 (target (car (erc-response.command-args parsed)))
3981 (msg (erc-response.contents parsed))
3982 (query (if (not erc-query-on-unjoined-chan-privmsg)
3984 (if (erc-current-nick-p target)
3987 (and (not (erc-ignored-user-p (erc-response.sender parsed)))
3988 (or erc-query-on-unjoined-chan-privmsg
3989 (string= target (erc-current-nick)))
3990 (not (erc-get-buffer query proc))
3991 (not (erc-is-message-ctcp-and-not-action-p msg))
3992 (let ((erc-query-display erc-auto-query))
3993 (erc-cmd-QUERY query))
3996 (defun erc-is-message-ctcp-p (message)
3997 "Check if MESSAGE is a CTCP message or not."
3998 (string-match "^\C-a\\([^\C-a]*\\)\C-a?$" message))
4000 (defun erc-is-message-ctcp-and-not-action-p (message)
4001 "Check if MESSAGE is a CTCP message or not."
4002 (and (erc-is-message-ctcp-p message)
4003 (not (string-match "^\C-a\\ACTION.*\C-a$" message))))
4005 (defun erc-format-privmessage (nick msg privp msgp)
4006 "Format a PRIVMSG in an insertable fashion."
4007 (let* ((mark-s (if msgp (if privp "*" "<") "-"))
4008 (mark-e (if msgp (if privp "*" ">") "-"))
4009 (str (format "%s%s%s %s" mark-s nick mark-e msg))
4010 (nick-face (if privp 'erc-nick-msg-face 'erc-nick-default-face))
4011 (msg-face (if privp 'erc-direct-msg-face 'erc-default-face)))
4012 ;; add text properties to text before the nick, the nick and after the nick
4013 (erc-put-text-property 0 (length mark-s) 'face msg-face str)
4014 (erc-put-text-property (length mark-s) (+ (length mark-s) (length nick))
4015 'face nick-face str)
4016 (erc-put-text-property (+ (length mark-s) (length nick)) (length str)
4020 (defcustom erc-format-nick-function 'erc-format-nick
4021 "Function to format a nickname for message display."
4025 (defun erc-format-nick (&optional user channel-data)
4026 "Return the nickname of USER.
4027 See also `erc-format-nick-function'."
4028 (when user (erc-server-user-nickname user)))
4030 (defun erc-format-@nick (&optional user channel-data)
4031 "Format the nickname of USER showing if USER is an operator or has voice.
4032 Operators have \"@\" and users with voice have \"+\" as a prefix.
4033 Use CHANNEL-DATA to determine op and voice status.
4034 See also `erc-format-nick-function'."
4036 (let ((op (and channel-data (erc-channel-user-op channel-data) "@"))
4037 (voice (and channel-data (erc-channel-user-voice channel-data) "+")))
4038 (concat voice op (erc-server-user-nickname user)))))
4040 (defun erc-format-my-nick ()
4041 "Return the beginning of this user's message, correctly propertized."
4042 (if erc-show-my-nick
4045 (nick (erc-current-nick)))
4047 (erc-propertize open 'face 'erc-default-face)
4048 (erc-propertize nick 'face 'erc-my-nick-face)
4049 (erc-propertize close 'face 'erc-default-face)))
4050 (let ((prefix "> "))
4051 (erc-propertize prefix 'face 'erc-default-face))))
4053 (defun erc-echo-notice-in-default-buffer (s parsed buffer sender)
4054 "Echos a private notice in the default buffer, namely the
4055 target buffer specified by BUFFER, or there is no target buffer,
4056 the server buffer. This function is designed to be added to
4057 either `erc-echo-notice-hook' or `erc-echo-notice-always-hook',
4058 and always returns t."
4059 (erc-display-message parsed nil buffer s)
4062 (defun erc-echo-notice-in-target-buffer (s parsed buffer sender)
4063 "Echos a private notice in BUFFER, if BUFFER is non-nil. This
4064 function is designed to be added to either `erc-echo-notice-hook'
4065 or `erc-echo-notice-always-hook', and returns non-nil if BUFFER
4068 (progn (erc-display-message parsed nil buffer s) t)
4071 (defun erc-echo-notice-in-minibuffer (s parsed buffer sender)
4072 "Echos a private notice in the minibuffer. This function is
4073 designed to be added to either `erc-echo-notice-hook' or
4074 `erc-echo-notice-always-hook', and always returns t."
4075 (message "%s" (concat "NOTICE: " s))
4078 (defun erc-echo-notice-in-server-buffer (s parsed buffer sender)
4079 "Echos a private notice in the server buffer. This function is
4080 designed to be added to either `erc-echo-notice-hook' or
4081 `erc-echo-notice-always-hook', and always returns t."
4082 (erc-display-message parsed nil nil s)
4085 (defun erc-echo-notice-in-active-non-server-buffer (s parsed buffer sender)
4086 "Echos a private notice in the active buffer if the active
4087 buffer is not the server buffer. This function is designed to be
4088 added to either `erc-echo-notice-hook' or
4089 `erc-echo-notice-always-hook', and returns non-nil if the active
4090 buffer is not the server buffer."
4091 (if (not (eq (erc-server-buffer) (erc-active-buffer)))
4092 (progn (erc-display-message parsed nil 'active s) t)
4095 (defun erc-echo-notice-in-active-buffer (s parsed buffer sender)
4096 "Echos a private notice in the active buffer. This function is
4097 designed to be added to either `erc-echo-notice-hook' or
4098 `erc-echo-notice-always-hook', and always returns t."
4099 (erc-display-message parsed nil 'active s)
4102 (defun erc-echo-notice-in-user-buffers (s parsed buffer sender)
4103 "Echos a private notice in all of the buffers for which SENDER
4104 is a member. This function is designed to be added to either
4105 `erc-echo-notice-hook' or `erc-echo-notice-always-hook', and
4106 returns non-nil if there is at least one buffer for which the
4109 See also: `erc-echo-notice-in-first-user-buffer',
4110 `erc-buffer-list-with-nick'."
4111 (let ((buffers (erc-buffer-list-with-nick sender erc-server-process)))
4113 (progn (erc-display-message parsed nil buffers s) t)
4116 (defun erc-echo-notice-in-user-and-target-buffers (s parsed buffer sender)
4117 "Echos a private notice in BUFFER and in all of the buffers for
4118 which SENDER is a member. This function is designed to be added
4119 to either `erc-echo-notice-hook' or
4120 `erc-echo-notice-always-hook', and returns non-nil if there is
4121 at least one buffer for which the sender is a member or the
4124 See also: `erc-echo-notice-in-user-buffers',
4125 `erc-buffer-list-with-nick'."
4126 (let ((buffers (erc-buffer-list-with-nick sender erc-server-process)))
4127 (add-to-list 'buffers buffer)
4129 (progn (erc-display-message parsed nil buffers s) t)
4132 (defun erc-echo-notice-in-first-user-buffer (s parsed buffer sender)
4133 "Echos a private notice in one of the buffers for which SENDER
4134 is a member. This function is designed to be added to either
4135 `erc-echo-notice-hook' or `erc-echo-notice-always-hook', and
4136 returns non-nil if there is at least one buffer for which the
4139 See also: `erc-echo-notice-in-user-buffers',
4140 `erc-buffer-list-with-nick'."
4141 (let ((buffers (erc-buffer-list-with-nick sender erc-server-process)))
4143 (progn (erc-display-message parsed nil (car buffers) s) t)
4146 ;;; Ban manipulation
4148 (defun erc-banlist-store (proc parsed)
4149 "Record ban entries for a channel."
4150 (multiple-value-bind (channel mask whoset)
4151 (values-list (cdr (erc-response.command-args parsed)))
4152 ;; Determine to which buffer the message corresponds
4153 (let ((buffer (erc-get-buffer channel proc)))
4154 (with-current-buffer buffer
4155 (unless (member (cons whoset mask) erc-channel-banlist)
4156 (setq erc-channel-banlist (cons (cons whoset mask)
4157 erc-channel-banlist))))))
4160 (defun erc-banlist-finished (proc parsed)
4161 "Record that we have received the banlist."
4162 (let* ((channel (second (erc-response.command-args parsed)))
4163 (buffer (erc-get-buffer channel proc)))
4164 (with-current-buffer buffer
4165 (put 'erc-channel-banlist 'received-from-server t)))
4166 t) ; suppress the 'end of banlist' message
4168 (defun erc-banlist-update (proc parsed)
4169 "Check MODE commands for bans and update the banlist appropriately."
4170 ;; FIXME: Possibly incorrect. -- Lawrence 2004-05-11
4171 (let* ((tgt (first (erc-response.command-args parsed)))
4172 (mode (erc-response.contents parsed))
4173 (whoset (erc-response.sender parsed))
4174 (buffer (erc-get-buffer tgt proc)))
4176 (with-current-buffer buffer
4177 (cond ((not (get 'erc-channel-banlist 'received-from-server)) nil)
4178 ((string-match "^\\([+-]\\)b" mode)
4181 ((string-match "^-" mode)
4182 ;; Remove the unbanned masks from the ban list
4183 (setq erc-channel-banlist
4186 (member (upcase (cdr y))
4188 (cdr (split-string mode)))))
4189 erc-channel-banlist)))
4190 ((string-match "^+" mode)
4191 ;; Add the banned mask(s) to the ban list
4194 (unless (member (cons whoset mask) erc-channel-banlist)
4195 (setq erc-channel-banlist
4196 (cons (cons whoset mask) erc-channel-banlist))))
4197 (cdr (split-string mode))))))))))
4200 ;; used for the banlist cmds
4201 (defun erc-group-list (list n)
4202 "Group LIST into sublists of length N."
4203 (cond ((null list) nil)
4204 ((null (nthcdr n list)) (list list))
4205 (t (cons (erc-subseq list 0 n) (erc-group-list (nthcdr n list) n)))))
4210 (defun erc-handle-login ()
4211 "Handle the logging in process of connection."
4212 (unless erc-logged-in
4213 (setq erc-logged-in t)
4214 (message "Logging in as \'%s\'... done" (erc-current-nick))
4215 ;; execute a startup script
4216 (let ((f (erc-select-startup-file)))
4218 (erc-load-script f)))))
4220 (defun erc-connection-established (proc parsed)
4221 "Run just after connection.
4223 Set user modes and run `erc-after-connect' hook."
4224 (with-current-buffer (process-buffer proc)
4225 (unless erc-server-connected ; only once per session
4226 (let ((server (or erc-server-announced-name
4227 (erc-response.sender parsed)))
4228 (nick (car (erc-response.command-args parsed)))
4229 (buffer (process-buffer proc)))
4230 (setq erc-server-connected t)
4231 (erc-update-mode-line)
4232 (erc-set-initial-user-mode nick buffer)
4233 (erc-server-setup-periodical-ping buffer)
4234 (run-hook-with-args 'erc-after-connect server nick)))))
4236 (defun erc-set-initial-user-mode (nick buffer)
4237 "If `erc-user-mode' is non-nil for NICK, set the user modes.
4238 The server buffer is given by BUFFER."
4239 (with-current-buffer buffer
4241 (let ((mode (if (functionp erc-user-mode)
4242 (funcall erc-user-mode)
4244 (when (stringp mode)
4245 (erc-log (format "changing mode for %s to %s" nick mode))
4246 (erc-server-send (format "MODE %s %s" nick mode)))))))
4248 (defun erc-display-error-notice (parsed string)
4249 "Display STRING as an error notice.
4251 See also `erc-display-message'."
4252 (erc-display-message
4253 parsed '(notice error) 'active string))
4255 (defun erc-process-ctcp-query (proc parsed nick login host)
4256 ;; FIXME: This needs a proper docstring -- Lawrence 2004-01-08
4257 "Process a CTCP query."
4258 (let ((queries (delete "" (split-string (erc-response.contents parsed)
4260 (if (> (length queries) 4)
4261 (erc-display-message
4262 parsed (list 'notice 'error) proc 'ctcp-too-many)
4263 (if (= 0 (length queries))
4264 (erc-display-message
4265 parsed (list 'notice 'error) proc
4266 'ctcp-empty ?n nick)
4268 (let* ((type (upcase (car (split-string (car queries)))))
4269 (hook (intern-soft (concat "erc-ctcp-query-" type "-hook"))))
4270 (if (and hook (boundp hook))
4271 (if (string-equal type "ACTION")
4272 (run-hook-with-args-until-success
4273 hook proc parsed nick login host
4274 (car (erc-response.command-args parsed))
4277 (if (erc-current-nick-p
4278 (car (erc-response.command-args parsed)))
4279 (erc-display-message
4280 parsed 'error 'active 'ctcp-request
4281 ?n nick ?u login ?h host ?r (car queries))
4282 (erc-display-message
4283 parsed 'error 'active 'ctcp-request-to
4284 ?n nick ?u login ?h host ?r (car queries)
4285 ?t (car (erc-response.command-args parsed)))))
4286 (run-hook-with-args-until-success
4287 hook proc nick login host
4288 (car (erc-response.command-args parsed))
4290 (erc-display-message
4291 parsed (list 'notice 'error) proc
4293 (setq queries (cdr queries)))))))
4295 (defvar erc-ctcp-query-ACTION-hook '(erc-ctcp-query-ACTION))
4297 (defun erc-ctcp-query-ACTION (proc parsed nick login host to msg)
4298 "Respond to a CTCP ACTION query."
4299 (when (string-match "^ACTION\\s-\\(.*\\)\\s-*$" msg)
4300 (let ((s (match-string 1 msg))
4301 (buf (or (erc-get-buffer to proc)
4302 (erc-get-buffer nick proc)
4303 (process-buffer proc))))
4304 (erc-display-message
4306 'ACTION ?n nick ?u login ?h host ?a s))))
4308 (defvar erc-ctcp-query-CLIENTINFO-hook '(erc-ctcp-query-CLIENTINFO))
4310 (defun erc-ctcp-query-CLIENTINFO (proc nick login host to msg)
4311 "Respond to a CTCP CLIENTINFO query."
4312 (when (string-match "^CLIENTINFO\\(\\s-*\\|\\s-+.*\\)$" msg)
4313 (let ((s (erc-client-info (erc-trim-string (match-string 1 msg)))))
4314 (unless erc-disable-ctcp-replies
4315 (erc-send-ctcp-notice nick (format "CLIENTINFO %s" s)))))
4318 (defvar erc-ctcp-query-ECHO-hook '(erc-ctcp-query-ECHO))
4319 (defun erc-ctcp-query-ECHO (proc nick login host to msg)
4320 "Respond to a CTCP ECHO query."
4321 (when (string-match "^ECHO\\s-+\\(.*\\)\\s-*$" msg)
4322 (let ((s (match-string 1 msg)))
4323 (unless erc-disable-ctcp-replies
4324 (erc-send-ctcp-notice nick (format "ECHO %s" s)))))
4327 (defvar erc-ctcp-query-FINGER-hook '(erc-ctcp-query-FINGER))
4328 (defun erc-ctcp-query-FINGER (proc nick login host to msg)
4329 "Respond to a CTCP FINGER query."
4330 (unless erc-disable-ctcp-replies
4331 (let ((s (if erc-anonymous-login
4332 (format "FINGER I'm %s." (erc-current-nick))
4333 (format "FINGER %s (%s@%s)."
4337 (ns (erc-time-diff erc-server-last-sent-time (erc-current-time))))
4339 (setq s (concat s " Idle for " (erc-sec-to-time ns))))
4340 (erc-send-ctcp-notice nick s)))
4343 (defvar erc-ctcp-query-PING-hook '(erc-ctcp-query-PING))
4344 (defun erc-ctcp-query-PING (proc nick login host to msg)
4345 "Respond to a CTCP PING query."
4346 (when (string-match "^PING\\s-+\\(.*\\)" msg)
4347 (unless erc-disable-ctcp-replies
4348 (let ((arg (match-string 1 msg)))
4349 (erc-send-ctcp-notice nick (format "PING %s" arg)))))
4352 (defvar erc-ctcp-query-TIME-hook '(erc-ctcp-query-TIME))
4353 (defun erc-ctcp-query-TIME (proc nick login host to msg)
4354 "Respond to a CTCP TIME query."
4355 (unless erc-disable-ctcp-replies
4356 (erc-send-ctcp-notice nick (format "TIME %s" (current-time-string))))
4359 (defvar erc-ctcp-query-USERINFO-hook '(erc-ctcp-query-USERINFO))
4360 (defun erc-ctcp-query-USERINFO (proc nick login host to msg)
4361 "Respond to a CTCP USERINFO query."
4362 (unless erc-disable-ctcp-replies
4363 (erc-send-ctcp-notice nick (format "USERINFO %s" erc-user-information)))
4366 (defvar erc-ctcp-query-VERSION-hook '(erc-ctcp-query-VERSION))
4367 (defun erc-ctcp-query-VERSION (proc nick login host to msg)
4368 "Respond to a CTCP VERSION query."
4369 (unless erc-disable-ctcp-replies
4370 (erc-send-ctcp-notice
4372 "VERSION \C-bERC\C-b %s - an IRC client for emacs (\C-b%s\C-b)"
4374 erc-official-location)))
4377 (defun erc-process-ctcp-reply (proc parsed nick login host msg)
4378 "Process MSG as a CTCP reply."
4379 (let* ((type (car (split-string msg)))
4380 (hook (intern (concat "erc-ctcp-reply-" type "-hook"))))
4382 (run-hook-with-args-until-success
4383 hook proc nick login host
4384 (car (erc-response.command-args parsed)) msg)
4385 (erc-display-message
4386 parsed 'notice 'active
4387 'CTCP-UNKNOWN ?n nick ?u login ?h host ?m msg))))
4389 (defvar erc-ctcp-reply-ECHO-hook '(erc-ctcp-reply-ECHO))
4390 (defun erc-ctcp-reply-ECHO (proc nick login host to msg)
4391 "Handle a CTCP ECHO reply."
4392 (when (string-match "^ECHO\\s-+\\(.*\\)\\s-*$" msg)
4393 (let ((message (match-string 1 msg)))
4394 (erc-display-message
4395 nil '(notice action) 'active
4396 'CTCP-ECHO ?n nick ?m message)))
4399 (defvar erc-ctcp-reply-CLIENTINFO-hook '(erc-ctcp-reply-CLIENTINFO))
4400 (defun erc-ctcp-reply-CLIENTINFO (proc nick login host to msg)
4401 "Handle a CTCP CLIENTINFO reply."
4402 (when (string-match "^CLIENTINFO\\s-+\\(.*\\)\\s-*$" msg)
4403 (let ((message (match-string 1 msg)))
4404 (erc-display-message
4406 'CTCP-CLIENTINFO ?n nick ?m message)))
4409 (defvar erc-ctcp-reply-FINGER-hook '(erc-ctcp-reply-FINGER))
4410 (defun erc-ctcp-reply-FINGER (proc nick login host to msg)
4411 "Handle a CTCP FINGER reply."
4412 (when (string-match "^FINGER\\s-+\\(.*\\)\\s-*$" msg)
4413 (let ((message (match-string 1 msg)))
4414 (erc-display-message
4416 'CTCP-FINGER ?n nick ?m message)))
4419 (defvar erc-ctcp-reply-PING-hook '(erc-ctcp-reply-PING))
4420 (defun erc-ctcp-reply-PING (proc nick login host to msg)
4421 "Handle a CTCP PING reply."
4422 (if (not (string-match "^PING\\s-+\\([0-9.]+\\)" msg))
4424 (let ((time (match-string 1 msg)))
4426 (let ((delta (erc-time-diff (string-to-number time)
4427 (erc-current-time))))
4428 (erc-display-message
4431 ?t (erc-sec-to-time delta)))
4433 (erc-display-message
4435 'bad-ping-response ?n nick ?t time))))))
4437 (defvar erc-ctcp-reply-TIME-hook '(erc-ctcp-reply-TIME))
4438 (defun erc-ctcp-reply-TIME (proc nick login host to msg)
4439 "Handle a CTCP TIME reply."
4440 (when (string-match "^TIME\\s-+\\(.*\\)\\s-*$" msg)
4441 (let ((message (match-string 1 msg)))
4442 (erc-display-message
4444 'CTCP-TIME ?n nick ?m message)))
4447 (defvar erc-ctcp-reply-VERSION-hook '(erc-ctcp-reply-VERSION))
4448 (defun erc-ctcp-reply-VERSION (proc nick login host to msg)
4449 "Handle a CTCP VERSION reply."
4450 (when (string-match "^VERSION\\s-+\\(.*\\)\\s-*$" msg)
4451 (let ((message (match-string 1 msg)))
4452 (erc-display-message
4454 'CTCP-VERSION ?n nick ?m message)))
4457 (defun erc-process-away (proc away-p)
4458 "Toggle the away status of the user depending on the value of AWAY-P.
4460 If nil, set the user as away.
4461 If non-nil, return from being away."
4462 (let ((sessionbuf (process-buffer proc)))
4464 (with-current-buffer sessionbuf
4465 (when erc-away-nickname
4466 (erc-log (format "erc-process-away: away-nick: %s, away-p: %s"
4467 erc-away-nickname away-p))
4468 (erc-cmd-NICK (if away-p
4473 (setq erc-away (current-time)))
4475 (let ((away-time erc-away))
4476 ;; away must be set to NIL BEFORE sending anything to prevent
4477 ;; an infinite recursion
4479 (with-current-buffer (erc-active-buffer)
4480 (when erc-public-away-p
4482 (erc-default-target)
4484 (format "is back (gone for %s)"
4487 (erc-emacs-time-to-erc-time away-time)
4488 (erc-current-time))))
4490 (erc-update-mode-line)))
4492 ;;;; List of channel members handling
4494 (defun erc-channel-begin-receiving-names ()
4497 Used when a channel names list is about to be received. Should
4498 be called with the current buffer set to the channel buffer.
4500 See also `erc-channel-end-receiving-names'."
4501 (setq erc-channel-new-member-names (make-hash-table :test 'equal)))
4503 (defun erc-channel-end-receiving-names ()
4506 Used to fix `erc-channel-users' after a channel names list has been
4507 received. Should be called with the current buffer set to the
4510 See also `erc-channel-begin-receiving-names'."
4511 (maphash (lambda (nick user)
4512 (if (null (gethash nick erc-channel-new-member-names))
4513 (erc-remove-channel-user nick)))
4515 (setq erc-channel-new-member-names nil))
4517 (defun erc-parse-prefix ()
4518 "Return an alist of valid prefix character types and their representations.
4519 Example: (operator) o => @, (voiced) v => +."
4520 (let ((str (or (cdr (assoc "PREFIX" (erc-with-server-buffer
4521 erc-server-parameters)))
4522 ;; provide a sane default
4525 (when (string-match "^(\\([^)]+\\))\\(.+\\)$" str)
4526 (setq types (match-string 1 str)
4527 chars (match-string 2 str))
4528 (let ((len (min (length types) (length chars)))
4532 (setq alist (cons (cons (elt types i) (elt chars i))
4537 (defun erc-channel-receive-names (names-string)
4538 "This function is for internal use only.
4540 Update `erc-channel-users' according to NAMES-STRING.
4541 NAMES-STRING is a string listing some of the names on the
4543 (let (prefix op-ch voice-ch names name op voice)
4544 (setq prefix (erc-parse-prefix))
4545 (setq op-ch (cdr (assq ?o prefix))
4546 voice-ch (cdr (assq ?v prefix)))
4547 ;; We need to delete "" because in XEmacs, (split-string "a ")
4548 ;; returns ("a" "").
4549 (setq names (delete "" (split-string names-string)))
4550 (let ((erc-channel-members-changed-hook nil))
4551 (dolist (item names)
4554 (if (rassq (elt item 0) prefix)
4555 (cond ((= (length item) 1)
4557 ((eq (elt item 0) op-ch)
4558 (setq name (substring item 1)
4561 ((eq (elt item 0) voice-ch)
4562 (setq name (substring item 1)
4565 (t (setq name (substring item 1)
4572 (puthash (erc-downcase name) t
4573 erc-channel-new-member-names)
4574 (erc-update-current-channel-member
4575 name name t op voice)))))
4576 (run-hooks 'erc-channel-members-changed-hook)))
4578 (defcustom erc-channel-members-changed-hook nil
4579 "This hook is called every time the variable `channel-members' changes.
4580 The buffer where the change happened is current while this hook is called."
4584 (defun erc-update-user-nick (nick &optional new-nick
4585 host login full-name info)
4586 "Updates the stored user information for the user with nickname
4589 See also: `erc-update-user'."
4590 (erc-update-user (erc-get-server-user nick) new-nick
4591 host login full-name info))
4593 (defun erc-update-user (user &optional new-nick
4594 host login full-name info)
4595 "Update user info for USER. USER must be an erc-server-user
4596 struct. Any of NEW-NICK, HOST, LOGIN, FULL-NAME, INFO which are
4597 non-nil and not equal to the existing values for USER are used to
4598 replace the stored values in USER.
4600 If, and only if, a change is made,
4601 `erc-channel-members-changed-hook' is run for each channel for
4602 which USER is a member, and t is returned."
4606 (not (equal (erc-server-user-nickname user)
4609 (erc-change-user-nickname user new-nick))
4611 (not (equal (erc-server-user-host user) host)))
4613 (setf (erc-server-user-host user) host))
4615 (not (equal (erc-server-user-login user) login)))
4617 (setf (erc-server-user-login user) login))
4618 (when (and full-name
4619 (not (equal (erc-server-user-full-name user)
4622 (setf (erc-server-user-full-name user) full-name))
4624 (not (equal (erc-server-user-info user) info)))
4626 (setf (erc-server-user-info user) info))
4628 (dolist (buf (erc-server-user-buffers user))
4629 (if (buffer-live-p buf)
4630 (with-current-buffer buf
4631 (run-hooks 'erc-channel-members-changed-hook))))))
4634 (defun erc-update-current-channel-member
4635 (nick new-nick &optional add op voice host login full-name info
4636 update-message-time)
4637 "Updates the stored user information for the user with nickname
4638 NICK. `erc-update-user' is called to handle changes to nickname,
4639 HOST, LOGIN, FULL-NAME, and INFO. If OP or VOICE are non-nil,
4640 they must be equal to either `on' or `off', in which case the
4641 operator or voice status of the user in the current channel is
4642 changed accordingly. If UPDATE-MESSAGE-TIME is non-nil, the
4643 last-message-time of the user in the current channel is set
4646 If ADD is non-nil, the user will be added with the specified
4647 information if it is not already present in the user or channel
4650 If, and only if, changes are made, or the user is added,
4651 `erc-channel-members-updated-hook' is run, and t is returned.
4653 See also: `erc-update-user' and `erc-update-channel-member'."
4654 (let* (changed user-changed
4655 (channel-data (erc-get-channel-user nick))
4656 (cuser (if channel-data (cdr channel-data)))
4657 (user (if channel-data (car channel-data)
4658 (erc-get-server-user nick))))
4661 (erc-log (format "update-member: user = %S, cuser = %S" user cuser))
4663 (not (eq (erc-channel-user-op cuser) op)))
4665 (setf (erc-channel-user-op cuser)
4666 (cond ((eq op 'on) t)
4670 (not (eq (erc-channel-user-voice cuser) voice)))
4672 (setf (erc-channel-user-voice cuser)
4673 (cond ((eq voice 'on) t)
4674 ((eq voice 'off) nil)
4676 (when update-message-time
4677 (setf (erc-channel-user-last-message-time cuser) (current-time)))
4679 (erc-update-user user new-nick
4680 host login full-name info)))
4684 (setq user (make-erc-server-user
4687 :full-name full-name
4690 :buffers (list (current-buffer))))
4691 (erc-add-server-user nick user))
4692 (setf (erc-server-user-buffers user)
4693 (cons (current-buffer)
4694 (erc-server-user-buffers user))))
4695 (setq cuser (make-erc-channel-user
4696 :op (cond ((eq op 'on) t)
4699 :voice (cond ((eq voice 'on) t)
4700 ((eq voice 'off) nil)
4703 (if update-message-time (current-time))))
4704 (puthash (erc-downcase nick) (cons user cuser)
4707 (when (and changed (null user-changed))
4708 (run-hooks 'erc-channel-members-changed-hook))
4709 (or changed user-changed add)))
4711 (defun erc-update-channel-member (channel nick new-nick
4712 &optional add op voice host login
4713 full-name info update-message-time)
4714 "Updates user and channel information for the user with
4715 nickname NICK in channel CHANNEL.
4717 See also: `erc-update-current-channel-member'."
4720 (erc-update-current-channel-member nick new-nick add op voice host
4721 login full-name info
4722 update-message-time)))
4724 (defun erc-remove-current-channel-member (nick)
4725 "Remove NICK from current channel membership list.
4726 Runs `erc-channel-members-changed-hook'."
4727 (let ((channel-data (erc-get-channel-user nick)))
4729 (erc-remove-channel-user nick)
4730 (run-hooks 'erc-channel-members-changed-hook))))
4732 (defun erc-remove-channel-member (channel nick)
4733 "Remove NICK from CHANNEL's membership list.
4735 See also `erc-remove-current-channel-member'."
4738 (erc-remove-current-channel-member nick)))
4740 (defun erc-update-channel-topic (channel topic &optional modify)
4741 "Find a buffer for CHANNEL and set the TOPIC for it.
4743 If optional MODIFY is 'append or 'prepend, then append or prepend the
4744 TOPIC string to the current topic."
4745 (erc-with-buffer (channel)
4746 (cond ((eq modify 'append)
4747 (setq erc-channel-topic (concat erc-channel-topic topic)))
4748 ((eq modify 'prepend)
4749 (setq erc-channel-topic (concat topic erc-channel-topic)))
4750 (t (setq erc-channel-topic topic)))
4751 (erc-update-mode-line-buffer (current-buffer))))
4753 (defun erc-set-modes (tgt mode-string)
4754 "Set the modes for the TGT provided as MODE-STRING."
4755 (let* ((modes (erc-parse-modes mode-string))
4756 (add-modes (nth 0 modes))
4757 (remove-modes (nth 1 modes))
4758 ;; list of triples: (mode-char 'on/'off argument)
4759 (arg-modes (nth 2 modes)))
4760 (cond ((erc-channel-p tgt); channel modes
4761 (let ((buf (and erc-server-process
4762 (erc-get-buffer tgt erc-server-process))))
4764 (with-current-buffer buf
4765 (setq erc-channel-modes add-modes)
4766 (setq erc-channel-user-limit nil)
4767 (setq erc-channel-key nil)
4769 (let ((mode (nth 0 (car arg-modes)))
4770 (onoff (nth 1 (car arg-modes)))
4771 (arg (nth 2 (car arg-modes))))
4772 (cond ((string-match "^[Ll]" mode)
4773 (erc-update-channel-limit tgt onoff arg))
4774 ((string-match "^[Kk]" mode)
4775 (erc-update-channel-key tgt onoff arg))
4777 (setq arg-modes (cdr arg-modes)))
4778 (erc-update-mode-line-buffer buf)))))
4779 ;; we do not keep our nick's modes yet
4780 ;;(t (setq erc-user-modes add-modes))
4784 (defun erc-sort-strings (list-of-strings)
4785 "Sort LIST-OF-STRINGS in lexicographic order.
4788 (sort (copy-sequence list-of-strings) 'string<))
4790 (defun erc-parse-modes (mode-string)
4791 "Parse MODE-STRING into a list.
4793 Returns a list of three elements:
4795 (ADD-MODES REMOVE-MODES ARG-MODES).
4797 The add-modes and remove-modes are lists of single-character strings
4798 for modes without parameters to add and remove respectively. The
4799 arg-modes is a list of triples of the form:
4801 (MODE-CHAR ON/OFF ARGUMENT)."
4802 (if (string-match "^\\s-*\\(\\S-+\\)\\(\\s-.*$\\|$\\)" mode-string)
4803 (let ((chars (mapcar 'char-to-string (match-string 1 mode-string)))
4804 ;; arguments in channel modes
4805 (args-str (match-string 2 mode-string))
4809 (arg-modes nil); list of triples: (mode-char 'on/'off argument)
4811 ;; make the argument list
4812 (while (string-match "^\\s-*\\(\\S-+\\)\\(\\s-+.*$\\|$\\)" args-str)
4813 (setq args (cons (match-string 1 args-str) args))
4814 (setq args-str (match-string 2 args-str)))
4815 (setq args (nreverse args))
4816 ;; collect what modes changed, and match them with arguments
4818 (cond ((string= (car chars) "+") (setq add-p t))
4819 ((string= (car chars) "-") (setq add-p nil))
4820 ((string-match "^[ovbOVB]" (car chars))
4821 (setq arg-modes (cons (list (car chars)
4823 (if args (car args) nil))
4825 (if args (setq args (cdr args))))
4826 ((string-match "^[LlKk]" (car chars))
4827 (setq arg-modes (cons (list (car chars)
4829 (if (and add-p args)
4832 (if (and add-p args) (setq args (cdr args))))
4833 (add-p (setq add-modes (cons (car chars) add-modes)))
4834 (t (setq remove-modes (cons (car chars) remove-modes))))
4835 (setq chars (cdr chars)))
4836 (setq add-modes (nreverse add-modes))
4837 (setq remove-modes (nreverse remove-modes))
4838 (setq arg-modes (nreverse arg-modes))
4839 (list add-modes remove-modes arg-modes))
4842 (defun erc-update-modes (tgt mode-string &optional nick host login)
4843 "Update the mode information for TGT, provided as MODE-STRING.
4844 Optional arguments: NICK, HOST and LOGIN - the attributes of the
4845 person who changed the modes."
4846 (let* ((modes (erc-parse-modes mode-string))
4847 (add-modes (nth 0 modes))
4848 (remove-modes (nth 1 modes))
4849 ;; list of triples: (mode-char 'on/'off argument)
4850 (arg-modes (nth 2 modes)))
4851 ;; now parse the modes changes and do the updates
4852 (cond ((erc-channel-p tgt); channel modes
4853 (let ((buf (and erc-server-process
4854 (erc-get-buffer tgt erc-server-process))))
4856 ;; FIXME! This used to have an original buffer
4857 ;; variable, but it never switched back to the original
4858 ;; buffer. Is this wanted behavior?
4860 (if (not (boundp 'erc-channel-modes))
4861 (setq erc-channel-modes nil))
4863 (setq erc-channel-modes (delete (car remove-modes)
4865 remove-modes (cdr remove-modes)))
4867 (setq erc-channel-modes (cons (car add-modes)
4869 add-modes (cdr add-modes)))
4870 (setq erc-channel-modes (erc-sort-strings erc-channel-modes))
4872 (let ((mode (nth 0 (car arg-modes)))
4873 (onoff (nth 1 (car arg-modes)))
4874 (arg (nth 2 (car arg-modes))))
4875 (cond ((string-match "^[oO]" mode)
4876 (erc-update-channel-member tgt arg arg nil onoff))
4877 ((string-match "^[Vv]" mode)
4878 (erc-update-channel-member tgt arg arg nil nil
4880 ((string-match "^[Ll]" mode)
4881 (erc-update-channel-limit tgt onoff arg))
4882 ((string-match "^[Kk]" mode)
4883 (erc-update-channel-key tgt onoff arg))
4884 (t nil)); only ops are tracked now
4885 (setq arg-modes (cdr arg-modes))))
4886 (erc-update-mode-line buf))))
4887 ;; nick modes - ignored at this point
4890 (defun erc-update-channel-limit (channel onoff n)
4891 ;; FIXME: what does ONOFF actually do? -- Lawrence 2004-01-08
4892 "Update CHANNEL's user limit to N."
4893 (if (or (not (eq onoff 'on))
4894 (and (stringp n) (string-match "^[0-9]+$" n)))
4897 (cond ((eq onoff 'on) (setq erc-channel-user-limit (string-to-number n)))
4898 (t (setq erc-channel-user-limit nil))))))
4900 (defun erc-update-channel-key (channel onoff key)
4901 "Update CHANNEL's key to KEY if ONOFF is 'on or to nil if it's 'off."
4904 (cond ((eq onoff 'on) (setq erc-channel-key key))
4905 (t (setq erc-channel-key nil)))))
4907 (defun erc-handle-user-status-change (type nlh &optional l)
4908 "Handle changes in any user's status.
4910 So far, only nick change is handled.
4912 Generally, the TYPE argument is a symbol describing the change type, NLH is
4913 a list containing the original nickname, login name and hostname for the user,
4914 and L is a list containing additional TYPE-specific arguments.
4916 So far the following TYPE/L pairs are supported:
4920 nickname change 'nick (NEW-NICK)"
4921 (erc-log (format "user-change: type: %S nlh: %S l: %S" type nlh l))
4929 (defun erc-highlight-notice (s)
4930 "Highlight notice message S and return it.
4931 See also variable `erc-notice-highlight-type'."
4933 ((eq erc-notice-highlight-type 'prefix)
4934 (erc-put-text-property 0 (length erc-notice-prefix)
4935 'face 'erc-notice-face s)
4937 ((eq erc-notice-highlight-type 'all)
4938 (erc-put-text-property 0 (length s) 'face 'erc-notice-face s)
4942 (defun erc-make-notice (message)
4943 "Notify the user of MESSAGE."
4944 (when erc-minibuffer-notice
4945 (message "%s" message))
4946 (erc-highlight-notice (concat erc-notice-prefix message)))
4948 (defun erc-highlight-error (s)
4949 "Highlight error message S and return it."
4950 (erc-put-text-property 0 (length s) 'face 'erc-error-face s)
4953 (defun erc-put-text-property (start end property value &optional object)
4954 "Set text-property for an object (usually a string).
4955 START and END define the characters covered.
4956 PROPERTY is the text-property set, usually the symbol `face'.
4957 VALUE is the value for the text-property, usually a face symbol such as
4958 the face `bold' or `erc-pal-face'.
4959 OBJECT is a string which will be modified and returned.
4960 OBJECT is modified without being copied first.
4962 You can redefine or `defadvice' this function in order to add
4963 EmacsSpeak support."
4964 (put-text-property start end property value object))
4966 (defun erc-list (thing)
4967 "Return THING if THING is a list, or a list with THING as its element."
4972 (defun erc-parse-user (string)
4973 "Parse STRING as a user specification (nick!login@host).
4975 Return a list of the three separate tokens."
4977 ((string-match "^\\([^!\n]*\\)!\\([^@\n]*\\)@\\(.*\\)$" string)
4978 (list (match-string 1 string)
4979 (match-string 2 string)
4980 (match-string 3 string)))
4981 ;; Some bogus bouncers send Nick!(null), try to live with that.
4982 ((string-match "^\\([^!\n]*\\)!\\(.*\\)$" string)
4983 (list (match-string 1 string)
4985 (match-string 2 string)))
4987 (list string "" ""))))
4989 (defun erc-extract-nick (string)
4990 "Return the nick corresponding to a user specification STRING.
4992 See also `erc-parse-user'."
4993 (car (erc-parse-user string)))
4995 (defun erc-put-text-properties (start end properties
4996 &optional object value-list)
4997 "Set text-properties for OBJECT.
4999 START and END describe positions in OBJECT.
5000 If VALUE-LIST is nil, set each property in PROPERTIES to t, else set
5001 each property to the corresponding value in VALUE-LIST."
5003 (setq value-list (mapcar (lambda (x)
5006 (while (and properties value-list)
5007 (erc-put-text-property
5008 start end (pop properties) (pop value-list) object)))
5010 ;;; Input area handling:
5012 (defun erc-beg-of-input-line ()
5013 "Return the value of `point' at the beginning of the input line.
5015 Specifically, return the position of `erc-insert-marker'."
5016 (or (and (boundp 'erc-insert-marker)
5017 (markerp erc-insert-marker))
5018 (error "erc-insert-marker has no value, please report a bug"))
5019 (marker-position erc-insert-marker))
5021 (defun erc-end-of-input-line ()
5022 "Return the value of `point' at the end of the input line."
5025 (defun erc-send-current-line ()
5026 "Parse current line and send it to IRC."
5030 (if (< (point) (erc-beg-of-input-line))
5031 (erc-error "Point is not in the input area")
5032 (let ((inhibit-read-only t)
5033 (str (erc-user-input))
5034 (old-buf (current-buffer)))
5035 (if (and (not (erc-server-buffer-live-p))
5036 (not (erc-command-no-process-p str)))
5037 (erc-error "ERC: No process running")
5038 (erc-set-active-buffer (current-buffer))
5040 ;; Kill the input and the prompt
5041 (delete-region (erc-beg-of-input-line)
5042 (erc-end-of-input-line))
5045 (erc-send-input str)
5046 ;; Fix the buffer if the command didn't kill it
5047 (when (buffer-live-p old-buf)
5048 (with-current-buffer old-buf
5051 (goto-char (point-max))
5052 (when (processp erc-server-process)
5053 (set-marker (process-mark erc-server-process) (point)))
5054 (set-marker erc-insert-marker (point))
5055 (let ((buffer-modified (buffer-modified-p)))
5056 (erc-display-prompt)
5057 (set-buffer-modified-p buffer-modified))))))
5059 ;; Only when last hook has been run...
5060 (run-hook-with-args 'erc-send-completed-hook str))))))
5062 (defun erc-user-input ()
5063 "Return the input of the user in the current buffer."
5064 (buffer-substring-no-properties
5066 (erc-end-of-input-line)))
5068 (defvar erc-command-regexp "^/\\([A-Za-z']+\\)\\(\\s-+.*\\|\\s-*\\)$"
5069 "Regular expression used for matching commands in ERC.")
5071 (defun erc-send-input (input)
5072 "Treat INPUT as typed in by the user. It is assumed that the input
5073 and the prompt is already deleted.
5074 This returns non-nil only if we actually send anything."
5075 ;; Handle different kinds of inputs
5077 ;; Ignore empty input
5078 ((if erc-send-whitespace-lines
5080 (string-match "\\`[ \t\r\f\n]*\\'" input))
5081 (when erc-warn-about-blank-lines
5082 (message "Blank line - ignoring...")
5087 (erc-insert-this t))
5088 (setq erc-send-this t)
5089 (run-hook-with-args 'erc-send-pre-hook input)
5091 (if (or (string-match "\n" str)
5092 (not (string-match erc-command-regexp str)))
5097 ;; Insert what has to be inserted for this.
5098 (erc-display-msg line)
5099 (erc-process-input-line (concat line "\n")
5100 (null erc-flood-protect) t))
5101 (or (and erc-flood-protect (erc-split-line line))
5103 (split-string str "\n"))
5104 ;; Insert the prompt along with the command.
5105 (erc-display-command str)
5106 (erc-process-input-line (concat str "\n") t nil))
5109 (defun erc-display-command (line)
5110 (when erc-insert-this
5111 (let ((insert-position (point)))
5112 (unless erc-hide-prompt
5113 (erc-display-prompt nil nil (erc-command-indicator)
5114 (and (erc-command-indicator)
5115 'erc-command-indicator-face)))
5116 (let ((beg (point)))
5118 (erc-put-text-property beg (point)
5119 'face 'erc-command-indicator-face)
5121 (when (processp erc-server-process)
5122 (set-marker (process-mark erc-server-process) (point)))
5123 (set-marker erc-insert-marker (point))
5126 (narrow-to-region insert-position (point))
5127 (run-hooks 'erc-send-modify-hook)
5128 (run-hooks 'erc-send-post-hook))))))
5130 (defun erc-display-msg (line)
5131 "Display LINE as a message of the user to the current target at the
5133 (when erc-insert-this
5134 (let ((insert-position (point)))
5135 (insert (erc-format-my-nick))
5136 (let ((beg (point)))
5138 (erc-put-text-property beg (point)
5139 'face 'erc-input-face))
5141 (when (processp erc-server-process)
5142 (set-marker (process-mark erc-server-process) (point)))
5143 (set-marker erc-insert-marker (point))
5146 (narrow-to-region insert-position (point))
5147 (run-hooks 'erc-send-modify-hook)
5148 (run-hooks 'erc-send-post-hook))))))
5150 (defun erc-command-symbol (command)
5151 "Return the ERC command symbol for COMMAND if it exists and is bound."
5152 (let ((cmd (intern-soft (format "erc-cmd-%s" (upcase command)))))
5153 (when (fboundp cmd) cmd)))
5155 (defun erc-extract-command-from-line (line)
5156 "Extract command and args from the input LINE.
5157 If no command was given, return nil. If command matches, return a
5158 list of the form: (command args) where both elements are strings."
5159 (when (string-match erc-command-regexp line)
5160 (let* ((cmd (erc-command-symbol (match-string 1 line)))
5161 ;; note: return is nil, we apply this simply for side effects
5162 (canon-defun (while (and cmd (symbolp (symbol-function cmd)))
5163 (setq cmd (symbol-function cmd))))
5164 (cmd-fun (or cmd #'erc-cmd-default))
5166 (if (get cmd-fun 'do-not-parse-args)
5167 (format "%s" (match-string 2 line))
5168 (delete "" (split-string (erc-trim-string
5169 (match-string 2 line)) " ")))
5171 (list cmd-fun arg))))
5173 (defun erc-split-multiline-safe (string)
5174 "Split STRING, containing multiple lines and return them in a list.
5175 Do it only for STRING as the complete input, do not carry unfinished
5176 strings over to the next call."
5181 (let ((i (string-match "\r?\n" string i0))
5182 (s (substring string i0)))
5183 (cond (i (setq l (cons (substring string i0 i) l))
5184 (setq i0 (match-end 0)))
5186 (setq l (cons s l))(setq doit nil))
5187 (t (setq doit nil)))))
5192 (defun erc-set-current-nick (nick)
5193 "Set the current nickname to NICK."
5194 (with-current-buffer (if (buffer-live-p (erc-server-buffer))
5197 (setq erc-server-current-nick nick)))
5199 (defun erc-current-nick ()
5200 "Return the current nickname."
5201 (with-current-buffer (if (buffer-live-p (erc-server-buffer))
5204 erc-server-current-nick))
5206 (defun erc-current-nick-p (nick)
5207 "Return non-nil if NICK is the current nickname."
5208 (erc-nick-equal-p nick (erc-current-nick)))
5210 (defun erc-nick-equal-p (nick1 nick2)
5211 "Return non-nil if NICK1 and NICK2 are the same.
5213 This matches strings according to the IRC protocol's case convention.
5215 See also `erc-downcase'."
5216 (string= (erc-downcase nick1)
5217 (erc-downcase nick2)))
5219 ;; default target handling
5221 (defun erc-default-target ()
5222 "Return the current default target (as a character string) or nil if none."
5223 (let ((tgt (car erc-default-recipients)))
5226 ((listp tgt) (cdr tgt))
5229 (defun erc-add-default-channel (channel)
5230 "Add CHANNEL to the default channel list."
5232 (let ((d1 (car erc-default-recipients))
5233 (d2 (cdr erc-default-recipients))
5234 (chl (downcase channel)))
5235 (setq erc-default-recipients
5236 (cons chl erc-default-recipients))))
5238 (defun erc-delete-default-channel (channel &optional buffer)
5239 "Delete CHANNEL from the default channel list."
5240 (let ((ob (current-buffer)))
5241 (with-current-buffer (if (and buffer
5245 (setq erc-default-recipients (delete (downcase channel)
5246 erc-default-recipients)))))
5248 (defun erc-add-query (nickname)
5249 "Add QUERY'd NICKNAME to the default channel list.
5251 The previous default target of QUERY type gets removed."
5252 (let ((d1 (car erc-default-recipients))
5253 (d2 (cdr erc-default-recipients))
5254 (qt (cons 'QUERY (downcase nickname))))
5256 (eq (car d1) 'QUERY))
5257 (setq erc-default-recipients (cons qt d2))
5258 (setq erc-default-recipients (cons qt erc-default-recipients)))))
5260 (defun erc-delete-query ()
5261 "Delete the topmost target if it is a QUERY."
5263 (let ((d1 (car erc-default-recipients))
5264 (d2 (cdr erc-default-recipients)))
5266 (eq (car d1) 'QUERY))
5267 (setq erc-default-recipients d2)
5268 (error "Current target is not a QUERY"))))
5270 (defun erc-ignored-user-p (spec)
5271 "Return non-nil if SPEC matches something in `erc-ignore-list'.
5273 Takes a full SPEC of a user in the form \"nick!login@host\", and
5274 matches against all the regexp's in `erc-ignore-list'. If any
5275 match, returns that regexp."
5277 (dolist (ignored (erc-with-server-buffer erc-ignore-list))
5278 (if (string-match ignored spec)
5279 (throw 'found ignored)))))
5281 (defun erc-ignored-reply-p (msg tgt proc)
5282 ;; FIXME: this docstring needs fixing -- Lawrence 2004-01-08
5283 "Return non-nil if MSG matches something in `erc-ignore-reply-list'.
5285 Takes a message MSG to a channel and returns non-nil if the addressed
5286 user matches any regexp in `erc-ignore-reply-list'."
5287 (let ((target-nick (erc-message-target msg)))
5288 (if (not target-nick)
5290 (erc-with-buffer (tgt proc)
5291 (let ((user (erc-get-server-user target-nick)))
5293 (erc-list-match erc-ignore-reply-list
5294 (erc-user-spec user))))))))
5296 (defun erc-message-target (msg)
5297 "Return the addressed target in MSG.
5299 The addressed target is the string before the first colon in MSG."
5300 (if (string-match "^\\([^: \n]*\\):" msg)
5301 (match-string 1 msg)
5304 (defun erc-user-spec (user)
5305 "Create a nick!user@host spec from a user struct."
5306 (let ((nick (erc-server-user-nickname user))
5307 (host (erc-server-user-host user))
5308 (login (erc-server-user-login user)))
5321 (defun erc-list-match (lst str)
5322 "Return non-nil if any regexp in LST matches STR."
5323 (memq nil (mapcar (lambda (regexp)
5324 (not (string-match regexp str)))
5329 (defun erc-toggle-ctcp-autoresponse (&optional arg)
5330 "Toggle automatic CTCP replies (like VERSION and PING).
5332 If ARG is positive, turns CTCP replies on.
5334 If ARG is non-nil and not positive, turns CTCP replies off."
5336 (cond ((and (numberp arg) (> arg 0))
5337 (setq erc-disable-ctcp-replies t))
5338 (arg (setq erc-disable-ctcp-replies nil))
5339 (t (setq erc-disable-ctcp-replies (not erc-disable-ctcp-replies))))
5340 (message "ERC CTCP replies are %s" (if erc-disable-ctcp-replies "OFF" "ON")))
5342 (defun erc-toggle-flood-control (&optional arg)
5343 "Toggle use of flood control on sent messages.
5345 If ARG is positive, use flood control.
5346 If ARG is non-nil and not positive, do not use flood control.
5348 See `erc-server-flood-margin' for an explanation of the available
5349 flood control parameters."
5351 (cond ((and (numberp arg) (> arg 0))
5352 (setq erc-flood-protect t))
5353 (arg (setq erc-flood-protect nil))
5354 (t (setq erc-flood-protect (not erc-flood-protect))))
5355 (message "ERC flood control is %s"
5356 (cond (erc-flood-protect "ON")
5359 ;; Some useful channel and nick commands for fast key bindings
5361 (defun erc-invite-only-mode (&optional arg)
5362 "Turn on the invite only mode (+i) for the current channel.
5364 If ARG is non-nil, turn this mode off (-i).
5366 This command is sent even if excess flood is detected."
5368 (erc-set-active-buffer (current-buffer))
5369 (let ((tgt (erc-default-target))
5371 (cond ((or (not tgt) (not (erc-channel-p tgt)))
5372 (erc-display-message nil 'error (current-buffer) 'no-target))
5373 (arg (erc-load-irc-script-lines (list (concat "/mode " tgt " -i"))
5375 (t (erc-load-irc-script-lines (list (concat "/mode " tgt " +i"))
5378 (defun erc-get-channel-mode-from-keypress (key)
5379 "Read a key sequence and call the corresponding channel mode function.
5380 After doing C-c C-o, type in a channel mode letter.
5383 RET lets you type more than one mode at a time.
5384 If \"l\" is pressed, `erc-set-channel-limit' gets called.
5385 If \"k\" is pressed, `erc-set-channel-key' gets called.
5386 Anything else will be sent to `erc-toggle-channel-mode'."
5387 (interactive "kChannel mode (RET to set more than one): ")
5388 (when (featurep 'xemacs)
5389 (setq key (char-to-string (event-to-character (aref key 0)))))
5390 (cond ((equal key "\C-g")
5393 (erc-insert-mode-command))
5395 (call-interactively 'erc-set-channel-limit))
5397 (call-interactively 'erc-set-channel-key))
5398 (t (erc-toggle-channel-mode key))))
5400 (defun erc-toggle-channel-mode (mode &optional channel)
5401 "Toggle channel MODE.
5403 If CHANNEL is non-nil, toggle MODE for that channel, otherwise use
5404 `erc-default-target'."
5406 (erc-set-active-buffer (current-buffer))
5407 (let ((tgt (or channel (erc-default-target)))
5409 (cond ((or (null tgt) (null (erc-channel-p tgt)))
5410 (erc-display-message nil 'error 'active 'no-target))
5411 ((member mode erc-channel-modes)
5412 (erc-log (format "%s: Toggle mode %s OFF" tgt mode))
5413 (message "Toggle channel mode %s OFF" mode)
5414 (erc-server-send (format "MODE %s -%s" tgt mode)))
5415 (t (erc-log (format "%s: Toggle channel mode %s ON" tgt mode))
5416 (message "Toggle channel mode %s ON" mode)
5417 (erc-server-send (format "MODE %s +%s" tgt mode))))))
5419 (defun erc-insert-mode-command ()
5420 "Insert the line \"/mode <current target> \" at `point'."
5422 (let ((tgt (erc-default-target)))
5423 (if tgt (insert (concat "/mode " tgt " "))
5424 (erc-display-message nil 'error (current-buffer) 'no-target))))
5426 (defun erc-channel-names ()
5427 "Run \"/names #channel\" in the current channel."
5429 (erc-set-active-buffer (current-buffer))
5430 (let ((tgt (erc-default-target)))
5431 (if tgt (erc-load-irc-script-lines (list (concat "/names " tgt)))
5432 (erc-display-message nil 'error (current-buffer) 'no-target))))
5434 (defun erc-remove-text-properties-region (start end &optional object)
5435 "Clears the region (START,END) in OBJECT from all colors, etc."
5438 (let ((inhibit-read-only t))
5439 (set-text-properties start end nil object))))
5440 (put 'erc-remove-text-properties-region 'disabled t)
5442 ;; script execution and startup
5444 (defun erc-find-file (file &optional path)
5445 "Search for a FILE in the filesystem.
5446 First the `default-directory' is searched for FILE, then any directories
5447 specified in the list PATH.
5449 If FILE is found, return the path to it."
5450 (let ((filepath file))
5451 (if (file-readable-p filepath) filepath
5454 (progn (setq filepath (expand-file-name file (car path)))
5455 (not (file-readable-p filepath))))
5456 (setq path (cdr path)))
5457 (if path filepath nil)))))
5459 (defun erc-select-startup-file ()
5460 "Select an ERC startup file.
5461 See also `erc-startup-file-list'."
5463 (dolist (f erc-startup-file-list)
5464 (setq f (convert-standard-filename f))
5465 (when (file-readable-p f)
5466 (throw 'found f)))))
5468 (defun erc-find-script-file (file)
5469 "Search for FILE in `default-directory', and any in `erc-script-path'."
5470 (erc-find-file file erc-script-path))
5472 (defun erc-load-script (file)
5473 "Load a script from FILE.
5475 FILE must be the full name, it is not searched in the
5476 `erc-script-path'. If the filename ends with `.el', then load it
5477 as an Emacs Lisp program. Otherwise, treat it as a regular IRC
5479 (erc-log (concat "erc-load-script: " file))
5481 ((string-match "\\.el$" file)
5484 (erc-load-irc-script file))))
5486 (defun erc-process-script-line (line &optional args)
5487 "Process an IRC script LINE.
5489 Does script-specific substitutions (script arguments, current nick,
5490 server, etc.) in LINE and returns it.
5492 Substitutions are: %C and %c = current target (channel or nick),
5493 %S %s = current server, %N %n = my current nick, and %x is x verbatim,
5494 where x is any other character;
5495 $* = the entire argument string, $1 = the first argument, $2 = the second,
5497 (if (not args) (setq args ""))
5498 (let* ((arg-esc-regexp "\\(\\$\\(\\*\\|[1-9][0-9]*\\)\\)\\([^0-9]\\|$\\)")
5499 (percent-regexp "\\(%.\\)")
5500 (esc-regexp (concat arg-esc-regexp "\\|" percent-regexp))
5501 (tgt (erc-default-target))
5502 (server (and (boundp 'erc-session-server) erc-session-server))
5503 (nick (erc-current-nick))
5508 (if (not tgt) (setq tgt ""))
5509 (if (not server) (setq server ""))
5510 (if (not nick) (setq nick ""))
5511 ;; First, compute the argument list
5513 (while (string-match "^\\s-*\\(\\S-+\\)\\(\\s-+.*$\\|$\\)" tmp)
5514 (setq arg-list (cons (match-string 1 tmp) arg-list))
5515 (setq tmp (match-string 2 tmp)))
5516 (setq arg-list (nreverse arg-list))
5517 (setq arg-num (length arg-list))
5518 ;; now do the substitution
5519 (setq tmp (string-match esc-regexp line))
5521 ;;(message "beginning of while: tmp=%S" tmp)
5522 (let* ((hd (substring line 0 tmp))
5525 (tail (substring line tmp)))
5526 (cond ((string-match (concat "^" arg-esc-regexp) tail)
5527 (setq esc (match-string 1 tail))
5528 (setq tail (substring tail (match-end 1))))
5529 ((string-match (concat "^" percent-regexp) tail)
5530 (setq esc (match-string 1 tail))
5531 (setq tail (substring tail (match-end 1)))))
5532 ;;(message "hd=%S, esc=%S, tail=%S, arg-num=%S" hd esc tail arg-num)
5533 (setq res (concat res hd))
5535 (cond ((string= esc "") "")
5536 ((string-match "^\\$\\*$" esc) args)
5537 ((string-match "^\\$\\([0-9]+\\)$" esc)
5538 (let ((n (string-to-number (match-string 1 esc))))
5539 (message "n = %S, integerp(n)=%S" n (integerp n))
5540 (if (<= n arg-num) (nth (1- n) arg-list) "")))
5541 ((string-match "^%[Cc]$" esc) tgt)
5542 ((string-match "^%[Ss]$" esc) server)
5543 ((string-match "^%[Nn]$" esc) nick)
5544 ((string-match "^%\\(.\\)$" esc) (match-string 1 esc))
5545 (t (erc-log (format "BUG in erc-process-script-line: bad escape sequence: %S\n" esc))
5546 (message "BUG IN ERC: esc=%S" esc)
5549 (setq tmp (string-match esc-regexp line))
5550 (setq res (concat res subst))
5551 ;;(message "end of while: line=%S, res=%S, tmp=%S" line res tmp)
5553 (setq res (concat res line))
5556 (defun erc-load-irc-script (file &optional force)
5557 "Load an IRC script from FILE."
5558 (erc-log (concat "erc-load-script: " file))
5559 (let ((str (with-temp-buffer
5560 (insert-file-contents file)
5562 (erc-load-irc-script-lines (erc-split-multiline-safe str) force)))
5564 (defun erc-load-irc-script-lines (lines &optional force noexpand)
5565 "Load IRC script LINES (a list of strings).
5567 If optional NOEXPAND is non-nil, do not expand script-specific
5568 sequences, process the lines verbatim. Use this for multiline
5570 (let* ((cb (current-buffer))
5573 (sp (or (erc-command-indicator) (erc-prompt)))
5574 (args (and (boundp 'erc-script-args) erc-script-args)))
5575 (if (and args (string-match "^ " args))
5576 (setq args (substring args 1)))
5577 ;; prepare the prompt string for echo
5578 (erc-put-text-property 0 (length sp)
5579 'face 'erc-command-indicator-face sp)
5581 (setq s (car lines))
5582 (erc-log (concat "erc-load-script: CMD: " s))
5583 (unless (string-match "^\\s-*$" s)
5584 (let ((line (if noexpand s (erc-process-script-line s args))))
5585 (if (and (erc-process-input-line line force)
5588 (erc-put-text-property 0 (length line)
5589 'face 'erc-input-face line)
5590 (erc-display-line (concat sp line) cb)))))
5591 (setq lines (cdr lines)))))
5596 "Perform user authentication at the IRC server."
5597 (erc-log (format "login: nick: %s, user: %s %s %s :%s"
5600 (or erc-system-name (system-name))
5602 erc-session-user-full-name))
5603 (if erc-session-password
5604 (erc-server-send (format "PASS %s" erc-session-password))
5605 (message "Logging in without password"))
5606 (erc-server-send (format "NICK %s" (erc-current-nick)))
5608 (format "USER %s %s %s :%s"
5610 (if erc-anonymous-login erc-email-userid (user-login-name))
5612 erc-session-user-full-name))
5613 (erc-update-mode-line))
5615 ;; connection properties' heuristics
5617 (defun erc-determine-parameters (&optional server port nick name)
5618 "Determine the connection and authentication parameters.
5619 Sets the buffer local variables:
5621 - `erc-session-connector'
5622 - `erc-session-server'
5623 - `erc-session-port'
5624 - `erc-session-full-name'
5625 - `erc-server-current-nick'"
5626 (setq erc-session-connector erc-server-connect-function
5627 erc-session-server (erc-compute-server server)
5628 erc-session-port (or port erc-default-port)
5629 erc-session-user-full-name (erc-compute-full-name name))
5630 (erc-set-current-nick (erc-compute-nick nick)))
5632 (defun erc-compute-server (&optional server)
5633 "Return an IRC server name.
5635 This tries a number of increasingly more default methods until a
5636 non-nil value is found.
5638 - SERVER (the argument passed to this function)
5639 - The `erc-server' option
5640 - The value of the IRCSERVER environment variable
5641 - The `erc-default-server' variable"
5644 (getenv "IRCSERVER")
5645 erc-default-server))
5647 (defun erc-compute-nick (&optional nick)
5648 "Return user's IRC nick.
5650 This tries a number of increasingly more default methods until a
5651 non-nil value is found.
5653 - NICK (the argument passed to this function)
5654 - The `erc-nick' option
5655 - The value of the IRCNICK environment variable
5656 - The result from the `user-login-name' function"
5658 (if (consp erc-nick) (car erc-nick) erc-nick)
5663 (defun erc-compute-full-name (&optional full-name)
5664 "Return user's full name.
5666 This tries a number of increasingly more default methods until a
5667 non-nil value is found.
5669 - FULL-NAME (the argument passed to this function)
5670 - The `erc-user-full-name' option
5671 - The value of the IRCNAME environment variable
5672 - The result from the `user-full-name' function"
5676 (if erc-anonymous-login "unknown" nil)
5679 (defun erc-compute-port (&optional port)
5680 "Return a port for an IRC server.
5682 This tries a number of increasingly more default methods until a
5683 non-nil value is found.
5685 - PORT (the argument passed to this function)
5686 - The `erc-port' option
5687 - The `erc-default-port' variable"
5688 (or port erc-port erc-default-port))
5692 (defun erc-string-to-emacs-time (string)
5693 "Convert the long number represented by STRING into an Emacs format.
5694 Returns a list of the form (HIGH LOW), compatible with Emacs time format."
5695 (let* ((n (string-to-number (concat string ".0"))))
5696 (list (truncate (/ n 65536))
5697 (truncate (mod n 65536)))))
5699 (defun erc-emacs-time-to-erc-time (time)
5700 "Convert Emacs TIME to a number of seconds since the epoch."
5702 (+ (* (nth 0 time) 65536.0) (nth 1 time))))
5703 ; (round (+ (* (nth 0 tm) 65536.0) (nth 1 tm))))
5705 (defun erc-current-time ()
5706 "Return the `current-time' as a number of seconds since the epoch.
5708 See also `erc-emacs-time-to-erc-time'."
5709 (erc-emacs-time-to-erc-time (current-time)))
5711 (defun erc-time-diff (t1 t2)
5712 "Return the time difference in seconds between T1 and T2."
5715 (defun erc-time-gt (t1 t2)
5716 "Check whether T1 > T2."
5719 (defun erc-sec-to-time (ns)
5720 "Convert NS to a time string HH:MM.SS."
5721 (setq ns (truncate ns))
5722 (format "%02d:%02d.%02d"
5727 (defun erc-seconds-to-string (seconds)
5728 "Convert a number of SECONDS into an English phrase."
5729 (let (days hours minutes format-args output)
5730 (setq days (/ seconds 86400)
5731 seconds (% seconds 86400)
5732 hours (/ seconds 3600)
5733 seconds (% seconds 3600)
5734 minutes (/ seconds 60)
5735 seconds (% seconds 60)
5736 format-args (if (> days 0)
5737 `("%d days, %d hours, %d minutes, %d seconds"
5738 ,days ,hours ,minutes ,seconds)
5740 `("%d hours, %d minutes, %d seconds"
5741 ,hours ,minutes ,seconds)
5743 `("%d minutes, %d seconds" ,minutes ,seconds)
5744 `("%d seconds" ,seconds))))
5745 output (apply 'format format-args))
5746 ;; Change all "1 units" to "1 unit".
5747 (while (string-match "\\([^0-9]\\|^\\)1 \\S-+\\(s\\)" output)
5748 (setq output (erc-replace-match-subexpression-in-string
5749 "" output (match-string 2 output) 2 (match-beginning 2))))
5755 (defconst erc-clientinfo-alist
5756 '(("ACTION" . "is used to inform about one's current activity")
5757 ("CLIENTINFO" . "gives help on CTCP commands supported by client")
5758 ("ECHO" . "echoes its arguments back")
5759 ("FINGER" . "shows user's name, location, and idle time")
5760 ("PING" . "measures delay between peers")
5761 ("TIME" . "shows client-side time")
5762 ("USERINFO" . "shows information provided by a user")
5763 ("VERSION" . "shows client type and version"))
5764 "Alist of CTCP CLIENTINFO for ERC commands.")
5766 (defun erc-client-info (s)
5767 "Return CTCP CLIENTINFO on command S.
5768 If S is nil or an empty string then return general CLIENTINFO."
5769 (if (or (not s) (string= s ""))
5773 (concat (car e) " "))
5774 erc-clientinfo-alist))
5775 ": use CLIENTINFO <COMMAND> to get more specific information")
5776 (let ((h (assoc (upcase s) erc-clientinfo-alist)))
5778 (concat s " " (cdr h))
5779 (concat s ": unknown command")))))
5783 (defun erc-directory-writable-p (dir)
5784 "Determine whether DIR is a writable directory.
5785 If it doesn't exist, create it."
5786 (unless (file-attributes dir) (make-directory dir))
5787 (or (file-accessible-directory-p dir) (error "Cannot access %s" dir)))
5789 (defun erc-kill-query-buffers (process)
5790 "Kill all buffers of PROCESS."
5791 ;; here, we only want to match the channel buffers, to avoid
5792 ;; "selecting killed buffers" b0rkage.
5793 (erc-with-all-buffers-of-server process
5795 (not (erc-server-buffer-p)))
5796 (kill-buffer (current-buffer))))
5798 (defun erc-nick-at-point ()
5799 "Give information about the nickname at `point'.
5801 If called interactively, give a human readable message in the
5802 minibuffer. If called programmatically, return the corresponding
5803 entry of `channel-members'."
5805 (require 'thingatpt)
5806 (let* ((word (word-at-point))
5807 (channel-data (erc-get-channel-user word))
5808 (cuser (cdr channel-data))
5809 (user (if channel-data
5811 (erc-get-server-user word)))
5812 host login full-name info nick op voice)
5814 (setq nick (erc-server-user-nickname user)
5815 host (erc-server-user-host user)
5816 login (erc-server-user-login user)
5817 full-name (erc-server-user-full-name user)
5818 info (erc-server-user-info user))
5820 (setq op (erc-channel-user-op cuser)
5821 voice (erc-channel-user-voice cuser)))
5823 (message "%s is %s@%s%s%s"
5825 (if full-name (format " (%s)" full-name) "")
5827 (format " and is +%s%s on %s"
5830 (erc-default-target))
5834 (defun erc-away-time ()
5835 "Return non-nil if the current ERC process is set away.
5837 In particular, the time that we were set away is returned.
5838 See `current-time' for details on the time format."
5839 (erc-with-server-buffer erc-away))
5841 ;; Mode line handling
5843 (defcustom erc-mode-line-format "%S %a"
5844 "A string to be formatted and shown in the mode-line in `erc-mode'.
5846 The string is formatted using `format-spec' and the result is set as the value
5847 of `mode-line-buffer-identification'.
5849 The following characters are replaced:
5850 %a: String indicating away status or \"\" if you are not away
5851 %l: The estimated lag time to the server
5852 %m: The modes of the channel
5853 %n: The current nick name
5854 %N: The name of the network
5855 %o: The topic of the channel
5856 %p: The session port
5857 %t: The name of the target (channel, nickname, or servername:port)
5858 %s: In the server-buffer, this gets filled with the value of
5859 `erc-server-announced-name', in a channel, the value of
5860 (erc-default-target) also get concatenated.
5861 %S: In the server-buffer, this gets filled with the value of
5862 `erc-network', in a channel, the value of (erc-default-target)
5863 also get concatenated."
5864 :group 'erc-mode-line-and-header
5867 (defcustom erc-header-line-format "%n on %t (%m,%l) %o"
5868 "A string to be formatted and shown in the header-line in `erc-mode'.
5869 Only used starting in Emacs 21.
5871 Set this to nil if you do not want the header line to be
5874 See `erc-mode-line-format' for which characters are can be used."
5875 :group 'erc-mode-line-and-header
5876 :set (lambda (sym val)
5878 (when (fboundp 'erc-update-mode-line)
5879 (erc-update-mode-line nil)))
5880 :type '(choice (const :tag "Disabled" nil)
5883 (defcustom erc-header-line-uses-tabbar-p nil
5884 "Use tabbar mode instead of the header line to display the header."
5885 :group 'erc-mode-line-and-header
5888 (defcustom erc-header-line-uses-help-echo-p t
5889 "Show the contents of the header line in the echo area or as a tooltip
5890 when you move point into the header line."
5891 :group 'erc-mode-line-and-header
5894 (defcustom erc-header-line-face-method nil
5895 "Determine what method to use when colorizing the header line text.
5897 If nil, don't colorize the header text.
5898 If given a function, call it and use the resulting face name.
5899 Otherwise, use the `erc-header-line' face."
5900 :group 'erc-mode-line-and-header
5901 :type '(choice (const :tag "Don't colorize" nil)
5902 (const :tag "Use the erc-header-line face" t)
5903 (function :tag "Call a function")))
5905 (defcustom erc-show-channel-key-p t
5906 "Show the channel key in the header line."
5907 :group 'erc-paranoia
5910 (defcustom erc-common-server-suffixes
5911 '(("openprojects.net$" . "OPN")
5912 ("freenode.net$" . "freenode")
5913 ("oftc.net$" . "OFTC"))
5914 "Alist of common server name suffixes.
5915 This variable is used in mode-line display to save screen
5916 real estate. Set it to nil if you want to avoid changing
5917 displayed hostnames."
5918 :group 'erc-mode-line-and-header
5921 (defcustom erc-mode-line-away-status-format
5922 "(AWAY since %a %b %d %H:%M) "
5923 "When you're away on a server, this is shown in the mode line.
5924 This should be a string with substitution variables recognized by
5925 `format-time-string'."
5926 :group 'erc-mode-line-and-header
5929 (defun erc-shorten-server-name (server-name)
5930 "Shorten SERVER-NAME according to `erc-common-server-suffixes'."
5931 (if (stringp server-name)
5933 (insert server-name)
5934 (let ((alist erc-common-server-suffixes))
5936 (goto-char (point-min))
5937 (if (re-search-forward (caar alist) nil t)
5938 (replace-match (cdar alist)))
5939 (setq alist (cdr alist))))
5942 (defun erc-format-target ()
5943 "Return the name of the target (channel or nickname or servername:port)."
5944 (let ((target (erc-default-target)))
5946 (concat (erc-shorten-server-name
5947 (or erc-server-announced-name
5948 erc-session-server))
5949 ":" (erc-port-to-string erc-session-port)))))
5951 (defun erc-format-target-and/or-server ()
5952 "Return the server name or the current target and server name combined."
5953 (let ((server-name (erc-shorten-server-name
5954 (or erc-server-announced-name
5955 erc-session-server))))
5956 (cond ((erc-default-target)
5957 (concat (erc-string-no-properties (erc-default-target))
5959 (server-name server-name)
5960 (t (buffer-name (current-buffer))))))
5962 (defun erc-format-network ()
5963 "Return the name of the network we are currently on."
5964 (let ((network (and (fboundp 'erc-network-name) (erc-network-name))))
5965 (if (and network (symbolp network))
5966 (symbol-name network)
5969 (defun erc-format-target-and/or-network ()
5970 "Return the network or the current target and network combined.
5971 If the name of the network is not available, then use the
5972 shortened server name instead."
5973 (let ((network-name (or (and (fboundp 'erc-network-name) (erc-network-name))
5974 (erc-shorten-server-name
5975 (or erc-server-announced-name
5976 erc-session-server)))))
5977 (when (and network-name (symbolp network-name))
5978 (setq network-name (symbol-name network-name)))
5979 (cond ((erc-default-target)
5980 (concat (erc-string-no-properties (erc-default-target))
5982 (network-name network-name)
5983 (t (buffer-name (current-buffer))))))
5985 (defun erc-format-away-status ()
5986 "Return a formatted `erc-mode-line-away-status-format'
5987 if `erc-away' is non-nil."
5988 (let ((a (erc-away-time)))
5990 (format-time-string erc-mode-line-away-status-format a)
5993 (defun erc-format-channel-modes ()
5994 "Return the current channel's modes."
5995 (concat (apply 'concat
5996 "+" erc-channel-modes)
5997 (cond ((and erc-channel-user-limit erc-channel-key)
5998 (if erc-show-channel-key-p
5999 (format "lk %.0f %s" erc-channel-user-limit
6001 (format "kl %.0f" erc-channel-user-limit)))
6002 (erc-channel-user-limit
6003 ;; Emacs has no bignums
6004 (format "l %.0f" erc-channel-user-limit))
6006 (if erc-show-channel-key-p
6007 (format "k %s" erc-channel-key)
6011 (defun erc-format-lag-time ()
6012 "Return the estimated lag time to server, `erc-server-lag'."
6013 (let ((lag (erc-with-server-buffer erc-server-lag)))
6014 (cond (lag (format "lag:%.0f" lag))
6017 ;; erc-goodies is required at end of this file.
6018 (declare-function erc-controls-strip "erc-goodies" (str))
6020 (defvar tabbar--local-hlf)
6022 (defun erc-update-mode-line-buffer (buffer)
6023 "Update the mode line in a single ERC buffer BUFFER."
6024 (with-current-buffer buffer
6025 (let ((spec (format-spec-make
6026 ?a (erc-format-away-status)
6027 ?l (erc-format-lag-time)
6028 ?m (erc-format-channel-modes)
6029 ?n (or (erc-current-nick) "")
6030 ?N (erc-format-network)
6031 ?o (erc-controls-strip erc-channel-topic)
6032 ?p (erc-port-to-string erc-session-port)
6033 ?s (erc-format-target-and/or-server)
6034 ?S (erc-format-target-and/or-network)
6035 ?t (erc-format-target)))
6036 (process-status (cond ((and (erc-server-process-alive)
6037 (not erc-server-connected))
6039 ((erc-server-process-alive)
6043 (face (cond ((eq erc-header-line-face-method nil)
6045 ((functionp erc-header-line-face-method)
6046 (funcall erc-header-line-face-method))
6048 'erc-header-line))))
6049 (cond ((featurep 'xemacs)
6050 (setq modeline-buffer-identification
6051 (list (format-spec erc-mode-line-format spec)))
6052 (setq modeline-process (list process-status)))
6054 (setq mode-line-buffer-identification
6055 (list (format-spec erc-mode-line-format spec)))
6056 (setq mode-line-process (list process-status))))
6057 (when (boundp 'header-line-format)
6058 (let ((header (if erc-header-line-format
6059 (format-spec erc-header-line-format spec)
6061 (cond (erc-header-line-uses-tabbar-p
6062 (set (make-local-variable 'tabbar--local-hlf)
6064 (kill-local-variable 'header-line-format))
6066 (setq header-line-format nil))
6067 (erc-header-line-uses-help-echo-p
6068 (let ((help-echo (with-temp-buffer
6070 (fill-region (point-min) (point-max))
6072 (setq header-line-format
6073 (erc-replace-regexp-in-string
6077 (erc-propertize header 'help-echo help-echo
6079 (erc-propertize header 'help-echo help-echo))))))
6080 (t (setq header-line-format
6082 (erc-propertize header 'face face)
6084 (if (featurep 'xemacs)
6086 (force-mode-line-update))))
6088 (defun erc-update-mode-line (&optional buffer)
6089 "Update the mode line in BUFFER.
6091 If BUFFER is nil, update the mode line in all ERC buffers."
6092 (if (and buffer (bufferp buffer))
6093 (erc-update-mode-line-buffer buffer)
6094 (dolist (buf (erc-buffer-list))
6095 (when (buffer-live-p buf)
6096 (erc-update-mode-line-buffer buf)))))
6100 (defun erc-port-to-string (p)
6101 "Convert port P to a string.
6102 P may be an integer or a service name."
6107 (defun erc-string-to-port (s)
6108 "Convert string S to either an integer port number or a service name."
6111 (let ((n (string-to-number s)))
6116 (defun erc-version (&optional here)
6117 "Show the version number of ERC in the minibuffer.
6118 If optional argument HERE is non-nil, insert version number at point."
6120 (let ((version-string
6121 (format "ERC %s (GNU Emacs %s)" erc-version-string emacs-version)))
6123 (insert version-string)
6125 (message "%s" version-string)
6128 (defun erc-modes (&optional here)
6129 "Show the active ERC modes in the minibuffer.
6130 If optional argument HERE is non-nil, insert version number at point."
6133 (mapconcat 'identity
6134 (let (modes (case-fold-search nil))
6135 (dolist (var (apropos-internal "^erc-.*mode$"))
6136 (when (and (boundp var)
6138 (setq modes (cons (symbol-name var)
6145 (message "%s" string)
6148 (defun erc-trim-string (s)
6149 "Trim leading and trailing spaces off S."
6151 ((not (stringp s)) nil)
6152 ((string-match "^\\s-*$" s)
6154 ((string-match "^\\s-*\\(.*\\S-\\)\\s-*$" s)
6159 (defun erc-arrange-session-in-multiple-windows ()
6160 "Open a window for every non-server buffer related to `erc-session-server'.
6162 All windows are opened in the current frame."
6164 (unless erc-server-process
6165 (error "No erc-server-process found in current buffer"))
6166 (let ((bufs (erc-buffer-list nil erc-server-process)))
6168 (delete-other-windows)
6169 (switch-to-buffer (car bufs))
6170 (setq bufs (cdr bufs))
6174 (switch-to-buffer (car bufs))
6175 (setq bufs (cdr bufs))
6176 (balance-windows)))))
6178 (defun erc-popup-input-buffer ()
6179 "Provide an input buffer."
6181 (let ((buffer-name (generate-new-buffer-name "*ERC input*"))
6186 (list (symbol-name e)))
6187 (apropos-internal "-mode$" 'commandp))
6189 (pop-to-buffer (make-indirect-buffer (current-buffer) buffer-name))
6191 (narrow-to-region (point) (point))
6192 (shrink-window-if-larger-than-buffer)))
6196 (defun erc-make-message-variable-name (catalog entry)
6197 "Create a variable name corresponding to CATALOG's ENTRY."
6198 (intern (concat "erc-message-"
6199 (symbol-name catalog) "-" (symbol-name entry))))
6201 (defun erc-define-catalog-entry (catalog entry format-spec)
6202 "Set CATALOG's ENTRY to FORMAT-SPEC."
6203 (set (erc-make-message-variable-name catalog entry)
6206 (defun erc-define-catalog (catalog entries)
6207 "Define a CATALOG according to ENTRIES."
6208 (dolist (entry entries)
6209 (erc-define-catalog-entry catalog (car entry) (cdr entry))))
6213 '((bad-ping-response . "Unexpected PING response from %n (time %t)")
6214 (bad-syntax . "Error occurred - incorrect usage?\n%c %u\n%d")
6215 (incorrect-args . "Incorrect arguments. Usage:\n%c %u\n%d")
6216 (cannot-find-file . "Cannot find file %f")
6217 (cannot-read-file . "Cannot read file %f")
6218 (connect . "Connecting to %S:%p... ")
6220 (country-unknown . "%d: No such domain")
6221 (ctcp-empty . "Illegal empty CTCP query received from %n. Ignoring.")
6222 (ctcp-request . "==> CTCP request from %n (%u@%h): %r")
6223 (ctcp-request-to . "==> CTCP request from %n (%u@%h) to %t: %r")
6224 (ctcp-too-many . "Too many CTCP queries in single message. Ignoring")
6225 (flood-ctcp-off . "FLOOD PROTECTION: Automatic CTCP responses turned off.")
6227 . "FLOOD PROTECTION: Switched to Strict Flood Control mode.")
6228 (disconnected . "\n\nConnection failed! Re-establishing connection...\n")
6229 (disconnected-noreconnect
6230 . "\n\nConnection failed! Not re-establishing connection.\n")
6231 (finished . "\n\n*** ERC finished ***\n")
6232 (terminated . "\n\n*** ERC terminated: %e\n")
6233 (login . "Logging in as \'%n\'...")
6234 (nick-in-use . "%n is in use. Choose new nickname: ")
6236 . "WARNING: Nick length (%i) exceeds max NICKLEN(%l) defined by server")
6237 (no-default-channel . "No default channel")
6238 (no-invitation . "You've got no invitation")
6239 (no-target . "No target")
6240 (ops . "%i operator%s: %o")
6241 (ops-none . "No operators in this channel.")
6242 (undefined-ctcp . "Undefined CTCP query received. Silently ignored")
6243 (variable-not-bound . "Variable not bound!")
6244 (ACTION . "* %n %a")
6245 (CTCP-CLIENTINFO . "Client info for %n: %m")
6246 (CTCP-ECHO . "Echo %n: %m")
6247 (CTCP-FINGER . "Finger info for %n: %m")
6248 (CTCP-PING . "Ping time to %n is %t")
6249 (CTCP-TIME . "Time by %n is %m")
6250 (CTCP-UNKNOWN . "Unknown CTCP message from %n (%u@%h): %m")
6251 (CTCP-VERSION . "Version for %n is %m")
6252 (ERROR . "==> ERROR from %s: %c\n")
6253 (INVITE . "%n (%u@%h) invites you to channel %c")
6254 (JOIN . "%n (%u@%h) has joined channel %c")
6255 (JOIN-you . "You have joined channel %c")
6256 (KICK . "%n (%u@%h) has kicked %k off channel %c: %r")
6257 (KICK-you . "You have been kicked off channel %c by %n (%u@%h): %r")
6258 (KICK-by-you . "You have kicked %k off channel %c: %r")
6259 (MODE . "%n (%u@%h) has changed mode for %t to %m")
6260 (MODE-nick . "%n has changed mode for %t to %m")
6261 (NICK . "%n (%u@%h) is now known as %N")
6262 (NICK-you . "Your new nickname is %N")
6263 (PART . erc-message-english-PART)
6264 (PING . "PING from server (last: %s sec. ago)")
6265 (PONG . "PONG from %h (%i second%s)")
6266 (QUIT . "%n (%u@%h) has quit: %r")
6267 (TOPIC . "%n (%u@%h) has set the topic for %c: \"%T\"")
6268 (WALLOPS . "Wallops from %n: %m")
6269 (s004 . "%s %v %U %C")
6270 (s221 . "User modes for %n: %m")
6271 (s252 . "%i operator(s) online")
6272 (s253 . "%i unknown connection(s)")
6273 (s254 . "%i channels formed")
6275 (s301 . "%n is AWAY: %r")
6276 (s303 . "Is online: %n")
6280 (s311 . "%n is %f (%u@%h)")
6281 (s312 . "%n is/was on server %s (%c)")
6282 (s313 . "%n is an IRC operator")
6283 (s314 . "%n was %f (%u@%h)")
6284 (s317 . "%n has been idle for %i")
6285 (s317-on-since . "%n has been idle for %i, on since %t")
6286 (s319 . "%n is on channel(s): %c")
6287 (s320 . "%n is an identified user")
6288 (s321 . "Channel Users Topic")
6289 (s322 . "%c [%u] %t")
6290 (s324 . "%c modes: %m")
6291 (s328 . "%c URL: %u")
6292 (s329 . "%c was created on %t")
6294 (s331 . "No topic is set for %c")
6295 (s332 . "Topic for %c: %T")
6296 (s333 . "%c: topic set by %n, %t")
6297 (s341 . "Inviting %n to channel %c")
6298 (s352 . "%-11c %-10n %-4a %u@%h (%f)")
6299 (s353 . "Users on %c: %u")
6300 (s367 . "Ban for %b on %c")
6301 (s367-set-by . "Ban for %b on %c set by %s on %t")
6302 (s368 . "Banlist of %c ends.")
6303 (s379 . "%c: Forwarded to %f")
6304 (s391 . "The time at %s is %t")
6305 (s401 . "%n: No such nick/channel")
6306 (s403 . "%c: No such channel")
6307 (s404 . "%c: Cannot send to channel")
6308 (s405 . "%c: You have joined too many channels")
6309 (s406 . "%n: There was no such nickname")
6310 (s412 . "No text to send")
6311 (s421 . "%c: Unknown command")
6312 (s431 . "No nickname given")
6313 (s432 . "%n is an erroneous nickname")
6314 (s442 . "%c: You're not on that channel")
6315 (s445 . "SUMMON has been disabled")
6316 (s446 . "USERS has been disabled")
6317 (s451 . "You have not registered")
6318 (s461 . "%c: not enough parameters")
6319 (s462 . "Unauthorized command (already registered)")
6320 (s463 . "Your host isn't among the privileged")
6321 (s464 . "Password incorrect")
6322 (s465 . "You are banned from this server")
6323 (s474 . "You can't join %c because you're banned (+b)")
6324 (s475 . "You must specify the correct channel key (+k) to join %c")
6325 (s481 . "Permission Denied - You're not an IRC operator")
6326 (s482 . "You need to be a channel operator of %c to do that")
6327 (s483 . "You can't kill a server!")
6328 (s484 . "Your connection is restricted!")
6329 (s485 . "You're not the original channel operator")
6330 (s491 . "No O-lines for your host")
6331 (s501 . "Unknown MODE flag")
6332 (s502 . "You can't change modes for other users")
6335 (defun erc-message-english-PART (&rest args)
6336 "Format a proper PART message.
6338 This function is an example on what could be done with formatting
6340 (let ((nick (cadr (memq ?n args)))
6341 (user (cadr (memq ?u args)))
6342 (host (cadr (memq ?h args)))
6343 (channel (cadr (memq ?c args)))
6344 (reason (cadr (memq ?r args))))
6345 (if (string= nick (erc-current-nick))
6346 (format "You have left channel %s" channel)
6347 (format "%s (%s@%s) has left channel %s%s"
6348 nick user host channel
6349 (if (not (string= reason ""))
6351 (erc-replace-regexp-in-string "%" "%%" reason))
6355 (defvar erc-current-message-catalog 'english)
6356 (make-variable-buffer-local 'erc-current-message-catalog)
6358 (defun erc-retrieve-catalog-entry (entry &optional catalog)
6359 "Retrieve ENTRY from CATALOG.
6361 If CATALOG is nil, `erc-current-message-catalog' is used.
6363 If ENTRY is nil in CATALOG, it is retrieved from the fallback,
6365 (unless catalog (setq catalog erc-current-message-catalog))
6366 (let ((var (erc-make-message-variable-name catalog entry)))
6369 (when (boundp (erc-make-message-variable-name 'english entry))
6370 (symbol-value (erc-make-message-variable-name 'english entry))))))
6372 (defun erc-format-message (msg &rest args)
6373 "Format MSG according to ARGS.
6375 See also `format-spec'."
6376 (when (eq (logand (length args) 1) 1) ; oddp
6377 (error "Obscure usage of this function appeared"))
6378 (let ((entry (erc-retrieve-catalog-entry msg)))
6380 (error "No format spec for message %s" msg))
6381 (when (functionp entry)
6382 (setq entry (apply entry args)))
6383 (format-spec entry (apply 'format-spec-make args))))
6385 ;;; Various hook functions
6387 (add-hook 'kill-buffer-hook 'erc-kill-buffer-function)
6389 (defcustom erc-kill-server-hook '(erc-kill-server)
6390 "Invoked whenever a server-buffer is killed via `kill-buffer'."
6394 (defcustom erc-kill-channel-hook '(erc-kill-channel)
6395 "Invoked whenever a channel-buffer is killed via `kill-buffer'."
6399 (defcustom erc-kill-buffer-hook nil
6400 "Hook run whenever a non-server or channel buffer is killed.
6402 See also `kill-buffer'."
6406 (defun erc-kill-buffer-function ()
6407 "Function to call when an ERC buffer is killed.
6408 This function should be on `kill-buffer-hook'.
6409 When the current buffer is in `erc-mode', this function will run
6410 one of the following hooks:
6411 `erc-kill-server-hook' if the server buffer was killed,
6412 `erc-kill-channel-hook' if a channel buffer was killed,
6413 or `erc-kill-buffer-hook' if any other buffer."
6414 (when (eq major-mode 'erc-mode)
6415 (erc-remove-channel-users)
6417 ((eq (erc-server-buffer) (current-buffer))
6418 (run-hooks 'erc-kill-server-hook))
6419 ((erc-channel-p (erc-default-target))
6420 (run-hooks 'erc-kill-channel-hook))
6422 (run-hooks 'erc-kill-buffer-hook)))))
6424 (defun erc-kill-server ()
6425 "Sends a QUIT command to the server when the server buffer is killed.
6426 This function should be on `erc-kill-server-hook'."
6427 (when (erc-server-process-alive)
6428 (setq erc-server-quitting t)
6429 (erc-server-send (format "QUIT :%s" (funcall erc-quit-reason nil)))))
6431 (defun erc-kill-channel ()
6432 "Sends a PART command to the server when the channel buffer is killed.
6433 This function should be on `erc-kill-channel-hook'."
6434 (when (erc-server-process-alive)
6435 (let ((tgt (erc-default-target)))
6436 (erc-server-send (format "PART %s :%s" tgt
6437 (funcall erc-part-reason nil))
6440 ;;; Dealing with `erc-parsed'
6442 (defun erc-find-parsed-property ()
6443 "Find the next occurrence of the `erc-parsed' text property."
6444 (text-property-not-all (point-min) (point-max) 'erc-parsed nil))
6446 (defun erc-restore-text-properties ()
6447 "Restore the property 'erc-parsed for the region."
6448 (let ((parsed-posn (erc-find-parsed-property)))
6450 (point-min) (point-max)
6451 'erc-parsed (when parsed-posn (erc-get-parsed-vector parsed-posn)))))
6453 (defun erc-get-parsed-vector (point)
6454 "Return the whole parsed vector on POINT."
6455 (get-text-property point 'erc-parsed))
6457 (defun erc-get-parsed-vector-nick (vect)
6458 "Return nickname in the parsed vector VECT."
6459 (let* ((untreated-nick (and vect (erc-response.sender vect)))
6460 (maybe-nick (when untreated-nick
6461 (car (split-string untreated-nick "!")))))
6462 (when (and (not (null maybe-nick))
6463 (erc-is-valid-nick-p maybe-nick))
6466 (defun erc-get-parsed-vector-type (vect)
6467 "Return message type in the parsed vector VECT."
6469 (erc-response.command vect)))
6471 ;; Teach url.el how to open irc:// URLs with ERC.
6472 ;; To activate, customize `url-irc-function' to `url-irc-erc'.
6475 (defun erc-handle-irc-url (host port channel user password)
6476 "Use ERC to IRC on HOST:PORT in CHANNEL as USER with PASSWORD.
6477 If ERC is already connected to HOST:PORT, simply /join CHANNEL.
6478 Otherwise, connect to HOST:PORT as USER and /join CHANNEL."
6479 (let ((server-buffer
6480 (car (erc-buffer-filter
6482 (and (string-equal erc-session-server host)
6483 (= erc-session-port port)
6484 (erc-open-server-buffer-p)))))))
6485 (with-current-buffer (or server-buffer (current-buffer))
6486 (if (and server-buffer channel)
6487 (erc-cmd-JOIN channel)
6488 (erc-open host port (or user (erc-compute-nick)) (erc-compute-full-name)
6489 (not server-buffer) password nil channel
6491 (get-buffer-process server-buffer)))))))
6495 ;;; Deprecated. We might eventually stop requiring the goodies automatically.
6496 ;;; IMPORTANT: This require must appear _after_ the above (provide 'erc) to
6497 ;;; avoid a recursive require error when byte-compiling the entire package.
6498 (require 'erc-goodies)
6500 ;;; erc.el ends here
6503 ;; outline-regexp: ";;+"
6504 ;; indent-tabs-mode: t