1 ;; erc.el --- An Emacs Internet Relay Chat client
3 ;; Copyright (C) 1997-2013 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)
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-lib
))
74 (require 'auth-source
)
77 (defvar erc-official-location
78 "http://emacswiki.org/cgi-bin/wiki/ERC (mailing list: erc-discuss@gnu.org)"
79 "Location of the ERC client on the Internet.")
82 "Emacs Internet Relay Chat client."
83 :link
'(url-link "http://www.emacswiki.org/cgi-bin/wiki/ERC")
87 (defgroup erc-buffers nil
88 "Creating new ERC buffers"
91 (defgroup erc-display nil
92 "Settings for how various things are displayed"
95 (defgroup erc-mode-line-and-header nil
96 "Displaying information in the mode-line and header"
99 (defgroup erc-ignore nil
100 "Ignoring certain messages"
103 (defgroup erc-lurker nil
104 "Hide specified message types sent by lurkers"
108 (defgroup erc-query nil
109 "Using separate buffers for private discussions"
112 (defgroup erc-quit-and-part nil
113 "Quitting and parting channels"
116 (defgroup erc-paranoia nil
117 "Know what is sent and received; control the display of sensitive data."
120 (defgroup erc-scripts nil
121 "Running scripts at startup and with /LOAD"
124 (require 'erc-backend
)
126 ;; compatibility with older ERC releases
128 (if (fboundp 'defvaralias
)
130 (defvaralias 'erc-announced-server-name
'erc-server-announced-name
)
131 (erc-make-obsolete-variable 'erc-announced-server-name
132 'erc-server-announced-name
134 (defvaralias 'erc-process
'erc-server-process
)
135 (erc-make-obsolete-variable 'erc-process
'erc-server-process
"ERC 5.1")
136 (defvaralias 'erc-default-coding-system
'erc-server-coding-system
)
137 (erc-make-obsolete-variable 'erc-default-coding-system
138 'erc-server-coding-system
140 (message (concat "ERC: The function `defvaralias' is not bound. See the "
141 "NEWS file for variable name changes since ERC 5.0.4.")))
143 (define-obsolete-function-alias 'erc-send-command
144 'erc-server-send
"ERC 5.1")
146 ;; tunable connection and authentication parameters
148 (defcustom erc-server nil
149 "IRC server to use if one is not provided.
150 See function `erc-compute-server' for more details on connection
151 parameters and authentication."
153 :type
'(choice (const :tag
"None" nil
)
154 (string :tag
"Server")))
156 (defcustom erc-port nil
157 "IRC port to use if not specified.
159 This can be either a string or a number."
161 :type
'(choice (const :tag
"None" nil
)
162 (integer :tag
"Port number")
163 (string :tag
"Port string")))
165 (defcustom erc-nick nil
166 "Nickname to use if one is not provided.
168 This can be either a string, or a list of strings.
169 In the latter case, if the first nick in the list is already in use,
170 other nicks are tried in the list order.
172 See function `erc-compute-nick' for more details on connection
173 parameters and authentication."
175 :type
'(choice (const :tag
"None" nil
)
176 (string :tag
"Nickname")
177 (repeat (string :tag
"Nickname"))))
179 (defcustom erc-nick-uniquifier
"`"
180 "The string to append to the nick if it is already in use."
184 (defcustom erc-try-new-nick-p t
185 "If the nickname you chose isn't available, and this option is non-nil,
186 ERC should automatically attempt to connect with another nickname.
188 You can manually set another nickname with the /NICK command."
192 (defcustom erc-user-full-name nil
195 This can be either a string or a function to call.
197 See function `erc-compute-full-name' for more details on connection
198 parameters and authentication."
200 :type
'(choice (const :tag
"No name" nil
)
202 (function :tag
"Get from function"))
203 :set
(lambda (sym val
)
205 (set sym
(funcall val
))
208 (defvar erc-password nil
209 "Password to use when authenticating to an IRC server.
210 It is not strictly necessary to provide this, since ERC will
213 (defcustom erc-user-mode nil
214 "Initial user modes to be set after a connection is established."
216 :type
'(choice (const nil
) string function
))
219 (defcustom erc-prompt-for-password t
220 "Asks before using the default password, or whether to enter a new one."
224 (defcustom erc-warn-about-blank-lines t
225 "Warn the user if they attempt to send a blank line."
229 (defcustom erc-send-whitespace-lines nil
230 "If set to non-nil, send lines consisting of only whitespace."
234 (defcustom erc-hide-prompt nil
235 "If non-nil, do not display the prompt for commands.
237 \(A command is any input starting with a '/').
239 See also the variables `erc-prompt' and `erc-command-indicator'."
245 (defcustom erc-show-my-nick t
246 "If non-nil, display one's own nickname when sending a message.
248 If non-nil, \"<nickname>\" will be shown.
249 If nil, only \"> \" will be shown."
253 (define-widget 'erc-message-type
'set
254 "A set of standard IRC Message types."
255 :args
'((const "JOIN")
261 (repeat :inline t
:tag
"Others" (string :tag
"IRC Message Type"))))
263 (defcustom erc-hide-list nil
264 "List of IRC type messages to hide.
265 A typical value would be '(\"JOIN\" \"PART\" \"QUIT\")."
267 :type
'erc-message-type
)
269 (defvar erc-session-password nil
270 "The password used for the current session.")
271 (make-variable-buffer-local 'erc-session-password
)
273 (defcustom erc-disconnected-hook nil
274 "Run this hook with arguments (NICK IP REASON) when disconnected.
275 This happens before automatic reconnection. Note, that
276 `erc-server-QUIT-functions' might not be run when we disconnect,
277 simply because we do not necessarily receive the QUIT event."
281 (defcustom erc-complete-functions nil
282 "These functions get called when the user hits TAB in ERC.
283 Each function in turn is called until one returns non-nil to
284 indicate it has handled the input."
288 (defcustom erc-join-hook nil
289 "Hook run when we join a channel. Hook functions are called
290 without arguments, with the current buffer set to the buffer of
293 See also `erc-server-JOIN-functions', `erc-part-hook'."
297 (defcustom erc-quit-hook nil
298 "Hook run when processing a quit command directed at our nick.
300 The hook receives one argument, the current PROCESS.
301 See also `erc-server-QUIT-functions' and `erc-disconnected-hook'."
305 (defcustom erc-part-hook nil
306 "Hook run when processing a PART message directed at our nick.
308 The hook receives one argument, the current BUFFER.
309 See also `erc-server-QUIT-functions', `erc-quit-hook' and
310 `erc-disconnected-hook'."
314 (defcustom erc-kick-hook nil
315 "Hook run when processing a KICK message directed at our nick.
317 The hook receives one argument, the current BUFFER.
318 See also `erc-server-PART-functions' and `erc-part-hook'."
322 (defcustom erc-nick-changed-functions nil
323 "List of functions run when your nick was successfully changed.
325 Each function should accept two arguments, NEW-NICK and OLD-NICK."
329 (defcustom erc-connect-pre-hook
'(erc-initialize-log-marker)
330 "Hook called just before `erc' calls `erc-connect'.
331 Functions are passed a buffer as the first argument."
336 (defvar erc-channel-users nil
337 "A hash table of members in the current channel, which
338 associates nicknames with cons cells of the form:
339 \(USER . MEMBER-DATA) where USER is a pointer to an
340 erc-server-user struct, and MEMBER-DATA is a pointer to an
341 erc-channel-user struct.")
342 (make-variable-buffer-local 'erc-channel-users
)
344 (defvar erc-server-users nil
345 "A hash table of users on the current server, which associates
346 nicknames with erc-server-user struct instances.")
347 (make-variable-buffer-local 'erc-server-users
)
349 (defun erc-downcase (string)
350 "Convert STRING to IRC standard conforming downcase."
351 (let ((s (downcase string
))
357 (while (string-match "[]\\[~]" s
)
358 (aset s
(match-beginning 0)
359 (cdr (assq (aref s
(match-beginning 0)) c
)))))
362 (defmacro erc-with-server-buffer
(&rest body
)
363 "Execute BODY in the current ERC server buffer.
364 If no server buffer exists, return nil."
365 (declare (indent 0) (debug (body)))
366 (let ((buffer (make-symbol "buffer")))
367 `(let ((,buffer
(erc-server-buffer)))
368 (when (buffer-live-p ,buffer
)
369 (with-current-buffer ,buffer
372 (cl-defstruct (erc-server-user (:type vector
) :named
)
374 nickname host login full-name info
377 ;; This is an alist of the form (BUFFER . CHANNEL-DATA), where
378 ;; CHANNEL-DATA is either nil or an erc-channel-user struct.
382 (cl-defstruct (erc-channel-user (:type vector
) :named
)
384 ;; Last message time (in the form of the return value of
387 ;; This is useful for ordered name completion.
388 (last-message-time nil
))
390 (defsubst erc-get-channel-user
(nick)
391 "Finds the (USER . CHANNEL-DATA) element corresponding to NICK
392 in the current buffer's `erc-channel-users' hash table."
393 (gethash (erc-downcase nick
) erc-channel-users
))
395 (defsubst erc-get-server-user
(nick)
396 "Finds the USER corresponding to NICK in the current server's
397 `erc-server-users' hash table."
398 (erc-with-server-buffer
399 (gethash (erc-downcase nick
) erc-server-users
)))
401 (defsubst erc-add-server-user
(nick user
)
402 "This function is for internal use only.
404 Adds USER with nickname NICK to the `erc-server-users' hash table."
405 (erc-with-server-buffer
406 (puthash (erc-downcase nick
) user erc-server-users
)))
408 (defsubst erc-remove-server-user
(nick)
409 "This function is for internal use only.
411 Removes the user with nickname NICK from the `erc-server-users'
412 hash table. This user is not removed from the
413 `erc-channel-users' lists of other buffers.
415 See also: `erc-remove-user'."
416 (erc-with-server-buffer
417 (remhash (erc-downcase nick
) erc-server-users
)))
419 (defun erc-change-user-nickname (user new-nick
)
420 "This function is for internal use only.
422 Changes the nickname of USER to NEW-NICK in the
423 `erc-server-users' hash table. The `erc-channel-users' lists of
424 other buffers are also changed."
425 (let ((nick (erc-server-user-nickname user
)))
426 (setf (erc-server-user-nickname user
) new-nick
)
427 (erc-with-server-buffer
428 (remhash (erc-downcase nick
) erc-server-users
)
429 (puthash (erc-downcase new-nick
) user erc-server-users
))
430 (dolist (buf (erc-server-user-buffers user
))
431 (if (buffer-live-p buf
)
432 (with-current-buffer buf
433 (let ((cdata (erc-get-channel-user nick
)))
434 (remhash (erc-downcase nick
) erc-channel-users
)
435 (puthash (erc-downcase new-nick
) cdata
436 erc-channel-users
)))))))
438 (defun erc-remove-channel-user (nick)
439 "This function is for internal use only.
441 Removes the user with nickname NICK from the `erc-channel-users'
442 list for this channel. If this user is not in the
443 `erc-channel-users' list of any other buffers, the user is also
444 removed from the server's `erc-server-users' list.
446 See also: `erc-remove-server-user' and `erc-remove-user'."
447 (let ((channel-data (erc-get-channel-user nick
)))
449 (let ((user (car channel-data
)))
450 (setf (erc-server-user-buffers user
)
451 (delq (current-buffer)
452 (erc-server-user-buffers user
)))
453 (remhash (erc-downcase nick
) erc-channel-users
)
454 (if (null (erc-server-user-buffers user
))
455 (erc-remove-server-user nick
))))))
457 (defun erc-remove-user (nick)
458 "This function is for internal use only.
460 Removes the user with nickname NICK from the `erc-server-users'
461 list as well as from all `erc-channel-users' lists.
463 See also: `erc-remove-server-user' and
464 `erc-remove-channel-user'."
465 (let ((user (erc-get-server-user nick
)))
467 (let ((buffers (erc-server-user-buffers user
)))
468 (dolist (buf buffers
)
469 (if (buffer-live-p buf
)
470 (with-current-buffer buf
471 (remhash (erc-downcase nick
) erc-channel-users
)
472 (run-hooks 'erc-channel-members-changed-hook
)))))
473 (erc-remove-server-user nick
))))
475 (defun erc-remove-channel-users ()
476 "This function is for internal use only.
478 Removes all users in the current channel. This is called by
479 `erc-server-PART' and `erc-server-QUIT'."
480 (when (and erc-server-connected
481 (erc-server-process-alive)
482 (hash-table-p erc-channel-users
))
483 (maphash (lambda (nick cdata
)
484 (erc-remove-channel-user nick
))
486 (clrhash erc-channel-users
)))
488 (defsubst erc-channel-user-op-p
(nick)
489 "Return t if NICK is an operator in the current channel."
491 (hash-table-p erc-channel-users
)
492 (let ((cdata (erc-get-channel-user nick
)))
493 (and cdata
(cdr cdata
)
494 (erc-channel-user-op (cdr cdata
))))))
496 (defsubst erc-channel-user-voice-p
(nick)
497 "Return t if NICK has voice in the current channel."
499 (hash-table-p erc-channel-users
)
500 (let ((cdata (erc-get-channel-user nick
)))
501 (and cdata
(cdr cdata
)
502 (erc-channel-user-voice (cdr cdata
))))))
504 (defun erc-get-channel-user-list ()
505 "Returns a list of users in the current channel. Each element
506 of the list is of the form (USER . CHANNEL-DATA), where USER is
507 an erc-server-user struct, and CHANNEL-DATA is either `nil' or an
508 erc-channel-user struct.
510 See also: `erc-sort-channel-users-by-activity'"
512 (if (hash-table-p erc-channel-users
)
513 (maphash (lambda (nick cdata
)
514 (setq users
(cons cdata users
)))
518 (defun erc-get-server-nickname-list ()
519 "Returns a list of known nicknames on the current server."
520 (erc-with-server-buffer
522 (when (hash-table-p erc-server-users
)
523 (maphash (lambda (n user
)
525 (cons (erc-server-user-nickname user
)
530 (defun erc-get-channel-nickname-list ()
531 "Returns a list of known nicknames on the current channel."
533 (when (hash-table-p erc-channel-users
)
534 (maphash (lambda (n cdata
)
536 (cons (erc-server-user-nickname (car cdata
))
541 (defun erc-get-server-nickname-alist ()
542 "Returns an alist of known nicknames on the current server."
543 (erc-with-server-buffer
545 (when (hash-table-p erc-server-users
)
546 (maphash (lambda (n user
)
548 (cons (cons (erc-server-user-nickname user
) nil
)
553 (defun erc-get-channel-nickname-alist ()
554 "Returns an alist of known nicknames on the current channel."
556 (when (hash-table-p erc-channel-users
)
557 (maphash (lambda (n cdata
)
559 (cons (cons (erc-server-user-nickname (car cdata
)) nil
)
564 (defun erc-sort-channel-users-by-activity (list)
565 "Sorts LIST such that users which have spoken most recently are
566 listed first. LIST must be of the form (USER . CHANNEL-DATA).
568 See also: `erc-get-channel-user-list'."
573 (let ((tx (erc-channel-user-last-message-time (cdr x
)))
574 (ty (erc-channel-user-last-message-time (cdr y
))))
581 (defun erc-sort-channel-users-alphabetically (list)
582 "Sort LIST so that users' nicknames are in alphabetical order.
583 LIST must be of the form (USER . CHANNEL-DATA).
585 See also: `erc-get-channel-user-list'."
590 (let ((nickx (downcase (erc-server-user-nickname (car x
))))
591 (nicky (downcase (erc-server-user-nickname (car y
)))))
594 (string-lessp nickx nicky
)
598 (defvar erc-channel-topic nil
599 "A topic string for the channel. Should only be used in channel-buffers.")
600 (make-variable-buffer-local 'erc-channel-topic
)
602 (defvar erc-channel-modes nil
603 "List of strings representing channel modes.
604 E.g. '(\"i\" \"m\" \"s\" \"b Quake!*@*\")
605 \(not sure the ban list will be here, but why not)")
606 (make-variable-buffer-local 'erc-channel-modes
)
608 (defvar erc-insert-marker nil
609 "The place where insertion of new text in erc buffers should happen.")
610 (make-variable-buffer-local 'erc-insert-marker
)
612 (defvar erc-input-marker nil
613 "The marker where input should be inserted.")
614 (make-variable-buffer-local 'erc-input-marker
)
616 (defun erc-string-no-properties (string)
617 "Return a copy of STRING will all text-properties removed."
618 (let ((newstring (copy-sequence string
)))
619 (set-text-properties 0 (length newstring
) nil newstring
)
622 (defcustom erc-prompt
"ERC>"
623 "Prompt used by ERC. Trailing whitespace is not required."
625 :type
'(choice string function
))
628 "Return the input prompt as a string.
630 See also the variable `erc-prompt'."
631 (let ((prompt (if (functionp erc-prompt
)
634 (if (> (length prompt
) 0)
638 (defcustom erc-command-indicator nil
639 "Indicator used by ERC for showing commands.
641 If non-nil, this will be used in the ERC buffer to indicate
642 commands (i.e., input starting with a '/').
644 If nil, the prompt will be constructed from the variable `erc-prompt'."
646 :type
'(choice (const nil
) string function
))
648 (defun erc-command-indicator ()
649 "Return the command indicator prompt as a string.
651 This only has any meaning if the variable `erc-command-indicator' is non-nil."
652 (and erc-command-indicator
653 (let ((prompt (if (functionp erc-command-indicator
)
654 (funcall erc-command-indicator
)
655 erc-command-indicator
)))
656 (if (> (length prompt
) 0)
660 (defcustom erc-notice-prefix
"*** "
661 "Prefix for all notices."
665 (defcustom erc-notice-highlight-type
'all
666 "Determines how to highlight notices.
667 See `erc-notice-prefix'.
669 The following values are allowed:
671 'prefix - highlight notice prefix only
672 'all - highlight the entire notice
674 Any other value disables notice's highlighting altogether."
676 :type
'(choice (const :tag
"highlight notice prefix only" prefix
)
677 (const :tag
"highlight the entire notice" all
)
678 (const :tag
"don't highlight notices at all" nil
)))
680 (defcustom erc-echo-notice-hook nil
681 "Specifies a list of functions to call to echo a private
682 notice. Each function is called with four arguments, the string
683 to display, the parsed server message, the target buffer (or
684 nil), and the sender. The functions are called in order, until a
685 function evaluates to non-nil. These hooks are called after
686 those specified in `erc-echo-notice-always-hook'.
688 See also: `erc-echo-notice-always-hook',
689 `erc-echo-notice-in-default-buffer',
690 `erc-echo-notice-in-target-buffer',
691 `erc-echo-notice-in-minibuffer',
692 `erc-echo-notice-in-server-buffer',
693 `erc-echo-notice-in-active-non-server-buffer',
694 `erc-echo-notice-in-active-buffer',
695 `erc-echo-notice-in-user-buffers',
696 `erc-echo-notice-in-user-and-target-buffers',
697 `erc-echo-notice-in-first-user-buffer'"
700 :options
'(erc-echo-notice-in-default-buffer
701 erc-echo-notice-in-target-buffer
702 erc-echo-notice-in-minibuffer
703 erc-echo-notice-in-server-buffer
704 erc-echo-notice-in-active-non-server-buffer
705 erc-echo-notice-in-active-buffer
706 erc-echo-notice-in-user-buffers
707 erc-echo-notice-in-user-and-target-buffers
708 erc-echo-notice-in-first-user-buffer
))
710 (defcustom erc-echo-notice-always-hook
711 '(erc-echo-notice-in-default-buffer)
712 "Specifies a list of functions to call to echo a private
713 notice. Each function is called with four arguments, the string
714 to display, the parsed server message, the target buffer (or
715 nil), and the sender. The functions are called in order, and all
716 functions are called. These hooks are called before those
717 specified in `erc-echo-notice-hook'.
719 See also: `erc-echo-notice-hook',
720 `erc-echo-notice-in-default-buffer',
721 `erc-echo-notice-in-target-buffer',
722 `erc-echo-notice-in-minibuffer',
723 `erc-echo-notice-in-server-buffer',
724 `erc-echo-notice-in-active-non-server-buffer',
725 `erc-echo-notice-in-active-buffer',
726 `erc-echo-notice-in-user-buffers',
727 `erc-echo-notice-in-user-and-target-buffers',
728 `erc-echo-notice-in-first-user-buffer'"
731 :options
'(erc-echo-notice-in-default-buffer
732 erc-echo-notice-in-target-buffer
733 erc-echo-notice-in-minibuffer
734 erc-echo-notice-in-server-buffer
735 erc-echo-notice-in-active-non-server-buffer
736 erc-echo-notice-in-active-buffer
737 erc-echo-notice-in-user-buffers
738 erc-echo-notice-in-user-and-target-buffers
739 erc-echo-notice-in-first-user-buffer
))
741 ;; other tunable parameters
743 (defcustom erc-whowas-on-nosuchnick nil
744 "If non-nil, do a whowas on a nick if no such nick."
748 (defcustom erc-verbose-server-ping nil
749 "If non-nil, show every time you get a PING or PONG from the server."
753 (defcustom erc-public-away-p nil
754 "Let others know you are back when you are no longer marked away.
755 This happens in this form:
756 * <nick> is back (gone for <time>)
758 Many consider it impolite to do so automatically."
762 (defcustom erc-away-nickname nil
763 "The nickname to take when you are marked as being away."
765 :type
'(choice (const nil
)
768 (defcustom erc-paranoid nil
769 "If non-nil, then all incoming CTCP requests will be shown."
773 (defcustom erc-disable-ctcp-replies nil
774 "Disable replies to CTCP requests that require a reply.
775 If non-nil, then all incoming CTCP requests that normally require
776 an automatic reply (like VERSION or PING) will be ignored. Good to
777 set if some hacker is trying to flood you away."
781 (defcustom erc-anonymous-login t
782 "Be paranoid, don't give away your machine name."
786 (defcustom erc-prompt-for-channel-key nil
787 "Prompt for channel key when using `erc-join-channel' interactively."
791 (defcustom erc-email-userid
"user"
792 "Use this as your email user ID."
796 (defcustom erc-system-name nil
797 "Use this as the name of your system.
798 If nil, ERC will call `system-name' to get this information."
800 :type
'(choice (const :tag
"Default system name" nil
)
803 (defcustom erc-ignore-list nil
804 "List of regexps matching user identifiers to ignore.
806 A user identifier has the form \"nick!login@host\". If an
807 identifier matches, the message from the person will not be
810 :type
'(repeat regexp
))
811 (make-variable-buffer-local 'erc-ignore-list
)
813 (defcustom erc-ignore-reply-list nil
814 "List of regexps matching user identifiers to ignore completely.
816 This differs from `erc-ignore-list' in that it also ignores any
817 messages directed at the user.
819 A user identifier has the form \"nick!login@host\".
821 If an identifier matches, or a message is addressed to a nick
822 whose identifier matches, the message will not be processed.
824 CAVEAT: ERC doesn't know about the user and host of anyone who
825 was already in the channel when you joined, but never said
826 anything, so it won't be able to match the user and host of those
827 people. You can update the ERC internal info using /WHO *."
829 :type
'(repeat regexp
))
831 (defvar erc-flood-protect t
832 "If non-nil, flood protection is enabled.
833 Flooding is sending too much information to the server in too
834 short of an interval, which may cause the server to terminate the
837 See `erc-server-flood-margin' for other flood-related parameters.")
841 (defcustom erc-startup-file-list
842 (list (concat erc-user-emacs-directory
".ercrc.el")
843 (concat erc-user-emacs-directory
".ercrc")
844 "~/.ercrc.el" "~/.ercrc" ".ercrc.el" ".ercrc")
845 "List of files to try for a startup script.
846 The first existent and readable one will get executed.
848 If the filename ends with `.el' it is presumed to be an Emacs Lisp
849 script and it gets (load)ed. Otherwise it is treated as a bunch of
850 regular IRC commands."
852 :type
'(repeat file
))
854 (defcustom erc-script-path nil
855 "List of directories to look for a script in /load command.
856 The script is first searched in the current directory, then in each
857 directory in the list."
859 :type
'(repeat directory
))
861 (defcustom erc-script-echo t
862 "If non-nil, echo the IRC script commands locally."
866 (defvar erc-last-saved-position nil
867 "A marker containing the position the current buffer was last saved at.")
868 (make-variable-buffer-local 'erc-last-saved-position
)
870 (defcustom erc-kill-buffer-on-part nil
871 "Kill the channel buffer on PART.
872 This variable should probably stay nil, as ERC can reuse buffers if
873 you rejoin them later."
874 :group
'erc-quit-and-part
877 (defcustom erc-kill-queries-on-quit nil
878 "Kill all query (also channel) buffers of this server on QUIT.
879 See the variable `erc-kill-buffer-on-part' for details."
880 :group
'erc-quit-and-part
883 (defcustom erc-kill-server-buffer-on-quit nil
884 "Kill the server buffer of the process on QUIT."
885 :group
'erc-quit-and-part
888 (defcustom erc-quit-reason-various-alist nil
889 "Alist of possible arguments to the /quit command.
891 Each element has the form:
894 If REGEXP matches the argument to /quit, then its relevant RESULT
895 will be used. RESULT may be either a string, or a function. If
896 a function, it should return the quit message as a string.
898 If no elements match, then the empty string is used.
901 (setq erc-quit-reason-various-alist
902 '((\"xmms\" dme:now-playing)
903 (\"version\" erc-quit-reason-normal)
904 (\"home\" \"Gone home !\")
905 (\"^$\" \"Default Reason\")))
906 If the user types \"/quit home\", then \"Gone home !\" will be used
907 as the quit message."
908 :group
'erc-quit-and-part
909 :type
'(repeat (list regexp
(choice (string) (function)))))
911 (defcustom erc-part-reason-various-alist nil
912 "Alist of possible arguments to the /part command.
914 Each element has the form:
917 If REGEXP matches the argument to /part, then its relevant RESULT
918 will be used. RESULT may be either a string, or a function. If
919 a function, it should return the part message as a string.
921 If no elements match, then the empty string is used.
924 (setq erc-part-reason-various-alist
925 '((\"xmms\" dme:now-playing)
926 (\"version\" erc-part-reason-normal)
927 (\"home\" \"Gone home !\")
928 (\"^$\" \"Default Reason\")))
929 If the user types \"/part home\", then \"Gone home !\" will be used
930 as the part message."
931 :group
'erc-quit-and-part
932 :type
'(repeat (list regexp
(choice (string) (function)))))
934 (defcustom erc-quit-reason
'erc-quit-reason-normal
935 "A function which returns the reason for quitting.
937 The function is passed a single argument, the string typed by the
938 user after \"/quit\"."
939 :group
'erc-quit-and-part
940 :type
'(choice (const erc-quit-reason-normal
)
941 (const erc-quit-reason-various
)
944 (defcustom erc-part-reason
'erc-part-reason-normal
945 "A function which returns the reason for parting a channel.
947 The function is passed a single argument, the string typed by the
948 user after \"/PART\"."
949 :group
'erc-quit-and-part
950 :type
'(choice (const erc-part-reason-normal
)
951 (const erc-part-reason-various
)
954 (defvar erc-grab-buffer-name
"*erc-grab*"
955 "The name of the buffer created by `erc-grab-region'.")
957 ;; variables available for IRC scripts
959 (defvar erc-user-information
"ERC User"
960 "USER_INFORMATION IRC variable.")
964 (defgroup erc-hooks nil
965 "Hook variables for fancy customizations of ERC."
968 (defcustom erc-mode-hook nil
969 "Hook run after `erc-mode' setup is finished."
972 :options
'(erc-add-scroll-to-bottom))
974 (defcustom erc-timer-hook nil
975 "Put functions which should get called more or less periodically here.
976 The idea is that servers always play ping pong with the client, and so there
977 is no need for any idle-timer games with Emacs."
981 (defcustom erc-insert-pre-hook nil
982 "Hook called first when some text is inserted through `erc-display-line'.
983 It gets called with one argument, STRING.
984 To be able to modify the inserted text, use `erc-insert-modify-hook' instead.
985 Filtering functions can set `erc-insert-this' to nil to avoid
986 display of that particular string at all."
990 (defcustom erc-send-pre-hook nil
991 "Hook called first when some text is sent through `erc-send-current-line'.
992 It gets called with one argument, STRING.
994 To change the text that will be sent, set the variable STR which is
995 used in `erc-send-current-line'.
997 To change the text inserted into the buffer without changing the text
998 that will be sent, use `erc-send-modify-hook' instead.
1000 Filtering functions can set `erc-send-this' to nil to avoid sending of
1001 that particular string at all and `erc-insert-this' to prevent
1002 inserting that particular string into the buffer.
1004 Note that it's useless to set `erc-send-this' to nil and
1005 `erc-insert-this' to t. ERC is sane enough to not insert the text
1010 (defvar erc-insert-this t
1011 "Insert the text into the target buffer or not.
1012 Functions on `erc-insert-pre-hook' can set this variable to nil
1013 if they wish to avoid insertion of a particular string.")
1015 (defvar erc-send-this t
1016 "Send the text to the target or not.
1017 Functions on `erc-send-pre-hook' can set this variable to nil
1018 if they wish to avoid sending of a particular string.")
1020 (defcustom erc-insert-modify-hook
()
1021 "Insertion hook for functions that will change the text's appearance.
1022 This hook is called just after `erc-insert-pre-hook' when the value
1023 of `erc-insert-this' is t.
1024 While this hook is run, narrowing is in effect and `current-buffer' is
1025 the buffer where the text got inserted. One possible value to add here
1030 (defcustom erc-insert-post-hook nil
1031 "This hook is called just after `erc-insert-modify-hook'.
1032 At this point, all modifications from prior hook functions are done."
1035 :options
'(erc-truncate-buffer
1037 erc-save-buffer-in-logs
))
1039 (defcustom erc-send-modify-hook nil
1040 "Sending hook for functions that will change the text's appearance.
1041 This hook is called just after `erc-send-pre-hook' when the values
1042 of `erc-send-this' and `erc-insert-this' are both t.
1043 While this hook is run, narrowing is in effect and `current-buffer' is
1044 the buffer where the text got inserted.
1046 Note that no function in this hook can change the appearance of the
1047 text that is sent. Only changing the sent text's appearance on the
1048 sending user's screen is possible. One possible value to add here
1053 (defcustom erc-send-post-hook nil
1054 "This hook is called just after `erc-send-modify-hook'.
1055 At this point, all modifications from prior hook functions are done.
1056 NOTE: The functions on this hook are called _before_ sending a command
1059 This function is called with narrowing, ala `erc-send-modify-hook'."
1062 :options
'(erc-make-read-only))
1064 (defcustom erc-send-completed-hook
1065 (when (featurep 'emacspeak
)
1068 (emacspeak-auditory-icon 'select-object
)))))
1069 "Hook called after a message has been parsed by ERC.
1071 The single argument to the functions is the unmodified string
1072 which the local user typed."
1075 ;; mode-specific tables
1077 (defvar erc-mode-syntax-table
1078 (let ((syntax-table (make-syntax-table)))
1079 (modify-syntax-entry ?
\" ". " syntax-table
)
1080 (modify-syntax-entry ?
\\ ". " syntax-table
)
1081 (modify-syntax-entry ?
' "w " syntax-table
)
1082 ;; Make dabbrev-expand useful for nick names
1083 (modify-syntax-entry ?
< "." syntax-table
)
1084 (modify-syntax-entry ?
> "." syntax-table
)
1086 "Syntax table used while in ERC mode.")
1088 (defvar erc-mode-abbrev-table nil
1089 "Abbrev table used while in ERC mode.")
1090 (define-abbrev-table 'erc-mode-abbrev-table
())
1092 (defvar erc-mode-map
1093 (let ((map (make-sparse-keymap)))
1094 (define-key map
"\C-m" 'erc-send-current-line
)
1095 (define-key map
"\C-a" 'erc-bol
)
1096 (define-key map
[home] 'erc-bol)
1097 (define-key map "\C-c\C-a" 'erc-bol)
1098 (define-key map "\C-c\C-b" 'erc-iswitchb)
1099 (define-key map "\C-c\C-c" 'erc-toggle-interpret-controls)
1100 (define-key map "\C-c\C-d" 'erc-input-action)
1101 (define-key map "\C-c\C-e" 'erc-toggle-ctcp-autoresponse)
1102 (define-key map "\C-c\C-f" 'erc-toggle-flood-control)
1103 (define-key map "\C-c\C-i" 'erc-invite-only-mode)
1104 (define-key map "\C-c\C-j" 'erc-join-channel)
1105 (define-key map "\C-c\C-n" 'erc-channel-names)
1106 (define-key map "\C-c\C-o" 'erc-get-channel-mode-from-keypress)
1107 (define-key map "\C-c\C-p" 'erc-part-from-channel)
1108 (define-key map "\C-c\C-q" 'erc-quit-server)
1109 (define-key map "\C-c\C-r" 'erc-remove-text-properties-region)
1110 (define-key map "\C-c\C-t" 'erc-set-topic)
1111 (define-key map "\C-c\C-u" 'erc-kill-input)
1112 (define-key map "\C-c\C-x" 'erc-quit-server)
1113 (define-key map "\M-\t" 'ispell-complete-word)
1114 (define-key map "\t" 'completion-at-point)
1116 ;; Suppress `font-lock-fontify-block' key binding since it
1117 ;; destroys face properties.
1118 (if (fboundp 'command-remapping)
1119 (define-key map [remap font-lock-fontify-block] 'undefined)
1120 (substitute-key-definition
1121 'font-lock-fontify-block 'undefined map global-map))
1128 ; Honestly, I have a horrible sense of color and the "defaults" below
1129 ; are supposed to be really bad. But colors ARE required in IRC to
1130 ; convey different parts of conversation. If you think you know better
1131 ; defaults - send them to me.
1133 ;; Now colors are a bit nicer, at least to my eyes.
1134 ;; You may still want to change them to better fit your background.-- S.B.
1136 (defgroup erc-faces nil
1140 (defface erc-default-face '((t))
1144 (defface erc-direct-msg-face '((t :foreground "IndianRed"))
1145 "ERC face used for messages you receive in the main erc buffer."
1148 (defface erc-header-line
1149 '((t :foreground "grey20" :background "grey90"))
1150 "ERC face used for the header line.
1152 This will only be used if `erc-header-line-face-method' is non-nil."
1155 (defface erc-input-face '((t :foreground "brown"))
1156 "ERC face used for your input."
1159 (defface erc-prompt-face
1160 '((t :weight bold :foreground "Black" :background "lightBlue2"))
1161 "ERC face for the prompt."
1164 (defface erc-command-indicator-face
1166 "ERC face for the command indicator.
1167 See the variable `erc-command-indicator'."
1170 (defface erc-notice-face
1171 '((default :weight bold)
1172 (((class color) (min-colors 88)) :foreground "SlateBlue")
1173 (t :foreground "blue"))
1174 "ERC face for notices."
1177 (defface erc-action-face '((t :weight bold))
1178 "ERC face for actions generated by /ME."
1181 (defface erc-error-face '((t :foreground "red"))
1182 "ERC face for errors."
1185 ;; same default color as `erc-input-face'
1186 (defface erc-my-nick-face '((t :weight bold :foreground "brown"))
1187 "ERC face for your current nickname in messages sent by you.
1188 See also `erc-show-my-nick'."
1191 (defface erc-nick-default-face '((t :weight bold))
1192 "ERC nickname default face."
1195 (defface erc-nick-msg-face '((t :weight bold :foreground "IndianRed"))
1196 "ERC nickname face for private messages."
1199 ;; Debugging support
1201 (defvar erc-log-p nil
1202 "When set to t, generate debug messages in a separate debug buffer.")
1204 (defvar erc-debug-log-file (expand-file-name "ERC.debug")
1205 "Debug log file name.")
1207 (defvar erc-dbuf nil)
1208 (make-variable-buffer-local 'erc-dbuf)
1210 (defmacro define-erc-module (name alias doc enable-body disable-body
1212 "Define a new minor mode using ERC conventions.
1213 Symbol NAME is the name of the module.
1214 Symbol ALIAS is the alias to use, or nil.
1215 DOC is the documentation string to use for the minor mode.
1216 ENABLE-BODY is a list of expressions used to enable the mode.
1217 DISABLE-BODY is a list of expressions used to disable the mode.
1218 If LOCAL-P is non-nil, the mode will be created as a buffer-local
1219 mode, rather than a global one.
1221 This will define a minor mode called erc-NAME-mode, possibly
1222 an alias erc-ALIAS-mode, as well as the helper functions
1223 erc-NAME-enable, and erc-NAME-disable.
1227 ;;;###autoload (autoload 'erc-replace-mode \"erc-replace\")
1228 (define-erc-module replace nil
1229 \"This mode replaces incoming text according to `erc-replace-alist'.\"
1230 ((add-hook 'erc-insert-modify-hook
1231 'erc-replace-insert))
1232 ((remove-hook 'erc-insert-modify-hook
1233 'erc-replace-insert)))"
1234 (declare (doc-string 3))
1235 (let* ((sn (symbol-name name))
1236 (mode (intern (format "erc-%s-mode" (downcase sn))))
1237 (group (intern (format "erc-%s" (downcase sn))))
1238 (enable (intern (format "erc-%s-enable" (downcase sn))))
1239 (disable (intern (format "erc-%s-disable" (downcase sn)))))
1241 (erc-define-minor-mode
1243 ,(format "Toggle ERC %S mode.
1244 With a prefix argument ARG, enable %s if ARG is positive,
1245 and disable it otherwise. If called from Lisp, enable the mode
1246 if ARG is omitted or nil.
1249 :global ,(not local-p) :group (quote ,group)
1254 ,(format "Enable ERC %S mode."
1257 (add-to-list 'erc-modules (quote ,name))
1261 ,(format "Disable ERC %S mode."
1264 (setq erc-modules (delq (quote ,name) erc-modules))
1267 ,(when (and alias (not (eq name alias)))
1271 (format "erc-%s-mode"
1272 (downcase (symbol-name alias)))))
1275 ;; For find-function and find-variable.
1276 (put ',mode 'definition-name ',name)
1277 (put ',enable 'definition-name ',name)
1278 (put ',disable 'definition-name ',name))))
1280 (defun erc-once-with-server-event (event &rest forms)
1281 "Execute FORMS the next time EVENT occurs in the `current-buffer'.
1283 You should make sure that `current-buffer' is a server buffer.
1285 This function temporarily adds a function to EVENT's hook to
1286 execute FORMS. After FORMS are run, the function is removed from
1287 EVENT's hook. The last expression of FORMS should be either nil
1288 or t, where nil indicates that the other functions on EVENT's hook
1289 should be run too, and t indicates that other functions should
1292 Please be sure to use this function in server-buffers. In
1293 channel-buffers it may not work at all, as it uses the LOCAL
1294 argument of `add-hook' and `remove-hook' to ensure multiserver
1296 (unless (erc-server-buffer-p)
1298 "You should only run `erc-once-with-server-event' in a server buffer"))
1299 (let ((fun (make-symbol "fun"))
1300 (hook (erc-get-hook event)))
1301 (put fun 'erc-original-buffer (current-buffer))
1302 (fset fun `(lambda (proc parsed)
1303 (with-current-buffer (get ',fun 'erc-original-buffer)
1304 (remove-hook ',hook ',fun t))
1307 (add-hook hook fun nil t)
1310 (defun erc-once-with-server-event-global (event &rest forms)
1311 "Execute FORMS the next time EVENT occurs in any server buffer.
1313 This function temporarily prepends a function to EVENT's hook to
1314 execute FORMS. After FORMS are run, the function is removed from
1315 EVENT's hook. The last expression of FORMS should be either nil
1316 or t, where nil indicates that the other functions on EVENT's hook
1317 should be run too, and t indicates that other functions should
1320 When FORMS execute, the current buffer is the server buffer associated with the
1321 connection over which the data was received that triggered EVENT."
1322 (let ((fun (make-symbol "fun"))
1323 (hook (erc-get-hook event)))
1324 (fset fun `(lambda (proc parsed)
1325 (remove-hook ',hook ',fun)
1328 (add-hook hook fun nil nil)
1331 (defsubst erc-log (string)
1332 "Logs STRING if logging is on (see `erc-log-p')."
1334 (erc-log-aux string)))
1336 (defun erc-server-buffer ()
1337 "Return the server buffer for the current buffer's process.
1338 The buffer-local variable `erc-server-process' is used to find
1339 the process buffer."
1340 (and (erc-server-buffer-live-p)
1341 (process-buffer erc-server-process)))
1343 (defun erc-server-buffer-live-p ()
1344 "Return t if the server buffer has not been killed."
1345 (and (processp erc-server-process)
1346 (buffer-live-p (process-buffer erc-server-process))))
1348 (defun erc-server-buffer-p (&optional buffer)
1349 "Return non-nil if argument BUFFER is an ERC server buffer.
1351 If BUFFER is nil, the current buffer is used."
1352 (with-current-buffer (or buffer (current-buffer))
1353 (and (eq major-mode 'erc-mode)
1354 (null (erc-default-target)))))
1356 (defun erc-open-server-buffer-p (&optional buffer)
1357 "Return non-nil if argument BUFFER is an ERC server buffer that
1358 has an open IRC process.
1360 If BUFFER is nil, the current buffer is used."
1361 (and (erc-server-buffer-p)
1362 (erc-server-process-alive)))
1364 (defun erc-query-buffer-p (&optional buffer)
1365 "Return non-nil if BUFFER is an ERC query buffer.
1366 If BUFFER is nil, the current buffer is used."
1367 (with-current-buffer (or buffer (current-buffer))
1368 (let ((target (erc-default-target)))
1369 (and (eq major-mode 'erc-mode)
1371 (not (memq (aref target 0) '(?# ?& ?+ ?!)))))))
1373 (defun erc-ison-p (nick)
1374 "Return non-nil if NICK is online."
1375 (interactive "sNick: ")
1376 (erc-with-server-buffer
1377 (let ((erc-online-p 'unknown))
1378 (erc-once-with-server-event
1380 `(let ((ison (split-string (aref parsed 3))))
1381 (setq erc-online-p (car (erc-member-ignore-case ,nick ison)))
1383 (erc-server-send (format "ISON %s" nick))
1384 (while (eq erc-online-p 'unknown) (accept-process-output))
1385 (if (called-interactively-p 'interactive)
1386 (message "%s is %sonline"
1387 (or erc-online-p nick)
1388 (if erc-online-p "" "not "))
1391 (defun erc-log-aux (string)
1392 "Do the debug logging of STRING."
1393 (let ((cb (current-buffer))
1396 (session-buffer (erc-server-buffer)))
1399 (set-buffer session-buffer)
1400 (if (not (and erc-dbuf (bufferp erc-dbuf) (buffer-live-p erc-dbuf)))
1402 (setq erc-dbuf (get-buffer-create
1403 (concat "*ERC-DEBUG: "
1404 erc-session-server "*")))))
1405 (set-buffer erc-dbuf)
1406 (setq point (point))
1407 (setq was-eob (eobp))
1408 (goto-char (point-max))
1409 (insert (concat "** " string "\n"))
1410 (if was-eob (goto-char (point-max))
1413 (message "ERC: ** %s" string))))
1415 ;; Last active buffer, to print server messages in the right place
1417 (defvar erc-active-buffer nil
1418 "The current active buffer, the one where the user typed the last command.
1419 Defaults to the server buffer, and should only be set in the
1421 (make-variable-buffer-local 'erc-active-buffer)
1423 (defun erc-active-buffer ()
1424 "Return the value of `erc-active-buffer' for the current server.
1425 Defaults to the server buffer."
1426 (erc-with-server-buffer
1427 (if (buffer-live-p erc-active-buffer)
1429 (setq erc-active-buffer (current-buffer)))))
1431 (defun erc-set-active-buffer (buffer)
1432 "Set the value of `erc-active-buffer' to BUFFER."
1433 (cond ((erc-server-buffer)
1434 (with-current-buffer (erc-server-buffer)
1435 (setq erc-active-buffer buffer)))
1436 (t (setq erc-active-buffer buffer))))
1438 ;; Mode activation routines
1440 (define-derived-mode erc-mode fundamental-mode "ERC"
1441 "Major mode for Emacs IRC."
1442 (setq local-abbrev-table erc-mode-abbrev-table)
1443 (when (boundp 'next-line-add-newlines)
1444 (set (make-local-variable 'next-line-add-newlines) nil))
1445 (setq line-move-ignore-invisible t)
1446 (set (make-local-variable 'paragraph-separate)
1447 (concat "\C-l\\|\\(^" (regexp-quote (erc-prompt)) "\\)"))
1448 (set (make-local-variable 'paragraph-start)
1449 (concat "\\(" (regexp-quote (erc-prompt)) "\\)"))
1450 (add-hook 'completion-at-point-functions 'erc-complete-word-at-point nil t))
1454 (defconst erc-default-server "irc.freenode.net"
1455 "IRC server to use if it cannot be detected otherwise.")
1457 (defconst erc-default-port 6667
1458 "IRC port to use if it cannot be detected otherwise.")
1460 (defcustom erc-join-buffer 'buffer
1461 "Determines how to display a newly created IRC buffer.
1463 The available choices are:
1465 'window - in another window,
1466 'window-noselect - in another window, but don't select that one,
1467 'frame - in another frame,
1468 'bury - bury it in a new buffer,
1469 'buffer - in place of the current buffer,
1470 any other value - in place of the current buffer."
1472 :type '(choice (const :tag "Split window and select" window)
1473 (const :tag "Split window, don't select" window-noselect)
1474 (const :tag "New frame" frame)
1475 (const :tag "Bury in new buffer" bury)
1476 (const :tag "Use current buffer" buffer)
1477 (const :tag "Use current buffer" t)))
1479 (defcustom erc-frame-alist nil
1480 "Alist of frame parameters for creating erc frames.
1481 A value of nil means to use `default-frame-alist'."
1483 :type '(repeat (cons :format "%v"
1484 (symbol :tag "Parameter")
1485 (sexp :tag "Value"))))
1487 (defcustom erc-frame-dedicated-flag nil
1488 "Non-nil means the erc frames are dedicated to that buffer.
1489 This only has effect when `erc-join-buffer' is set to `frame'."
1493 (defcustom erc-reuse-frames t
1494 "Determines whether new frames are always created.
1495 Non-nil means that a new frame is not created to display an ERC
1496 buffer if there is already a window displaying it. This only has
1497 effect when `erc-join-buffer' is set to `frame'."
1501 (defun erc-channel-p (channel)
1502 "Return non-nil if CHANNEL seems to be an IRC channel name."
1503 (cond ((stringp channel)
1504 (memq (aref channel 0) '(?# ?& ?+ ?!)))
1505 ((and (bufferp channel) (buffer-live-p channel))
1506 (with-current-buffer channel
1507 (erc-channel-p (erc-default-target))))
1510 (defcustom erc-reuse-buffers t
1511 "If nil, create new buffers on joining a channel/query.
1512 If non-nil, a new buffer will only be created when you join
1513 channels with same names on different servers, or have query buffers
1514 open with nicks of the same name on different servers. Otherwise,
1515 the existing buffers will be reused."
1519 (defun erc-normalize-port (port)
1520 "Normalize the port specification PORT to integer form.
1521 PORT may be an integer, a string or a symbol. If it is a string or a
1522 symbol, it may have these values:
1526 * ircd-dalnet -> 7000"
1529 (erc-normalize-port (symbol-name port)))
1531 (let ((port-nr (string-to-number port)))
1535 ((string-equal port "irc")
1537 ((string-equal port "ircs")
1539 ((string-equal port "ircd")
1541 ((string-equal port "ircd-dalnet")
1550 (defun erc-port-equal (a b)
1551 "Check whether ports A and B are equal."
1552 (= (erc-normalize-port a) (erc-normalize-port b)))
1554 (defun erc-generate-new-buffer-name (server port target &optional proc)
1555 "Create a new buffer name based on the arguments."
1556 (when (numberp port) (setq port (number-to-string port)))
1557 (let ((buf-name (or target
1558 (or (let ((name (concat server ":" port)))
1559 (when (> (length name) 1)
1561 ;; This fallback should in fact never happen
1562 "*erc-server-buffer*")))
1564 ;; Reuse existing buffers, but not if the buffer is a connected server
1565 ;; buffer and not if its associated with a different server than the
1566 ;; current ERC buffer.
1567 ;; if buf-name is taken by a different connection (or by something !erc)
1568 ;; then see if "buf-name/server" meets the same criteria
1569 (dolist (candidate (list buf-name (concat buf-name "/" server)))
1570 (if (and (not buffer-name)
1572 (get-buffer candidate)
1574 (with-current-buffer (get-buffer candidate)
1575 (and (erc-server-buffer-p)
1576 (not (erc-server-process-alive)))))
1577 (with-current-buffer (get-buffer candidate)
1578 (and (string= erc-session-server server)
1579 (erc-port-equal erc-session-port port))))
1580 (setq buffer-name candidate)))
1581 ;; if buffer-name is unset, neither candidate worked out for us,
1582 ;; fallback to the old <N> uniquification method:
1583 (or buffer-name (generate-new-buffer-name buf-name)) ))
1585 (defun erc-get-buffer-create (server port target &optional proc)
1586 "Create a new buffer based on the arguments."
1587 (get-buffer-create (erc-generate-new-buffer-name server port target proc)))
1590 (defun erc-member-ignore-case (string list)
1591 "Return non-nil if STRING is a member of LIST.
1593 All strings are compared according to IRC protocol case rules, see
1595 (setq string (erc-downcase string))
1598 (if (string= string (erc-downcase (car list)))
1599 (throw 'result list)
1600 (setq list (cdr list))))))
1602 (defmacro erc-with-buffer (spec &rest body)
1603 "Execute BODY in the buffer associated with SPEC.
1605 SPEC should have the form
1609 If TARGET is a buffer, use it. Otherwise, use the buffer
1610 matching TARGET in the process specified by PROCESS.
1612 If PROCESS is nil, use the current `erc-server-process'.
1613 See `erc-get-buffer' for details.
1615 See also `with-current-buffer'.
1617 \(fn (TARGET [PROCESS]) BODY...)"
1618 (declare (indent 1) (debug ((form &optional form) body)))
1619 (let ((buf (make-symbol "buf"))
1620 (proc (make-symbol "proc"))
1621 (target (make-symbol "target"))
1622 (process (make-symbol "process")))
1623 `(let* ((,target ,(car spec))
1624 (,process ,(cadr spec))
1625 (,buf (if (bufferp ,target)
1627 (let ((,proc (or ,process
1628 (and (processp erc-server-process)
1629 erc-server-process))))
1630 (if (and ,target ,proc)
1631 (erc-get-buffer ,target ,proc))))))
1632 (when (buffer-live-p ,buf)
1633 (with-current-buffer ,buf
1636 (defun erc-get-buffer (target &optional proc)
1637 "Return the buffer matching TARGET in the process PROC.
1638 If PROC is not supplied, all processes are searched."
1639 (let ((downcased-target (erc-downcase target)))
1643 (let ((current (erc-default-target)))
1644 (and (stringp current)
1645 (string-equal downcased-target (erc-downcase current))
1646 (throw 'buffer (current-buffer)))))
1649 (defun erc-buffer-filter (predicate &optional proc)
1650 "Return a list of `erc-mode' buffers matching certain criteria.
1651 PREDICATE is a function executed with each buffer, if it returns t, that buffer
1652 is considered a valid match.
1654 PROC is either an `erc-server-process', identifying a certain
1655 server connection, or nil which means all open connections."
1659 (mapcar (lambda (buf)
1660 (when (buffer-live-p buf)
1661 (with-current-buffer buf
1662 (and (eq major-mode 'erc-mode)
1664 (eq proc erc-server-process))
1669 (defun erc-buffer-list (&optional predicate proc)
1670 "Return a list of ERC buffers.
1671 PREDICATE is a function which executes with every buffer satisfying
1672 the predicate. If PREDICATE is passed as nil, return a list of all ERC
1673 buffers. If PROC is given, the buffers local variable `erc-server-process'
1674 needs to match PROC."
1676 (setq predicate (lambda () t)))
1677 (erc-buffer-filter predicate proc))
1679 (defmacro erc-with-all-buffers-of-server (process pred &rest forms)
1680 "Execute FORMS in all buffers which have same process as this server.
1681 FORMS will be evaluated in all buffers having the process PROCESS and
1682 where PRED matches or in all buffers of the server process if PRED is
1684 (declare (indent 1) (debug (form form body)))
1685 ;; Make the evaluation have the correct order
1686 (let ((pre (make-symbol "pre"))
1687 (pro (make-symbol "pro")))
1688 `(let* ((,pro ,process)
1690 (res (mapcar (lambda (buffer)
1691 (with-current-buffer buffer
1693 (erc-buffer-list ,pre
1695 ;; Silence the byte-compiler by binding the result of mapcar to
1699 ;; (iswitchb-mode) will autoload iswitchb.el
1700 (defvar iswitchb-temp-buflist)
1701 (declare-function iswitchb-read-buffer "iswitchb"
1702 (prompt &optional default require-match start matches-set))
1704 (defun erc-iswitchb (&optional arg)
1705 "Use `iswitchb-read-buffer' to prompt for a ERC buffer to switch to.
1706 When invoked with prefix argument, use all erc buffers. Without prefix
1707 ARG, allow only buffers related to same session server.
1708 If `erc-track-mode' is in enabled, put the last element of
1709 `erc-modified-channels-alist' in front of the buffer list.
1711 Due to some yet unresolved reason, global function `iswitchb-mode'
1712 needs to be active for this function to work."
1714 (let ((enabled (bound-and-true-p iswitchb-mode)))
1715 (or enabled (iswitchb-mode 1))
1717 (let ((iswitchb-make-buflist-hook
1719 (setq iswitchb-temp-buflist
1720 (mapcar 'buffer-name
1723 (when arg erc-server-process)))))))
1725 (iswitchb-read-buffer
1727 (if (boundp 'erc-modified-channels-alist)
1728 (buffer-name (caar (last erc-modified-channels-alist)))
1731 (or enabled (iswitchb-mode -1)))))
1733 (defun erc-channel-list (proc)
1734 "Return a list of channel buffers.
1735 PROC is the process for the server connection. If PROC is nil, return
1736 all channel buffers on all servers."
1739 (and (erc-default-target)
1740 (erc-channel-p (erc-default-target))))
1743 (defun erc-buffer-list-with-nick (nick proc)
1744 "Return buffers containing NICK in the `erc-channel-users' list."
1745 (with-current-buffer (process-buffer proc)
1746 (let ((user (gethash (erc-downcase nick) erc-server-users)))
1748 (erc-server-user-buffers user)
1751 ;; Some local variables
1753 (defvar erc-default-recipients nil
1754 "List of default recipients of the current buffer.")
1755 (make-variable-buffer-local 'erc-default-recipients)
1757 (defvar erc-session-user-full-name nil
1758 "Full name of the user on the current server.")
1759 (make-variable-buffer-local 'erc-session-user-full-name)
1761 (defvar erc-channel-user-limit nil
1762 "Limit of users per channel.")
1763 (make-variable-buffer-local 'erc-channel-user-limit)
1765 (defvar erc-channel-key nil
1766 "Key needed to join channel.")
1767 (make-variable-buffer-local 'erc-channel-key)
1769 (defvar erc-invitation nil
1770 "Last invitation channel.")
1771 (make-variable-buffer-local 'erc-invitation)
1773 (defvar erc-away nil
1774 "Non-nil indicates that we are away.
1776 Use `erc-away-time' to access this if you might be in a channel
1777 buffer rather than a server buffer.")
1778 (make-variable-buffer-local 'erc-away)
1780 (defvar erc-channel-list nil
1781 "Server channel list.")
1782 (make-variable-buffer-local 'erc-channel-list)
1784 (defvar erc-bad-nick nil
1785 "Non-nil indicates that we got a `nick in use' error while connecting.")
1786 (make-variable-buffer-local 'erc-bad-nick)
1788 (defvar erc-logged-in nil
1789 "Non-nil indicates that we are logged in.")
1790 (make-variable-buffer-local 'erc-logged-in)
1792 (defvar erc-default-nicks nil
1793 "The local copy of `erc-nick' - the list of nicks to choose from.")
1794 (make-variable-buffer-local 'erc-default-nicks)
1796 (defvar erc-nick-change-attempt-count 0
1797 "Used to keep track of how many times an attempt at changing nick is made.")
1798 (make-variable-buffer-local 'erc-nick-change-attempt-count)
1800 (defun erc-migrate-modules (mods)
1801 "Migrate old names of ERC modules to new ones."
1802 ;; modify `transforms' to specify what needs to be changed
1803 ;; each item is in the format '(old . new)
1804 (let ((transforms '((pcomplete . completion))))
1806 (mapcar (lambda (m) (or (cdr (assoc m transforms)) m))
1809 (defcustom erc-modules '(netsplit fill button match track completion readonly
1810 networks ring autojoin noncommands irccontrols
1811 move-to-prompt stamp menu list)
1812 "A list of modules which ERC should enable.
1813 If you set the value of this without using `customize' remember to call
1814 \(erc-update-modules) after you change it. When using `customize', modules
1815 removed from the list will be disabled."
1817 ;; replace outdated names with their newer equivalents
1818 (erc-migrate-modules (symbol-value sym)))
1819 :set (lambda (sym val)
1820 ;; disable modules which have just been removed
1821 (when (and (boundp 'erc-modules) erc-modules val)
1822 (dolist (module erc-modules)
1823 (unless (member module val)
1824 (let ((f (intern-soft (format "erc-%s-mode" module))))
1825 (when (and (fboundp f) (boundp f) (symbol-value f))
1826 (message "Disabling `erc-%s'" module)
1829 ;; this test is for the case where erc hasn't been loaded yet
1830 (when (fboundp 'erc-update-modules)
1831 (erc-update-modules)))
1835 (const :tag "autoaway: Set away status automatically" autoaway)
1836 (const :tag "autojoin: Join channels automatically" autojoin)
1837 (const :tag "button: Buttonize URLs, nicknames, and other text" button)
1838 (const :tag "capab: Mark unidentified users on servers supporting CAPAB"
1840 (const :tag "completion: Complete nicknames and commands (programmable)"
1842 (const :tag "hecomplete: Complete nicknames and commands (obsolete, use \"completion\")" hecomplete)
1843 (const :tag "dcc: Provide Direct Client-to-Client support" dcc)
1844 (const :tag "fill: Wrap long lines" fill)
1845 (const :tag "identd: Launch an identd server on port 8113" identd)
1846 (const :tag "irccontrols: Highlight or remove IRC control characters"
1848 (const :tag "keep-place: Leave point above un-viewed text" keep-place)
1849 (const :tag "list: List channels in a separate buffer" list)
1850 (const :tag "log: Save buffers in logs" log)
1851 (const :tag "match: Highlight pals, fools, and other keywords" match)
1852 (const :tag "menu: Display a menu in ERC buffers" menu)
1853 (const :tag "move-to-prompt: Move to the prompt when typing text"
1855 (const :tag "netsplit: Detect netsplits" netsplit)
1856 (const :tag "networks: Provide data about IRC networks" networks)
1857 (const :tag "noncommands: Don't display non-IRC commands after evaluation"
1860 "notify: Notify when the online status of certain users changes"
1862 (const :tag "notifications: Send notifications on PRIVMSG or nickname mentions"
1864 (const :tag "page: Process CTCP PAGE requests from IRC" page)
1865 (const :tag "readonly: Make displayed lines read-only" readonly)
1866 (const :tag "replace: Replace text in messages" replace)
1867 (const :tag "ring: Enable an input history" ring)
1868 (const :tag "scrolltobottom: Scroll to the bottom of the buffer"
1870 (const :tag "services: Identify to Nickserv (IRC Services) automatically"
1872 (const :tag "smiley: Convert smileys to pretty icons" smiley)
1873 (const :tag "sound: Play sounds when you receive CTCP SOUND requests"
1875 (const :tag "stamp: Add timestamps to messages" stamp)
1876 (const :tag "spelling: Check spelling" spelling)
1877 (const :tag "track: Track channel activity in the mode-line" track)
1878 (const :tag "truncate: Truncate buffers to a certain size" truncate)
1879 (const :tag "unmorse: Translate morse code in messages" unmorse)
1880 (const :tag "xdcc: Act as an XDCC file-server" xdcc)
1881 (repeat :tag "Others" :inline t symbol))
1884 (defun erc-update-modules ()
1885 "Run this to enable erc-foo-mode for all modules in `erc-modules'."
1887 (dolist (mod erc-modules)
1888 (setq req (concat "erc-" (symbol-name mod)))
1890 ;; yuck. perhaps we should bring the filenames into sync?
1891 ((string= req "erc-capab-identify")
1892 (setq req "erc-capab"))
1893 ((string= req "erc-completion")
1894 (setq req "erc-pcomplete"))
1895 ((string= req "erc-pcomplete")
1896 (setq mod 'completion))
1897 ((string= req "erc-autojoin")
1898 (setq req "erc-join")))
1900 (require (intern req))
1902 (let ((sym (intern-soft (concat "erc-" (symbol-name mod) "-mode"))))
1905 (error "`%s' is not a known ERC module" mod))))))
1907 (defun erc-setup-buffer (buffer)
1908 "Consults `erc-join-buffer' to find out how to display `BUFFER'."
1909 (cond ((eq erc-join-buffer 'window)
1910 (if (active-minibuffer-window)
1911 (display-buffer buffer)
1912 (switch-to-buffer-other-window buffer)))
1913 ((eq erc-join-buffer 'window-noselect)
1914 (display-buffer buffer))
1915 ((eq erc-join-buffer 'bury)
1917 ((eq erc-join-buffer 'frame)
1918 (when (or (not erc-reuse-frames)
1919 (not (get-buffer-window buffer t)))
1922 (select-frame frame))
1923 (make-frame (or erc-frame-alist
1924 default-frame-alist)))
1925 (switch-to-buffer buffer)
1926 (when erc-frame-dedicated-flag
1927 (set-window-dedicated-p (selected-window) t))))
1929 (if (active-minibuffer-window)
1930 (display-buffer buffer)
1931 (switch-to-buffer buffer)))))
1933 (defun erc-open (&optional server port nick full-name
1934 connect passwd tgt-list channel process)
1935 "Connect to SERVER on PORT as NICK with FULL-NAME.
1937 If CONNECT is non-nil, connect to the server. Otherwise assume
1938 already connected and just create a separate buffer for the new
1941 Use PASSWD as user password on the server. If TGT-LIST is
1942 non-nil, use it to initialize `erc-default-recipients'.
1944 Returns the buffer for the given server or channel."
1945 (let ((server-announced-name (when (and (boundp 'erc-session-server)
1946 (string= server erc-session-server))
1947 erc-server-announced-name))
1948 (connected-p (unless connect erc-server-connected))
1949 (buffer (erc-get-buffer-create server port channel))
1950 (old-buffer (current-buffer))
1953 (when connect (run-hook-with-args 'erc-before-connect server port nick))
1954 (erc-update-modules)
1956 (setq old-point (point))
1958 (setq erc-server-announced-name server-announced-name)
1959 (setq erc-server-connected connected-p)
1960 ;; connection parameters
1961 (setq erc-server-process process)
1962 (setq erc-insert-marker (make-marker))
1963 (setq erc-input-marker (make-marker))
1964 ;; go to the end of the buffer and open a new line
1965 ;; (the buffer may have existed)
1966 (goto-char (point-max))
1968 (when (get-text-property (point) 'erc-prompt)
1969 (setq continued-session t)
1970 (set-marker erc-input-marker
1971 (or (next-single-property-change (point) 'erc-prompt)
1973 (unless continued-session
1974 (goto-char (point-max))
1976 (set-marker erc-insert-marker (point))
1977 ;; stack of default recipients
1978 (setq erc-default-recipients tgt-list)
1979 (setq erc-server-current-nick nil)
1980 ;; Initialize erc-server-users and erc-channel-users
1982 (progn ;; server buffer
1983 (setq erc-server-users
1984 (make-hash-table :test 'equal))
1985 (setq erc-channel-users nil))
1986 (progn ;; target buffer
1987 (setq erc-server-users nil)
1988 (setq erc-channel-users
1989 (make-hash-table :test 'equal))))
1990 ;; clear last incomplete line read
1991 (setq erc-server-filter-data nil)
1992 (setq erc-channel-topic "")
1993 ;; limit on the number of users on the channel (mode +l)
1994 (setq erc-channel-user-limit nil)
1995 (setq erc-channel-key nil)
1996 ;; last active buffer, defaults to this one
1997 (erc-set-active-buffer buffer)
1998 ;; last invitation channel
1999 (setq erc-invitation nil)
2000 ;; Server channel list
2001 (setq erc-channel-list ())
2002 ;; login-time 'nick in use' error
2003 (setq erc-bad-nick nil)
2004 ;; whether we have logged in
2005 (setq erc-logged-in nil)
2006 ;; The local copy of `erc-nick' - the list of nicks to choose
2007 (setq erc-default-nicks (if (consp erc-nick) erc-nick (list erc-nick)))
2009 (setq erc-session-password (or passwd
2013 (auth-source-search :host server
2017 :require '(:secret)))
2019 (if (functionp secret)
2022 ;; debug output buffer
2025 (get-buffer-create (concat "*ERC-DEBUG: " server "*"))))
2027 (unless continued-session
2028 (goto-char (point-max))
2030 (if continued-session
2031 (goto-char old-point)
2032 (set-marker erc-insert-marker (point))
2033 (erc-display-prompt)
2034 (goto-char (point-max)))
2036 (erc-determine-parameters server port nick full-name)
2038 ;; Saving log file on exit
2039 (run-hook-with-args 'erc-connect-pre-hook buffer)
2042 (erc-server-connect erc-session-server erc-session-port buffer))
2043 (erc-update-mode-line)
2045 ;; Now display the buffer in a window as per user wishes.
2046 (unless (eq buffer old-buffer)
2048 ;; we can't log to debug buffer, it may not exist yet
2049 (message "erc: old buffer %s, switching to %s"
2051 (erc-setup-buffer buffer))
2055 (defun erc-initialize-log-marker (buffer)
2056 "Initialize the `erc-last-saved-position' marker to a sensible position.
2057 BUFFER is the current buffer."
2058 (with-current-buffer buffer
2059 (setq erc-last-saved-position (make-marker))
2060 (move-marker erc-last-saved-position
2061 (1- (marker-position erc-insert-marker)))))
2063 ;; interactive startup
2065 (defvar erc-server-history-list nil
2066 "IRC server interactive selection history list.")
2068 (defvar erc-nick-history-list nil
2069 "Nickname interactive selection history list.")
2071 (defun erc-already-logged-in (server port nick)
2072 "Return the buffers corresponding to a NICK on PORT of a session SERVER.
2073 This is determined by looking for the appropriate buffer and checking
2074 whether the connection is still alive.
2075 If no buffer matches, return nil."
2078 (and (erc-server-process-alive)
2079 (string= erc-session-server server)
2080 (erc-port-equal erc-session-port port)
2081 (erc-current-nick-p nick)))))
2083 (if (not (fboundp 'read-passwd))
2084 (defun read-passwd (prompt)
2085 "Substitute for `read-passwd' in early emacsen."
2086 (read-from-minibuffer prompt)))
2088 (defcustom erc-before-connect nil
2089 "Hook called before connecting to a server.
2090 This hook gets executed before `erc' actually invokes `erc-mode'
2091 with your input data. The functions in here get called with three
2092 parameters, SERVER, PORT and NICK."
2096 (defcustom erc-after-connect nil
2097 "Hook called after connecting to a server.
2098 This hook gets executed when an end of MOTD has been received. All
2099 functions in here get called with the parameters SERVER and NICK."
2104 (defun erc-select-read-args ()
2105 "Prompt the user for values of nick, server, port, and password."
2106 (let (user-input server port nick passwd)
2107 (setq user-input (read-from-minibuffer
2109 (erc-compute-server) nil nil 'erc-server-history-list))
2111 (if (string-match "\\(.*\\):\\(.*\\)\\'" user-input)
2112 (setq port (erc-string-to-port (match-string 2 user-input))
2113 user-input (match-string 1 user-input))
2115 (erc-string-to-port (read-from-minibuffer
2116 "IRC port: " (erc-port-to-string
2117 (erc-compute-port))))))
2119 (if (string-match "\\`\\(.*\\)@\\(.*\\)" user-input)
2120 (setq nick (match-string 1 user-input)
2121 user-input (match-string 2 user-input))
2123 (if (erc-already-logged-in server port nick)
2124 (read-from-minibuffer
2125 (erc-format-message 'nick-in-use ?n nick)
2127 nil nil 'erc-nick-history-list)
2128 (read-from-minibuffer
2129 "Nickname: " (erc-compute-nick nick)
2130 nil nil 'erc-nick-history-list))))
2132 (setq server user-input)
2134 (setq passwd (if erc-prompt-for-password
2135 (if (and erc-password
2136 (y-or-n-p "Use the default password? "))
2138 (read-passwd "Password: "))
2140 (when (and passwd (string= "" passwd))
2143 (while (erc-already-logged-in server port nick)
2144 ;; hmm, this is a problem when using multiple connections to a bnc
2145 ;; with the same nick. Currently this code prevents using more than one
2146 ;; bnc with the same nick. actually it would be nice to have
2147 ;; bncs transparent, so that erc-compute-buffer-name displays
2148 ;; the server one is connected to.
2149 (setq nick (read-from-minibuffer
2150 (erc-format-message 'nick-in-use ?n nick)
2152 nil nil 'erc-nick-history-list)))
2153 (list :server server :port port :nick nick :password passwd)))
2156 (cl-defun erc (&key (server (erc-compute-server))
2157 (port (erc-compute-port))
2158 (nick (erc-compute-nick))
2160 (full-name (erc-compute-full-name)))
2161 "ERC is a powerful, modular, and extensible IRC client.
2162 This function is the main entry point for ERC.
2164 It permits you to select connection parameters, and then starts ERC.
2166 Non-interactively, it takes the keyword arguments
2167 (server (erc-compute-server))
2168 (port (erc-compute-port))
2169 (nick (erc-compute-nick))
2171 (full-name (erc-compute-full-name)))
2173 That is, if called with
2175 (erc :server \"irc.freenode.net\" :full-name \"Harry S Truman\")
2177 then the server and full-name will be set to those values, whereas
2178 `erc-compute-port', `erc-compute-nick' and `erc-compute-full-name' will
2179 be invoked for the values of the other parameters."
2180 (interactive (erc-select-read-args))
2181 (erc-open server port nick full-name t password))
2184 (defalias 'erc-select 'erc)
2185 (defalias 'erc-ssl 'erc-tls)
2188 (defun erc-tls (&rest r)
2189 "Interactively select TLS connection parameters and run ERC.
2190 Arguments are the same as for `erc'."
2191 (interactive (erc-select-read-args))
2192 (let ((erc-server-connect-function 'erc-open-tls-stream))
2195 (defun erc-open-tls-stream (name buffer host port)
2196 "Open an TLS stream to an IRC server.
2197 The process will be given the name NAME, its target buffer will be
2198 BUFFER. HOST and PORT specify the connection target."
2199 (open-network-stream name buffer host port
2202 ;;; Displaying error messages
2204 (defun erc-error (&rest args)
2205 "Pass ARGS to `format', and display the result as an error message.
2206 If `debug-on-error' is set to non-nil, then throw a real error with this
2207 message instead, to make debugging easier."
2209 (apply #'error args)
2210 (apply #'message args)
2213 ;;; Debugging the protocol
2215 (defvar erc-debug-irc-protocol nil
2216 "If non-nil, log all IRC protocol traffic to the buffer \"*erc-protocol*\".
2218 The buffer is created if it doesn't exist.
2220 NOTE: If this variable is non-nil, and you kill the only
2221 visible \"*erc-protocol*\" buffer, it will be recreated shortly,
2222 but you won't see it.
2224 WARNING: Do not set this variable directly! Instead, use the
2225 function `erc-toggle-debug-irc-protocol' to toggle its value.")
2227 (declare-function erc-network-name "erc-networks" ())
2229 (defun erc-log-irc-protocol (string &optional outbound)
2230 "Append STRING to the buffer *erc-protocol*.
2232 This only has any effect if `erc-debug-irc-protocol' is non-nil.
2234 The buffer is created if it doesn't exist.
2236 If OUTBOUND is non-nil, STRING is being sent to the IRC server
2237 and appears in face `erc-input-face' in the buffer."
2238 (when erc-debug-irc-protocol
2239 (let ((network-name (or (ignore-errors (erc-network-name))
2241 (with-current-buffer (get-buffer-create "*erc-protocol*")
2243 (goto-char (point-max))
2244 (let ((inhibit-read-only t))
2245 (insert (if (not outbound)
2246 ;; Cope with the fact that string might
2247 ;; contain multiple lines of text.
2248 (let ((lines (delete "" (split-string string
2251 (dolist (line lines)
2252 (setq result (concat result network-name
2256 (concat network-name " >> " string
2259 (1- (length string))))
2261 'face 'erc-input-face)))))
2262 (let ((orig-win (selected-window))
2263 (debug-buffer-window (get-buffer-window (current-buffer) t)))
2264 (when debug-buffer-window
2265 (select-window debug-buffer-window)
2266 (when (= 1 (count-lines (point) (point-max)))
2267 (goto-char (point-max))
2269 (select-window orig-win)))))))
2271 (defun erc-toggle-debug-irc-protocol (&optional arg)
2272 "Toggle the value of `erc-debug-irc-protocol'.
2274 If ARG is non-nil, show the *erc-protocol* buffer."
2276 (let* ((buf (get-buffer-create "*erc-protocol*")))
2277 (with-current-buffer buf
2278 (erc-view-mode-enter)
2279 (when (null (current-local-map))
2280 (let ((inhibit-read-only t))
2281 (insert (erc-make-notice "This buffer displays all IRC protocol traffic exchanged with each server.\n"))
2282 (insert (erc-make-notice "Kill this buffer to terminate protocol logging.\n\n")))
2283 (use-local-map (make-sparse-keymap))
2284 (local-set-key (kbd "t") 'erc-toggle-debug-irc-protocol))
2285 (add-hook 'kill-buffer-hook
2286 #'(lambda () (setq erc-debug-irc-protocol nil))
2288 (goto-char (point-max))
2289 (let ((inhibit-read-only t))
2290 (insert (erc-make-notice
2291 (format "IRC protocol logging %s at %s -- Press `t' to toggle logging.\n"
2292 (if erc-debug-irc-protocol "disabled" "enabled")
2293 (current-time-string))))))
2294 (setq erc-debug-irc-protocol (not erc-debug-irc-protocol))
2296 (not (get-buffer-window "*erc-protocol*" t)))
2297 (display-buffer buf t))
2298 (message "IRC protocol traffic logging %s (see buffer *erc-protocol*)."
2299 (if erc-debug-irc-protocol "enabled" "disabled"))))
2305 (defun erc-send-action (tgt str &optional force)
2306 "Send CTCP ACTION information described by STR to TGT."
2307 (erc-send-ctcp-message tgt (format "ACTION %s" str) force)
2308 (erc-display-message
2309 nil 'input (current-buffer)
2310 'ACTION ?n (erc-current-nick) ?a str ?u "" ?h ""))
2312 ;; Display interface
2314 (defun erc-string-invisible-p (string)
2315 "Check whether STRING is invisible or not.
2316 I.e. any char in it has the `invisible' property set."
2317 (text-property-any 0 (length string) 'invisible t string))
2319 (defcustom erc-remove-parsed-property t
2320 "Whether to remove the erc-parsed text property after displaying a message.
2322 The default is to remove it, since it causes ERC to take up extra
2323 memory. If you have code that relies on this property, then set
2324 this option to nil."
2328 (defun erc-display-line-1 (string buffer)
2329 "Display STRING in `erc-mode' BUFFER.
2330 Auxiliary function used in `erc-display-line'. The line gets filtered to
2331 interpret the control characters. Then, `erc-insert-pre-hook' gets called.
2332 If `erc-insert-this' is still t, STRING gets inserted into the buffer.
2333 Afterwards, `erc-insert-modify' and `erc-insert-post-hook' get called.
2334 If STRING is nil, the function does nothing."
2336 (with-current-buffer (or buffer (process-buffer erc-server-process))
2337 (let ((insert-position (or (marker-position erc-insert-marker)
2339 (let ((string string) ;; FIXME! Can this be removed?
2340 (buffer-undo-list t)
2341 (inhibit-read-only t))
2342 (unless (string-match "\n$" string)
2343 (setq string (concat string "\n"))
2344 (when (erc-string-invisible-p string)
2345 (erc-put-text-properties 0 (length string)
2346 '(invisible intangible) string)))
2347 (erc-log (concat "erc-display-line: " string
2348 (format "(%S)" string) " in buffer "
2349 (format "%s" buffer)))
2350 (setq erc-insert-this t)
2351 (run-hook-with-args 'erc-insert-pre-hook string)
2352 (if (null erc-insert-this)
2353 ;; Leave erc-insert-this set to t as much as possible. Fran
2354 ;; Litterio <franl> has seen erc-insert-this set to nil while
2355 ;; erc-send-pre-hook is running, which should never happen. This
2357 (setq erc-insert-this t)
2358 (save-excursion ;; to restore point in the new buffer
2361 (goto-char insert-position)
2362 (insert-before-markers string)
2363 ;; run insertion hook, with point at restored location
2365 (narrow-to-region insert-position (point))
2366 (run-hooks 'erc-insert-modify-hook)
2367 (run-hooks 'erc-insert-post-hook)
2368 (when erc-remove-parsed-property
2369 (remove-text-properties (point-min) (point-max)
2370 '(erc-parsed nil))))))))
2371 (erc-update-undo-list (- (or (marker-position erc-insert-marker)
2373 insert-position))))))
2375 (defun erc-update-undo-list (shift)
2376 ;; Translate buffer positions in buffer-undo-list by SHIFT.
2377 (unless (or (zerop shift) (atom buffer-undo-list))
2378 (let ((list buffer-undo-list) elt)
2380 (setq elt (car list))
2381 (cond ((integerp elt) ; POSITION
2382 (cl-incf (car list) shift))
2383 ((or (atom elt) ; nil, EXTENT
2384 ;; (eq t (car elt)) ; (t . TIME)
2385 (markerp (car elt))) ; (MARKER . DISTANCE)
2387 ((integerp (car elt)) ; (BEGIN . END)
2388 (cl-incf (car elt) shift)
2389 (cl-incf (cdr elt) shift))
2390 ((stringp (car elt)) ; (TEXT . POSITION)
2391 (cl-incf (cdr elt) (* (if (natnump (cdr elt)) 1 -1) shift)))
2392 ((null (car elt)) ; (nil PROPERTY VALUE BEG . END)
2393 (let ((cons (nthcdr 3 elt)))
2394 (cl-incf (car cons) shift)
2395 (cl-incf (cdr cons) shift)))
2396 ((and (featurep 'xemacs)
2397 (extentp (car elt))) ; (EXTENT START END)
2398 (cl-incf (nth 1 elt) shift)
2399 (cl-incf (nth 2 elt) shift)))
2400 (setq list (cdr list))))))
2402 (defvar erc-valid-nick-regexp "[]a-zA-Z^[;\\`_{}|][]^[;\\`_{}|a-zA-Z0-9-]*"
2403 "Regexp which matches all valid characters in a IRC nickname.")
2405 (defun erc-is-valid-nick-p (nick)
2406 "Check if NICK is a valid IRC nickname."
2407 (string-match (concat "^" erc-valid-nick-regexp "$") nick))
2409 (defun erc-display-line (string &optional buffer)
2410 "Display STRING in the ERC BUFFER.
2411 All screen output must be done through this function. If BUFFER is nil
2412 or omitted, the default ERC buffer for the `erc-session-server' is used.
2413 The BUFFER can be an actual buffer, a list of buffers, 'all or 'active.
2414 If BUFFER = 'all, the string is displayed in all the ERC buffers for the
2415 current session. 'active means the current active buffer
2416 \(`erc-active-buffer'). If the buffer can't be resolved, the current
2417 buffer is used. `erc-display-line-1' is used to display STRING.
2419 If STRING is nil, the function does nothing."
2420 (let ((inhibit-point-motion-hooks t)
2423 ((bufferp buffer) (list buffer))
2424 ((listp buffer) buffer)
2425 ((processp buffer) (list (process-buffer buffer)))
2427 ;; Hmm, or all of the same session server?
2428 (erc-buffer-list nil erc-server-process))
2429 ((and (eq 'active buffer) (erc-active-buffer))
2430 (list (erc-active-buffer)))
2431 ((erc-server-buffer-live-p)
2432 (list (process-buffer erc-server-process)))
2433 (t (list (current-buffer)))))
2434 (when (buffer-live-p buf)
2435 (erc-display-line-1 string buf)
2436 (add-to-list 'new-bufs buf)))
2437 (when (null new-bufs)
2438 (if (erc-server-buffer-live-p)
2439 (erc-display-line-1 string (process-buffer erc-server-process))
2440 (erc-display-line-1 string (current-buffer))))))
2442 (defun erc-display-message-highlight (type string)
2443 "Highlight STRING according to TYPE, where erc-TYPE-face is an ERC face.
2445 See also `erc-make-notice'."
2446 (cond ((eq type 'notice)
2447 (erc-make-notice string))
2449 (erc-put-text-property
2451 'face (or (intern-soft
2452 (concat "erc-" (symbol-name type) "-face"))
2457 (defvar erc-lurker-state nil
2458 "Track the time of the last PRIVMSG for each (server,nick) pair.
2460 This is implemented as a hash of hashes, where the outer key is
2461 the canonicalized server name (as returned by
2462 `erc-canonicalize-server-name') and the outer value is a hash
2463 table mapping nicks (as returned by `erc-lurker-maybe-trim') to
2464 the times of their most recently received PRIVMSG on any channel
2465 on the given server.")
2467 (defcustom erc-lurker-trim-nicks t
2468 "If t, trim trailing `erc-lurker-ignore-chars' from nicks.
2470 This causes e.g. nick and nick` to be considered as the same
2471 individual for activity tracking and lurkiness detection
2476 (defcustom erc-lurker-ignore-chars "`_"
2477 "Characters at the end of a nick to strip for activity tracking purposes.
2479 See also `erc-lurker-trim-nicks'."
2483 (defun erc-lurker-maybe-trim (nick)
2484 "Maybe trim trailing `erc-lurker-ignore-chars' from NICK.
2486 Returns NICK unmodified unless `erc-lurker-trim-nicks' is
2488 (if erc-lurker-trim-nicks
2489 (replace-regexp-in-string
2491 (mapconcat (lambda (char)
2492 (regexp-quote (char-to-string char)))
2493 erc-lurker-ignore-chars ""))
2497 (defcustom erc-lurker-hide-list nil
2498 "List of IRC type messages to hide when sent by lurkers.
2500 A typical value would be '(\"JOIN\" \"PART\" \"QUIT\").
2501 See also `erc-lurker-p' and `erc-hide-list'."
2503 :type 'erc-message-type)
2505 (defcustom erc-lurker-threshold-time (* 60 60 24) ; 24h by default
2506 "Nicks from which no PRIVMSGs have been received within this
2507 interval (in units of seconds) are considered lurkers by
2508 `erc-lurker-p' and as a result their messages of types in
2509 `erc-lurker-hide-list' will be hidden."
2513 (defun erc-lurker-initialize ()
2514 "Initialize ERC lurker tracking functionality.
2516 This function adds `erc-lurker-update-status' to
2517 `erc-insert-pre-hook' in order to record the time of each nick's
2518 most recent PRIVMSG as well as initializing the state variable
2519 storing this information."
2520 (setq erc-lurker-state (make-hash-table :test 'equal))
2521 (add-hook 'erc-insert-pre-hook 'erc-lurker-update-status))
2523 (defun erc-lurker-cleanup ()
2524 "Remove all last PRIVMSG state older than `erc-lurker-threshold-time'.
2526 This should be called regularly to avoid excessive resource
2527 consumption for long-lived IRC or Emacs sessions."
2529 (lambda (server hash)
2531 (lambda (nick last-PRIVMSG-time)
2533 (> (float-time (time-subtract
2536 erc-lurker-threshold-time)
2537 (remhash nick hash)))
2539 (if (zerop (hash-table-count hash))
2540 (remhash server erc-lurker-state)))
2543 (defvar erc-lurker-cleanup-count 0
2544 "Internal counter variable for use with `erc-lurker-cleanup-interval'.")
2546 (defvar erc-lurker-cleanup-interval 100
2547 "Specifies frequency of cleaning up stale erc-lurker state.
2549 `erc-lurker-update-status' calls `erc-lurker-cleanup' once for
2550 every `erc-lurker-cleanup-interval' updates to
2551 `erc-lurker-state'. This is designed to limit the memory
2552 consumption of lurker state during long Emacs sessions and/or ERC
2553 sessions with large numbers of incoming PRIVMSGs.")
2555 (defun erc-lurker-update-status (message)
2556 "Update `erc-lurker-state' if necessary.
2558 This function is called from `erc-insert-pre-hook'. If the
2559 current message is a PRIVMSG, update `erc-lurker-state' to
2560 reflect the fact that its sender has issued a PRIVMSG at the
2561 current time. Otherwise, take no action.
2563 This function depends on the fact that `erc-display-message'
2564 dynamically binds `parsed', which is used to check if the current
2565 message is a PRIVMSG and to determine its sender. See also
2566 `erc-lurker-trim-nicks' and `erc-lurker-ignore-chars'.
2568 In order to limit memory consumption, this function also calls
2569 `erc-lurker-cleanup' once every `erc-lurker-cleanup-interval'
2570 updates of `erc-lurker-state'."
2571 (when (and (boundp 'parsed) (erc-response-p parsed))
2572 (let* ((command (erc-response.command parsed))
2574 (erc-lurker-maybe-trim
2575 (car (erc-parse-user (erc-response.sender parsed)))))
2577 (erc-canonicalize-server-name erc-server-announced-name)))
2578 (when (equal command "PRIVMSG")
2579 (when (>= (cl-incf erc-lurker-cleanup-count)
2580 erc-lurker-cleanup-interval)
2581 (setq erc-lurker-cleanup-count 0)
2582 (erc-lurker-cleanup))
2583 (unless (gethash server erc-lurker-state)
2584 (puthash server (make-hash-table :test 'equal) erc-lurker-state))
2585 (puthash sender (current-time)
2586 (gethash server erc-lurker-state))))))
2588 (defun erc-lurker-p (nick)
2589 "Predicate indicating NICK's lurking status on the current server.
2591 Lurking is the condition where NICK has issued no PRIVMSG on this
2592 server within `erc-lurker-threshold-time'. See also
2593 `erc-lurker-trim-nicks' and `erc-lurker-ignore-chars'."
2594 (unless erc-lurker-state (erc-lurker-initialize))
2596 (erc-canonicalize-server-name erc-server-announced-name))
2598 (gethash (erc-lurker-maybe-trim nick)
2599 (gethash server erc-lurker-state (make-hash-table)))))
2600 (or (null last-PRIVMSG-time)
2602 (time-subtract (current-time) last-PRIVMSG-time))
2603 erc-lurker-threshold-time))))
2605 (defcustom erc-common-server-suffixes
2606 '(("openprojects.net$" . "OPN")
2607 ("freenode.net$" . "freenode")
2608 ("oftc.net$" . "OFTC"))
2609 "Alist of common server name suffixes.
2610 This variable is used in mode-line display to save screen
2611 real estate. Set it to nil if you want to avoid changing
2612 displayed hostnames."
2613 :group 'erc-mode-line-and-header
2616 (defun erc-canonicalize-server-name (server)
2617 "Returns the canonical network name for SERVER if any,
2618 otherwise `erc-server-announced-name'. SERVER is matched against
2619 `erc-common-server-suffixes'."
2621 (or (cdar (erc-remove-if-not
2622 (lambda (net) (string-match (car net) server))
2623 erc-common-server-suffixes))
2624 erc-server-announced-name)))
2626 (defun erc-hide-current-message-p (parsed)
2627 "Predicate indicating whether the parsed ERC response PARSED should be hidden.
2629 Messages are always hidden if the message type of PARSED appears in
2630 `erc-hide-list'. In addition, messages whose type is a member of
2631 `erc-lurker-hide-list' are hidden if `erc-lurker-p' returns true."
2632 (let* ((command (erc-response.command parsed))
2633 (sender (car (erc-parse-user (erc-response.sender parsed)))))
2634 (or (member command erc-hide-list)
2635 (and (member command erc-lurker-hide-list) (erc-lurker-p sender)))))
2637 (defun erc-display-message (parsed type buffer msg &rest args)
2638 "Display MSG in BUFFER.
2640 ARGS, PARSED, and TYPE are used to format MSG sensibly.
2642 See also `erc-format-message' and `erc-display-line'."
2643 (let ((string (if (symbolp msg)
2644 (apply 'erc-format-message msg args)
2651 (mapc (lambda (type)
2653 (erc-display-message-highlight type string)))
2657 (erc-display-message-highlight type string))))
2659 (if (not (erc-response-p parsed))
2660 (erc-display-line string buffer)
2661 (unless (erc-hide-current-message-p parsed)
2662 (erc-put-text-property 0 (length string) 'erc-parsed parsed string)
2663 (erc-put-text-property 0 (length string) 'rear-sticky t string)
2664 (erc-display-line string buffer)))))
2666 (defun erc-message-type-member (position list)
2667 "Return non-nil if the erc-parsed text-property at POSITION is in LIST.
2669 This function relies on the erc-parsed text-property being
2671 (let ((prop-val (erc-get-parsed-vector position)))
2672 (and prop-val (member (erc-response.command prop-val) list))))
2674 (defvar erc-send-input-line-function 'erc-send-input-line)
2675 (make-variable-buffer-local 'erc-send-input-line-function)
2677 (defun erc-send-input-line (target line &optional force)
2678 "Send LINE to TARGET.
2680 See also `erc-server-send'."
2681 (setq line (format "PRIVMSG %s :%s"
2683 ;; If the line is empty, we still want to
2684 ;; send it - i.e. an empty pasted line.
2685 (if (string= line "\n")
2688 (erc-server-send line force target))
2690 (defun erc-get-arglist (fun)
2691 "Return the argument list of a function without the parens."
2692 (let ((arglist (format "%S" (erc-function-arglist fun))))
2693 (if (string-match "^(\\(.*\\))$" arglist)
2694 (match-string 1 arglist)
2697 (defun erc-command-no-process-p (str)
2698 "Return non-nil if STR is an ERC command that can be run when the process
2699 is not alive, nil otherwise."
2700 (let ((fun (erc-extract-command-from-line str)))
2703 (get (car fun) 'process-not-needed))))
2705 (defun erc-command-name (cmd)
2706 "For CMD being the function name of a ERC command, something like
2707 erc-cmd-FOO, this returns a string /FOO."
2708 (let ((command-name (symbol-name cmd)))
2709 (if (string-match "^erc-cmd-\\(.*\\)$" command-name)
2710 (concat "/" (match-string 1 command-name))
2713 (defun erc-process-input-line (line &optional force no-command)
2714 "Translate LINE to an RFC1459 command and send it based.
2715 Returns non-nil if the command is actually sent to the server, and nil
2718 If the command in the LINE is not bound as a function `erc-cmd-<COMMAND>',
2719 it is passed to `erc-cmd-default'. If LINE is not a command (i.e. doesn't
2720 start with /<COMMAND>) then it is sent as a message.
2722 An optional FORCE argument forces sending the line when flood
2723 protection is in effect. The optional NO-COMMAND argument prohibits
2724 this function from interpreting the line as a command."
2725 (let ((command-list (erc-extract-command-from-line line)))
2726 (if (and command-list
2728 (let* ((cmd (nth 0 command-list))
2729 (args (nth 1 command-list)))
2734 (wrong-number-of-arguments
2735 (erc-display-message nil 'error (current-buffer) 'incorrect-args
2736 ?c (erc-command-name cmd)
2737 ?u (or (erc-get-arglist cmd)
2740 (or (documentation cmd) "")))
2742 (let ((r (erc-default-target)))
2744 (funcall erc-send-input-line-function r line force)
2745 (erc-display-message nil 'error (current-buffer) 'no-target)
2748 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2749 ;; Input commands handlers
2750 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2752 (defun erc-cmd-AMSG (line)
2753 "Send LINE to all channels of the current server that you are on."
2754 (interactive "sSend to all channels you're on: ")
2755 (setq line (erc-trim-string line))
2756 (erc-with-all-buffers-of-server nil
2758 (erc-channel-p (erc-default-target)))
2759 (erc-send-message line)))
2760 (put 'erc-cmd-AMSG 'do-not-parse-args t)
2762 (defun erc-cmd-SAY (line)
2763 "Send LINE to the current query or channel as a message, not a command.
2765 Use this when you want to send a message with a leading '/'. Note
2766 that since multi-line messages are never a command, you don't
2767 need this when pasting multiple lines of text."
2768 (if (string-match "^\\s-*$" line)
2770 (string-match "^ ?\\(.*\\)" line)
2771 (erc-process-input-line (match-string 1 line) nil t)))
2772 (put 'erc-cmd-SAY 'do-not-parse-args t)
2774 (defun erc-cmd-SET (line)
2775 "Set the variable named by the first word in LINE to some VALUE.
2776 VALUE is computed by evaluating the rest of LINE in Lisp."
2778 ((string-match "^\\s-*\\(\\S-+\\)\\s-+\\(.*\\)$" line)
2779 (let ((var (read (concat "erc-" (match-string 1 line))))
2780 (val (read (match-string 2 line))))
2783 (set var (eval val))
2784 (erc-display-message
2785 nil nil 'active (format "Set %S to %S" var val))
2787 (setq var (read (match-string 1 line)))
2790 (set var (eval val))
2791 (erc-display-message
2792 nil nil 'active (format "Set %S to %S" var val))
2794 (erc-display-message nil 'error 'active 'variable-not-bound)
2796 ((string-match "^\\s-*$" line)
2798 (concat "Available user variables:\n"
2803 (let ((val (symbol-value var)))
2804 (concat (format "%S:" var)
2806 (concat "\n" (pp-to-string val))
2807 (format " %S\n" val)))))
2808 (apropos-internal "^erc-" 'custom-variable-p))))
2809 (current-buffer)) t)
2811 (defalias 'erc-cmd-VAR 'erc-cmd-SET)
2812 (defalias 'erc-cmd-VARIABLE 'erc-cmd-SET)
2813 (put 'erc-cmd-SET 'do-not-parse-args t)
2814 (put 'erc-cmd-SET 'process-not-needed t)
2816 (defun erc-cmd-default (line)
2819 Commands for which no erc-cmd-xxx exists, are tunneled through
2820 this function. LINE is sent to the server verbatim, and
2821 therefore has to contain the command itself as well."
2822 (erc-log (format "cmd: DEFAULT: %s" line))
2823 (erc-server-send (substring line 1))
2826 (defun erc-cmd-IGNORE (&optional user)
2827 "Ignore USER. This should be a regexp matching nick!user@host.
2828 If no USER argument is specified, list the contents of `erc-ignore-list'."
2830 (let ((quoted (regexp-quote user)))
2831 (when (and (not (string= user quoted))
2832 (y-or-n-p (format "Use regexp-quoted form (%s) instead? "
2836 (erc-make-notice (format "Now ignoring %s" user))
2838 (erc-with-server-buffer (add-to-list 'erc-ignore-list user)))
2839 (if (null (erc-with-server-buffer erc-ignore-list))
2840 (erc-display-line (erc-make-notice "Ignore list is empty") 'active)
2841 (erc-display-line (erc-make-notice "Ignore list:") 'active)
2842 (mapc #'(lambda (item)
2843 (erc-display-line (erc-make-notice item)
2845 (erc-with-server-buffer erc-ignore-list))))
2848 (defun erc-cmd-UNIGNORE (user)
2849 "Remove the user specified in USER from the ignore list."
2850 (let ((ignored-nick (car (erc-with-server-buffer
2851 (erc-member-ignore-case (regexp-quote user)
2852 erc-ignore-list)))))
2853 (unless ignored-nick
2854 (if (setq ignored-nick (erc-ignored-user-p user))
2855 (unless (y-or-n-p (format "Remove this regexp (%s)? "
2857 (setq ignored-nick nil))
2859 (erc-make-notice (format "%s is not currently ignored!" user))
2863 (erc-make-notice (format "No longer ignoring %s" user))
2865 (erc-with-server-buffer
2866 (setq erc-ignore-list (delete ignored-nick erc-ignore-list)))))
2869 (defun erc-cmd-CLEAR ()
2870 "Clear the window content."
2873 (put 'erc-cmd-CLEAR 'process-not-needed t)
2875 (defun erc-cmd-OPS ()
2876 "Show the ops in the current channel."
2879 (if erc-channel-users
2880 (maphash (lambda (nick user-data)
2881 (let ((cuser (cdr user-data)))
2883 (erc-channel-user-op cuser))
2884 (setq ops (cons (erc-server-user-nickname
2888 (setq ops (sort ops 'string-lessp))
2890 (erc-display-message
2891 nil 'notice (current-buffer) 'ops
2892 ?i (length ops) ?s (if (> (length ops) 1) "s" "")
2893 ?o (mapconcat 'identity ops " "))
2894 (erc-display-message nil 'notice (current-buffer) 'ops-none)))
2897 (defun erc-cmd-COUNTRY (tld)
2898 "Display the country associated with the top level domain TLD."
2899 (require 'mail-extr)
2900 (let ((co (ignore-errors (what-domain tld))))
2902 (erc-display-message
2903 nil 'notice 'active 'country ?c co ?d tld)
2904 (erc-display-message
2905 nil 'notice 'active 'country-unknown ?d tld))
2907 (put 'erc-cmd-COUNTRY 'process-not-needed t)
2909 (defun erc-cmd-AWAY (line)
2910 "Mark the user as being away, the reason being indicated by LINE.
2911 If no reason is given, unset away status."
2912 (when (string-match "^\\s-*\\(.*\\)$" line)
2913 (let ((reason (match-string 1 line)))
2914 (erc-log (format "cmd: AWAY: %s" reason))
2916 (if (string= reason "")
2918 (concat "AWAY :" reason))))
2920 (put 'erc-cmd-AWAY 'do-not-parse-args t)
2922 (defun erc-cmd-GAWAY (line)
2923 "Mark the user as being away everywhere, the reason being indicated by LINE."
2924 ;; on all server buffers.
2925 (erc-with-all-buffers-of-server nil
2926 #'erc-open-server-buffer-p
2927 (erc-cmd-AWAY line)))
2928 (put 'erc-cmd-GAWAY 'do-not-parse-args t)
2930 (defun erc-cmd-CTCP (nick cmd &rest args)
2931 "Send a Client To Client Protocol message to NICK.
2933 CMD is the CTCP command, possible values being ECHO, FINGER, CLIENTINFO, TIME,
2934 VERSION and so on. It is called with ARGS."
2935 (let ((str (concat cmd
2937 (concat " " (mapconcat #'identity args " "))))))
2938 (erc-log (format "cmd: CTCP [%s]: [%s]" nick str))
2939 (erc-send-ctcp-message nick str)
2942 (defun erc-cmd-HELP (&optional func)
2943 "Popup help information.
2945 If FUNC contains a valid function or variable, help about that
2946 will be displayed. If FUNC is empty, display an apropos about
2947 ERC commands. Otherwise, do `apropos' in the ERC namespace
2951 To find out about erc and bbdb, do
2954 For help about the WHOIS command, do:
2957 For a list of user commands (/join /part, ...):
2960 (let* ((sym (or (let ((sym (intern-soft
2961 (concat "erc-cmd-" (upcase func)))))
2962 (if (and sym (or (boundp sym) (fboundp sym)))
2965 (let ((sym (intern-soft func)))
2966 (if (and sym (or (boundp sym) (fboundp sym)))
2969 (let ((sym (intern-soft (concat "erc-" func))))
2970 (if (and sym (or (boundp sym) (fboundp sym)))
2975 ((boundp sym) (describe-variable sym))
2976 ((fboundp sym) (describe-function sym))
2978 (apropos-command (concat "erc-.*" func) nil
2981 (get x 'custom-type))))
2983 (apropos "erc-cmd-")
2984 (message "Type C-h m to get additional information about keybindings.")
2987 (defalias 'erc-cmd-H 'erc-cmd-HELP)
2988 (put 'erc-cmd-HELP 'process-not-needed t)
2990 (defun erc-cmd-JOIN (channel &optional key)
2991 "Join the channel given in CHANNEL, optionally with KEY.
2992 If CHANNEL is specified as \"-invite\", join the channel to which you
2993 were most recently invited. See also `invitation'."
2995 (if (string= (upcase channel) "-INVITE")
2997 (setq chnl erc-invitation)
2998 (erc-display-message nil 'error (current-buffer) 'no-invitation))
2999 (setq chnl (erc-ensure-channel-name channel)))
3001 ;; Prevent double joining of same channel on same server.
3002 (let ((joined-channels
3003 (mapcar #'(lambda (chanbuf)
3004 (with-current-buffer chanbuf (erc-default-target)))
3005 (erc-channel-list erc-server-process))))
3006 (if (erc-member-ignore-case chnl joined-channels)
3007 (switch-to-buffer (car (erc-member-ignore-case chnl
3009 (erc-log (format "cmd: JOIN: %s" chnl))
3011 (erc-server-send (format "JOIN %s %s" chnl key))
3012 (erc-server-send (format "JOIN %s" chnl)))))))
3015 (defalias 'erc-cmd-CHANNEL 'erc-cmd-JOIN)
3016 (defalias 'erc-cmd-J 'erc-cmd-JOIN)
3018 (defvar erc-channel-new-member-names nil
3019 "If non-nil, a names list is currently being received.
3021 If non-nil, this variable is a hash-table that associates
3022 received nicks with t.")
3023 (make-variable-buffer-local 'erc-channel-new-member-names)
3025 (defun erc-cmd-NAMES (&optional channel)
3026 "Display the users in CHANNEL.
3027 If CHANNEL is not specified, display the users in the current channel.
3028 This function clears the channel name list first, then sends the
3030 (let ((tgt (or (and (erc-channel-p channel) channel)
3031 (erc-default-target))))
3032 (if (and tgt (erc-channel-p tgt))
3034 (erc-log (format "cmd: DEFAULT: NAMES %s" tgt))
3037 (erc-channel-begin-receiving-names))
3038 (erc-server-send (concat "NAMES " tgt)))
3039 (erc-display-message nil 'error (current-buffer) 'no-default-channel)))
3041 (defalias 'erc-cmd-N 'erc-cmd-NAMES)
3043 (defun erc-cmd-KICK (target &optional reason-or-nick &rest reasonwords)
3044 "Kick the user indicated in LINE from the current channel.
3045 LINE has the format: \"#CHANNEL NICK REASON\" or \"NICK REASON\"."
3046 (let ((reasonstring (mapconcat 'identity reasonwords " ")))
3047 (if (string= "" reasonstring)
3048 (setq reasonstring (format "Kicked by %s" (erc-current-nick))))
3049 (if (erc-channel-p target)
3050 (let ((nick reason-or-nick))
3051 (erc-log (format "cmd: KICK: %s/%s: %s" nick target reasonstring))
3052 (erc-server-send (format "KICK %s %s :%s" target nick reasonstring)
3056 (let ((ch (erc-default-target)))
3057 (setq reasonstring (concat
3058 (if reason-or-nick (concat reason-or-nick " "))
3063 (format "cmd: KICK: %s/%s: %s" target ch reasonstring))
3065 (format "KICK %s %s :%s" ch target reasonstring) nil ch))
3066 (erc-display-message nil 'error (current-buffer)
3067 'no-default-channel))
3070 (defvar erc-script-args nil)
3072 (defun erc-cmd-LOAD (line)
3073 "Load the script provided in the LINE.
3074 If LINE continues beyond the file name, the rest of
3075 it is put in a (local) variable `erc-script-args',
3076 which can be used in Emacs Lisp scripts.
3078 The optional FORCE argument is ignored here - you can't force loading
3079 a script after exceeding the flood threshold."
3081 ((string-match "^\\s-*\\(\\S-+\\)\\(.*\\)$" line)
3082 (let* ((file-to-find (match-string 1 line))
3083 (erc-script-args (match-string 2 line))
3084 (file (erc-find-file file-to-find erc-script-path)))
3085 (erc-log (format "cmd: LOAD: %s" file-to-find))
3088 (erc-display-message nil 'error (current-buffer)
3089 'cannot-find-file ?f file-to-find))
3090 ((not (file-readable-p file))
3091 (erc-display-message nil 'error (current-buffer)
3092 'cannot-read-file ?f file))
3094 (message "Loading \'%s\'..." file)
3095 (erc-load-script file)
3096 (message "Loading \'%s\'...done" file))))
3100 (defun erc-cmd-WHOIS (user &optional server)
3101 "Display whois information for USER.
3103 If SERVER is non-nil, use that, rather than the current server."
3104 ;; FIXME: is the above docstring correct? -- Lawrence 2004-01-08
3105 (let ((send (if server
3106 (format "WHOIS %s %s" user server)
3107 (format "WHOIS %s" user))))
3108 (erc-log (format "cmd: %s" send))
3109 (erc-server-send send)
3111 (defalias 'erc-cmd-WI 'erc-cmd-WHOIS)
3113 (defun erc-cmd-WHOAMI ()
3114 "Display whois information about yourself."
3115 (erc-cmd-WHOIS (erc-current-nick))
3118 (defun erc-cmd-IDLE (nick)
3119 "Show the length of time NICK has been idle."
3120 (let ((origbuf (current-buffer))
3122 (erc-with-server-buffer
3123 (add-to-list 'symlist
3124 (cons (erc-once-with-server-event
3127 (erc-response.command-args parsed))))
3128 'erc-server-311-functions))
3129 (add-to-list 'symlist
3130 (cons (erc-once-with-server-event
3133 (erc-response.command-args parsed))))
3134 'erc-server-312-functions))
3135 (add-to-list 'symlist
3136 (cons (erc-once-with-server-event
3139 (erc-response.command-args parsed))))
3140 'erc-server-318-functions))
3141 (add-to-list 'symlist
3142 (cons (erc-once-with-server-event
3145 (erc-response.command-args parsed))))
3146 'erc-server-319-functions))
3147 (add-to-list 'symlist
3148 (cons (erc-once-with-server-event
3151 (erc-response.command-args parsed))))
3152 'erc-server-320-functions))
3153 (add-to-list 'symlist
3154 (cons (erc-once-with-server-event
3157 (erc-response.command-args parsed))))
3158 'erc-server-330-functions))
3159 (add-to-list 'symlist
3160 (cons (erc-once-with-server-event
3165 (erc-response.command-args parsed)))))
3168 (format "%s has been idle for %s."
3169 (erc-string-no-properties ,nick)
3170 (erc-seconds-to-string idleseconds)))
3173 'erc-server-317-functions))
3175 ;; Send the WHOIS command.
3176 (erc-cmd-WHOIS nick)
3178 ;; Remove the uninterned symbols from the server hooks that did not run.
3179 (run-at-time 20 nil `(lambda ()
3180 (with-current-buffer ,(current-buffer)
3181 (dolist (sym ',symlist)
3182 (let ((hooksym (cdr sym))
3183 (funcsym (car sym)))
3184 (remove-hook hooksym funcsym t))))))))
3187 (defun erc-cmd-DESCRIBE (line)
3188 "Pose some action to a certain user.
3189 LINE has the format \"USER ACTION\"."
3192 "^\\s-*\\(\\S-+\\)\\s-\\(.*\\)$" line)
3193 (let ((dst (match-string 1 line))
3194 (s (match-string 2 line)))
3195 (erc-log (format "cmd: DESCRIBE: [%s] %s" dst s))
3196 (erc-send-action dst s))
3199 (put 'erc-cmd-DESCRIBE 'do-not-parse-args t)
3201 (defun erc-cmd-ME (line)
3202 "Send LINE as an action."
3204 ((string-match "^\\s-\\(.*\\)$" line)
3205 (let ((s (match-string 1 line)))
3206 (erc-log (format "cmd: ME: %s" s))
3207 (erc-send-action (erc-default-target) s))
3210 (put 'erc-cmd-ME 'do-not-parse-args t)
3212 (defun erc-cmd-ME\'S (line)
3213 "Do a /ME command, but add the string \" 's\" to the beginning."
3214 (erc-cmd-ME (concat " 's" line)))
3215 (put 'erc-cmd-ME\'S 'do-not-parse-args t)
3217 (defun erc-cmd-LASTLOG (line)
3218 "Show all lines in the current buffer matching the regexp LINE.
3220 If a match spreads across multiple lines, all those lines are shown.
3222 The lines are shown in a buffer named `*Occur*'.
3223 It serves as a menu to find any of the occurrences in this buffer.
3224 \\[describe-mode] in that buffer will explain how.
3226 If LINE contains upper case characters (excluding those preceded by `\'),
3227 the matching is case-sensitive."
3230 (put 'erc-cmd-LASTLOG 'do-not-parse-args t)
3231 (put 'erc-cmd-LASTLOG 'process-not-needed t)
3233 (defun erc-send-message (line &optional force)
3234 "Send LINE to the current channel or user and display it.
3236 See also `erc-message' and `erc-display-line'."
3237 (erc-message "PRIVMSG" (concat (erc-default-target) " " line) force)
3239 (concat (erc-format-my-nick) line)
3241 ;; FIXME - treat multiline, run hooks, or remove me?
3244 (defun erc-cmd-MODE (line)
3245 "Change or display the mode value of a channel or user.
3246 The first word specifies the target. The rest is the mode string
3249 If only one word is given, display the mode of that target.
3251 A list of valid mode strings for Freenode may be found at
3252 URL `http://freenode.net/using_the_network.shtml'."
3254 ((string-match "^\\s-\\(.*\\)$" line)
3255 (let ((s (match-string 1 line)))
3256 (erc-log (format "cmd: MODE: %s" s))
3257 (erc-server-send (concat "MODE " line)))
3260 (put 'erc-cmd-MODE 'do-not-parse-args t)
3262 (defun erc-cmd-NOTICE (channel-or-user &rest message)
3263 "Send a notice to the channel or user given as the first word.
3264 The rest is the message to send."
3265 (erc-message "NOTICE" (concat channel-or-user " "
3266 (mapconcat #'identity message " "))))
3268 (defun erc-cmd-MSG (line)
3269 "Send a message to the channel or user given as the first word in LINE.
3271 The rest of LINE is the message to send."
3272 (erc-message "PRIVMSG" line))
3274 (defalias 'erc-cmd-M 'erc-cmd-MSG)
3275 (put 'erc-cmd-MSG 'do-not-parse-args t)
3277 (defun erc-cmd-SQUERY (line)
3278 "Send a Service Query to the service given as the first word in LINE.
3280 The rest of LINE is the message to send."
3281 (erc-message "SQUERY" line))
3283 (defun erc-cmd-NICK (nick)
3284 "Change current nickname to NICK."
3285 (erc-log (format "cmd: NICK: %s (erc-bad-nick: %S)" nick erc-bad-nick))
3286 (let ((nicklen (cdr (assoc "NICKLEN" (erc-with-server-buffer
3287 erc-server-parameters)))))
3288 (and nicklen (> (length nick) (string-to-number nicklen))
3289 (erc-display-message
3290 nil 'notice 'active 'nick-too-long
3291 ?i (length nick) ?l nicklen)))
3292 (erc-server-send (format "NICK %s" nick))
3294 (erc-set-current-nick nick)
3295 (erc-update-mode-line)
3296 (setq erc-bad-nick nil)))
3299 (defun erc-cmd-PART (line)
3300 "When LINE is an empty string, leave the current channel.
3301 Otherwise leave the channel indicated by LINE."
3303 ((string-match "^\\s-*\\([&#+!]\\S-+\\)\\s-?\\(.*\\)$" line)
3304 (let* ((ch (match-string 1 line))
3305 (msg (match-string 2 line))
3306 (reason (funcall erc-part-reason (if (equal msg "") nil msg))))
3307 (erc-log (format "cmd: PART: %s: %s" ch reason))
3308 (erc-server-send (if (string= reason "")
3309 (format "PART %s" ch)
3310 (format "PART %s :%s" ch reason))
3313 ((string-match "^\\s-*\\(.*\\)$" line)
3314 (let* ((ch (erc-default-target))
3315 (msg (match-string 1 line))
3316 (reason (funcall erc-part-reason (if (equal msg "") nil msg))))
3317 (if (and ch (erc-channel-p ch))
3319 (erc-log (format "cmd: PART: %s: %s" ch reason))
3320 (erc-server-send (if (string= reason "")
3321 (format "PART %s" ch)
3322 (format "PART %s :%s" ch reason))
3324 (erc-display-message nil 'error (current-buffer) 'no-target)))
3327 (put 'erc-cmd-PART 'do-not-parse-args t)
3329 (defalias 'erc-cmd-LEAVE 'erc-cmd-PART)
3331 (defun erc-cmd-PING (recipient)
3333 (let ((time (format "%f" (erc-current-time))))
3334 (erc-log (format "cmd: PING: %s" time))
3335 (erc-cmd-CTCP recipient "PING" time)))
3337 (defun erc-cmd-QUOTE (line)
3338 "Send LINE directly to the server.
3339 All the text given as argument is sent to the sever as unmodified,
3340 just as you provided it. Use this command with care!"
3342 ((string-match "^ ?\\(.+\\)$" line)
3343 (erc-server-send (match-string 1 line)))
3345 (put 'erc-cmd-QUOTE 'do-not-parse-args t)
3347 (defcustom erc-query-display 'window
3348 "Indicates how to display query buffers when using the /QUERY
3349 command to talk to someone.
3351 The default behavior is to display the message in a new window
3352 and bring it to the front. See the documentation for
3353 `erc-join-buffer' for a description of the available choices.
3355 See also `erc-auto-query' to decide how private messages from
3356 other people should be displayed."
3358 :type '(choice (const :tag "Split window and select" window)
3359 (const :tag "Split window, don't select" window-noselect)
3360 (const :tag "New frame" frame)
3361 (const :tag "Bury in new buffer" bury)
3362 (const :tag "Use current buffer" buffer)
3363 (const :tag "Use current buffer" t)))
3365 (defun erc-cmd-QUERY (&optional user)
3366 "Open a query with USER.
3367 The type of query window/frame/etc will depend on the value of
3368 `erc-query-display'.
3370 If USER is omitted, close the current query buffer if one exists
3371 - except this is broken now ;-)"
3373 (list (read-from-minibuffer "Start a query with: " nil)))
3374 (let ((session-buffer (erc-server-buffer))
3375 (erc-join-buffer erc-query-display))
3377 (erc-query user session-buffer)
3378 ;; currently broken, evil hack to display help anyway
3379 ;(erc-delete-query))))
3380 (signal 'wrong-number-of-arguments ""))))
3381 (defalias 'erc-cmd-Q 'erc-cmd-QUERY)
3383 (defun erc-quit-reason-normal (&optional s)
3384 "Normal quit message.
3386 If S is non-nil, it will be used as the quit reason."
3388 (format "\C-bERC\C-b %s (IRC client for Emacs)"; - \C-b%s\C-b"
3389 erc-version-string) ; erc-official-location)
3392 (defun erc-quit-reason-zippy (&optional s)
3393 "Zippy quit message.
3395 If S is non-nil, it will be used as the quit reason."
3398 (erc-replace-regexp-in-string "\n" "" (yow))
3399 (erc-quit-reason-normal))))
3401 (make-obsolete 'erc-quit-reason-zippy "it will be removed." "24.4")
3403 (defun erc-quit-reason-various (s)
3404 "Choose a quit reason based on S (a string)."
3405 (when (featurep 'xemacs) (require 'poe))
3406 (let ((res (car (assoc-default (or s "")
3407 erc-quit-reason-various-alist 'string-match))))
3409 ((functionp res) (funcall res))
3412 (t (erc-quit-reason-normal)))))
3414 (defun erc-part-reason-normal (&optional s)
3415 "Normal part message.
3417 If S is non-nil, it will be used as the quit reason."
3419 (format "\C-bERC\C-b %s (IRC client for Emacs)"; - \C-b%s\C-b"
3420 erc-version-string) ; erc-official-location)
3423 (defun erc-part-reason-zippy (&optional s)
3424 "Zippy part message.
3426 If S is non-nil, it will be used as the quit reason."
3429 (erc-replace-regexp-in-string "\n" "" (yow))
3430 (erc-part-reason-normal))))
3432 (make-obsolete 'erc-part-reason-zippy "it will be removed." "24.4")
3434 (defun erc-part-reason-various (s)
3435 "Choose a part reason based on S (a string)."
3436 (when (featurep 'xemacs) (require 'poe))
3437 (let ((res (car (assoc-default (or s "")
3438 erc-part-reason-various-alist 'string-match))))
3440 ((functionp res) (funcall res))
3443 (t (erc-part-reason-normal)))))
3445 (defun erc-cmd-QUIT (reason)
3446 "Disconnect from the current server.
3447 If REASON is omitted, display a default quit message, otherwise display
3448 the message given by REASON."
3452 ((string-match "^\\s-*\\(.*\\)$" reason)
3453 (let* ((s (match-string 1 reason))
3454 (buffer (erc-server-buffer))
3455 (reason (funcall erc-quit-reason (if (equal s "") nil s)))
3457 (with-current-buffer (if (and buffer
3461 (erc-log (format "cmd: QUIT: %s" reason))
3462 (setq erc-server-quitting t)
3463 (erc-set-active-buffer (erc-server-buffer))
3464 (setq server-proc erc-server-process)
3465 (erc-server-send (format "QUIT :%s" reason)))
3466 (run-hook-with-args 'erc-quit-hook server-proc)
3467 (when erc-kill-queries-on-quit
3468 (erc-kill-query-buffers server-proc))
3469 ;; if the process has not been killed within 4 seconds, kill it
3472 (when (and (processp proc)
3473 (memq (process-status proc) '(run open)))
3474 (delete-process proc)))
3479 (defalias 'erc-cmd-BYE 'erc-cmd-QUIT)
3480 (defalias 'erc-cmd-EXIT 'erc-cmd-QUIT)
3481 (defalias 'erc-cmd-SIGNOFF 'erc-cmd-QUIT)
3482 (put 'erc-cmd-QUIT 'do-not-parse-args t)
3483 (put 'erc-cmd-QUIT 'process-not-needed t)
3485 (defun erc-cmd-GQUIT (reason)
3486 "Disconnect from all servers at once with the same quit REASON."
3487 (erc-with-all-buffers-of-server nil #'erc-open-server-buffer-p
3488 (erc-cmd-QUIT reason))
3489 (when erc-kill-queries-on-quit
3490 ;; if the query buffers have not been killed within 4 seconds,
3495 (dolist (buffer (erc-buffer-list (lambda (buf)
3496 (not (erc-server-buffer-p buf)))))
3497 (kill-buffer buffer)))))
3500 (defalias 'erc-cmd-GQ 'erc-cmd-GQUIT)
3501 (put 'erc-cmd-GQUIT 'do-not-parse-args t)
3502 (put 'erc-cmd-GQUIT 'process-not-needed t)
3504 (defun erc-cmd-RECONNECT ()
3505 "Try to reconnect to the current IRC server."
3506 (let ((buffer (erc-server-buffer))
3508 (unless (buffer-live-p buffer)
3509 (setq buffer (current-buffer)))
3510 (with-current-buffer buffer
3511 (setq erc-server-quitting nil)
3512 (setq erc-server-reconnecting t)
3513 (setq erc-server-reconnect-count 0)
3514 (setq process (get-buffer-process (erc-server-buffer)))
3516 (delete-process process)
3517 (erc-server-reconnect))
3518 (setq erc-server-reconnecting nil)))
3520 (put 'erc-cmd-RECONNECT 'process-not-needed t)
3522 (defun erc-cmd-SERVER (server)
3523 "Connect to SERVER, leaving existing connection intact."
3524 (erc-log (format "cmd: SERVER: %s" server))
3526 (erc :server server :nick (erc-current-nick))
3528 (erc-error "Cannot find host %s." server)))
3530 (put 'erc-cmd-SERVER 'process-not-needed t)
3532 (defvar motif-version-string)
3533 (defvar gtk-version-string)
3535 (defun erc-cmd-SV ()
3536 "Say the current ERC and Emacs version into channel."
3537 (erc-send-message (format "I'm using ERC %s with %s %s (%s%s) of %s."
3539 (if (featurep 'xemacs) "XEmacs" "GNU Emacs")
3541 system-configuration
3543 (cond ((featurep 'motif)
3544 (concat ", " (substring
3545 motif-version-string 4)))
3547 (concat ", GTK+ Version "
3548 gtk-version-string))
3549 ((featurep 'x-toolkit) ", X toolkit")
3551 (if (and (boundp 'x-toolkit-scroll-bars)
3552 (memq x-toolkit-scroll-bars
3554 (format ", %s scroll bars"
3555 (capitalize (symbol-name
3556 x-toolkit-scroll-bars)))
3558 (if (featurep 'multi-tty) ", multi-tty" ""))
3559 erc-emacs-build-time))
3562 (defun erc-cmd-SM ()
3563 "Say the current ERC modes into channel."
3564 (erc-send-message (format "I'm using the following modules: %s!"
3568 (defun erc-cmd-DEOP (&rest people)
3569 "Remove the operator setting from user(s) given in PEOPLE."
3570 (when (> (length people) 0)
3571 (erc-server-send (concat "MODE " (erc-default-target)
3573 (make-string (length people) ?o)
3575 (mapconcat 'identity people " ")))
3578 (defun erc-cmd-OP (&rest people)
3579 "Add the operator setting to users(s) given in PEOPLE."
3580 (when (> (length people) 0)
3581 (erc-server-send (concat "MODE " (erc-default-target)
3583 (make-string (length people) ?o)
3585 (mapconcat 'identity people " ")))
3588 (defun erc-cmd-TIME (&optional line)
3589 "Request the current time and date from the current server."
3591 ((and line (string-match "^\\s-*\\(.*\\)$" line))
3592 (let ((args (match-string 1 line)))
3593 (erc-log (format "cmd: TIME: %s" args))
3594 (erc-server-send (concat "TIME " args)))
3596 (t (erc-server-send "TIME"))))
3597 (defalias 'erc-cmd-DATE 'erc-cmd-TIME)
3599 (defun erc-cmd-TOPIC (topic)
3600 "Set or request the topic for a channel.
3601 LINE has the format: \"#CHANNEL TOPIC\", \"#CHANNEL\", \"TOPIC\"
3602 or the empty string.
3604 If no #CHANNEL is given, the default channel is used. If TOPIC is
3605 given, the channel topic is modified, otherwise the current topic will
3608 ;; /topic #channel TOPIC
3609 ((string-match "^\\s-*\\([&#+!]\\S-+\\)\\s-\\(.*\\)$" topic)
3610 (let ((ch (match-string 1 topic))
3611 (topic (match-string 2 topic)))
3612 (erc-log (format "cmd: TOPIC [%s]: %s" ch topic))
3613 (erc-server-send (format "TOPIC %s :%s" ch topic) nil ch))
3616 ((string-match "^\\s-*\\([&#+!]\\S-+\\)" topic)
3617 (let ((ch (match-string 1 topic)))
3618 (erc-server-send (format "TOPIC %s" ch) nil ch)
3621 ((string-match "^\\s-*$" topic)
3622 (let ((ch (erc-default-target)))
3623 (erc-server-send (format "TOPIC %s" ch) nil ch)
3626 ((string-match "^\\s-*\\(.*\\)$" topic)
3627 (let ((ch (erc-default-target))
3628 (topic (match-string 1 topic)))
3629 (if (and ch (erc-channel-p ch))
3631 (erc-log (format "cmd: TOPIC [%s]: %s" ch topic))
3632 (erc-server-send (format "TOPIC %s :%s" ch topic) nil ch))
3633 (erc-display-message nil 'error (current-buffer) 'no-target)))
3636 (defalias 'erc-cmd-T 'erc-cmd-TOPIC)
3637 (put 'erc-cmd-TOPIC 'do-not-parse-args t)
3639 (defun erc-cmd-APPENDTOPIC (topic)
3640 "Append TOPIC to the current channel topic, separated by a space."
3641 (let ((oldtopic erc-channel-topic))
3642 ;; display help when given no arguments
3643 (when (string-match "^\\s-*$" topic)
3644 (signal 'wrong-number-of-arguments nil))
3645 ;; strip trailing ^O
3646 (when (string-match "\\(.*\\)\C-o" oldtopic)
3647 (erc-cmd-TOPIC (concat (match-string 1 oldtopic) topic)))))
3648 (defalias 'erc-cmd-AT 'erc-cmd-APPENDTOPIC)
3649 (put 'erc-cmd-APPENDTOPIC 'do-not-parse-args t)
3651 (defun erc-cmd-CLEARTOPIC (&optional channel)
3652 "Clear the topic for a CHANNEL.
3653 If CHANNEL is not specified, clear the topic for the default channel."
3654 (interactive "sClear topic of channel (RET is current channel): ")
3655 (let ((chnl (or (and (erc-channel-p channel) channel) (erc-default-target))))
3657 (erc-server-send (format "TOPIC %s :" chnl))
3662 (defvar erc-channel-banlist nil
3663 "A list of bans seen for the current channel.
3665 Each ban is an alist of the form:
3668 The property `received-from-server' indicates whether
3669 or not the ban list has been requested from the server.")
3670 (make-variable-buffer-local 'erc-channel-banlist)
3671 (put 'erc-channel-banlist 'received-from-server nil)
3673 (defun erc-cmd-BANLIST ()
3674 "Pretty-print the contents of `erc-channel-banlist'.
3676 The ban list is fetched from the server if necessary."
3677 (let ((chnl (erc-default-target))
3678 (chnl-name (buffer-name)))
3681 ((not (erc-channel-p chnl))
3682 (erc-display-line (erc-make-notice "You're not on a channel\n")
3685 ((not (get 'erc-channel-banlist 'received-from-server))
3686 (let ((old-367-hook erc-server-367-functions))
3687 (setq erc-server-367-functions 'erc-banlist-store
3688 erc-channel-banlist nil)
3689 ;; fetch the ban list then callback
3690 (erc-with-server-buffer
3691 (erc-once-with-server-event
3693 `(with-current-buffer ,chnl-name
3694 (put 'erc-channel-banlist 'received-from-server t)
3695 (setq erc-server-367-functions ',old-367-hook)
3698 (erc-server-send (format "MODE %s b" chnl)))))
3700 ((null erc-channel-banlist)
3701 (erc-display-line (erc-make-notice
3702 (format "No bans for channel: %s\n" chnl))
3704 (put 'erc-channel-banlist 'received-from-server nil))
3707 (let* ((erc-fill-column (or (and (boundp 'erc-fill-column)
3709 (and (boundp 'fill-column)
3711 (1- (window-width))))
3712 (separator (make-string erc-fill-column ?=))
3714 "%-" (number-to-string (/ erc-fill-column 2)) "s"
3715 "%" (number-to-string (/ erc-fill-column 2)) "s")))
3718 (erc-make-notice (format "Ban list for channel: %s\n"
3719 (erc-default-target)))
3722 (erc-display-line separator 'active)
3723 (erc-display-line (format fmt "Ban Mask" "Banned By") 'active)
3724 (erc-display-line separator 'active)
3730 (truncate-string-to-width (cdr x) (/ erc-fill-column 2))
3732 (truncate-string-to-width (car x) (/ erc-fill-column 2))
3735 erc-channel-banlist)
3737 (erc-display-line (erc-make-notice "End of Ban list")
3739 (put 'erc-channel-banlist 'received-from-server nil)))))
3742 (defalias 'erc-cmd-BL 'erc-cmd-BANLIST)
3744 (defun erc-cmd-MASSUNBAN ()
3747 Unban all currently banned users in the current channel."
3748 (let ((chnl (erc-default-target)))
3751 ((not (erc-channel-p chnl))
3753 (erc-make-notice "You're not on a channel\n")
3756 ((not (get 'erc-channel-banlist 'received-from-server))
3757 (let ((old-367-hook erc-server-367-functions))
3758 (setq erc-server-367-functions 'erc-banlist-store)
3759 ;; fetch the ban list then callback
3760 (erc-with-server-buffer
3761 (erc-once-with-server-event
3763 `(with-current-buffer ,chnl
3764 (put 'erc-channel-banlist 'received-from-server t)
3765 (setq erc-server-367-functions ,old-367-hook)
3768 (erc-server-send (format "MODE %s b" chnl)))))
3770 (t (let ((bans (mapcar 'cdr erc-channel-banlist)))
3772 ;; Glob the bans into groups of three, and carry out the unban.
3773 ;; eg. /mode #foo -bbb a*!*@* b*!*@* c*!*@*
3777 (format "MODE %s -%s %s" (erc-default-target)
3778 (make-string (length x) ?b)
3779 (mapconcat 'identity x " "))))
3780 (erc-group-list bans 3))))
3783 (defalias 'erc-cmd-MUB 'erc-cmd-MASSUNBAN)
3785 ;;;; End of IRC commands
3787 (defun erc-ensure-channel-name (channel)
3788 "Return CHANNEL if it is a valid channel name.
3789 Eventually add a # in front of it, if that turns it into a valid channel name."
3790 (if (erc-channel-p channel)
3792 (concat "#" channel)))
3794 (defun erc-grab-region (start end)
3795 "Copy the region between START and END in a recreatable format.
3797 Converts all the IRC text properties in each line of the region
3798 into control codes and writes them to a separate buffer. The
3799 resulting text may be used directly as a script to generate this
3802 (erc-set-active-buffer (current-buffer))
3804 (let* ((cb (current-buffer))
3805 (buf (generate-new-buffer erc-grab-buffer-name))
3806 (region (buffer-substring start end))
3807 (lines (erc-split-multiline-safe region)))
3809 (dolist (line lines)
3810 (insert (concat line "\n")))
3812 (switch-to-buffer-other-window buf)))
3813 (message "erc-grab-region doesn't grab colors etc. anymore. If you use this, please tell the maintainers.")
3816 (defun erc-display-prompt (&optional buffer pos prompt face)
3817 "Display PROMPT in BUFFER at position POS.
3818 Display an ERC prompt in BUFFER.
3820 If PROMPT is nil, one is constructed with the function `erc-prompt'.
3821 If BUFFER is nil, the `current-buffer' is used.
3822 If POS is nil, PROMPT will be displayed at `point'.
3823 If FACE is non-nil, it will be used to propertize the prompt. If it is nil,
3824 `erc-prompt-face' will be used."
3825 (let* ((prompt (or prompt (erc-prompt)))
3827 (ob (current-buffer)))
3828 ;; We cannot use save-excursion because we move point, therefore
3829 ;; we resort to the ol' ob trick to restore this.
3830 (when (and buffer (bufferp buffer))
3831 (set-buffer buffer))
3833 ;; now save excursion again to store where point and mark are
3834 ;; in the current buffer
3836 (setq pos (or pos (point)))
3839 ;; Do not extend the text properties when typing at the end
3840 ;; of the prompt, but stuff typed in front of the prompt
3841 ;; shall remain part of the prompt.
3842 (setq prompt (erc-propertize prompt
3843 'start-open t ; XEmacs
3844 'rear-nonsticky t ; Emacs
3849 (erc-put-text-property 0 (1- (length prompt))
3850 'face (or face 'erc-prompt-face)
3853 ;; Set the input marker
3854 (set-marker erc-input-marker (point)))
3856 ;; Now we are back at the old position. If the prompt was
3857 ;; inserted here or before us, advance point by the length of
3859 (when (or (not pos) (<= (point) pos))
3861 ;; Clear the undo buffer now, so the user can undo his stuff,
3862 ;; but not the stuff we did. Sneaky!
3863 (setq buffer-undo-list nil)
3866 ;; interactive operations
3868 (defun erc-input-message ()
3869 "Read input from the minibuffer."
3871 (let ((minibuffer-allow-text-properties t)
3872 (read-map minibuffer-local-map))
3873 (insert (read-from-minibuffer "Message: "
3874 (string (if (featurep 'xemacs)
3876 last-command-event)) read-map))
3877 (erc-send-current-line)))
3879 (defvar erc-action-history-list ()
3880 "History list for interactive action input.")
3882 (defun erc-input-action ()
3883 "Interactively input a user action and send it to IRC."
3885 (erc-set-active-buffer (current-buffer))
3886 (let ((action (read-from-minibuffer
3887 "Action: " nil nil nil 'erc-action-history-list)))
3888 (if (not (string-match "^\\s-*$" action))
3889 (erc-send-action (erc-default-target) action))))
3891 (defun erc-join-channel (channel &optional key)
3894 If `point' is at the beginning of a channel name, use that as default."
3897 (let ((chnl (if (looking-at "\\([&#+!][^ \n]+\\)") (match-string 1) ""))
3898 (table (when (erc-server-buffer-live-p)
3899 (set-buffer (process-buffer erc-server-process))
3901 (completing-read "Join channel: " table nil nil nil nil chnl))
3902 (when (or current-prefix-arg erc-prompt-for-channel-key)
3903 (read-from-minibuffer "Channel key (RET for none): " nil))))
3904 (erc-cmd-JOIN channel (when (>= (length key) 1) key)))
3906 (defun erc-part-from-channel (reason)
3907 "Part from the current channel and prompt for a REASON."
3910 (if (and (boundp 'reason) (stringp reason) (not (string= reason "")))
3912 (read-from-minibuffer (concat "Reason for leaving " (erc-default-target)
3914 (erc-cmd-PART (concat (erc-default-target)" " reason)))
3916 (defun erc-set-topic (topic)
3917 "Prompt for a TOPIC for the current channel."
3920 (read-from-minibuffer
3921 (concat "Set topic of " (erc-default-target) ": ")
3922 (when erc-channel-topic
3923 (let ((ss (split-string erc-channel-topic "\C-o")))
3924 (cons (apply 'concat (if (cdr ss) (butlast ss) ss))
3926 (let ((topic-list (split-string topic "\C-o"))) ; strip off the topic setter
3927 (erc-cmd-TOPIC (concat (erc-default-target) " " (car topic-list)))))
3929 (defun erc-set-channel-limit (&optional limit)
3930 "Set a LIMIT for the current channel. Remove limit if nil.
3931 Prompt for one if called interactively."
3932 (interactive (list (read-from-minibuffer
3933 (format "Limit for %s (RET to remove limit): "
3934 (erc-default-target)))))
3935 (let ((tgt (erc-default-target)))
3936 (if (and limit (>= (length limit) 1))
3937 (erc-server-send (format "MODE %s +l %s" tgt limit))
3938 (erc-server-send (format "MODE %s -l" tgt)))))
3940 (defun erc-set-channel-key (&optional key)
3941 "Set a KEY for the current channel. Remove key if nil.
3942 Prompt for one if called interactively."
3943 (interactive (list (read-from-minibuffer
3944 (format "Key for %s (RET to remove key): "
3945 (erc-default-target)))))
3946 (let ((tgt (erc-default-target)))
3947 (if (and key (>= (length key) 1))
3948 (erc-server-send (format "MODE %s +k %s" tgt key))
3949 (erc-server-send (format "MODE %s -k" tgt)))))
3951 (defun erc-quit-server (reason)
3952 "Disconnect from current server after prompting for REASON.
3953 `erc-quit-reason' works with this just like with `erc-cmd-QUIT'."
3954 (interactive (list (read-from-minibuffer
3955 (format "Reason for quitting %s: "
3956 (or erc-server-announced-name
3957 erc-session-server)))))
3958 (erc-cmd-QUIT reason))
3960 ;; Movement of point
3963 "Move `point' to the beginning of the current line.
3965 This places `point' just after the prompt, or at the beginning of the line."
3968 (when (get-text-property (point) 'erc-prompt)
3969 (goto-char erc-input-marker))
3972 (defun erc-kill-input ()
3973 "Kill current input line using `erc-bol' followed by `kill-line'."
3975 (when (and (erc-bol)
3976 (/= (point) (point-max))) ;; Prevent a (ding) and an error when
3977 ;; there's nothing to kill
3978 (if (boundp 'erc-input-ring-index)
3979 (setq erc-input-ring-index nil))
3982 (defun erc-complete-word-at-point ()
3983 (run-hook-with-args-until-success 'erc-complete-functions))
3985 (define-obsolete-function-alias 'erc-complete-word 'completion-at-point "24.1")
3987 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3989 ;; IRC SERVER INPUT HANDLING
3991 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3993 ;;;; New Input parsing
3995 ; Stolen from ZenIRC. I just wanna test this code, so here is
3998 (defcustom erc-default-server-hook '(erc-debug-missing-hooks
3999 erc-default-server-handler)
4000 "Default for server messages which aren't covered by `erc-server-hooks'."
4001 :group 'erc-server-hooks
4004 (defun erc-default-server-handler (proc parsed)
4005 "Default server handler.
4007 Displays PROC and PARSED appropriately using `erc-display-message'."
4008 (erc-display-message
4015 (setq res (append res (list x)))))
4020 (defvar erc-server-vectors
4021 '(["msgtype" "sender" "to" "arg1" "arg2" "arg3" "..."])
4022 "List of received server messages which ERC does not specifically handle.
4023 See `erc-debug-missing-hooks'.")
4024 ;(make-variable-buffer-local 'erc-server-vectors)
4026 (defun erc-debug-missing-hooks (proc parsed)
4027 "Add PARSED server message ERC does not yet handle to `erc-server-vectors'.
4028 These vectors can be helpful when adding new server message handlers to ERC.
4029 See `erc-default-server-hook'."
4030 (nconc erc-server-vectors (list parsed))
4033 (defun erc-query (target server)
4034 "Open a query buffer on TARGET, using SERVER.
4035 To change how this query window is displayed, use `let' to bind
4036 `erc-join-buffer' before calling this."
4038 (buffer-live-p server)
4039 (set-buffer server))
4040 (error "Couldn't switch to server buffer"))
4041 (let ((buf (erc-open erc-session-server
4044 erc-session-user-full-name
4049 erc-server-process)))
4051 (error "Couldn't open query window"))
4052 (erc-update-mode-line)
4055 (defcustom erc-auto-query 'window-noselect
4056 "If non-nil, create a query buffer each time you receive a private message.
4057 If the buffer doesn't already exist, it is created.
4059 This can be set to a symbol, to control how the new query window
4060 should appear. The default behavior is to display the buffer in
4061 a new window, but not to select it. See the documentation for
4062 `erc-join-buffer' for a description of the available choices."
4064 :type '(choice (const :tag "Don't create query window" nil)
4065 (const :tag "Split window and select" window)
4066 (const :tag "Split window, don't select" window-noselect)
4067 (const :tag "New frame" frame)
4068 (const :tag "Bury in new buffer" bury)
4069 (const :tag "Use current buffer" buffer)
4070 (const :tag "Use current buffer" t)))
4072 (defcustom erc-query-on-unjoined-chan-privmsg t
4073 "If non-nil create query buffer on receiving any PRIVMSG at all.
4074 This includes PRIVMSGs directed to channels. If you are using an IRC
4075 bouncer, such as dircproxy, to keep a log of channels when you are
4076 disconnected, you should set this option to t."
4080 (defcustom erc-format-query-as-channel-p t
4081 "If non-nil, format text from others in a query buffer like in a channel,
4082 otherwise format like a private message."
4086 (defcustom erc-minibuffer-notice nil
4087 "If non-nil, print ERC notices for the user in the minibuffer.
4088 Only happens when the session buffer isn't visible."
4092 (defcustom erc-minibuffer-ignored nil
4093 "If non-nil, print a message in the minibuffer if we ignored something."
4097 (defun erc-wash-quit-reason (reason nick login host)
4098 "Remove duplicate text from quit REASON.
4099 Specifically in relation to NICK (user@host) information. Returns REASON
4100 unmodified if nothing can be removed.
4101 E.g. \"Read error to Nick [user@some.host]: 110\" would be shortened to
4102 \"Read error: 110\". The same applies for \"Ping Timeout\"."
4103 (setq nick (regexp-quote nick)
4104 login (regexp-quote login)
4105 host (regexp-quote host))
4106 (or (when (string-match (concat "^\\(Read error\\) to "
4107 nick "\\[" host "\\]: "
4108 "\\(.+\\)$") reason)
4109 (concat (match-string 1 reason) ": " (match-string 2 reason)))
4110 (when (string-match (concat "^\\(Ping timeout\\) for "
4111 nick "\\[" host "\\]$") reason)
4112 (match-string 1 reason))
4115 (defun erc-nickname-in-use (nick reason)
4116 "If NICK is unavailable, tell the user the REASON.
4118 See also `erc-display-error-notice'."
4119 (if (or (not erc-try-new-nick-p)
4120 ;; how many default-nicks are left + one more try...
4121 (eq erc-nick-change-attempt-count
4122 (if (consp erc-nick)
4123 (+ (length erc-nick) 1)
4125 (erc-display-error-notice
4127 (format "Nickname %s is %s, try another." nick reason))
4128 (setq erc-nick-change-attempt-count (+ erc-nick-change-attempt-count 1))
4129 (let ((newnick (nth 1 erc-default-nicks))
4130 (nicklen (cdr (assoc "NICKLEN"
4131 (erc-with-server-buffer
4132 erc-server-parameters)))))
4133 (setq erc-bad-nick t)
4134 ;; try to use a different nick
4135 (if erc-default-nicks
4136 (setq erc-default-nicks (cdr erc-default-nicks)))
4138 (setq newnick (concat (truncate-string-to-width
4140 (if (and erc-server-connected nicklen)
4141 (- (string-to-number nicklen)
4142 (length erc-nick-uniquifier))
4143 ;; rfc2812 max nick length = 9
4144 ;; we must assume this is the
4145 ;; server's setting if we haven't
4146 ;; established a connection yet
4147 (- 9 (length erc-nick-uniquifier))))
4148 erc-nick-uniquifier)))
4149 (erc-cmd-NICK newnick)
4150 (erc-display-error-notice
4152 (format "Nickname %s is %s, trying %s"
4153 nick reason newnick)))))
4157 (defgroup erc-server-hooks nil
4158 "Server event callbacks.
4159 Every server event - like numeric replies - has its own hook.
4160 Those hooks are all called using `run-hook-with-args-until-success'.
4161 They receive as first argument the process object from where the event
4163 and as second argument the event parsed as a vector."
4166 (defun erc-display-server-message (proc parsed)
4167 "Display the message sent by the server as a notice."
4168 (erc-display-message
4169 parsed 'notice 'active (erc-response.contents parsed)))
4171 (defun erc-auto-query (proc parsed)
4172 ;; FIXME: This needs more documentation, unless it's not a user function --
4173 ;; Lawrence 2004-01-08
4174 "Put this on `erc-server-PRIVMSG-functions'."
4175 (when erc-auto-query
4176 (let* ((nick (car (erc-parse-user (erc-response.sender parsed))))
4177 (target (car (erc-response.command-args parsed)))
4178 (msg (erc-response.contents parsed))
4179 (query (if (not erc-query-on-unjoined-chan-privmsg)
4181 (if (erc-current-nick-p target)
4184 (and (not (erc-ignored-user-p (erc-response.sender parsed)))
4185 (or erc-query-on-unjoined-chan-privmsg
4186 (string= target (erc-current-nick)))
4187 (not (erc-get-buffer query proc))
4188 (not (erc-is-message-ctcp-and-not-action-p msg))
4189 (let ((erc-query-display erc-auto-query))
4190 (erc-cmd-QUERY query))
4193 (defun erc-is-message-ctcp-p (message)
4194 "Check if MESSAGE is a CTCP message or not."
4195 (string-match "^\C-a\\([^\C-a]*\\)\C-a?$" message))
4197 (defun erc-is-message-ctcp-and-not-action-p (message)
4198 "Check if MESSAGE is a CTCP message or not."
4199 (and (erc-is-message-ctcp-p message)
4200 (not (string-match "^\C-a\\ACTION.*\C-a$" message))))
4202 (defun erc-format-privmessage (nick msg privp msgp)
4203 "Format a PRIVMSG in an insertable fashion."
4204 (let* ((mark-s (if msgp (if privp "*" "<") "-"))
4205 (mark-e (if msgp (if privp "*" ">") "-"))
4206 (str (format "%s%s%s %s" mark-s nick mark-e msg))
4207 (nick-face (if privp 'erc-nick-msg-face 'erc-nick-default-face))
4208 (msg-face (if privp 'erc-direct-msg-face 'erc-default-face)))
4209 ;; add text properties to text before the nick, the nick and after the nick
4210 (erc-put-text-property 0 (length mark-s) 'face msg-face str)
4211 (erc-put-text-property (length mark-s) (+ (length mark-s) (length nick))
4212 'face nick-face str)
4213 (erc-put-text-property (+ (length mark-s) (length nick)) (length str)
4217 (defcustom erc-format-nick-function 'erc-format-nick
4218 "Function to format a nickname for message display."
4222 (defun erc-format-nick (&optional user channel-data)
4223 "Return the nickname of USER.
4224 See also `erc-format-nick-function'."
4225 (when user (erc-server-user-nickname user)))
4227 (defun erc-format-@nick (&optional user channel-data)
4228 "Format the nickname of USER showing if USER is an operator or has voice.
4229 Operators have \"@\" and users with voice have \"+\" as a prefix.
4230 Use CHANNEL-DATA to determine op and voice status.
4231 See also `erc-format-nick-function'."
4233 (let ((op (and channel-data (erc-channel-user-op channel-data) "@"))
4234 (voice (and channel-data (erc-channel-user-voice channel-data) "+")))
4235 (concat voice op (erc-server-user-nickname user)))))
4237 (defun erc-format-my-nick ()
4238 "Return the beginning of this user's message, correctly propertized."
4239 (if erc-show-my-nick
4242 (nick (erc-current-nick)))
4244 (erc-propertize open 'face 'erc-default-face)
4245 (erc-propertize nick 'face 'erc-my-nick-face)
4246 (erc-propertize close 'face 'erc-default-face)))
4247 (let ((prefix "> "))
4248 (erc-propertize prefix 'face 'erc-default-face))))
4250 (defun erc-echo-notice-in-default-buffer (s parsed buffer sender)
4251 "Echos a private notice in the default buffer, namely the
4252 target buffer specified by BUFFER, or there is no target buffer,
4253 the server buffer. This function is designed to be added to
4254 either `erc-echo-notice-hook' or `erc-echo-notice-always-hook',
4255 and always returns t."
4256 (erc-display-message parsed nil buffer s)
4259 (defun erc-echo-notice-in-target-buffer (s parsed buffer sender)
4260 "Echos a private notice in BUFFER, if BUFFER is non-nil. This
4261 function is designed to be added to either `erc-echo-notice-hook'
4262 or `erc-echo-notice-always-hook', and returns non-nil if BUFFER
4265 (progn (erc-display-message parsed nil buffer s) t)
4268 (defun erc-echo-notice-in-minibuffer (s parsed buffer sender)
4269 "Echos a private notice in the minibuffer. This function is
4270 designed to be added to either `erc-echo-notice-hook' or
4271 `erc-echo-notice-always-hook', and always returns t."
4272 (message "%s" (concat "NOTICE: " s))
4275 (defun erc-echo-notice-in-server-buffer (s parsed buffer sender)
4276 "Echos a private notice in the server buffer. This function is
4277 designed to be added to either `erc-echo-notice-hook' or
4278 `erc-echo-notice-always-hook', and always returns t."
4279 (erc-display-message parsed nil nil s)
4282 (defun erc-echo-notice-in-active-non-server-buffer (s parsed buffer sender)
4283 "Echos a private notice in the active buffer if the active
4284 buffer is not the server buffer. This function is designed to be
4285 added to either `erc-echo-notice-hook' or
4286 `erc-echo-notice-always-hook', and returns non-nil if the active
4287 buffer is not the server buffer."
4288 (if (not (eq (erc-server-buffer) (erc-active-buffer)))
4289 (progn (erc-display-message parsed nil 'active s) t)
4292 (defun erc-echo-notice-in-active-buffer (s parsed buffer sender)
4293 "Echos a private notice in the active buffer. This function is
4294 designed to be added to either `erc-echo-notice-hook' or
4295 `erc-echo-notice-always-hook', and always returns t."
4296 (erc-display-message parsed nil 'active s)
4299 (defun erc-echo-notice-in-user-buffers (s parsed buffer sender)
4300 "Echos a private notice in all of the buffers for which SENDER
4301 is a member. This function is designed to be added to either
4302 `erc-echo-notice-hook' or `erc-echo-notice-always-hook', and
4303 returns non-nil if there is at least one buffer for which the
4306 See also: `erc-echo-notice-in-first-user-buffer',
4307 `erc-buffer-list-with-nick'."
4308 (let ((buffers (erc-buffer-list-with-nick sender erc-server-process)))
4310 (progn (erc-display-message parsed nil buffers s) t)
4313 (defun erc-echo-notice-in-user-and-target-buffers (s parsed buffer sender)
4314 "Echos a private notice in BUFFER and in all of the buffers for
4315 which SENDER is a member. This function is designed to be added
4316 to either `erc-echo-notice-hook' or
4317 `erc-echo-notice-always-hook', and returns non-nil if there is
4318 at least one buffer for which the sender is a member or the
4321 See also: `erc-echo-notice-in-user-buffers',
4322 `erc-buffer-list-with-nick'."
4323 (let ((buffers (erc-buffer-list-with-nick sender erc-server-process)))
4324 (add-to-list 'buffers buffer)
4326 (progn (erc-display-message parsed nil buffers s) t)
4329 (defun erc-echo-notice-in-first-user-buffer (s parsed buffer sender)
4330 "Echos a private notice in one of the buffers for which SENDER
4331 is a member. This function is designed to be added to either
4332 `erc-echo-notice-hook' or `erc-echo-notice-always-hook', and
4333 returns non-nil if there is at least one buffer for which the
4336 See also: `erc-echo-notice-in-user-buffers',
4337 `erc-buffer-list-with-nick'."
4338 (let ((buffers (erc-buffer-list-with-nick sender erc-server-process)))
4340 (progn (erc-display-message parsed nil (car buffers) s) t)
4343 ;;; Ban manipulation
4345 (defun erc-banlist-store (proc parsed)
4346 "Record ban entries for a channel."
4347 (pcase-let ((`(,channel ,mask ,whoset)
4348 (cdr (erc-response.command-args parsed))))
4349 ;; Determine to which buffer the message corresponds
4350 (let ((buffer (erc-get-buffer channel proc)))
4351 (with-current-buffer buffer
4352 (unless (member (cons whoset mask) erc-channel-banlist)
4353 (setq erc-channel-banlist (cons (cons whoset mask)
4354 erc-channel-banlist))))))
4357 (defun erc-banlist-finished (proc parsed)
4358 "Record that we have received the banlist."
4359 (let* ((channel (nth 1 (erc-response.command-args parsed)))
4360 (buffer (erc-get-buffer channel proc)))
4361 (with-current-buffer buffer
4362 (put 'erc-channel-banlist 'received-from-server t)))
4363 t) ; suppress the 'end of banlist' message
4365 (defun erc-banlist-update (proc parsed)
4366 "Check MODE commands for bans and update the banlist appropriately."
4367 ;; FIXME: Possibly incorrect. -- Lawrence 2004-05-11
4368 (let* ((tgt (car (erc-response.command-args parsed)))
4369 (mode (erc-response.contents parsed))
4370 (whoset (erc-response.sender parsed))
4371 (buffer (erc-get-buffer tgt proc)))
4373 (with-current-buffer buffer
4374 (cond ((not (get 'erc-channel-banlist 'received-from-server)) nil)
4375 ((string-match "^\\([+-]\\)b" mode)
4378 ((string-match "^-" mode)
4379 ;; Remove the unbanned masks from the ban list
4380 (setq erc-channel-banlist
4383 (member (upcase (cdr y))
4385 (cdr (split-string mode)))))
4386 erc-channel-banlist)))
4387 ((string-match "^+" mode)
4388 ;; Add the banned mask(s) to the ban list
4391 (unless (member (cons whoset mask) erc-channel-banlist)
4392 (setq erc-channel-banlist
4393 (cons (cons whoset mask) erc-channel-banlist))))
4394 (cdr (split-string mode))))))))))
4397 ;; used for the banlist cmds
4398 (defun erc-group-list (list n)
4399 "Group LIST into sublists of length N."
4400 (cond ((null list) nil)
4401 ((null (nthcdr n list)) (list list))
4402 (t (cons (erc-subseq list 0 n) (erc-group-list (nthcdr n list) n)))))
4407 (defun erc-handle-login ()
4408 "Handle the logging in process of connection."
4409 (unless erc-logged-in
4410 (setq erc-logged-in t)
4411 (message "Logging in as \'%s\'... done" (erc-current-nick))
4412 ;; execute a startup script
4413 (let ((f (erc-select-startup-file)))
4415 (erc-load-script f)))))
4417 (defun erc-connection-established (proc parsed)
4418 "Run just after connection.
4420 Set user modes and run `erc-after-connect' hook."
4421 (with-current-buffer (process-buffer proc)
4422 (unless erc-server-connected ; only once per session
4423 (let ((server (or erc-server-announced-name
4424 (erc-response.sender parsed)))
4425 (nick (car (erc-response.command-args parsed)))
4426 (buffer (process-buffer proc)))
4427 (setq erc-server-connected t)
4428 (erc-update-mode-line)
4429 (erc-set-initial-user-mode nick buffer)
4430 (erc-server-setup-periodical-ping buffer)
4431 (run-hook-with-args 'erc-after-connect server nick)))))
4433 (defun erc-set-initial-user-mode (nick buffer)
4434 "If `erc-user-mode' is non-nil for NICK, set the user modes.
4435 The server buffer is given by BUFFER."
4436 (with-current-buffer buffer
4438 (let ((mode (if (functionp erc-user-mode)
4439 (funcall erc-user-mode)
4441 (when (stringp mode)
4442 (erc-log (format "changing mode for %s to %s" nick mode))
4443 (erc-server-send (format "MODE %s %s" nick mode)))))))
4445 (defun erc-display-error-notice (parsed string)
4446 "Display STRING as an error notice.
4448 See also `erc-display-message'."
4449 (erc-display-message
4450 parsed '(notice error) 'active string))
4452 (defun erc-process-ctcp-query (proc parsed nick login host)
4453 ;; FIXME: This needs a proper docstring -- Lawrence 2004-01-08
4454 "Process a CTCP query."
4455 (let ((queries (delete "" (split-string (erc-response.contents parsed)
4457 (if (> (length queries) 4)
4458 (erc-display-message
4459 parsed (list 'notice 'error) proc 'ctcp-too-many)
4460 (if (= 0 (length queries))
4461 (erc-display-message
4462 parsed (list 'notice 'error) proc
4463 'ctcp-empty ?n nick)
4465 (let* ((type (upcase (car (split-string (car queries)))))
4466 (hook (intern-soft (concat "erc-ctcp-query-" type "-hook"))))
4467 (if (and hook (boundp hook))
4468 (if (string-equal type "ACTION")
4469 (run-hook-with-args-until-success
4470 hook proc parsed nick login host
4471 (car (erc-response.command-args parsed))
4474 (if (erc-current-nick-p
4475 (car (erc-response.command-args parsed)))
4476 (erc-display-message
4477 parsed 'error 'active 'ctcp-request
4478 ?n nick ?u login ?h host ?r (car queries))
4479 (erc-display-message
4480 parsed 'error 'active 'ctcp-request-to
4481 ?n nick ?u login ?h host ?r (car queries)
4482 ?t (car (erc-response.command-args parsed)))))
4483 (run-hook-with-args-until-success
4484 hook proc nick login host
4485 (car (erc-response.command-args parsed))
4487 (erc-display-message
4488 parsed (list 'notice 'error) proc
4490 (setq queries (cdr queries)))))))
4492 (defvar erc-ctcp-query-ACTION-hook '(erc-ctcp-query-ACTION))
4494 (defun erc-ctcp-query-ACTION (proc parsed nick login host to msg)
4495 "Respond to a CTCP ACTION query."
4496 (when (string-match "^ACTION\\s-\\(.*\\)\\s-*$" msg)
4497 (let ((s (match-string 1 msg))
4498 (buf (or (erc-get-buffer to proc)
4499 (erc-get-buffer nick proc)
4500 (process-buffer proc))))
4501 (erc-display-message
4503 'ACTION ?n nick ?u login ?h host ?a s))))
4505 (defvar erc-ctcp-query-CLIENTINFO-hook '(erc-ctcp-query-CLIENTINFO))
4507 (defun erc-ctcp-query-CLIENTINFO (proc nick login host to msg)
4508 "Respond to a CTCP CLIENTINFO query."
4509 (when (string-match "^CLIENTINFO\\(\\s-*\\|\\s-+.*\\)$" msg)
4510 (let ((s (erc-client-info (erc-trim-string (match-string 1 msg)))))
4511 (unless erc-disable-ctcp-replies
4512 (erc-send-ctcp-notice nick (format "CLIENTINFO %s" s)))))
4515 (defvar erc-ctcp-query-ECHO-hook '(erc-ctcp-query-ECHO))
4516 (defun erc-ctcp-query-ECHO (proc nick login host to msg)
4517 "Respond to a CTCP ECHO query."
4518 (when (string-match "^ECHO\\s-+\\(.*\\)\\s-*$" msg)
4519 (let ((s (match-string 1 msg)))
4520 (unless erc-disable-ctcp-replies
4521 (erc-send-ctcp-notice nick (format "ECHO %s" s)))))
4524 (defvar erc-ctcp-query-FINGER-hook '(erc-ctcp-query-FINGER))
4525 (defun erc-ctcp-query-FINGER (proc nick login host to msg)
4526 "Respond to a CTCP FINGER query."
4527 (unless erc-disable-ctcp-replies
4528 (let ((s (if erc-anonymous-login
4529 (format "FINGER I'm %s." (erc-current-nick))
4530 (format "FINGER %s (%s@%s)."
4534 (ns (erc-time-diff erc-server-last-sent-time (erc-current-time))))
4536 (setq s (concat s " Idle for " (erc-sec-to-time ns))))
4537 (erc-send-ctcp-notice nick s)))
4540 (defvar erc-ctcp-query-PING-hook '(erc-ctcp-query-PING))
4541 (defun erc-ctcp-query-PING (proc nick login host to msg)
4542 "Respond to a CTCP PING query."
4543 (when (string-match "^PING\\s-+\\(.*\\)" msg)
4544 (unless erc-disable-ctcp-replies
4545 (let ((arg (match-string 1 msg)))
4546 (erc-send-ctcp-notice nick (format "PING %s" arg)))))
4549 (defvar erc-ctcp-query-TIME-hook '(erc-ctcp-query-TIME))
4550 (defun erc-ctcp-query-TIME (proc nick login host to msg)
4551 "Respond to a CTCP TIME query."
4552 (unless erc-disable-ctcp-replies
4553 (erc-send-ctcp-notice nick (format "TIME %s" (current-time-string))))
4556 (defvar erc-ctcp-query-USERINFO-hook '(erc-ctcp-query-USERINFO))
4557 (defun erc-ctcp-query-USERINFO (proc nick login host to msg)
4558 "Respond to a CTCP USERINFO query."
4559 (unless erc-disable-ctcp-replies
4560 (erc-send-ctcp-notice nick (format "USERINFO %s" erc-user-information)))
4563 (defvar erc-ctcp-query-VERSION-hook '(erc-ctcp-query-VERSION))
4564 (defun erc-ctcp-query-VERSION (proc nick login host to msg)
4565 "Respond to a CTCP VERSION query."
4566 (unless erc-disable-ctcp-replies
4567 (erc-send-ctcp-notice
4569 "VERSION \C-bERC\C-b %s - an IRC client for emacs (\C-b%s\C-b)"
4571 erc-official-location)))
4574 (defun erc-process-ctcp-reply (proc parsed nick login host msg)
4575 "Process MSG as a CTCP reply."
4576 (let* ((type (car (split-string msg)))
4577 (hook (intern (concat "erc-ctcp-reply-" type "-hook"))))
4579 (run-hook-with-args-until-success
4580 hook proc nick login host
4581 (car (erc-response.command-args parsed)) msg)
4582 (erc-display-message
4583 parsed 'notice 'active
4584 'CTCP-UNKNOWN ?n nick ?u login ?h host ?m msg))))
4586 (defvar erc-ctcp-reply-ECHO-hook '(erc-ctcp-reply-ECHO))
4587 (defun erc-ctcp-reply-ECHO (proc nick login host to msg)
4588 "Handle a CTCP ECHO reply."
4589 (when (string-match "^ECHO\\s-+\\(.*\\)\\s-*$" msg)
4590 (let ((message (match-string 1 msg)))
4591 (erc-display-message
4592 nil '(notice action) 'active
4593 'CTCP-ECHO ?n nick ?m message)))
4596 (defvar erc-ctcp-reply-CLIENTINFO-hook '(erc-ctcp-reply-CLIENTINFO))
4597 (defun erc-ctcp-reply-CLIENTINFO (proc nick login host to msg)
4598 "Handle a CTCP CLIENTINFO reply."
4599 (when (string-match "^CLIENTINFO\\s-+\\(.*\\)\\s-*$" msg)
4600 (let ((message (match-string 1 msg)))
4601 (erc-display-message
4603 'CTCP-CLIENTINFO ?n nick ?m message)))
4606 (defvar erc-ctcp-reply-FINGER-hook '(erc-ctcp-reply-FINGER))
4607 (defun erc-ctcp-reply-FINGER (proc nick login host to msg)
4608 "Handle a CTCP FINGER reply."
4609 (when (string-match "^FINGER\\s-+\\(.*\\)\\s-*$" msg)
4610 (let ((message (match-string 1 msg)))
4611 (erc-display-message
4613 'CTCP-FINGER ?n nick ?m message)))
4616 (defvar erc-ctcp-reply-PING-hook '(erc-ctcp-reply-PING))
4617 (defun erc-ctcp-reply-PING (proc nick login host to msg)
4618 "Handle a CTCP PING reply."
4619 (if (not (string-match "^PING\\s-+\\([0-9.]+\\)" msg))
4621 (let ((time (match-string 1 msg)))
4623 (let ((delta (erc-time-diff (string-to-number time)
4624 (erc-current-time))))
4625 (erc-display-message
4628 ?t (erc-sec-to-time delta)))
4630 (erc-display-message
4632 'bad-ping-response ?n nick ?t time))))))
4634 (defvar erc-ctcp-reply-TIME-hook '(erc-ctcp-reply-TIME))
4635 (defun erc-ctcp-reply-TIME (proc nick login host to msg)
4636 "Handle a CTCP TIME reply."
4637 (when (string-match "^TIME\\s-+\\(.*\\)\\s-*$" msg)
4638 (let ((message (match-string 1 msg)))
4639 (erc-display-message
4641 'CTCP-TIME ?n nick ?m message)))
4644 (defvar erc-ctcp-reply-VERSION-hook '(erc-ctcp-reply-VERSION))
4645 (defun erc-ctcp-reply-VERSION (proc nick login host to msg)
4646 "Handle a CTCP VERSION reply."
4647 (when (string-match "^VERSION\\s-+\\(.*\\)\\s-*$" msg)
4648 (let ((message (match-string 1 msg)))
4649 (erc-display-message
4651 'CTCP-VERSION ?n nick ?m message)))
4654 (defun erc-process-away (proc away-p)
4655 "Toggle the away status of the user depending on the value of AWAY-P.
4657 If nil, set the user as away.
4658 If non-nil, return from being away."
4659 (let ((sessionbuf (process-buffer proc)))
4661 (with-current-buffer sessionbuf
4662 (when erc-away-nickname
4663 (erc-log (format "erc-process-away: away-nick: %s, away-p: %s"
4664 erc-away-nickname away-p))
4665 (erc-cmd-NICK (if away-p
4670 (setq erc-away (current-time)))
4672 (let ((away-time erc-away))
4673 ;; away must be set to NIL BEFORE sending anything to prevent
4674 ;; an infinite recursion
4676 (with-current-buffer (erc-active-buffer)
4677 (when erc-public-away-p
4679 (erc-default-target)
4681 (format "is back (gone for %s)"
4684 (erc-emacs-time-to-erc-time away-time)
4685 (erc-current-time))))
4687 (erc-update-mode-line)))
4689 ;;;; List of channel members handling
4691 (defun erc-channel-begin-receiving-names ()
4694 Used when a channel names list is about to be received. Should
4695 be called with the current buffer set to the channel buffer.
4697 See also `erc-channel-end-receiving-names'."
4698 (setq erc-channel-new-member-names (make-hash-table :test 'equal)))
4700 (defun erc-channel-end-receiving-names ()
4703 Used to fix `erc-channel-users' after a channel names list has been
4704 received. Should be called with the current buffer set to the
4707 See also `erc-channel-begin-receiving-names'."
4708 (maphash (lambda (nick user)
4709 (if (null (gethash nick erc-channel-new-member-names))
4710 (erc-remove-channel-user nick)))
4712 (setq erc-channel-new-member-names nil))
4714 (defun erc-parse-prefix ()
4715 "Return an alist of valid prefix character types and their representations.
4716 Example: (operator) o => @, (voiced) v => +."
4717 (let ((str (or (cdr (assoc "PREFIX" (erc-with-server-buffer
4718 erc-server-parameters)))
4719 ;; provide a sane default
4722 (when (string-match "^(\\([^)]+\\))\\(.+\\)$" str)
4723 (setq types (match-string 1 str)
4724 chars (match-string 2 str))
4725 (let ((len (min (length types) (length chars)))
4729 (setq alist (cons (cons (elt types i) (elt chars i))
4734 (defun erc-channel-receive-names (names-string)
4735 "This function is for internal use only.
4737 Update `erc-channel-users' according to NAMES-STRING.
4738 NAMES-STRING is a string listing some of the names on the
4740 (let (prefix op-ch voice-ch names name op voice)
4741 (setq prefix (erc-parse-prefix))
4742 (setq op-ch (cdr (assq ?o prefix))
4743 voice-ch (cdr (assq ?v prefix)))
4744 ;; We need to delete "" because in XEmacs, (split-string "a ")
4745 ;; returns ("a" "").
4746 (setq names (delete "" (split-string names-string)))
4747 (let ((erc-channel-members-changed-hook nil))
4748 (dolist (item names)
4751 (if (rassq (elt item 0) prefix)
4752 (cond ((= (length item) 1)
4754 ((eq (elt item 0) op-ch)
4755 (setq name (substring item 1)
4758 ((eq (elt item 0) voice-ch)
4759 (setq name (substring item 1)
4762 (t (setq name (substring item 1)
4769 (puthash (erc-downcase name) t
4770 erc-channel-new-member-names)
4771 (erc-update-current-channel-member
4772 name name t op voice)))))
4773 (run-hooks 'erc-channel-members-changed-hook)))
4775 (defcustom erc-channel-members-changed-hook nil
4776 "This hook is called every time the variable `channel-members' changes.
4777 The buffer where the change happened is current while this hook is called."
4781 (defun erc-update-user-nick (nick &optional new-nick
4782 host login full-name info)
4783 "Updates the stored user information for the user with nickname
4786 See also: `erc-update-user'."
4787 (erc-update-user (erc-get-server-user nick) new-nick
4788 host login full-name info))
4790 (defun erc-update-user (user &optional new-nick
4791 host login full-name info)
4792 "Update user info for USER. USER must be an erc-server-user
4793 struct. Any of NEW-NICK, HOST, LOGIN, FULL-NAME, INFO which are
4794 non-nil and not equal to the existing values for USER are used to
4795 replace the stored values in USER.
4797 If, and only if, a change is made,
4798 `erc-channel-members-changed-hook' is run for each channel for
4799 which USER is a member, and t is returned."
4803 (not (equal (erc-server-user-nickname user)
4806 (erc-change-user-nickname user new-nick))
4808 (not (equal (erc-server-user-host user) host)))
4810 (setf (erc-server-user-host user) host))
4812 (not (equal (erc-server-user-login user) login)))
4814 (setf (erc-server-user-login user) login))
4815 (when (and full-name
4816 (not (equal (erc-server-user-full-name user)
4819 (setf (erc-server-user-full-name user) full-name))
4821 (not (equal (erc-server-user-info user) info)))
4823 (setf (erc-server-user-info user) info))
4825 (dolist (buf (erc-server-user-buffers user))
4826 (if (buffer-live-p buf)
4827 (with-current-buffer buf
4828 (run-hooks 'erc-channel-members-changed-hook))))))
4831 (defun erc-update-current-channel-member
4832 (nick new-nick &optional add op voice host login full-name info
4833 update-message-time)
4834 "Updates the stored user information for the user with nickname
4835 NICK. `erc-update-user' is called to handle changes to nickname,
4836 HOST, LOGIN, FULL-NAME, and INFO. If OP or VOICE are non-nil,
4837 they must be equal to either `on' or `off', in which case the
4838 operator or voice status of the user in the current channel is
4839 changed accordingly. If UPDATE-MESSAGE-TIME is non-nil, the
4840 last-message-time of the user in the current channel is set
4843 If ADD is non-nil, the user will be added with the specified
4844 information if it is not already present in the user or channel
4847 If, and only if, changes are made, or the user is added,
4848 `erc-channel-members-updated-hook' is run, and t is returned.
4850 See also: `erc-update-user' and `erc-update-channel-member'."
4851 (let* (changed user-changed
4852 (channel-data (erc-get-channel-user nick))
4853 (cuser (if channel-data (cdr channel-data)))
4854 (user (if channel-data (car channel-data)
4855 (erc-get-server-user nick))))
4858 (erc-log (format "update-member: user = %S, cuser = %S" user cuser))
4860 (not (eq (erc-channel-user-op cuser) op)))
4862 (setf (erc-channel-user-op cuser)
4863 (cond ((eq op 'on) t)
4867 (not (eq (erc-channel-user-voice cuser) voice)))
4869 (setf (erc-channel-user-voice cuser)
4870 (cond ((eq voice 'on) t)
4871 ((eq voice 'off) nil)
4873 (when update-message-time
4874 (setf (erc-channel-user-last-message-time cuser) (current-time)))
4876 (erc-update-user user new-nick
4877 host login full-name info)))
4881 (setq user (make-erc-server-user
4884 :full-name full-name
4887 :buffers (list (current-buffer))))
4888 (erc-add-server-user nick user))
4889 (setf (erc-server-user-buffers user)
4890 (cons (current-buffer)
4891 (erc-server-user-buffers user))))
4892 (setq cuser (make-erc-channel-user
4893 :op (cond ((eq op 'on) t)
4896 :voice (cond ((eq voice 'on) t)
4897 ((eq voice 'off) nil)
4900 (if update-message-time (current-time))))
4901 (puthash (erc-downcase nick) (cons user cuser)
4904 (when (and changed (null user-changed))
4905 (run-hooks 'erc-channel-members-changed-hook))
4906 (or changed user-changed add)))
4908 (defun erc-update-channel-member (channel nick new-nick
4909 &optional add op voice host login
4910 full-name info update-message-time)
4911 "Updates user and channel information for the user with
4912 nickname NICK in channel CHANNEL.
4914 See also: `erc-update-current-channel-member'."
4917 (erc-update-current-channel-member nick new-nick add op voice host
4918 login full-name info
4919 update-message-time)))
4921 (defun erc-remove-current-channel-member (nick)
4922 "Remove NICK from current channel membership list.
4923 Runs `erc-channel-members-changed-hook'."
4924 (let ((channel-data (erc-get-channel-user nick)))
4926 (erc-remove-channel-user nick)
4927 (run-hooks 'erc-channel-members-changed-hook))))
4929 (defun erc-remove-channel-member (channel nick)
4930 "Remove NICK from CHANNEL's membership list.
4932 See also `erc-remove-current-channel-member'."
4935 (erc-remove-current-channel-member nick)))
4937 (defun erc-update-channel-topic (channel topic &optional modify)
4938 "Find a buffer for CHANNEL and set the TOPIC for it.
4940 If optional MODIFY is 'append or 'prepend, then append or prepend the
4941 TOPIC string to the current topic."
4942 (erc-with-buffer (channel)
4943 (cond ((eq modify 'append)
4944 (setq erc-channel-topic (concat erc-channel-topic topic)))
4945 ((eq modify 'prepend)
4946 (setq erc-channel-topic (concat topic erc-channel-topic)))
4947 (t (setq erc-channel-topic topic)))
4948 (erc-update-mode-line-buffer (current-buffer))))
4950 (defun erc-set-modes (tgt mode-string)
4951 "Set the modes for the TGT provided as MODE-STRING."
4952 (let* ((modes (erc-parse-modes mode-string))
4953 (add-modes (nth 0 modes))
4954 (remove-modes (nth 1 modes))
4955 ;; list of triples: (mode-char 'on/'off argument)
4956 (arg-modes (nth 2 modes)))
4957 (cond ((erc-channel-p tgt); channel modes
4958 (let ((buf (and erc-server-process
4959 (erc-get-buffer tgt erc-server-process))))
4961 (with-current-buffer buf
4962 (setq erc-channel-modes add-modes)
4963 (setq erc-channel-user-limit nil)
4964 (setq erc-channel-key nil)
4966 (let ((mode (nth 0 (car arg-modes)))
4967 (onoff (nth 1 (car arg-modes)))
4968 (arg (nth 2 (car arg-modes))))
4969 (cond ((string-match "^[Ll]" mode)
4970 (erc-update-channel-limit tgt onoff arg))
4971 ((string-match "^[Kk]" mode)
4972 (erc-update-channel-key tgt onoff arg))
4974 (setq arg-modes (cdr arg-modes)))
4975 (erc-update-mode-line-buffer buf)))))
4976 ;; we do not keep our nick's modes yet
4977 ;;(t (setq erc-user-modes add-modes))
4981 (defun erc-sort-strings (list-of-strings)
4982 "Sort LIST-OF-STRINGS in lexicographic order.
4985 (sort (copy-sequence list-of-strings) 'string<))
4987 (defun erc-parse-modes (mode-string)
4988 "Parse MODE-STRING into a list.
4990 Returns a list of three elements:
4992 (ADD-MODES REMOVE-MODES ARG-MODES).
4994 The add-modes and remove-modes are lists of single-character strings
4995 for modes without parameters to add and remove respectively. The
4996 arg-modes is a list of triples of the form:
4998 (MODE-CHAR ON/OFF ARGUMENT)."
4999 (if (string-match "^\\s-*\\(\\S-+\\)\\(\\s-.*$\\|$\\)" mode-string)
5000 (let ((chars (mapcar 'char-to-string (match-string 1 mode-string)))
5001 ;; arguments in channel modes
5002 (args-str (match-string 2 mode-string))
5006 (arg-modes nil); list of triples: (mode-char 'on/'off argument)
5008 ;; make the argument list
5009 (while (string-match "^\\s-*\\(\\S-+\\)\\(\\s-+.*$\\|$\\)" args-str)
5010 (setq args (cons (match-string 1 args-str) args))
5011 (setq args-str (match-string 2 args-str)))
5012 (setq args (nreverse args))
5013 ;; collect what modes changed, and match them with arguments
5015 (cond ((string= (car chars) "+") (setq add-p t))
5016 ((string= (car chars) "-") (setq add-p nil))
5017 ((string-match "^[ovbOVB]" (car chars))
5018 (setq arg-modes (cons (list (car chars)
5020 (if args (car args) nil))
5022 (if args (setq args (cdr args))))
5023 ((string-match "^[LlKk]" (car chars))
5024 (setq arg-modes (cons (list (car chars)
5026 (if (and add-p args)
5029 (if (and add-p args) (setq args (cdr args))))
5030 (add-p (setq add-modes (cons (car chars) add-modes)))
5031 (t (setq remove-modes (cons (car chars) remove-modes))))
5032 (setq chars (cdr chars)))
5033 (setq add-modes (nreverse add-modes))
5034 (setq remove-modes (nreverse remove-modes))
5035 (setq arg-modes (nreverse arg-modes))
5036 (list add-modes remove-modes arg-modes))
5039 (defun erc-update-modes (tgt mode-string &optional nick host login)
5040 "Update the mode information for TGT, provided as MODE-STRING.
5041 Optional arguments: NICK, HOST and LOGIN - the attributes of the
5042 person who changed the modes."
5043 (let* ((modes (erc-parse-modes mode-string))
5044 (add-modes (nth 0 modes))
5045 (remove-modes (nth 1 modes))
5046 ;; list of triples: (mode-char 'on/'off argument)
5047 (arg-modes (nth 2 modes)))
5048 ;; now parse the modes changes and do the updates
5049 (cond ((erc-channel-p tgt); channel modes
5050 (let ((buf (and erc-server-process
5051 (erc-get-buffer tgt erc-server-process))))
5053 ;; FIXME! This used to have an original buffer
5054 ;; variable, but it never switched back to the original
5055 ;; buffer. Is this wanted behavior?
5057 (if (not (boundp 'erc-channel-modes))
5058 (setq erc-channel-modes nil))
5060 (setq erc-channel-modes (delete (car remove-modes)
5062 remove-modes (cdr remove-modes)))
5064 (setq erc-channel-modes (cons (car add-modes)
5066 add-modes (cdr add-modes)))
5067 (setq erc-channel-modes (erc-sort-strings erc-channel-modes))
5069 (let ((mode (nth 0 (car arg-modes)))
5070 (onoff (nth 1 (car arg-modes)))
5071 (arg (nth 2 (car arg-modes))))
5072 (cond ((string-match "^[oO]" mode)
5073 (erc-update-channel-member tgt arg arg nil onoff))
5074 ((string-match "^[Vv]" mode)
5075 (erc-update-channel-member tgt arg arg nil nil
5077 ((string-match "^[Ll]" mode)
5078 (erc-update-channel-limit tgt onoff arg))
5079 ((string-match "^[Kk]" mode)
5080 (erc-update-channel-key tgt onoff arg))
5081 (t nil)); only ops are tracked now
5082 (setq arg-modes (cdr arg-modes))))
5083 (erc-update-mode-line buf))))
5084 ;; nick modes - ignored at this point
5087 (defun erc-update-channel-limit (channel onoff n)
5088 ;; FIXME: what does ONOFF actually do? -- Lawrence 2004-01-08
5089 "Update CHANNEL's user limit to N."
5090 (if (or (not (eq onoff 'on))
5091 (and (stringp n) (string-match "^[0-9]+$" n)))
5094 (cond ((eq onoff 'on) (setq erc-channel-user-limit (string-to-number n)))
5095 (t (setq erc-channel-user-limit nil))))))
5097 (defun erc-update-channel-key (channel onoff key)
5098 "Update CHANNEL's key to KEY if ONOFF is 'on or to nil if it's 'off."
5101 (cond ((eq onoff 'on) (setq erc-channel-key key))
5102 (t (setq erc-channel-key nil)))))
5104 (defun erc-handle-user-status-change (type nlh &optional l)
5105 "Handle changes in any user's status.
5107 So far, only nick change is handled.
5109 Generally, the TYPE argument is a symbol describing the change type, NLH is
5110 a list containing the original nickname, login name and hostname for the user,
5111 and L is a list containing additional TYPE-specific arguments.
5113 So far the following TYPE/L pairs are supported:
5117 nickname change 'nick (NEW-NICK)"
5118 (erc-log (format "user-change: type: %S nlh: %S l: %S" type nlh l))
5126 (defun erc-highlight-notice (s)
5127 "Highlight notice message S and return it.
5128 See also variable `erc-notice-highlight-type'."
5130 ((eq erc-notice-highlight-type 'prefix)
5131 (erc-put-text-property 0 (length erc-notice-prefix)
5132 'face 'erc-notice-face s)
5134 ((eq erc-notice-highlight-type 'all)
5135 (erc-put-text-property 0 (length s) 'face 'erc-notice-face s)
5139 (defun erc-make-notice (message)
5140 "Notify the user of MESSAGE."
5141 (when erc-minibuffer-notice
5142 (message "%s" message))
5143 (erc-highlight-notice (concat erc-notice-prefix message)))
5145 (defun erc-highlight-error (s)
5146 "Highlight error message S and return it."
5147 (erc-put-text-property 0 (length s) 'face 'erc-error-face s)
5150 (defun erc-put-text-property (start end property value &optional object)
5151 "Set text-property for an object (usually a string).
5152 START and END define the characters covered.
5153 PROPERTY is the text-property set, usually the symbol `face'.
5154 VALUE is the value for the text-property, usually a face symbol such as
5155 the face `bold' or `erc-pal-face'.
5156 OBJECT is a string which will be modified and returned.
5157 OBJECT is modified without being copied first.
5159 You can redefine or `defadvice' this function in order to add
5160 EmacsSpeak support."
5161 (put-text-property start end property value object))
5163 (defun erc-list (thing)
5164 "Return THING if THING is a list, or a list with THING as its element."
5169 (defun erc-parse-user (string)
5170 "Parse STRING as a user specification (nick!login@host).
5172 Return a list of the three separate tokens."
5174 ((string-match "^\\([^!\n]*\\)!\\([^@\n]*\\)@\\(.*\\)$" string)
5175 (list (match-string 1 string)
5176 (match-string 2 string)
5177 (match-string 3 string)))
5178 ;; Some bogus bouncers send Nick!(null), try to live with that.
5179 ((string-match "^\\([^!\n]*\\)!\\(.*\\)$" string)
5180 (list (match-string 1 string)
5182 (match-string 2 string)))
5184 (list string "" ""))))
5186 (defun erc-extract-nick (string)
5187 "Return the nick corresponding to a user specification STRING.
5189 See also `erc-parse-user'."
5190 (car (erc-parse-user string)))
5192 (defun erc-put-text-properties (start end properties
5193 &optional object value-list)
5194 "Set text-properties for OBJECT.
5196 START and END describe positions in OBJECT.
5197 If VALUE-LIST is nil, set each property in PROPERTIES to t, else set
5198 each property to the corresponding value in VALUE-LIST."
5200 (setq value-list (mapcar (lambda (x)
5203 (while (and properties value-list)
5204 (erc-put-text-property
5205 start end (pop properties) (pop value-list) object)))
5207 ;;; Input area handling:
5209 (defun erc-beg-of-input-line ()
5210 "Return the value of `point' at the beginning of the input line.
5212 Specifically, return the position of `erc-insert-marker'."
5213 (or (and (boundp 'erc-insert-marker)
5214 (markerp erc-insert-marker))
5215 (error "erc-insert-marker has no value, please report a bug"))
5216 (marker-position erc-insert-marker))
5218 (defun erc-end-of-input-line ()
5219 "Return the value of `point' at the end of the input line."
5222 (defvar erc-last-input-time 0
5223 "Time of last call to `erc-send-current-line'.
5224 If that function has never been called, the value is 0.")
5226 (defcustom erc-accidental-paste-threshold-seconds nil
5227 "Minimum time, in seconds, before sending new lines via IRC.
5228 If the value is a number, `erc-send-current-line' signals an
5229 error if its previous invocation was less than this much time
5230 ago. This is useful so that if you accidentally enter large
5231 amounts of text into the ERC buffer, that text is not sent to the
5234 If the value is nil, `erc-send-current-line' always considers any
5235 submitted line to be intentional."
5238 :type '(choice number (other :tag "disabled" nil)))
5240 (defun erc-send-current-line ()
5241 "Parse current line and send it to IRC."
5243 (let ((now (float-time)))
5244 (if (or (not erc-accidental-paste-threshold-seconds)
5245 (< erc-accidental-paste-threshold-seconds
5246 (- now erc-last-input-time)))
5249 (if (< (point) (erc-beg-of-input-line))
5250 (erc-error "Point is not in the input area")
5251 (let ((inhibit-read-only t)
5252 (str (erc-user-input))
5253 (old-buf (current-buffer)))
5254 (if (and (not (erc-server-buffer-live-p))
5255 (not (erc-command-no-process-p str)))
5256 (erc-error "ERC: No process running")
5257 (erc-set-active-buffer (current-buffer))
5258 ;; Kill the input and the prompt
5259 (delete-region (erc-beg-of-input-line)
5260 (erc-end-of-input-line))
5262 (erc-send-input str)
5263 ;; Fix the buffer if the command didn't kill it
5264 (when (buffer-live-p old-buf)
5265 (with-current-buffer old-buf
5268 (goto-char (point-max))
5269 (when (processp erc-server-process)
5270 (set-marker (process-mark erc-server-process) (point)))
5271 (set-marker erc-insert-marker (point))
5272 (let ((buffer-modified (buffer-modified-p)))
5273 (erc-display-prompt)
5274 (set-buffer-modified-p buffer-modified))))))
5276 ;; Only when last hook has been run...
5277 (run-hook-with-args 'erc-send-completed-hook str))))
5278 (setq erc-last-input-time now))
5279 (switch-to-buffer "*ERC Accidental Paste Overflow*")
5280 (lwarn 'erc :warning
5281 "You seem to have accidentally pasted some text!"))))
5283 (defun erc-user-input ()
5284 "Return the input of the user in the current buffer."
5285 (buffer-substring-no-properties
5287 (erc-end-of-input-line)))
5289 (defvar erc-command-regexp "^/\\([A-Za-z']+\\)\\(\\s-+.*\\|\\s-*\\)$"
5290 "Regular expression used for matching commands in ERC.")
5292 (defun erc-send-input (input)
5293 "Treat INPUT as typed in by the user. It is assumed that the input
5294 and the prompt is already deleted.
5295 This returns non-nil only if we actually send anything."
5296 ;; Handle different kinds of inputs
5298 ;; Ignore empty input
5299 ((if erc-send-whitespace-lines
5301 (string-match "\\`[ \t\r\f\n]*\\'" input))
5302 (when erc-warn-about-blank-lines
5303 (message "Blank line - ignoring...")
5308 (erc-insert-this t))
5309 (setq erc-send-this t)
5310 (run-hook-with-args 'erc-send-pre-hook input)
5312 (if (or (string-match "\n" str)
5313 (not (string-match erc-command-regexp str)))
5318 ;; Insert what has to be inserted for this.
5319 (erc-display-msg line)
5320 (erc-process-input-line (concat line "\n")
5321 (null erc-flood-protect) t))
5322 (or (and erc-flood-protect (erc-split-line line))
5324 (split-string str "\n"))
5325 ;; Insert the prompt along with the command.
5326 (erc-display-command str)
5327 (erc-process-input-line (concat str "\n") t nil))
5330 (defun erc-display-command (line)
5331 (when erc-insert-this
5332 (let ((insert-position (point)))
5333 (unless erc-hide-prompt
5334 (erc-display-prompt nil nil (erc-command-indicator)
5335 (and (erc-command-indicator)
5336 'erc-command-indicator-face)))
5337 (let ((beg (point)))
5339 (erc-put-text-property beg (point)
5340 'face 'erc-command-indicator-face)
5342 (when (processp erc-server-process)
5343 (set-marker (process-mark erc-server-process) (point)))
5344 (set-marker erc-insert-marker (point))
5347 (narrow-to-region insert-position (point))
5348 (run-hooks 'erc-send-modify-hook)
5349 (run-hooks 'erc-send-post-hook))))))
5351 (defun erc-display-msg (line)
5352 "Display LINE as a message of the user to the current target at the
5354 (when erc-insert-this
5355 (let ((insert-position (point)))
5356 (insert (erc-format-my-nick))
5357 (let ((beg (point)))
5359 (erc-put-text-property beg (point)
5360 'face 'erc-input-face))
5362 (when (processp erc-server-process)
5363 (set-marker (process-mark erc-server-process) (point)))
5364 (set-marker erc-insert-marker (point))
5367 (narrow-to-region insert-position (point))
5368 (run-hooks 'erc-send-modify-hook)
5369 (run-hooks 'erc-send-post-hook))))))
5371 (defun erc-command-symbol (command)
5372 "Return the ERC command symbol for COMMAND if it exists and is bound."
5373 (let ((cmd (intern-soft (format "erc-cmd-%s" (upcase command)))))
5374 (when (fboundp cmd) cmd)))
5376 (defun erc-extract-command-from-line (line)
5377 "Extract command and args from the input LINE.
5378 If no command was given, return nil. If command matches, return a
5379 list of the form: (command args) where both elements are strings."
5380 (when (string-match erc-command-regexp line)
5381 (let* ((cmd (erc-command-symbol (match-string 1 line)))
5382 ;; note: return is nil, we apply this simply for side effects
5383 (canon-defun (while (and cmd (symbolp (symbol-function cmd)))
5384 (setq cmd (symbol-function cmd))))
5385 (cmd-fun (or cmd #'erc-cmd-default))
5387 (if (get cmd-fun 'do-not-parse-args)
5388 (format "%s" (match-string 2 line))
5389 (delete "" (split-string (erc-trim-string
5390 (match-string 2 line)) " ")))
5392 (list cmd-fun arg))))
5394 (defun erc-split-multiline-safe (string)
5395 "Split STRING, containing multiple lines and return them in a list.
5396 Do it only for STRING as the complete input, do not carry unfinished
5397 strings over to the next call."
5402 (let ((i (string-match "\r?\n" string i0))
5403 (s (substring string i0)))
5404 (cond (i (setq l (cons (substring string i0 i) l))
5405 (setq i0 (match-end 0)))
5407 (setq l (cons s l))(setq doit nil))
5408 (t (setq doit nil)))))
5413 (defun erc-set-current-nick (nick)
5414 "Set the current nickname to NICK."
5415 (with-current-buffer (if (buffer-live-p (erc-server-buffer))
5418 (setq erc-server-current-nick nick)))
5420 (defun erc-current-nick ()
5421 "Return the current nickname."
5422 (with-current-buffer (if (buffer-live-p (erc-server-buffer))
5425 erc-server-current-nick))
5427 (defun erc-current-nick-p (nick)
5428 "Return non-nil if NICK is the current nickname."
5429 (erc-nick-equal-p nick (erc-current-nick)))
5431 (defun erc-nick-equal-p (nick1 nick2)
5432 "Return non-nil if NICK1 and NICK2 are the same.
5434 This matches strings according to the IRC protocol's case convention.
5436 See also `erc-downcase'."
5437 (string= (erc-downcase nick1)
5438 (erc-downcase nick2)))
5440 ;; default target handling
5442 (defun erc-default-target ()
5443 "Return the current default target (as a character string) or nil if none."
5444 (let ((tgt (car erc-default-recipients)))
5447 ((listp tgt) (cdr tgt))
5450 (defun erc-add-default-channel (channel)
5451 "Add CHANNEL to the default channel list."
5453 (let ((d1 (car erc-default-recipients))
5454 (d2 (cdr erc-default-recipients))
5455 (chl (downcase channel)))
5456 (setq erc-default-recipients
5457 (cons chl erc-default-recipients))))
5459 (defun erc-delete-default-channel (channel &optional buffer)
5460 "Delete CHANNEL from the default channel list."
5461 (let ((ob (current-buffer)))
5462 (with-current-buffer (if (and buffer
5466 (setq erc-default-recipients (delete (downcase channel)
5467 erc-default-recipients)))))
5469 (defun erc-add-query (nickname)
5470 "Add QUERY'd NICKNAME to the default channel list.
5472 The previous default target of QUERY type gets removed."
5473 (let ((d1 (car erc-default-recipients))
5474 (d2 (cdr erc-default-recipients))
5475 (qt (cons 'QUERY (downcase nickname))))
5477 (eq (car d1) 'QUERY))
5478 (setq erc-default-recipients (cons qt d2))
5479 (setq erc-default-recipients (cons qt erc-default-recipients)))))
5481 (defun erc-delete-query ()
5482 "Delete the topmost target if it is a QUERY."
5484 (let ((d1 (car erc-default-recipients))
5485 (d2 (cdr erc-default-recipients)))
5487 (eq (car d1) 'QUERY))
5488 (setq erc-default-recipients d2)
5489 (error "Current target is not a QUERY"))))
5491 (defun erc-ignored-user-p (spec)
5492 "Return non-nil if SPEC matches something in `erc-ignore-list'.
5494 Takes a full SPEC of a user in the form \"nick!login@host\", and
5495 matches against all the regexp's in `erc-ignore-list'. If any
5496 match, returns that regexp."
5498 (dolist (ignored (erc-with-server-buffer erc-ignore-list))
5499 (if (string-match ignored spec)
5500 (throw 'found ignored)))))
5502 (defun erc-ignored-reply-p (msg tgt proc)
5503 ;; FIXME: this docstring needs fixing -- Lawrence 2004-01-08
5504 "Return non-nil if MSG matches something in `erc-ignore-reply-list'.
5506 Takes a message MSG to a channel and returns non-nil if the addressed
5507 user matches any regexp in `erc-ignore-reply-list'."
5508 (let ((target-nick (erc-message-target msg)))
5509 (if (not target-nick)
5511 (erc-with-buffer (tgt proc)
5512 (let ((user (erc-get-server-user target-nick)))
5514 (erc-list-match erc-ignore-reply-list
5515 (erc-user-spec user))))))))
5517 (defun erc-message-target (msg)
5518 "Return the addressed target in MSG.
5520 The addressed target is the string before the first colon in MSG."
5521 (if (string-match "^\\([^: \n]*\\):" msg)
5522 (match-string 1 msg)
5525 (defun erc-user-spec (user)
5526 "Create a nick!user@host spec from a user struct."
5527 (let ((nick (erc-server-user-nickname user))
5528 (host (erc-server-user-host user))
5529 (login (erc-server-user-login user)))
5542 (defun erc-list-match (lst str)
5543 "Return non-nil if any regexp in LST matches STR."
5544 (memq nil (mapcar (lambda (regexp)
5545 (not (string-match regexp str)))
5550 (defun erc-toggle-ctcp-autoresponse (&optional arg)
5551 "Toggle automatic CTCP replies (like VERSION and PING).
5553 If ARG is positive, turns CTCP replies on.
5555 If ARG is non-nil and not positive, turns CTCP replies off."
5557 (cond ((and (numberp arg) (> arg 0))
5558 (setq erc-disable-ctcp-replies t))
5559 (arg (setq erc-disable-ctcp-replies nil))
5560 (t (setq erc-disable-ctcp-replies (not erc-disable-ctcp-replies))))
5561 (message "ERC CTCP replies are %s" (if erc-disable-ctcp-replies "OFF" "ON")))
5563 (defun erc-toggle-flood-control (&optional arg)
5564 "Toggle use of flood control on sent messages.
5566 If ARG is positive, use flood control.
5567 If ARG is non-nil and not positive, do not use flood control.
5569 See `erc-server-flood-margin' for an explanation of the available
5570 flood control parameters."
5572 (cond ((and (numberp arg) (> arg 0))
5573 (setq erc-flood-protect t))
5574 (arg (setq erc-flood-protect nil))
5575 (t (setq erc-flood-protect (not erc-flood-protect))))
5576 (message "ERC flood control is %s"
5577 (cond (erc-flood-protect "ON")
5580 ;; Some useful channel and nick commands for fast key bindings
5582 (defun erc-invite-only-mode (&optional arg)
5583 "Turn on the invite only mode (+i) for the current channel.
5585 If ARG is non-nil, turn this mode off (-i).
5587 This command is sent even if excess flood is detected."
5589 (erc-set-active-buffer (current-buffer))
5590 (let ((tgt (erc-default-target))
5592 (cond ((or (not tgt) (not (erc-channel-p tgt)))
5593 (erc-display-message nil 'error (current-buffer) 'no-target))
5594 (arg (erc-load-irc-script-lines (list (concat "/mode " tgt " -i"))
5596 (t (erc-load-irc-script-lines (list (concat "/mode " tgt " +i"))
5599 (defun erc-get-channel-mode-from-keypress (key)
5600 "Read a key sequence and call the corresponding channel mode function.
5601 After doing C-c C-o, type in a channel mode letter.
5604 RET lets you type more than one mode at a time.
5605 If \"l\" is pressed, `erc-set-channel-limit' gets called.
5606 If \"k\" is pressed, `erc-set-channel-key' gets called.
5607 Anything else will be sent to `erc-toggle-channel-mode'."
5608 (interactive "kChannel mode (RET to set more than one): ")
5609 (when (featurep 'xemacs)
5610 (setq key (char-to-string (event-to-character (aref key 0)))))
5611 (cond ((equal key "\C-g")
5614 (erc-insert-mode-command))
5616 (call-interactively 'erc-set-channel-limit))
5618 (call-interactively 'erc-set-channel-key))
5619 (t (erc-toggle-channel-mode key))))
5621 (defun erc-toggle-channel-mode (mode &optional channel)
5622 "Toggle channel MODE.
5624 If CHANNEL is non-nil, toggle MODE for that channel, otherwise use
5625 `erc-default-target'."
5627 (erc-set-active-buffer (current-buffer))
5628 (let ((tgt (or channel (erc-default-target)))
5630 (cond ((or (null tgt) (null (erc-channel-p tgt)))
5631 (erc-display-message nil 'error 'active 'no-target))
5632 ((member mode erc-channel-modes)
5633 (erc-log (format "%s: Toggle mode %s OFF" tgt mode))
5634 (message "Toggle channel mode %s OFF" mode)
5635 (erc-server-send (format "MODE %s -%s" tgt mode)))
5636 (t (erc-log (format "%s: Toggle channel mode %s ON" tgt mode))
5637 (message "Toggle channel mode %s ON" mode)
5638 (erc-server-send (format "MODE %s +%s" tgt mode))))))
5640 (defun erc-insert-mode-command ()
5641 "Insert the line \"/mode <current target> \" at `point'."
5643 (let ((tgt (erc-default-target)))
5644 (if tgt (insert (concat "/mode " tgt " "))
5645 (erc-display-message nil 'error (current-buffer) 'no-target))))
5647 (defun erc-channel-names ()
5648 "Run \"/names #channel\" in the current channel."
5650 (erc-set-active-buffer (current-buffer))
5651 (let ((tgt (erc-default-target)))
5652 (if tgt (erc-load-irc-script-lines (list (concat "/names " tgt)))
5653 (erc-display-message nil 'error (current-buffer) 'no-target))))
5655 (defun erc-remove-text-properties-region (start end &optional object)
5656 "Clears the region (START,END) in OBJECT from all colors, etc."
5659 (let ((inhibit-read-only t))
5660 (set-text-properties start end nil object))))
5661 (put 'erc-remove-text-properties-region 'disabled t)
5663 ;; script execution and startup
5665 (defun erc-find-file (file &optional path)
5666 "Search for a FILE in the filesystem.
5667 First the `default-directory' is searched for FILE, then any directories
5668 specified in the list PATH.
5670 If FILE is found, return the path to it."
5671 (let ((filepath file))
5672 (if (file-readable-p filepath) filepath
5675 (progn (setq filepath (expand-file-name file (car path)))
5676 (not (file-readable-p filepath))))
5677 (setq path (cdr path)))
5678 (if path filepath nil)))))
5680 (defun erc-select-startup-file ()
5681 "Select an ERC startup file.
5682 See also `erc-startup-file-list'."
5684 (dolist (f erc-startup-file-list)
5685 (setq f (convert-standard-filename f))
5686 (when (file-readable-p f)
5687 (throw 'found f)))))
5689 (defun erc-find-script-file (file)
5690 "Search for FILE in `default-directory', and any in `erc-script-path'."
5691 (erc-find-file file erc-script-path))
5693 (defun erc-load-script (file)
5694 "Load a script from FILE.
5696 FILE must be the full name, it is not searched in the
5697 `erc-script-path'. If the filename ends with `.el', then load it
5698 as an Emacs Lisp program. Otherwise, treat it as a regular IRC
5700 (erc-log (concat "erc-load-script: " file))
5702 ((string-match "\\.el$" file)
5705 (erc-load-irc-script file))))
5707 (defun erc-process-script-line (line &optional args)
5708 "Process an IRC script LINE.
5710 Does script-specific substitutions (script arguments, current nick,
5711 server, etc.) in LINE and returns it.
5713 Substitutions are: %C and %c = current target (channel or nick),
5714 %S %s = current server, %N %n = my current nick, and %x is x verbatim,
5715 where x is any other character;
5716 $* = the entire argument string, $1 = the first argument, $2 = the second,
5718 (if (not args) (setq args ""))
5719 (let* ((arg-esc-regexp "\\(\\$\\(\\*\\|[1-9][0-9]*\\)\\)\\([^0-9]\\|$\\)")
5720 (percent-regexp "\\(%.\\)")
5721 (esc-regexp (concat arg-esc-regexp "\\|" percent-regexp))
5722 (tgt (erc-default-target))
5723 (server (and (boundp 'erc-session-server) erc-session-server))
5724 (nick (erc-current-nick))
5729 (if (not tgt) (setq tgt ""))
5730 (if (not server) (setq server ""))
5731 (if (not nick) (setq nick ""))
5732 ;; First, compute the argument list
5734 (while (string-match "^\\s-*\\(\\S-+\\)\\(\\s-+.*$\\|$\\)" tmp)
5735 (setq arg-list (cons (match-string 1 tmp) arg-list))
5736 (setq tmp (match-string 2 tmp)))
5737 (setq arg-list (nreverse arg-list))
5738 (setq arg-num (length arg-list))
5739 ;; now do the substitution
5740 (setq tmp (string-match esc-regexp line))
5742 ;;(message "beginning of while: tmp=%S" tmp)
5743 (let* ((hd (substring line 0 tmp))
5746 (tail (substring line tmp)))
5747 (cond ((string-match (concat "^" arg-esc-regexp) tail)
5748 (setq esc (match-string 1 tail))
5749 (setq tail (substring tail (match-end 1))))
5750 ((string-match (concat "^" percent-regexp) tail)
5751 (setq esc (match-string 1 tail))
5752 (setq tail (substring tail (match-end 1)))))
5753 ;;(message "hd=%S, esc=%S, tail=%S, arg-num=%S" hd esc tail arg-num)
5754 (setq res (concat res hd))
5756 (cond ((string= esc "") "")
5757 ((string-match "^\\$\\*$" esc) args)
5758 ((string-match "^\\$\\([0-9]+\\)$" esc)
5759 (let ((n (string-to-number (match-string 1 esc))))
5760 (message "n = %S, integerp(n)=%S" n (integerp n))
5761 (if (<= n arg-num) (nth (1- n) arg-list) "")))
5762 ((string-match "^%[Cc]$" esc) tgt)
5763 ((string-match "^%[Ss]$" esc) server)
5764 ((string-match "^%[Nn]$" esc) nick)
5765 ((string-match "^%\\(.\\)$" esc) (match-string 1 esc))
5766 (t (erc-log (format "BUG in erc-process-script-line: bad escape sequence: %S\n" esc))
5767 (message "BUG IN ERC: esc=%S" esc)
5770 (setq tmp (string-match esc-regexp line))
5771 (setq res (concat res subst))
5772 ;;(message "end of while: line=%S, res=%S, tmp=%S" line res tmp)
5774 (setq res (concat res line))
5777 (defun erc-load-irc-script (file &optional force)
5778 "Load an IRC script from FILE."
5779 (erc-log (concat "erc-load-script: " file))
5780 (let ((str (with-temp-buffer
5781 (insert-file-contents file)
5783 (erc-load-irc-script-lines (erc-split-multiline-safe str) force)))
5785 (defun erc-load-irc-script-lines (lines &optional force noexpand)
5786 "Load IRC script LINES (a list of strings).
5788 If optional NOEXPAND is non-nil, do not expand script-specific
5789 sequences, process the lines verbatim. Use this for multiline
5791 (let* ((cb (current-buffer))
5794 (sp (or (erc-command-indicator) (erc-prompt)))
5795 (args (and (boundp 'erc-script-args) erc-script-args)))
5796 (if (and args (string-match "^ " args))
5797 (setq args (substring args 1)))
5798 ;; prepare the prompt string for echo
5799 (erc-put-text-property 0 (length sp)
5800 'face 'erc-command-indicator-face sp)
5802 (setq s (car lines))
5803 (erc-log (concat "erc-load-script: CMD: " s))
5804 (unless (string-match "^\\s-*$" s)
5805 (let ((line (if noexpand s (erc-process-script-line s args))))
5806 (if (and (erc-process-input-line line force)
5809 (erc-put-text-property 0 (length line)
5810 'face 'erc-input-face line)
5811 (erc-display-line (concat sp line) cb)))))
5812 (setq lines (cdr lines)))))
5817 "Perform user authentication at the IRC server."
5818 (erc-log (format "login: nick: %s, user: %s %s %s :%s"
5821 (or erc-system-name (system-name))
5823 erc-session-user-full-name))
5824 (if erc-session-password
5825 (erc-server-send (format "PASS %s" erc-session-password))
5826 (message "Logging in without password"))
5827 (erc-server-send (format "NICK %s" (erc-current-nick)))
5829 (format "USER %s %s %s :%s"
5831 (if erc-anonymous-login erc-email-userid (user-login-name))
5833 erc-session-user-full-name))
5834 (erc-update-mode-line))
5836 ;; connection properties' heuristics
5838 (defun erc-determine-parameters (&optional server port nick name)
5839 "Determine the connection and authentication parameters.
5840 Sets the buffer local variables:
5842 - `erc-session-connector'
5843 - `erc-session-server'
5844 - `erc-session-port'
5845 - `erc-session-full-name'
5846 - `erc-server-current-nick'"
5847 (setq erc-session-connector erc-server-connect-function
5848 erc-session-server (erc-compute-server server)
5849 erc-session-port (or port erc-default-port)
5850 erc-session-user-full-name (erc-compute-full-name name))
5851 (erc-set-current-nick (erc-compute-nick nick)))
5853 (defun erc-compute-server (&optional server)
5854 "Return an IRC server name.
5856 This tries a number of increasingly more default methods until a
5857 non-nil value is found.
5859 - SERVER (the argument passed to this function)
5860 - The `erc-server' option
5861 - The value of the IRCSERVER environment variable
5862 - The `erc-default-server' variable"
5865 (getenv "IRCSERVER")
5866 erc-default-server))
5868 (defun erc-compute-nick (&optional nick)
5869 "Return user's IRC nick.
5871 This tries a number of increasingly more default methods until a
5872 non-nil value is found.
5874 - NICK (the argument passed to this function)
5875 - The `erc-nick' option
5876 - The value of the IRCNICK environment variable
5877 - The result from the `user-login-name' function"
5879 (if (consp erc-nick) (car erc-nick) erc-nick)
5884 (defun erc-compute-full-name (&optional full-name)
5885 "Return user's full name.
5887 This tries a number of increasingly more default methods until a
5888 non-nil value is found.
5890 - FULL-NAME (the argument passed to this function)
5891 - The `erc-user-full-name' option
5892 - The value of the IRCNAME environment variable
5893 - The result from the `user-full-name' function"
5897 (if erc-anonymous-login "unknown" nil)
5900 (defun erc-compute-port (&optional port)
5901 "Return a port for an IRC server.
5903 This tries a number of increasingly more default methods until a
5904 non-nil value is found.
5906 - PORT (the argument passed to this function)
5907 - The `erc-port' option
5908 - The `erc-default-port' variable"
5909 (or port erc-port erc-default-port))
5913 (defun erc-string-to-emacs-time (string)
5914 "Convert the long number represented by STRING into an Emacs format.
5915 Returns a list of the form (HIGH LOW), compatible with Emacs time format."
5916 (let* ((n (string-to-number (concat string ".0"))))
5917 (list (truncate (/ n 65536))
5918 (truncate (mod n 65536)))))
5920 (defun erc-emacs-time-to-erc-time (time)
5921 "Convert Emacs TIME to a number of seconds since the epoch."
5923 (+ (* (nth 0 time) 65536.0) (nth 1 time))))
5924 ; (round (+ (* (nth 0 tm) 65536.0) (nth 1 tm))))
5926 (defun erc-current-time ()
5927 "Return the `current-time' as a number of seconds since the epoch.
5929 See also `erc-emacs-time-to-erc-time'."
5930 (erc-emacs-time-to-erc-time (current-time)))
5932 (defun erc-time-diff (t1 t2)
5933 "Return the time difference in seconds between T1 and T2."
5936 (defun erc-time-gt (t1 t2)
5937 "Check whether T1 > T2."
5940 (defun erc-sec-to-time (ns)
5941 "Convert NS to a time string HH:MM.SS."
5942 (setq ns (truncate ns))
5943 (format "%02d:%02d.%02d"
5948 (defun erc-seconds-to-string (seconds)
5949 "Convert a number of SECONDS into an English phrase."
5950 (let (days hours minutes format-args output)
5951 (setq days (/ seconds 86400)
5952 seconds (% seconds 86400)
5953 hours (/ seconds 3600)
5954 seconds (% seconds 3600)
5955 minutes (/ seconds 60)
5956 seconds (% seconds 60)
5957 format-args (if (> days 0)
5958 `("%d days, %d hours, %d minutes, %d seconds"
5959 ,days ,hours ,minutes ,seconds)
5961 `("%d hours, %d minutes, %d seconds"
5962 ,hours ,minutes ,seconds)
5964 `("%d minutes, %d seconds" ,minutes ,seconds)
5965 `("%d seconds" ,seconds))))
5966 output (apply 'format format-args))
5967 ;; Change all "1 units" to "1 unit".
5968 (while (string-match "\\([^0-9]\\|^\\)1 \\S-+\\(s\\)" output)
5969 (setq output (erc-replace-match-subexpression-in-string
5970 "" output (match-string 2 output) 2 (match-beginning 2))))
5976 (defconst erc-clientinfo-alist
5977 '(("ACTION" . "is used to inform about one's current activity")
5978 ("CLIENTINFO" . "gives help on CTCP commands supported by client")
5979 ("ECHO" . "echoes its arguments back")
5980 ("FINGER" . "shows user's name, location, and idle time")
5981 ("PING" . "measures delay between peers")
5982 ("TIME" . "shows client-side time")
5983 ("USERINFO" . "shows information provided by a user")
5984 ("VERSION" . "shows client type and version"))
5985 "Alist of CTCP CLIENTINFO for ERC commands.")
5987 (defun erc-client-info (s)
5988 "Return CTCP CLIENTINFO on command S.
5989 If S is nil or an empty string then return general CLIENTINFO."
5990 (if (or (not s) (string= s ""))
5994 (concat (car e) " "))
5995 erc-clientinfo-alist))
5996 ": use CLIENTINFO <COMMAND> to get more specific information")
5997 (let ((h (assoc (upcase s) erc-clientinfo-alist)))
5999 (concat s " " (cdr h))
6000 (concat s ": unknown command")))))
6004 (defun erc-directory-writable-p (dir)
6005 "Determine whether DIR is a writable directory.
6006 If it doesn't exist, create it."
6007 (unless (file-attributes dir) (make-directory dir))
6008 (or (file-accessible-directory-p dir) (error "Cannot access %s" dir)))
6010 (defun erc-kill-query-buffers (process)
6011 "Kill all buffers of PROCESS."
6012 ;; here, we only want to match the channel buffers, to avoid
6013 ;; "selecting killed buffers" b0rkage.
6014 (erc-with-all-buffers-of-server process
6016 (not (erc-server-buffer-p)))
6017 (kill-buffer (current-buffer))))
6019 (defun erc-nick-at-point ()
6020 "Give information about the nickname at `point'.
6022 If called interactively, give a human readable message in the
6023 minibuffer. If called programmatically, return the corresponding
6024 entry of `channel-members'."
6026 (require 'thingatpt)
6027 (let* ((word (word-at-point))
6028 (channel-data (erc-get-channel-user word))
6029 (cuser (cdr channel-data))
6030 (user (if channel-data
6032 (erc-get-server-user word)))
6033 host login full-name info nick op voice)
6035 (setq nick (erc-server-user-nickname user)
6036 host (erc-server-user-host user)
6037 login (erc-server-user-login user)
6038 full-name (erc-server-user-full-name user)
6039 info (erc-server-user-info user))
6041 (setq op (erc-channel-user-op cuser)
6042 voice (erc-channel-user-voice cuser)))
6043 (if (called-interactively-p 'interactive)
6044 (message "%s is %s@%s%s%s"
6046 (if full-name (format " (%s)" full-name) "")
6048 (format " and is +%s%s on %s"
6051 (erc-default-target))
6055 (defun erc-away-time ()
6056 "Return non-nil if the current ERC process is set away.
6058 In particular, the time that we were set away is returned.
6059 See `current-time' for details on the time format."
6060 (erc-with-server-buffer erc-away))
6062 ;; Mode line handling
6064 (defcustom erc-mode-line-format "%S %a"
6065 "A string to be formatted and shown in the mode-line in `erc-mode'.
6067 The string is formatted using `format-spec' and the result is set as the value
6068 of `mode-line-buffer-identification'.
6070 The following characters are replaced:
6071 %a: String indicating away status or \"\" if you are not away
6072 %l: The estimated lag time to the server
6073 %m: The modes of the channel
6074 %n: The current nick name
6075 %N: The name of the network
6076 %o: The topic of the channel
6077 %p: The session port
6078 %t: The name of the target (channel, nickname, or servername:port)
6079 %s: In the server-buffer, this gets filled with the value of
6080 `erc-server-announced-name', in a channel, the value of
6081 (erc-default-target) also get concatenated.
6082 %S: In the server-buffer, this gets filled with the value of
6083 `erc-network', in a channel, the value of (erc-default-target)
6084 also get concatenated."
6085 :group 'erc-mode-line-and-header
6088 (defcustom erc-header-line-format "%n on %t (%m,%l) %o"
6089 "A string to be formatted and shown in the header-line in `erc-mode'.
6090 Only used starting in Emacs 21.
6092 Set this to nil if you do not want the header line to be
6095 See `erc-mode-line-format' for which characters are can be used."
6096 :group 'erc-mode-line-and-header
6097 :set (lambda (sym val)
6099 (when (fboundp 'erc-update-mode-line)
6100 (erc-update-mode-line nil)))
6101 :type '(choice (const :tag "Disabled" nil)
6104 (defcustom erc-header-line-uses-tabbar-p nil
6105 "Use tabbar mode instead of the header line to display the header."
6106 :group 'erc-mode-line-and-header
6109 (defcustom erc-header-line-uses-help-echo-p t
6110 "Show the contents of the header line in the echo area or as a tooltip
6111 when you move point into the header line."
6112 :group 'erc-mode-line-and-header
6115 (defcustom erc-header-line-face-method nil
6116 "Determine what method to use when colorizing the header line text.
6118 If nil, don't colorize the header text.
6119 If given a function, call it and use the resulting face name.
6120 Otherwise, use the `erc-header-line' face."
6121 :group 'erc-mode-line-and-header
6122 :type '(choice (const :tag "Don't colorize" nil)
6123 (const :tag "Use the erc-header-line face" t)
6124 (function :tag "Call a function")))
6126 (defcustom erc-show-channel-key-p t
6127 "Show the channel key in the header line."
6128 :group 'erc-paranoia
6131 (defcustom erc-mode-line-away-status-format
6132 "(AWAY since %a %b %d %H:%M) "
6133 "When you're away on a server, this is shown in the mode line.
6134 This should be a string with substitution variables recognized by
6135 `format-time-string'."
6136 :group 'erc-mode-line-and-header
6139 (defun erc-shorten-server-name (server-name)
6140 "Shorten SERVER-NAME according to `erc-common-server-suffixes'."
6141 (if (stringp server-name)
6143 (insert server-name)
6144 (let ((alist erc-common-server-suffixes))
6146 (goto-char (point-min))
6147 (if (re-search-forward (caar alist) nil t)
6148 (replace-match (cdar alist)))
6149 (setq alist (cdr alist))))
6152 (defun erc-format-target ()
6153 "Return the name of the target (channel or nickname or servername:port)."
6154 (let ((target (erc-default-target)))
6156 (concat (erc-shorten-server-name
6157 (or erc-server-announced-name
6158 erc-session-server))
6159 ":" (erc-port-to-string erc-session-port)))))
6161 (defun erc-format-target-and/or-server ()
6162 "Return the server name or the current target and server name combined."
6163 (let ((server-name (erc-shorten-server-name
6164 (or erc-server-announced-name
6165 erc-session-server))))
6166 (cond ((erc-default-target)
6167 (concat (erc-string-no-properties (erc-default-target))
6169 (server-name server-name)
6170 (t (buffer-name (current-buffer))))))
6172 (defun erc-format-network ()
6173 "Return the name of the network we are currently on."
6174 (let ((network (and (fboundp 'erc-network-name) (erc-network-name))))
6175 (if (and network (symbolp network))
6176 (symbol-name network)
6179 (defun erc-format-target-and/or-network ()
6180 "Return the network or the current target and network combined.
6181 If the name of the network is not available, then use the
6182 shortened server name instead."
6183 (let ((network-name (or (and (fboundp 'erc-network-name) (erc-network-name))
6184 (erc-shorten-server-name
6185 (or erc-server-announced-name
6186 erc-session-server)))))
6187 (when (and network-name (symbolp network-name))
6188 (setq network-name (symbol-name network-name)))
6189 (cond ((erc-default-target)
6190 (concat (erc-string-no-properties (erc-default-target))
6192 (network-name network-name)
6193 (t (buffer-name (current-buffer))))))
6195 (defun erc-format-away-status ()
6196 "Return a formatted `erc-mode-line-away-status-format'
6197 if `erc-away' is non-nil."
6198 (let ((a (erc-away-time)))
6200 (format-time-string erc-mode-line-away-status-format a)
6203 (defun erc-format-channel-modes ()
6204 "Return the current channel's modes."
6205 (concat (apply 'concat
6206 "+" erc-channel-modes)
6207 (cond ((and erc-channel-user-limit erc-channel-key)
6208 (if erc-show-channel-key-p
6209 (format "lk %.0f %s" erc-channel-user-limit
6211 (format "kl %.0f" erc-channel-user-limit)))
6212 (erc-channel-user-limit
6213 ;; Emacs has no bignums
6214 (format "l %.0f" erc-channel-user-limit))
6216 (if erc-show-channel-key-p
6217 (format "k %s" erc-channel-key)
6221 (defun erc-format-lag-time ()
6222 "Return the estimated lag time to server, `erc-server-lag'."
6223 (let ((lag (erc-with-server-buffer erc-server-lag)))
6224 (cond (lag (format "lag:%.0f" lag))
6227 ;; erc-goodies is required at end of this file.
6228 (declare-function erc-controls-strip "erc-goodies" (str))
6230 (defvar tabbar--local-hlf)
6232 (defun erc-update-mode-line-buffer (buffer)
6233 "Update the mode line in a single ERC buffer BUFFER."
6234 (with-current-buffer buffer
6235 (let ((spec (format-spec-make
6236 ?a (erc-format-away-status)
6237 ?l (erc-format-lag-time)
6238 ?m (erc-format-channel-modes)
6239 ?n (or (erc-current-nick) "")
6240 ?N (erc-format-network)
6241 ?o (erc-controls-strip erc-channel-topic)
6242 ?p (erc-port-to-string erc-session-port)
6243 ?s (erc-format-target-and/or-server)
6244 ?S (erc-format-target-and/or-network)
6245 ?t (erc-format-target)))
6246 (process-status (cond ((and (erc-server-process-alive)
6247 (not erc-server-connected))
6249 ((erc-server-process-alive)
6253 (face (cond ((eq erc-header-line-face-method nil)
6255 ((functionp erc-header-line-face-method)
6256 (funcall erc-header-line-face-method))
6258 'erc-header-line))))
6259 (cond ((featurep 'xemacs)
6260 (setq modeline-buffer-identification
6261 (list (format-spec erc-mode-line-format spec)))
6262 (setq modeline-process (list process-status)))
6264 (setq mode-line-buffer-identification
6265 (list (format-spec erc-mode-line-format spec)))
6266 (setq mode-line-process (list process-status))))
6267 (when (boundp 'header-line-format)
6268 (let ((header (if erc-header-line-format
6269 (format-spec erc-header-line-format spec)
6271 (cond (erc-header-line-uses-tabbar-p
6272 (set (make-local-variable 'tabbar--local-hlf)
6274 (kill-local-variable 'header-line-format))
6276 (setq header-line-format nil))
6277 (erc-header-line-uses-help-echo-p
6278 (let ((help-echo (with-temp-buffer
6280 (fill-region (point-min) (point-max))
6282 (setq header-line-format
6283 (erc-replace-regexp-in-string
6287 (erc-propertize header 'help-echo help-echo
6289 (erc-propertize header 'help-echo help-echo))))))
6290 (t (setq header-line-format
6292 (erc-propertize header 'face face)
6294 (if (featurep 'xemacs)
6296 (force-mode-line-update))))
6298 (defun erc-update-mode-line (&optional buffer)
6299 "Update the mode line in BUFFER.
6301 If BUFFER is nil, update the mode line in all ERC buffers."
6302 (if (and buffer (bufferp buffer))
6303 (erc-update-mode-line-buffer buffer)
6304 (dolist (buf (erc-buffer-list))
6305 (when (buffer-live-p buf)
6306 (erc-update-mode-line-buffer buf)))))
6310 (defun erc-port-to-string (p)
6311 "Convert port P to a string.
6312 P may be an integer or a service name."
6317 (defun erc-string-to-port (s)
6318 "Convert string S to either an integer port number or a service name."
6321 (let ((n (string-to-number s)))
6326 (defun erc-version (&optional here)
6327 "Show the version number of ERC in the minibuffer.
6328 If optional argument HERE is non-nil, insert version number at point."
6330 (let ((version-string
6331 (format "ERC %s (GNU Emacs %s)" erc-version-string emacs-version)))
6333 (insert version-string)
6334 (if (called-interactively-p 'interactive)
6335 (message "%s" version-string)
6338 (defun erc-modes (&optional here)
6339 "Show the active ERC modes in the minibuffer.
6340 If optional argument HERE is non-nil, insert version number at point."
6343 (mapconcat 'identity
6344 (let (modes (case-fold-search nil))
6345 (dolist (var (apropos-internal "^erc-.*mode$"))
6346 (when (and (boundp var)
6348 (setq modes (cons (symbol-name var)
6354 (if (called-interactively-p 'interactive)
6355 (message "%s" string)
6358 (defun erc-trim-string (s)
6359 "Trim leading and trailing spaces off S."
6361 ((not (stringp s)) nil)
6362 ((string-match "^\\s-*$" s)
6364 ((string-match "^\\s-*\\(.*\\S-\\)\\s-*$" s)
6369 (defun erc-arrange-session-in-multiple-windows ()
6370 "Open a window for every non-server buffer related to `erc-session-server'.
6372 All windows are opened in the current frame."
6374 (unless erc-server-process
6375 (error "No erc-server-process found in current buffer"))
6376 (let ((bufs (erc-buffer-list nil erc-server-process)))
6378 (delete-other-windows)
6379 (switch-to-buffer (car bufs))
6380 (setq bufs (cdr bufs))
6384 (switch-to-buffer (car bufs))
6385 (setq bufs (cdr bufs))
6386 (balance-windows)))))
6388 (defun erc-popup-input-buffer ()
6389 "Provide an input buffer."
6391 (let ((buffer-name (generate-new-buffer-name "*ERC input*"))
6396 (list (symbol-name e)))
6397 (apropos-internal "-mode$" 'commandp))
6399 (pop-to-buffer (make-indirect-buffer (current-buffer) buffer-name))
6401 (narrow-to-region (point) (point))
6402 (shrink-window-if-larger-than-buffer)))
6406 (defun erc-make-message-variable-name (catalog entry)
6407 "Create a variable name corresponding to CATALOG's ENTRY."
6408 (intern (concat "erc-message-"
6409 (symbol-name catalog) "-" (symbol-name entry))))
6411 (defun erc-define-catalog-entry (catalog entry format-spec)
6412 "Set CATALOG's ENTRY to FORMAT-SPEC."
6413 (set (erc-make-message-variable-name catalog entry)
6416 (defun erc-define-catalog (catalog entries)
6417 "Define a CATALOG according to ENTRIES."
6418 (dolist (entry entries)
6419 (erc-define-catalog-entry catalog (car entry) (cdr entry))))
6423 '((bad-ping-response . "Unexpected PING response from %n (time %t)")
6424 (bad-syntax . "Error occurred - incorrect usage?\n%c %u\n%d")
6425 (incorrect-args . "Incorrect arguments. Usage:\n%c %u\n%d")
6426 (cannot-find-file . "Cannot find file %f")
6427 (cannot-read-file . "Cannot read file %f")
6428 (connect . "Connecting to %S:%p... ")
6430 (country-unknown . "%d: No such domain")
6431 (ctcp-empty . "Illegal empty CTCP query received from %n. Ignoring.")
6432 (ctcp-request . "==> CTCP request from %n (%u@%h): %r")
6433 (ctcp-request-to . "==> CTCP request from %n (%u@%h) to %t: %r")
6434 (ctcp-too-many . "Too many CTCP queries in single message. Ignoring")
6435 (flood-ctcp-off . "FLOOD PROTECTION: Automatic CTCP responses turned off.")
6437 . "FLOOD PROTECTION: Switched to Strict Flood Control mode.")
6438 (disconnected . "\n\nConnection failed! Re-establishing connection...\n")
6439 (disconnected-noreconnect
6440 . "\n\nConnection failed! Not re-establishing connection.\n")
6441 (finished . "\n\n*** ERC finished ***\n")
6442 (terminated . "\n\n*** ERC terminated: %e\n")
6443 (login . "Logging in as \'%n\'...")
6444 (nick-in-use . "%n is in use. Choose new nickname: ")
6446 . "WARNING: Nick length (%i) exceeds max NICKLEN(%l) defined by server")
6447 (no-default-channel . "No default channel")
6448 (no-invitation . "You've got no invitation")
6449 (no-target . "No target")
6450 (ops . "%i operator%s: %o")
6451 (ops-none . "No operators in this channel.")
6452 (undefined-ctcp . "Undefined CTCP query received. Silently ignored")
6453 (variable-not-bound . "Variable not bound!")
6454 (ACTION . "* %n %a")
6455 (CTCP-CLIENTINFO . "Client info for %n: %m")
6456 (CTCP-ECHO . "Echo %n: %m")
6457 (CTCP-FINGER . "Finger info for %n: %m")
6458 (CTCP-PING . "Ping time to %n is %t")
6459 (CTCP-TIME . "Time by %n is %m")
6460 (CTCP-UNKNOWN . "Unknown CTCP message from %n (%u@%h): %m")
6461 (CTCP-VERSION . "Version for %n is %m")
6462 (ERROR . "==> ERROR from %s: %c\n")
6463 (INVITE . "%n (%u@%h) invites you to channel %c")
6464 (JOIN . "%n (%u@%h) has joined channel %c")
6465 (JOIN-you . "You have joined channel %c")
6466 (KICK . "%n (%u@%h) has kicked %k off channel %c: %r")
6467 (KICK-you . "You have been kicked off channel %c by %n (%u@%h): %r")
6468 (KICK-by-you . "You have kicked %k off channel %c: %r")
6469 (MODE . "%n (%u@%h) has changed mode for %t to %m")
6470 (MODE-nick . "%n has changed mode for %t to %m")
6471 (NICK . "%n (%u@%h) is now known as %N")
6472 (NICK-you . "Your new nickname is %N")
6473 (PART . erc-message-english-PART)
6474 (PING . "PING from server (last: %s sec. ago)")
6475 (PONG . "PONG from %h (%i second%s)")
6476 (QUIT . "%n (%u@%h) has quit: %r")
6477 (TOPIC . "%n (%u@%h) has set the topic for %c: \"%T\"")
6478 (WALLOPS . "Wallops from %n: %m")
6479 (s004 . "%s %v %U %C")
6480 (s221 . "User modes for %n: %m")
6481 (s252 . "%i operator(s) online")
6482 (s253 . "%i unknown connection(s)")
6483 (s254 . "%i channels formed")
6485 (s301 . "%n is AWAY: %r")
6486 (s303 . "Is online: %n")
6490 (s311 . "%n is %f (%u@%h)")
6491 (s312 . "%n is/was on server %s (%c)")
6492 (s313 . "%n is an IRC operator")
6493 (s314 . "%n was %f (%u@%h)")
6494 (s317 . "%n has been idle for %i")
6495 (s317-on-since . "%n has been idle for %i, on since %t")
6496 (s319 . "%n is on channel(s): %c")
6497 (s320 . "%n is an identified user")
6498 (s321 . "Channel Users Topic")
6499 (s322 . "%c [%u] %t")
6500 (s324 . "%c modes: %m")
6501 (s328 . "%c URL: %u")
6502 (s329 . "%c was created on %t")
6504 (s331 . "No topic is set for %c")
6505 (s332 . "Topic for %c: %T")
6506 (s333 . "%c: topic set by %n, %t")
6507 (s341 . "Inviting %n to channel %c")
6508 (s352 . "%-11c %-10n %-4a %u@%h (%f)")
6509 (s353 . "Users on %c: %u")
6510 (s367 . "Ban for %b on %c")
6511 (s367-set-by . "Ban for %b on %c set by %s on %t")
6512 (s368 . "Banlist of %c ends.")
6513 (s379 . "%c: Forwarded to %f")
6514 (s391 . "The time at %s is %t")
6515 (s401 . "%n: No such nick/channel")
6516 (s403 . "%c: No such channel")
6517 (s404 . "%c: Cannot send to channel")
6518 (s405 . "%c: You have joined too many channels")
6519 (s406 . "%n: There was no such nickname")
6520 (s412 . "No text to send")
6521 (s421 . "%c: Unknown command")
6522 (s431 . "No nickname given")
6523 (s432 . "%n is an erroneous nickname")
6524 (s442 . "%c: You're not on that channel")
6525 (s445 . "SUMMON has been disabled")
6526 (s446 . "USERS has been disabled")
6527 (s451 . "You have not registered")
6528 (s461 . "%c: not enough parameters")
6529 (s462 . "Unauthorized command (already registered)")
6530 (s463 . "Your host isn't among the privileged")
6531 (s464 . "Password incorrect")
6532 (s465 . "You are banned from this server")
6533 (s474 . "You can't join %c because you're banned (+b)")
6534 (s475 . "You must specify the correct channel key (+k) to join %c")
6535 (s481 . "Permission Denied - You're not an IRC operator")
6536 (s482 . "You need to be a channel operator of %c to do that")
6537 (s483 . "You can't kill a server!")
6538 (s484 . "Your connection is restricted!")
6539 (s485 . "You're not the original channel operator")
6540 (s491 . "No O-lines for your host")
6541 (s501 . "Unknown MODE flag")
6542 (s502 . "You can't change modes for other users")
6545 (defun erc-message-english-PART (&rest args)
6546 "Format a proper PART message.
6548 This function is an example on what could be done with formatting
6550 (let ((nick (cadr (memq ?n args)))
6551 (user (cadr (memq ?u args)))
6552 (host (cadr (memq ?h args)))
6553 (channel (cadr (memq ?c args)))
6554 (reason (cadr (memq ?r args))))
6555 (if (string= nick (erc-current-nick))
6556 (format "You have left channel %s" channel)
6557 (format "%s (%s@%s) has left channel %s%s"
6558 nick user host channel
6559 (if (not (string= reason ""))
6561 (erc-replace-regexp-in-string "%" "%%" reason))
6565 (defvar erc-current-message-catalog 'english)
6566 (make-variable-buffer-local 'erc-current-message-catalog)
6568 (defun erc-retrieve-catalog-entry (entry &optional catalog)
6569 "Retrieve ENTRY from CATALOG.
6571 If CATALOG is nil, `erc-current-message-catalog' is used.
6573 If ENTRY is nil in CATALOG, it is retrieved from the fallback,
6575 (unless catalog (setq catalog erc-current-message-catalog))
6576 (let ((var (erc-make-message-variable-name catalog entry)))
6579 (when (boundp (erc-make-message-variable-name 'english entry))
6580 (symbol-value (erc-make-message-variable-name 'english entry))))))
6582 (defun erc-format-message (msg &rest args)
6583 "Format MSG according to ARGS.
6585 See also `format-spec'."
6586 (when (eq (logand (length args) 1) 1) ; oddp
6587 (error "Obscure usage of this function appeared"))
6588 (let ((entry (erc-retrieve-catalog-entry msg)))
6590 (error "No format spec for message %s" msg))
6591 (when (functionp entry)
6592 (setq entry (apply entry args)))
6593 (format-spec entry (apply 'format-spec-make args))))
6595 ;;; Various hook functions
6597 (add-hook 'kill-buffer-hook 'erc-kill-buffer-function)
6599 (defcustom erc-kill-server-hook '(erc-kill-server)
6600 "Invoked whenever a server-buffer is killed via `kill-buffer'."
6604 (defcustom erc-kill-channel-hook '(erc-kill-channel)
6605 "Invoked whenever a channel-buffer is killed via `kill-buffer'."
6609 (defcustom erc-kill-buffer-hook nil
6610 "Hook run whenever a non-server or channel buffer is killed.
6612 See also `kill-buffer'."
6616 (defun erc-kill-buffer-function ()
6617 "Function to call when an ERC buffer is killed.
6618 This function should be on `kill-buffer-hook'.
6619 When the current buffer is in `erc-mode', this function will run
6620 one of the following hooks:
6621 `erc-kill-server-hook' if the server buffer was killed,
6622 `erc-kill-channel-hook' if a channel buffer was killed,
6623 or `erc-kill-buffer-hook' if any other buffer."
6624 (when (eq major-mode 'erc-mode)
6625 (erc-remove-channel-users)
6627 ((eq (erc-server-buffer) (current-buffer))
6628 (run-hooks 'erc-kill-server-hook))
6629 ((erc-channel-p (erc-default-target))
6630 (run-hooks 'erc-kill-channel-hook))
6632 (run-hooks 'erc-kill-buffer-hook)))))
6634 (defun erc-kill-server ()
6635 "Sends a QUIT command to the server when the server buffer is killed.
6636 This function should be on `erc-kill-server-hook'."
6637 (when (erc-server-process-alive)
6638 (setq erc-server-quitting t)
6639 (erc-server-send (format "QUIT :%s" (funcall erc-quit-reason nil)))))
6641 (defun erc-kill-channel ()
6642 "Sends a PART command to the server when the channel buffer is killed.
6643 This function should be on `erc-kill-channel-hook'."
6644 (when (erc-server-process-alive)
6645 (let ((tgt (erc-default-target)))
6646 (erc-server-send (format "PART %s :%s" tgt
6647 (funcall erc-part-reason nil))
6650 ;;; Dealing with `erc-parsed'
6652 (defun erc-find-parsed-property ()
6653 "Find the next occurrence of the `erc-parsed' text property."
6654 (text-property-not-all (point-min) (point-max) 'erc-parsed nil))
6656 (defun erc-restore-text-properties ()
6657 "Restore the property 'erc-parsed for the region."
6658 (let ((parsed-posn (erc-find-parsed-property)))
6660 (point-min) (point-max)
6661 'erc-parsed (when parsed-posn (erc-get-parsed-vector parsed-posn)))))
6663 (defun erc-get-parsed-vector (point)
6664 "Return the whole parsed vector on POINT."
6665 (get-text-property point 'erc-parsed))
6667 (defun erc-get-parsed-vector-nick (vect)
6668 "Return nickname in the parsed vector VECT."
6669 (let* ((untreated-nick (and vect (erc-response.sender vect)))
6670 (maybe-nick (when untreated-nick
6671 (car (split-string untreated-nick "!")))))
6672 (when (and (not (null maybe-nick))
6673 (erc-is-valid-nick-p maybe-nick))
6676 (defun erc-get-parsed-vector-type (vect)
6677 "Return message type in the parsed vector VECT."
6679 (erc-response.command vect)))
6681 ;; Teach url.el how to open irc:// URLs with ERC.
6682 ;; To activate, customize `url-irc-function' to `url-irc-erc'.
6685 (defun erc-handle-irc-url (host port channel user password)
6686 "Use ERC to IRC on HOST:PORT in CHANNEL as USER with PASSWORD.
6687 If ERC is already connected to HOST:PORT, simply /join CHANNEL.
6688 Otherwise, connect to HOST:PORT as USER and /join CHANNEL."
6689 (let ((server-buffer
6690 (car (erc-buffer-filter
6692 (and (string-equal erc-session-server host)
6693 (= erc-session-port port)
6694 (erc-open-server-buffer-p)))))))
6695 (with-current-buffer (or server-buffer (current-buffer))
6696 (if (and server-buffer channel)
6697 (erc-cmd-JOIN channel)
6698 (erc-open host port (or user (erc-compute-nick)) (erc-compute-full-name)
6699 (not server-buffer) password nil channel
6701 (get-buffer-process server-buffer)))))))
6705 ;;; Deprecated. We might eventually stop requiring the goodies automatically.
6706 ;;; IMPORTANT: This require must appear _after_ the above (provide 'erc) to
6707 ;;; avoid a recursive require error when byte-compiling the entire package.
6708 (require 'erc-goodies)
6710 ;;; erc.el ends here
6713 ;; outline-regexp: ";;+"
6714 ;; indent-tabs-mode: t