1 ;; erc.el --- An Emacs Internet Relay Chat client -*- lexical-binding:t -*-
3 ;; Copyright (C) 1997-2014 Free Software Foundation, Inc.
5 ;; Author: Alexander L. Belikoff (alexander@belikoff.net)
6 ;; Contributors: Sergey Berezin (sergey.berezin@cs.cmu.edu),
7 ;; Mario Lang (mlang@delysid.org),
8 ;; Alex Schroeder (alex@gnu.org)
9 ;; Andreas Fuchs (afs@void.at)
10 ;; Gergely Nagy (algernon@midgard.debian.net)
11 ;; David Edmondson (dme@dme.org)
12 ;; Kelvin White <kelvin.white77@gmail.com>
13 ;; Maintainer: emacs-devel@gnu.org
14 ;; Keywords: IRC, chat, client, Internet
17 ;; This file is part of GNU Emacs.
19 ;; GNU Emacs is free software: you can redistribute it and/or modify
20 ;; it under the terms of the GNU General Public License as published by
21 ;; the Free Software Foundation, either version 3 of the License, or
22 ;; (at your option) any later version.
24 ;; GNU Emacs is distributed in the hope that it will be useful,
25 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
26 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 ;; GNU General Public License for more details.
29 ;; You should have received a copy of the GNU General Public License
30 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
34 ;; ERC is a powerful, modular, and extensible IRC client for Emacs.
36 ;; For more information, see the following URLs:
37 ;; * http://sv.gnu.org/projects/erc/
38 ;; * http://www.emacswiki.org/cgi-bin/wiki/ERC
40 ;; As of 2006-06-13, ERC development is now hosted on Savannah
41 ;; (http://sv.gnu.org/projects/erc). I invite everyone who wants to
42 ;; hack on it to contact me <mwolson@gnu.org> in order to get write
43 ;; access to the shared Arch archive.
47 ;; Put erc.el in your load-path, and put (require 'erc) in your .emacs.
51 ;; Use M-x customize-group RET erc RET to get an overview
52 ;; of all the variables you can tweak.
56 ;; To connect to an IRC server, do
60 ;; After you are connected to a server, you can use C-h m or have a look at
68 (defconst erc-version-string
"Version 5.3"
69 "ERC version. This is used by function `erc-version'.")
71 (eval-when-compile (require 'cl-lib
))
75 (require 'auth-source
)
78 (defvar erc-official-location
79 "http://emacswiki.org/cgi-bin/wiki/ERC (mailing list: erc-discuss@gnu.org)"
80 "Location of the ERC client on the Internet.")
83 "Emacs Internet Relay Chat client."
84 :link
'(url-link "http://www.emacswiki.org/cgi-bin/wiki/ERC")
85 :link
'(custom-manual "(erc) Top")
89 (defgroup erc-buffers nil
90 "Creating new ERC buffers"
93 (defgroup erc-display nil
94 "Settings for how various things are displayed"
97 (defgroup erc-mode-line-and-header nil
98 "Displaying information in the mode-line and header"
101 (defgroup erc-ignore nil
102 "Ignoring certain messages"
105 (defgroup erc-lurker nil
106 "Hide specified message types sent by lurkers"
110 (defgroup erc-query nil
111 "Using separate buffers for private discussions"
114 (defgroup erc-quit-and-part nil
115 "Quitting and parting channels"
118 (defgroup erc-paranoia nil
119 "Know what is sent and received; control the display of sensitive data."
122 (defgroup erc-scripts nil
123 "Running scripts at startup and with /LOAD"
126 (require 'erc-backend
)
128 ;; compatibility with older ERC releases
130 (define-obsolete-variable-alias 'erc-announced-server-name
131 'erc-server-announced-name
"ERC 5.1")
132 (define-obsolete-variable-alias 'erc-process
'erc-server-process
"ERC 5.1")
133 (define-obsolete-variable-alias 'erc-default-coding-system
134 'erc-server-coding-system
"ERC 5.1")
136 (define-obsolete-function-alias 'erc-send-command
137 'erc-server-send
"ERC 5.1")
139 ;; tunable connection and authentication parameters
141 (defcustom erc-server nil
142 "IRC server to use if one is not provided.
143 See function `erc-compute-server' for more details on connection
144 parameters and authentication."
146 :type
'(choice (const :tag
"None" nil
)
147 (string :tag
"Server")))
149 (defcustom erc-port nil
150 "IRC port to use if not specified.
152 This can be either a string or a number."
154 :type
'(choice (const :tag
"None" nil
)
155 (integer :tag
"Port number")
156 (string :tag
"Port string")))
158 (defcustom erc-nick nil
159 "Nickname to use if one is not provided.
161 This can be either a string, or a list of strings.
162 In the latter case, if the first nick in the list is already in use,
163 other nicks are tried in the list order.
165 See function `erc-compute-nick' for more details on connection
166 parameters and authentication."
168 :type
'(choice (const :tag
"None" nil
)
169 (string :tag
"Nickname")
170 (repeat (string :tag
"Nickname"))))
172 (defcustom erc-nick-uniquifier
"`"
173 "The string to append to the nick if it is already in use."
177 (defcustom erc-try-new-nick-p t
178 "If the nickname you chose isn't available, and this option is non-nil,
179 ERC should automatically attempt to connect with another nickname.
181 You can manually set another nickname with the /NICK command."
185 (defcustom erc-user-full-name nil
188 This can be either a string or a function to call.
190 See function `erc-compute-full-name' for more details on connection
191 parameters and authentication."
193 :type
'(choice (const :tag
"No name" nil
)
195 (function :tag
"Get from function"))
196 :set
(lambda (sym val
)
197 (set sym
(if (functionp val
) (funcall val
) val
))))
199 (defvar erc-password nil
200 "Password to use when authenticating to an IRC server.
201 It is not strictly necessary to provide this, since ERC will
204 (defcustom erc-user-mode nil
205 "Initial user modes to be set after a connection is established."
207 :type
'(choice (const nil
) string function
))
210 (defcustom erc-prompt-for-password t
211 "Asks before using the default password, or whether to enter a new one."
215 (defcustom erc-warn-about-blank-lines t
216 "Warn the user if they attempt to send a blank line."
220 (defcustom erc-send-whitespace-lines nil
221 "If set to non-nil, send lines consisting of only whitespace."
225 (defcustom erc-hide-prompt nil
226 "If non-nil, do not display the prompt for commands.
228 \(A command is any input starting with a '/').
230 See also the variables `erc-prompt' and `erc-command-indicator'."
236 (defcustom erc-show-my-nick t
237 "If non-nil, display one's own nickname when sending a message.
239 If non-nil, \"<nickname>\" will be shown.
240 If nil, only \"> \" will be shown."
244 (define-widget 'erc-message-type
'set
245 "A set of standard IRC Message types."
246 :args
'((const "JOIN")
252 (repeat :inline t
:tag
"Others" (string :tag
"IRC Message Type"))))
254 (defcustom erc-hide-list nil
255 "List of IRC type messages to hide.
256 A typical value would be '(\"JOIN\" \"PART\" \"QUIT\")."
258 :type
'erc-message-type
)
260 (defvar erc-session-password nil
261 "The password used for the current session.")
262 (make-variable-buffer-local 'erc-session-password
)
264 (defcustom erc-disconnected-hook nil
265 "Run this hook with arguments (NICK IP REASON) when disconnected.
266 This happens before automatic reconnection. Note, that
267 `erc-server-QUIT-functions' might not be run when we disconnect,
268 simply because we do not necessarily receive the QUIT event."
272 (defcustom erc-complete-functions nil
273 "These functions get called when the user hits TAB in ERC.
274 Each function in turn is called until one returns non-nil to
275 indicate it has handled the input."
279 (defcustom erc-join-hook nil
280 "Hook run when we join a channel. Hook functions are called
281 without arguments, with the current buffer set to the buffer of
284 See also `erc-server-JOIN-functions', `erc-part-hook'."
288 (defcustom erc-quit-hook nil
289 "Hook run when processing a quit command directed at our nick.
291 The hook receives one argument, the current PROCESS.
292 See also `erc-server-QUIT-functions' and `erc-disconnected-hook'."
296 (defcustom erc-part-hook nil
297 "Hook run when processing a PART message directed at our nick.
299 The hook receives one argument, the current BUFFER.
300 See also `erc-server-QUIT-functions', `erc-quit-hook' and
301 `erc-disconnected-hook'."
305 (defcustom erc-kick-hook nil
306 "Hook run when processing a KICK message directed at our nick.
308 The hook receives one argument, the current BUFFER.
309 See also `erc-server-PART-functions' and `erc-part-hook'."
313 (defcustom erc-nick-changed-functions nil
314 "List of functions run when your nick was successfully changed.
316 Each function should accept two arguments, NEW-NICK and OLD-NICK."
320 (defcustom erc-connect-pre-hook
'(erc-initialize-log-marker)
321 "Hook called just before `erc' calls `erc-connect'.
322 Functions are passed a buffer as the first argument."
327 (defvar erc-channel-users nil
328 "A hash table of members in the current channel, which
329 associates nicknames with cons cells of the form:
330 \(USER . MEMBER-DATA) where USER is a pointer to an
331 erc-server-user struct, and MEMBER-DATA is a pointer to an
332 erc-channel-user struct.")
333 (make-variable-buffer-local 'erc-channel-users
)
335 (defvar erc-server-users nil
336 "A hash table of users on the current server, which associates
337 nicknames with erc-server-user struct instances.")
338 (make-variable-buffer-local 'erc-server-users
)
340 (defun erc-downcase (string)
341 "Convert STRING to IRC standard conforming downcase."
342 (let ((s (downcase string
))
348 (while (string-match "[]\\[~]" s
)
349 (aset s
(match-beginning 0)
350 (cdr (assq (aref s
(match-beginning 0)) c
)))))
353 (defmacro erc-with-server-buffer
(&rest body
)
354 "Execute BODY in the current ERC server buffer.
355 If no server buffer exists, return nil."
356 (declare (indent 0) (debug (body)))
357 (let ((buffer (make-symbol "buffer")))
358 `(let ((,buffer
(erc-server-buffer)))
359 (when (buffer-live-p ,buffer
)
360 (with-current-buffer ,buffer
363 (cl-defstruct (erc-server-user (:type vector
) :named
)
365 nickname host login full-name info
368 ;; This is an alist of the form (BUFFER . CHANNEL-DATA), where
369 ;; CHANNEL-DATA is either nil or an erc-channel-user struct.
373 (cl-defstruct (erc-channel-user (:type vector
) :named
)
374 voice halfop op admin owner
375 ;; Last message time (in the form of the return value of
378 ;; This is useful for ordered name completion.
379 (last-message-time nil
))
381 (defsubst erc-get-channel-user
(nick)
382 "Find the (USER . CHANNEL-DATA) element corresponding to NICK
383 in the current buffer's `erc-channel-users' hash table."
384 (gethash (erc-downcase nick
) erc-channel-users
))
386 (defsubst erc-get-server-user
(nick)
387 "Find the USER corresponding to NICK in the current server's
388 `erc-server-users' hash table."
389 (erc-with-server-buffer
390 (gethash (erc-downcase nick
) erc-server-users
)))
392 (defsubst erc-add-server-user
(nick user
)
393 "This function is for internal use only.
395 Adds USER with nickname NICK to the `erc-server-users' hash table."
396 (erc-with-server-buffer
397 (puthash (erc-downcase nick
) user erc-server-users
)))
399 (defsubst erc-remove-server-user
(nick)
400 "This function is for internal use only.
402 Removes the user with nickname NICK from the `erc-server-users'
403 hash table. This user is not removed from the
404 `erc-channel-users' lists of other buffers.
406 See also: `erc-remove-user'."
407 (erc-with-server-buffer
408 (remhash (erc-downcase nick
) erc-server-users
)))
410 (defun erc-change-user-nickname (user new-nick
)
411 "This function is for internal use only.
413 Changes the nickname of USER to NEW-NICK in the
414 `erc-server-users' hash table. The `erc-channel-users' lists of
415 other buffers are also changed."
416 (let ((nick (erc-server-user-nickname user
)))
417 (setf (erc-server-user-nickname user
) new-nick
)
418 (erc-with-server-buffer
419 (remhash (erc-downcase nick
) erc-server-users
)
420 (puthash (erc-downcase new-nick
) user erc-server-users
))
421 (dolist (buf (erc-server-user-buffers user
))
422 (if (buffer-live-p buf
)
423 (with-current-buffer buf
424 (let ((cdata (erc-get-channel-user nick
)))
425 (remhash (erc-downcase nick
) erc-channel-users
)
426 (puthash (erc-downcase new-nick
) cdata
427 erc-channel-users
)))))))
429 (defun erc-remove-channel-user (nick)
430 "This function is for internal use only.
432 Removes the user with nickname NICK from the `erc-channel-users'
433 list for this channel. If this user is not in the
434 `erc-channel-users' list of any other buffers, the user is also
435 removed from the server's `erc-server-users' list.
437 See also: `erc-remove-server-user' and `erc-remove-user'."
438 (let ((channel-data (erc-get-channel-user nick
)))
440 (let ((user (car channel-data
)))
441 (setf (erc-server-user-buffers user
)
442 (delq (current-buffer)
443 (erc-server-user-buffers user
)))
444 (remhash (erc-downcase nick
) erc-channel-users
)
445 (if (null (erc-server-user-buffers user
))
446 (erc-remove-server-user nick
))))))
448 (defun erc-remove-user (nick)
449 "This function is for internal use only.
451 Removes the user with nickname NICK from the `erc-server-users'
452 list as well as from all `erc-channel-users' lists.
454 See also: `erc-remove-server-user' and
455 `erc-remove-channel-user'."
456 (let ((user (erc-get-server-user nick
)))
458 (let ((buffers (erc-server-user-buffers user
)))
459 (dolist (buf buffers
)
460 (if (buffer-live-p buf
)
461 (with-current-buffer buf
462 (remhash (erc-downcase nick
) erc-channel-users
)
463 (run-hooks 'erc-channel-members-changed-hook
)))))
464 (erc-remove-server-user nick
))))
466 (defun erc-remove-channel-users ()
467 "This function is for internal use only.
469 Removes all users in the current channel. This is called by
470 `erc-server-PART' and `erc-server-QUIT'."
471 (when (and erc-server-connected
472 (erc-server-process-alive)
473 (hash-table-p erc-channel-users
))
474 (maphash (lambda (nick _cdata
)
475 (erc-remove-channel-user nick
))
477 (clrhash erc-channel-users
)))
479 (defsubst erc-channel-user-owner-p
(nick)
480 "Return non-nil if NICK is an owner of the current channel."
482 (hash-table-p erc-channel-users
)
483 (let ((cdata (erc-get-channel-user nick
)))
484 (and cdata
(cdr cdata
)
485 (erc-channel-user-owner (cdr cdata
))))))
487 (defsubst erc-channel-user-admin-p
(nick)
488 "Return non-nil if NICK is an admin in the current channel."
490 (hash-table-p erc-channel-users
)
491 (let ((cdata (erc-get-channel-user nick
)))
492 (and cdata
(cdr cdata
)
493 (erc-channel-user-admin (cdr cdata
))))))
495 (defsubst erc-channel-user-op-p
(nick)
496 "Return non-nil if NICK is an operator in the current channel."
498 (hash-table-p erc-channel-users
)
499 (let ((cdata (erc-get-channel-user nick
)))
500 (and cdata
(cdr cdata
)
501 (erc-channel-user-op (cdr cdata
))))))
503 (defsubst erc-channel-user-halfop-p
(nick)
504 "Return non-nil if NICK is a half-operator in the current channel."
506 (hash-table-p erc-channel-users
)
507 (let ((cdata (erc-get-channel-user nick
)))
508 (and cdata
(cdr cdata
)
509 (erc-channel-user-halfop (cdr cdata
))))))
511 (defsubst erc-channel-user-voice-p
(nick)
512 "Return non-nil if NICK has voice in the current channel."
514 (hash-table-p erc-channel-users
)
515 (let ((cdata (erc-get-channel-user nick
)))
516 (and cdata
(cdr cdata
)
517 (erc-channel-user-voice (cdr cdata
))))))
519 (defun erc-get-channel-user-list ()
520 "Return a list of users in the current channel. Each element
521 of the list is of the form (USER . CHANNEL-DATA), where USER is
522 an erc-server-user struct, and CHANNEL-DATA is either nil or an
523 erc-channel-user struct.
525 See also: `erc-sort-channel-users-by-activity'"
527 (if (hash-table-p erc-channel-users
)
528 (maphash (lambda (_nick cdata
)
529 (setq users
(cons cdata users
)))
533 (defun erc-get-server-nickname-list ()
534 "Return a list of known nicknames on the current server."
535 (erc-with-server-buffer
537 (when (hash-table-p erc-server-users
)
538 (maphash (lambda (_n user
)
540 (cons (erc-server-user-nickname user
)
545 (defun erc-get-channel-nickname-list ()
546 "Return a list of known nicknames on the current channel."
548 (when (hash-table-p erc-channel-users
)
549 (maphash (lambda (_n cdata
)
551 (cons (erc-server-user-nickname (car cdata
))
556 (defun erc-get-server-nickname-alist ()
557 "Return an alist of known nicknames on the current server."
558 (erc-with-server-buffer
560 (when (hash-table-p erc-server-users
)
561 (maphash (lambda (_n user
)
563 (cons (cons (erc-server-user-nickname user
) nil
)
568 (defun erc-get-channel-nickname-alist ()
569 "Return an alist of known nicknames on the current channel."
571 (when (hash-table-p erc-channel-users
)
572 (maphash (lambda (_n cdata
)
574 (cons (cons (erc-server-user-nickname (car cdata
)) nil
)
579 (defun erc-sort-channel-users-by-activity (list)
580 "Sort LIST such that users which have spoken most recently are listed first.
581 LIST must be of the form (USER . CHANNEL-DATA).
583 See also: `erc-get-channel-user-list'."
586 (when (and (cdr x
) (cdr y
))
587 (let ((tx (erc-channel-user-last-message-time (cdr x
)))
588 (ty (erc-channel-user-last-message-time (cdr y
))))
591 (time-less-p ty tx
))))))))
593 (defun erc-sort-channel-users-alphabetically (list)
594 "Sort LIST so that users' nicknames are in alphabetical order.
595 LIST must be of the form (USER . CHANNEL-DATA).
597 See also: `erc-get-channel-user-list'."
600 (when (and (cdr x
) (cdr y
))
601 (let ((nickx (downcase (erc-server-user-nickname (car x
))))
602 (nicky (downcase (erc-server-user-nickname (car y
)))))
605 (string-lessp nickx nicky
))))))))
607 (defvar erc-channel-topic nil
608 "A topic string for the channel. Should only be used in channel-buffers.")
609 (make-variable-buffer-local 'erc-channel-topic
)
611 (defvar erc-channel-modes nil
612 "List of strings representing channel modes.
613 E.g. '(\"i\" \"m\" \"s\" \"b Quake!*@*\")
614 \(not sure the ban list will be here, but why not)")
615 (make-variable-buffer-local 'erc-channel-modes
)
617 (defvar erc-insert-marker nil
618 "The place where insertion of new text in erc buffers should happen.")
619 (make-variable-buffer-local 'erc-insert-marker
)
621 (defvar erc-input-marker nil
622 "The marker where input should be inserted.")
623 (make-variable-buffer-local 'erc-input-marker
)
625 (defun erc-string-no-properties (string)
626 "Return a copy of STRING will all text-properties removed."
627 (let ((newstring (copy-sequence string
)))
628 (set-text-properties 0 (length newstring
) nil newstring
)
631 (defcustom erc-prompt
"ERC>"
632 "Prompt used by ERC. Trailing whitespace is not required."
634 :type
'(choice string function
))
637 "Return the input prompt as a string.
639 See also the variable `erc-prompt'."
640 (let ((prompt (if (functionp erc-prompt
)
643 (if (> (length prompt
) 0)
647 (defcustom erc-command-indicator nil
648 "Indicator used by ERC for showing commands.
650 If non-nil, this will be used in the ERC buffer to indicate
651 commands (i.e., input starting with a '/').
653 If nil, the prompt will be constructed from the variable `erc-prompt'."
655 :type
'(choice (const nil
) string function
))
657 (defun erc-command-indicator ()
658 "Return the command indicator prompt as a string.
660 This only has any meaning if the variable `erc-command-indicator' is non-nil."
661 (and erc-command-indicator
662 (let ((prompt (if (functionp erc-command-indicator
)
663 (funcall erc-command-indicator
)
664 erc-command-indicator
)))
665 (if (> (length prompt
) 0)
669 (defcustom erc-notice-prefix
"*** "
670 "Prefix for all notices."
674 (defcustom erc-notice-highlight-type
'all
675 "Determines how to highlight notices.
676 See `erc-notice-prefix'.
678 The following values are allowed:
680 'prefix - highlight notice prefix only
681 'all - highlight the entire notice
683 Any other value disables notice's highlighting altogether."
685 :type
'(choice (const :tag
"highlight notice prefix only" prefix
)
686 (const :tag
"highlight the entire notice" all
)
687 (const :tag
"don't highlight notices at all" nil
)))
689 (defcustom erc-echo-notice-hook nil
690 "List of functions to call to echo a private notice.
691 Each function is called with four arguments, the string
692 to display, the parsed server message, the target buffer (or
693 nil), and the sender. The functions are called in order, until a
694 function evaluates to non-nil. These hooks are called after
695 those specified in `erc-echo-notice-always-hook'.
697 See also: `erc-echo-notice-always-hook',
698 `erc-echo-notice-in-default-buffer',
699 `erc-echo-notice-in-target-buffer',
700 `erc-echo-notice-in-minibuffer',
701 `erc-echo-notice-in-server-buffer',
702 `erc-echo-notice-in-active-non-server-buffer',
703 `erc-echo-notice-in-active-buffer',
704 `erc-echo-notice-in-user-buffers',
705 `erc-echo-notice-in-user-and-target-buffers',
706 `erc-echo-notice-in-first-user-buffer'"
709 :options
'(erc-echo-notice-in-default-buffer
710 erc-echo-notice-in-target-buffer
711 erc-echo-notice-in-minibuffer
712 erc-echo-notice-in-server-buffer
713 erc-echo-notice-in-active-non-server-buffer
714 erc-echo-notice-in-active-buffer
715 erc-echo-notice-in-user-buffers
716 erc-echo-notice-in-user-and-target-buffers
717 erc-echo-notice-in-first-user-buffer
))
719 (defcustom erc-echo-notice-always-hook
720 '(erc-echo-notice-in-default-buffer)
721 "List of functions to call to echo a private notice.
722 Each function is called with four arguments, the string
723 to display, the parsed server message, the target buffer (or
724 nil), and the sender. The functions are called in order, and all
725 functions are called. These hooks are called before those
726 specified in `erc-echo-notice-hook'.
728 See also: `erc-echo-notice-hook',
729 `erc-echo-notice-in-default-buffer',
730 `erc-echo-notice-in-target-buffer',
731 `erc-echo-notice-in-minibuffer',
732 `erc-echo-notice-in-server-buffer',
733 `erc-echo-notice-in-active-non-server-buffer',
734 `erc-echo-notice-in-active-buffer',
735 `erc-echo-notice-in-user-buffers',
736 `erc-echo-notice-in-user-and-target-buffers',
737 `erc-echo-notice-in-first-user-buffer'"
740 :options
'(erc-echo-notice-in-default-buffer
741 erc-echo-notice-in-target-buffer
742 erc-echo-notice-in-minibuffer
743 erc-echo-notice-in-server-buffer
744 erc-echo-notice-in-active-non-server-buffer
745 erc-echo-notice-in-active-buffer
746 erc-echo-notice-in-user-buffers
747 erc-echo-notice-in-user-and-target-buffers
748 erc-echo-notice-in-first-user-buffer
))
750 ;; other tunable parameters
752 (defcustom erc-whowas-on-nosuchnick nil
753 "If non-nil, do a whowas on a nick if no such nick."
757 (defcustom erc-verbose-server-ping nil
758 "If non-nil, show every time you get a PING or PONG from the server."
762 (defcustom erc-public-away-p nil
763 "Let others know you are back when you are no longer marked away.
764 This happens in this form:
765 * <nick> is back (gone for <time>)
767 Many consider it impolite to do so automatically."
771 (defcustom erc-away-nickname nil
772 "The nickname to take when you are marked as being away."
774 :type
'(choice (const nil
)
777 (defcustom erc-paranoid nil
778 "If non-nil, then all incoming CTCP requests will be shown."
782 (defcustom erc-disable-ctcp-replies nil
783 "Disable replies to CTCP requests that require a reply.
784 If non-nil, then all incoming CTCP requests that normally require
785 an automatic reply (like VERSION or PING) will be ignored. Good to
786 set if some hacker is trying to flood you away."
790 (defcustom erc-anonymous-login t
791 "Be paranoid, don't give away your machine name."
795 (defcustom erc-prompt-for-channel-key nil
796 "Prompt for channel key when using `erc-join-channel' interactively."
800 (defcustom erc-email-userid
"user"
801 "Use this as your email user ID."
805 (defcustom erc-system-name nil
806 "Use this as the name of your system.
807 If nil, ERC will call `system-name' to get this information."
809 :type
'(choice (const :tag
"Default system name" nil
)
812 (defcustom erc-ignore-list nil
813 "List of regexps matching user identifiers to ignore.
815 A user identifier has the form \"nick!login@host\". If an
816 identifier matches, the message from the person will not be
819 :type
'(repeat regexp
))
820 (make-variable-buffer-local 'erc-ignore-list
)
822 (defcustom erc-ignore-reply-list nil
823 "List of regexps matching user identifiers to ignore completely.
825 This differs from `erc-ignore-list' in that it also ignores any
826 messages directed at the user.
828 A user identifier has the form \"nick!login@host\".
830 If an identifier matches, or a message is addressed to a nick
831 whose identifier matches, the message will not be processed.
833 CAVEAT: ERC doesn't know about the user and host of anyone who
834 was already in the channel when you joined, but never said
835 anything, so it won't be able to match the user and host of those
836 people. You can update the ERC internal info using /WHO *."
838 :type
'(repeat regexp
))
840 (defvar erc-flood-protect t
841 "If non-nil, flood protection is enabled.
842 Flooding is sending too much information to the server in too
843 short of an interval, which may cause the server to terminate the
846 See `erc-server-flood-margin' for other flood-related parameters.")
850 (defcustom erc-startup-file-list
851 (list (concat erc-user-emacs-directory
".ercrc.el")
852 (concat erc-user-emacs-directory
".ercrc")
853 "~/.ercrc.el" "~/.ercrc" ".ercrc.el" ".ercrc")
854 "List of files to try for a startup script.
855 The first existent and readable one will get executed.
857 If the filename ends with `.el' it is presumed to be an Emacs Lisp
858 script and it gets (load)ed. Otherwise it is treated as a bunch of
859 regular IRC commands."
861 :type
'(repeat file
))
863 (defcustom erc-script-path nil
864 "List of directories to look for a script in /load command.
865 The script is first searched in the current directory, then in each
866 directory in the list."
868 :type
'(repeat directory
))
870 (defcustom erc-script-echo t
871 "If non-nil, echo the IRC script commands locally."
875 (defvar erc-last-saved-position nil
876 "A marker containing the position the current buffer was last saved at.")
877 (make-variable-buffer-local 'erc-last-saved-position
)
879 (defcustom erc-kill-buffer-on-part nil
880 "Kill the channel buffer on PART.
881 This variable should probably stay nil, as ERC can reuse buffers if
882 you rejoin them later."
883 :group
'erc-quit-and-part
886 (defcustom erc-kill-queries-on-quit nil
887 "Kill all query (also channel) buffers of this server on QUIT.
888 See the variable `erc-kill-buffer-on-part' for details."
889 :group
'erc-quit-and-part
892 (defcustom erc-kill-server-buffer-on-quit nil
893 "Kill the server buffer of the process on QUIT."
894 :group
'erc-quit-and-part
897 (defcustom erc-quit-reason-various-alist nil
898 "Alist of possible arguments to the /quit command.
900 Each element has the form:
903 If REGEXP matches the argument to /quit, then its relevant RESULT
904 will be used. RESULT may be either a string, or a function. If
905 a function, it should return the quit message as a string.
907 If no elements match, then the empty string is used.
910 (setq erc-quit-reason-various-alist
911 '((\"xmms\" dme:now-playing)
912 (\"version\" erc-quit-reason-normal)
913 (\"home\" \"Gone home !\")
914 (\"^$\" \"Default Reason\")))
915 If the user types \"/quit home\", then \"Gone home !\" will be used
916 as the quit message."
917 :group
'erc-quit-and-part
918 :type
'(repeat (list regexp
(choice (string) (function)))))
920 (defcustom erc-part-reason-various-alist nil
921 "Alist of possible arguments to the /part command.
923 Each element has the form:
926 If REGEXP matches the argument to /part, then its relevant RESULT
927 will be used. RESULT may be either a string, or a function. If
928 a function, it should return the part message as a string.
930 If no elements match, then the empty string is used.
933 (setq erc-part-reason-various-alist
934 '((\"xmms\" dme:now-playing)
935 (\"version\" erc-part-reason-normal)
936 (\"home\" \"Gone home !\")
937 (\"^$\" \"Default Reason\")))
938 If the user types \"/part home\", then \"Gone home !\" will be used
939 as the part message."
940 :group
'erc-quit-and-part
941 :type
'(repeat (list regexp
(choice (string) (function)))))
943 (defcustom erc-quit-reason
'erc-quit-reason-normal
944 "A function which returns the reason for quitting.
946 The function is passed a single argument, the string typed by the
947 user after \"/quit\"."
948 :group
'erc-quit-and-part
949 :type
'(choice (const erc-quit-reason-normal
)
950 (const erc-quit-reason-various
)
953 (defcustom erc-part-reason
'erc-part-reason-normal
954 "A function which returns the reason for parting a channel.
956 The function is passed a single argument, the string typed by the
957 user after \"/PART\"."
958 :group
'erc-quit-and-part
959 :type
'(choice (const erc-part-reason-normal
)
960 (const erc-part-reason-various
)
963 (defvar erc-grab-buffer-name
"*erc-grab*"
964 "The name of the buffer created by `erc-grab-region'.")
966 ;; variables available for IRC scripts
968 (defvar erc-user-information
"ERC User"
969 "USER_INFORMATION IRC variable.")
973 (defgroup erc-hooks nil
974 "Hook variables for fancy customizations of ERC."
977 (defcustom erc-mode-hook nil
978 "Hook run after `erc-mode' setup is finished."
981 :options
'(erc-add-scroll-to-bottom))
983 (defcustom erc-timer-hook nil
984 "Put functions which should get called more or less periodically here.
985 The idea is that servers always play ping pong with the client, and so there
986 is no need for any idle-timer games with Emacs."
990 (defcustom erc-insert-pre-hook nil
991 "Hook called first when some text is inserted through `erc-display-line'.
992 It gets called with one argument, STRING.
993 To be able to modify the inserted text, use `erc-insert-modify-hook' instead.
994 Filtering functions can set `erc-insert-this' to nil to avoid
995 display of that particular string at all."
999 (defcustom erc-send-pre-hook nil
1000 "Hook called first when some text is sent through `erc-send-current-line'.
1001 It gets called with one argument, STRING.
1003 To change the text that will be sent, set the variable STR which is
1004 used in `erc-send-current-line'.
1006 To change the text inserted into the buffer without changing the text
1007 that will be sent, use `erc-send-modify-hook' instead.
1009 Filtering functions can set `erc-send-this' to nil to avoid sending of
1010 that particular string at all and `erc-insert-this' to prevent
1011 inserting that particular string into the buffer.
1013 Note that it's useless to set `erc-send-this' to nil and
1014 `erc-insert-this' to t. ERC is sane enough to not insert the text
1019 (defvar erc-insert-this t
1020 "Insert the text into the target buffer or not.
1021 Functions on `erc-insert-pre-hook' can set this variable to nil
1022 if they wish to avoid insertion of a particular string.")
1024 (defvar erc-send-this t
1025 "Send the text to the target or not.
1026 Functions on `erc-send-pre-hook' can set this variable to nil
1027 if they wish to avoid sending of a particular string.")
1029 (defcustom erc-insert-modify-hook
()
1030 "Insertion hook for functions that will change the text's appearance.
1031 This hook is called just after `erc-insert-pre-hook' when the value
1032 of `erc-insert-this' is t.
1033 While this hook is run, narrowing is in effect and `current-buffer' is
1034 the buffer where the text got inserted. One possible value to add here
1039 (defcustom erc-insert-post-hook nil
1040 "This hook is called just after `erc-insert-modify-hook'.
1041 At this point, all modifications from prior hook functions are done."
1044 :options
'(erc-truncate-buffer
1046 erc-save-buffer-in-logs
))
1048 (defcustom erc-send-modify-hook nil
1049 "Sending hook for functions that will change the text's appearance.
1050 This hook is called just after `erc-send-pre-hook' when the values
1051 of `erc-send-this' and `erc-insert-this' are both t.
1052 While this hook is run, narrowing is in effect and `current-buffer' is
1053 the buffer where the text got inserted.
1055 Note that no function in this hook can change the appearance of the
1056 text that is sent. Only changing the sent text's appearance on the
1057 sending user's screen is possible. One possible value to add here
1062 (defcustom erc-send-post-hook nil
1063 "This hook is called just after `erc-send-modify-hook'.
1064 At this point, all modifications from prior hook functions are done.
1065 NOTE: The functions on this hook are called _before_ sending a command
1068 This function is called with narrowing, ala `erc-send-modify-hook'."
1071 :options
'(erc-make-read-only))
1073 (defcustom erc-send-completed-hook
1074 (when (fboundp 'emacspeak-auditory-icon
)
1077 (emacspeak-auditory-icon 'select-object
)))))
1078 "Hook called after a message has been parsed by ERC.
1080 The single argument to the functions is the unmodified string
1081 which the local user typed."
1084 ;; mode-specific tables
1086 (defvar erc-mode-syntax-table
1087 (let ((syntax-table (make-syntax-table)))
1088 (modify-syntax-entry ?
\" ". " syntax-table
)
1089 (modify-syntax-entry ?
\\ ". " syntax-table
)
1090 (modify-syntax-entry ?
' "w " syntax-table
)
1091 ;; Make dabbrev-expand useful for nick names
1092 (modify-syntax-entry ?
< "." syntax-table
)
1093 (modify-syntax-entry ?
> "." syntax-table
)
1095 "Syntax table used while in ERC mode.")
1097 (defvar erc-mode-abbrev-table nil
1098 "Abbrev table used while in ERC mode.")
1099 (define-abbrev-table 'erc-mode-abbrev-table
())
1101 (defvar erc-mode-map
1102 (let ((map (make-sparse-keymap)))
1103 (define-key map
"\C-m" 'erc-send-current-line
)
1104 (define-key map
"\C-a" 'erc-bol
)
1105 (define-key map
[home] 'erc-bol)
1106 (define-key map "\C-c\C-a" 'erc-bol)
1107 (define-key map "\C-c\C-b" 'erc-iswitchb)
1108 (define-key map "\C-c\C-c" 'erc-toggle-interpret-controls)
1109 (define-key map "\C-c\C-d" 'erc-input-action)
1110 (define-key map "\C-c\C-e" 'erc-toggle-ctcp-autoresponse)
1111 (define-key map "\C-c\C-f" 'erc-toggle-flood-control)
1112 (define-key map "\C-c\C-i" 'erc-invite-only-mode)
1113 (define-key map "\C-c\C-j" 'erc-join-channel)
1114 (define-key map "\C-c\C-n" 'erc-channel-names)
1115 (define-key map "\C-c\C-o" 'erc-get-channel-mode-from-keypress)
1116 (define-key map "\C-c\C-p" 'erc-part-from-channel)
1117 (define-key map "\C-c\C-q" 'erc-quit-server)
1118 (define-key map "\C-c\C-r" 'erc-remove-text-properties-region)
1119 (define-key map "\C-c\C-t" 'erc-set-topic)
1120 (define-key map "\C-c\C-u" 'erc-kill-input)
1121 (define-key map "\C-c\C-x" 'erc-quit-server)
1122 (define-key map "\M-\t" 'ispell-complete-word)
1123 (define-key map "\t" 'completion-at-point)
1125 ;; Suppress `font-lock-fontify-block' key binding since it
1126 ;; destroys face properties.
1127 (define-key map [remap font-lock-fontify-block] 'undefined)
1134 ; Honestly, I have a horrible sense of color and the "defaults" below
1135 ; are supposed to be really bad. But colors ARE required in IRC to
1136 ; convey different parts of conversation. If you think you know better
1137 ; defaults - send them to me.
1139 ;; Now colors are a bit nicer, at least to my eyes.
1140 ;; You may still want to change them to better fit your background.-- S.B.
1142 (defgroup erc-faces nil
1146 (defface erc-default-face '((t))
1150 (defface erc-nick-prefix-face '((t :inherit erc-nick-default-face :weight bold))
1151 "ERC face used for user mode prefix."
1154 (defface erc-my-nick-prefix-face '((t :inherit erc-nick-default-face :weight bold))
1155 "ERC face used for my user mode prefix."
1158 (defface erc-direct-msg-face '((t :foreground "IndianRed"))
1159 "ERC face used for messages you receive in the main erc buffer."
1162 (defface erc-header-line
1163 '((t :foreground "grey20" :background "grey90"))
1164 "ERC face used for the header line.
1166 This will only be used if `erc-header-line-face-method' is non-nil."
1169 (defface erc-input-face '((t :foreground "brown"))
1170 "ERC face used for your input."
1173 (defface erc-prompt-face
1174 '((t :weight bold :foreground "Black" :background "lightBlue2"))
1175 "ERC face for the prompt."
1178 (defface erc-command-indicator-face
1180 "ERC face for the command indicator.
1181 See the variable `erc-command-indicator'."
1184 (defface erc-notice-face
1185 '((default :weight bold)
1186 (((class color) (min-colors 88)) :foreground "SlateBlue")
1187 (t :foreground "blue"))
1188 "ERC face for notices."
1191 (defface erc-action-face '((t :weight bold))
1192 "ERC face for actions generated by /ME."
1195 (defface erc-error-face '((t :foreground "red"))
1196 "ERC face for errors."
1199 ;; same default color as `erc-input-face'
1200 (defface erc-my-nick-face '((t :weight bold :foreground "brown"))
1201 "ERC face for your current nickname in messages sent by you.
1202 See also `erc-show-my-nick'."
1205 (defface erc-nick-default-face '((t :weight bold))
1206 "ERC nickname default face."
1209 (defface erc-nick-msg-face '((t :weight bold :foreground "IndianRed"))
1210 "ERC nickname face for private messages."
1213 ;; Debugging support
1215 (defvar erc-log-p nil
1216 "When set to t, generate debug messages in a separate debug buffer.")
1218 (defvar erc-debug-log-file (expand-file-name "ERC.debug")
1219 "Debug log file name.")
1221 (defvar erc-dbuf nil)
1222 (make-variable-buffer-local 'erc-dbuf)
1224 (defmacro define-erc-module (name alias doc enable-body disable-body
1226 "Define a new minor mode using ERC conventions.
1227 Symbol NAME is the name of the module.
1228 Symbol ALIAS is the alias to use, or nil.
1229 DOC is the documentation string to use for the minor mode.
1230 ENABLE-BODY is a list of expressions used to enable the mode.
1231 DISABLE-BODY is a list of expressions used to disable the mode.
1232 If LOCAL-P is non-nil, the mode will be created as a buffer-local
1233 mode, rather than a global one.
1235 This will define a minor mode called erc-NAME-mode, possibly
1236 an alias erc-ALIAS-mode, as well as the helper functions
1237 erc-NAME-enable, and erc-NAME-disable.
1241 ;;;###autoload (autoload 'erc-replace-mode \"erc-replace\")
1242 (define-erc-module replace nil
1243 \"This mode replaces incoming text according to `erc-replace-alist'.\"
1244 ((add-hook 'erc-insert-modify-hook
1245 'erc-replace-insert))
1246 ((remove-hook 'erc-insert-modify-hook
1247 'erc-replace-insert)))"
1248 (declare (doc-string 3))
1249 (let* ((sn (symbol-name name))
1250 (mode (intern (format "erc-%s-mode" (downcase sn))))
1251 (group (intern (format "erc-%s" (downcase sn))))
1252 (enable (intern (format "erc-%s-enable" (downcase sn))))
1253 (disable (intern (format "erc-%s-disable" (downcase sn)))))
1255 (erc-define-minor-mode
1257 ,(format "Toggle ERC %S mode.
1258 With a prefix argument ARG, enable %s if ARG is positive,
1259 and disable it otherwise. If called from Lisp, enable the mode
1260 if ARG is omitted or nil.
1263 :global ,(not local-p) :group (quote ,group)
1268 ,(format "Enable ERC %S mode."
1271 (add-to-list 'erc-modules (quote ,name))
1275 ,(format "Disable ERC %S mode."
1278 (setq erc-modules (delq (quote ,name) erc-modules))
1281 ,(when (and alias (not (eq name alias)))
1285 (format "erc-%s-mode"
1286 (downcase (symbol-name alias)))))
1289 ;; For find-function and find-variable.
1290 (put ',mode 'definition-name ',name)
1291 (put ',enable 'definition-name ',name)
1292 (put ',disable 'definition-name ',name))))
1294 (defun erc-once-with-server-event (event f)
1295 "Run function F the next time EVENT occurs in the `current-buffer'.
1297 You should make sure that `current-buffer' is a server buffer.
1299 This function temporarily adds a function to EVENT's hook to call F with
1300 two arguments (`proc' and `parsed'). After F is called, the function is
1301 removed from EVENT's hook. F should return either nil
1302 or t, where nil indicates that the other functions on EVENT's hook
1303 should be run too, and t indicates that other functions should
1306 Please be sure to use this function in server-buffers. In
1307 channel-buffers it may not work at all, as it uses the LOCAL
1308 argument of `add-hook' and `remove-hook' to ensure multiserver
1310 (unless (erc-server-buffer-p)
1312 "You should only run `erc-once-with-server-event' in a server buffer"))
1313 (let ((fun (make-symbol "fun"))
1314 (hook (erc-get-hook event)))
1315 (put fun 'erc-original-buffer (current-buffer))
1316 (fset fun (lambda (proc parsed)
1317 (with-current-buffer (get fun 'erc-original-buffer)
1318 (remove-hook hook fun t))
1320 (funcall f proc parsed)))
1321 (add-hook hook fun nil t)
1324 (defsubst erc-log (string)
1325 "Logs STRING if logging is on (see `erc-log-p')."
1327 (erc-log-aux string)))
1329 (defun erc-server-buffer ()
1330 "Return the server buffer for the current buffer's process.
1331 The buffer-local variable `erc-server-process' is used to find
1332 the process buffer."
1333 (and (erc-server-buffer-live-p)
1334 (process-buffer erc-server-process)))
1336 (defun erc-server-buffer-live-p ()
1337 "Return t if the server buffer has not been killed."
1338 (and (processp erc-server-process)
1339 (buffer-live-p (process-buffer erc-server-process))))
1341 (defun erc-server-buffer-p (&optional buffer)
1342 "Return non-nil if argument BUFFER is an ERC server buffer.
1344 If BUFFER is nil, the current buffer is used."
1345 (with-current-buffer (or buffer (current-buffer))
1346 (and (eq major-mode 'erc-mode)
1347 (null (erc-default-target)))))
1349 (defun erc-open-server-buffer-p (&optional buffer)
1350 "Return non-nil if argument BUFFER is an ERC server buffer that
1351 has an open IRC process.
1353 If BUFFER is nil, the current buffer is used."
1354 (and (erc-server-buffer-p buffer)
1355 (erc-server-process-alive buffer)))
1357 (defun erc-query-buffer-p (&optional buffer)
1358 "Return non-nil if BUFFER is an ERC query buffer.
1359 If BUFFER is nil, the current buffer is used."
1360 (with-current-buffer (or buffer (current-buffer))
1361 (let ((target (erc-default-target)))
1362 (and (eq major-mode 'erc-mode)
1364 (not (memq (aref target 0) '(?# ?& ?+ ?!)))))))
1366 (defun erc-ison-p (nick)
1367 "Return non-nil if NICK is online."
1368 (interactive "sNick: ")
1369 (erc-with-server-buffer
1370 (let ((erc-online-p 'unknown))
1371 (erc-once-with-server-event
1373 (lambda (_proc parsed)
1374 (let ((ison (split-string (aref parsed 3))))
1375 (setq erc-online-p (car (erc-member-ignore-case nick ison)))
1377 (erc-server-send (format "ISON %s" nick))
1378 (while (eq erc-online-p 'unknown) (accept-process-output))
1379 (if (called-interactively-p 'interactive)
1380 (message "%s is %sonline"
1381 (or erc-online-p nick)
1382 (if erc-online-p "" "not "))
1385 (defun erc-log-aux (string)
1386 "Do the debug logging of STRING."
1387 (let ((cb (current-buffer))
1390 (session-buffer (erc-server-buffer)))
1393 (set-buffer session-buffer)
1394 (if (not (and erc-dbuf (bufferp erc-dbuf) (buffer-live-p erc-dbuf)))
1396 (setq erc-dbuf (get-buffer-create
1397 (concat "*ERC-DEBUG: "
1398 erc-session-server "*")))))
1399 (set-buffer erc-dbuf)
1400 (setq point (point))
1401 (setq was-eob (eobp))
1402 (goto-char (point-max))
1403 (insert (concat "** " string "\n"))
1404 (if was-eob (goto-char (point-max))
1407 (message "ERC: ** %s" string))))
1409 ;; Last active buffer, to print server messages in the right place
1411 (defvar erc-active-buffer nil
1412 "The current active buffer, the one where the user typed the last command.
1413 Defaults to the server buffer, and should only be set in the
1415 (make-variable-buffer-local 'erc-active-buffer)
1417 (defun erc-active-buffer ()
1418 "Return the value of `erc-active-buffer' for the current server.
1419 Defaults to the server buffer."
1420 (erc-with-server-buffer
1421 (if (buffer-live-p erc-active-buffer)
1423 (setq erc-active-buffer (current-buffer)))))
1425 (defun erc-set-active-buffer (buffer)
1426 "Set the value of `erc-active-buffer' to BUFFER."
1427 (cond ((erc-server-buffer)
1428 (with-current-buffer (erc-server-buffer)
1429 (setq erc-active-buffer buffer)))
1430 (t (setq erc-active-buffer buffer))))
1432 ;; Mode activation routines
1434 (define-derived-mode erc-mode fundamental-mode "ERC"
1435 "Major mode for Emacs IRC."
1436 (setq local-abbrev-table erc-mode-abbrev-table)
1437 (when (boundp 'next-line-add-newlines)
1438 (set (make-local-variable 'next-line-add-newlines) nil))
1439 (setq line-move-ignore-invisible t)
1440 (set (make-local-variable 'paragraph-separate)
1441 (concat "\C-l\\|\\(^" (regexp-quote (erc-prompt)) "\\)"))
1442 (set (make-local-variable 'paragraph-start)
1443 (concat "\\(" (regexp-quote (erc-prompt)) "\\)"))
1444 (add-hook 'completion-at-point-functions 'erc-complete-word-at-point nil t))
1448 (defconst erc-default-server "irc.freenode.net"
1449 "IRC server to use if it cannot be detected otherwise.")
1451 (defconst erc-default-port 6667
1452 "IRC port to use if it cannot be detected otherwise.")
1454 (defcustom erc-join-buffer 'buffer
1455 "Determines how to display a newly created IRC buffer.
1457 The available choices are:
1459 'window - in another window,
1460 'window-noselect - in another window, but don't select that one,
1461 'frame - in another frame,
1462 'bury - bury it in a new buffer,
1463 'buffer - in place of the current buffer,
1464 any other value - in place of the current buffer."
1466 :type '(choice (const :tag "Split window and select" window)
1467 (const :tag "Split window, don't select" window-noselect)
1468 (const :tag "New frame" frame)
1469 (const :tag "Bury in new buffer" bury)
1470 (const :tag "Use current buffer" buffer)
1471 (const :tag "Use current buffer" t)))
1473 (defcustom erc-frame-alist nil
1474 "Alist of frame parameters for creating erc frames.
1475 A value of nil means to use `default-frame-alist'."
1477 :type '(repeat (cons :format "%v"
1478 (symbol :tag "Parameter")
1479 (sexp :tag "Value"))))
1481 (defcustom erc-frame-dedicated-flag nil
1482 "Non-nil means the erc frames are dedicated to that buffer.
1483 This only has effect when `erc-join-buffer' is set to `frame'."
1487 (defcustom erc-reuse-frames t
1488 "Determines whether new frames are always created.
1489 Non-nil means that a new frame is not created to display an ERC
1490 buffer if there is already a window displaying it. This only has
1491 effect when `erc-join-buffer' is set to `frame'."
1495 (defun erc-channel-p (channel)
1496 "Return non-nil if CHANNEL seems to be an IRC channel name."
1497 (cond ((stringp channel)
1498 (memq (aref channel 0) '(?# ?& ?+ ?!)))
1499 ((and (bufferp channel) (buffer-live-p channel))
1500 (with-current-buffer channel
1501 (erc-channel-p (erc-default-target))))
1504 (defcustom erc-reuse-buffers t
1505 "If nil, create new buffers on joining a channel/query.
1506 If non-nil, a new buffer will only be created when you join
1507 channels with same names on different servers, or have query buffers
1508 open with nicks of the same name on different servers. Otherwise,
1509 the existing buffers will be reused."
1513 (defun erc-normalize-port (port)
1514 "Normalize the port specification PORT to integer form.
1515 PORT may be an integer, a string or a symbol. If it is a string or a
1516 symbol, it may have these values:
1520 * ircd-dalnet -> 7000"
1523 (erc-normalize-port (symbol-name port)))
1525 (let ((port-nr (string-to-number port)))
1529 ((string-equal port "irc")
1531 ((string-equal port "ircs")
1533 ((string-equal port "ircd")
1535 ((string-equal port "ircd-dalnet")
1544 (defun erc-port-equal (a b)
1545 "Check whether ports A and B are equal."
1546 (= (erc-normalize-port a) (erc-normalize-port b)))
1548 (defun erc-generate-new-buffer-name (server port target)
1549 "Create a new buffer name based on the arguments."
1550 (when (numberp port) (setq port (number-to-string port)))
1551 (let ((buf-name (or target
1552 (or (let ((name (concat server ":" port)))
1553 (when (> (length name) 1)
1555 ;; This fallback should in fact never happen
1556 "*erc-server-buffer*")))
1558 ;; Reuse existing buffers, but not if the buffer is a connected server
1559 ;; buffer and not if its associated with a different server than the
1560 ;; current ERC buffer.
1561 ;; if buf-name is taken by a different connection (or by something !erc)
1562 ;; then see if "buf-name/server" meets the same criteria
1563 (dolist (candidate (list buf-name (concat buf-name "/" server)))
1564 (if (and (not buffer-name)
1566 (get-buffer candidate)
1568 (with-current-buffer (get-buffer candidate)
1569 (and (erc-server-buffer-p)
1570 (not (erc-server-process-alive)))))
1571 (with-current-buffer (get-buffer candidate)
1572 (and (string= erc-session-server server)
1573 (erc-port-equal erc-session-port port))))
1574 (setq buffer-name candidate)))
1575 ;; if buffer-name is unset, neither candidate worked out for us,
1576 ;; fallback to the old <N> uniquification method:
1577 (or buffer-name (generate-new-buffer-name buf-name)) ))
1579 (defun erc-get-buffer-create (server port target)
1580 "Create a new buffer based on the arguments."
1581 (get-buffer-create (erc-generate-new-buffer-name server port target)))
1584 (defun erc-member-ignore-case (string list)
1585 "Return non-nil if STRING is a member of LIST.
1587 All strings are compared according to IRC protocol case rules, see
1589 (setq string (erc-downcase string))
1592 (if (string= string (erc-downcase (car list)))
1593 (throw 'result list)
1594 (setq list (cdr list))))))
1596 (defmacro erc-with-buffer (spec &rest body)
1597 "Execute BODY in the buffer associated with SPEC.
1599 SPEC should have the form
1603 If TARGET is a buffer, use it. Otherwise, use the buffer
1604 matching TARGET in the process specified by PROCESS.
1606 If PROCESS is nil, use the current `erc-server-process'.
1607 See `erc-get-buffer' for details.
1609 See also `with-current-buffer'.
1611 \(fn (TARGET [PROCESS]) BODY...)"
1612 (declare (indent 1) (debug ((form &optional form) body)))
1613 (let ((buf (make-symbol "buf"))
1614 (proc (make-symbol "proc"))
1615 (target (make-symbol "target"))
1616 (process (make-symbol "process")))
1617 `(let* ((,target ,(car spec))
1618 (,process ,(cadr spec))
1619 (,buf (if (bufferp ,target)
1621 (let ((,proc (or ,process
1622 (and (processp erc-server-process)
1623 erc-server-process))))
1624 (if (and ,target ,proc)
1625 (erc-get-buffer ,target ,proc))))))
1626 (when (buffer-live-p ,buf)
1627 (with-current-buffer ,buf
1630 (defun erc-get-buffer (target &optional proc)
1631 "Return the buffer matching TARGET in the process PROC.
1632 If PROC is not supplied, all processes are searched."
1633 (let ((downcased-target (erc-downcase target)))
1637 (let ((current (erc-default-target)))
1638 (and (stringp current)
1639 (string-equal downcased-target (erc-downcase current))
1640 (throw 'buffer (current-buffer)))))
1643 (defun erc-buffer-filter (predicate &optional proc)
1644 "Return a list of `erc-mode' buffers matching certain criteria.
1645 PREDICATE is a function executed with each buffer, if it returns t, that buffer
1646 is considered a valid match.
1648 PROC is either an `erc-server-process', identifying a certain
1649 server connection, or nil which means all open connections."
1653 (mapcar (lambda (buf)
1654 (when (buffer-live-p buf)
1655 (with-current-buffer buf
1656 (and (eq major-mode 'erc-mode)
1658 (eq proc erc-server-process))
1663 (defun erc-buffer-list (&optional predicate proc)
1664 "Return a list of ERC buffers.
1665 PREDICATE is a function which executes with every buffer satisfying
1666 the predicate. If PREDICATE is passed as nil, return a list of all ERC
1667 buffers. If PROC is given, the buffers local variable `erc-server-process'
1668 needs to match PROC."
1670 (setq predicate (lambda () t)))
1671 (erc-buffer-filter predicate proc))
1673 (defmacro erc-with-all-buffers-of-server (process pred &rest forms)
1674 "Execute FORMS in all buffers which have same process as this server.
1675 FORMS will be evaluated in all buffers having the process PROCESS and
1676 where PRED matches or in all buffers of the server process if PRED is
1678 (declare (indent 1) (debug (form form body)))
1679 ;; Make the evaluation have the correct order
1680 (let ((pre (make-symbol "pre"))
1681 (pro (make-symbol "pro")))
1682 `(let* ((,pro ,process)
1684 (res (mapcar (lambda (buffer)
1685 (with-current-buffer buffer
1687 (erc-buffer-list ,pre
1689 ;; Silence the byte-compiler by binding the result of mapcar to
1693 ;; (iswitchb-mode) will autoload iswitchb.el
1694 (defvar iswitchb-temp-buflist)
1695 (declare-function iswitchb-read-buffer "iswitchb"
1696 (prompt &optional default require-match start matches-set))
1697 (defvar iswitchb-make-buflist-hook)
1699 (defun erc-iswitchb (&optional arg)
1700 "Use `iswitchb-read-buffer' to prompt for a ERC buffer to switch to.
1701 When invoked with prefix argument, use all erc buffers. Without prefix
1702 ARG, allow only buffers related to same session server.
1703 If `erc-track-mode' is in enabled, put the last element of
1704 `erc-modified-channels-alist' in front of the buffer list.
1706 Due to some yet unresolved reason, global function `iswitchb-mode'
1707 needs to be active for this function to work."
1709 (let ((enabled (bound-and-true-p iswitchb-mode)))
1710 (or enabled (iswitchb-mode 1))
1712 (let ((iswitchb-make-buflist-hook
1714 (setq iswitchb-temp-buflist
1715 (mapcar 'buffer-name
1718 (when arg erc-server-process)))))))
1720 (iswitchb-read-buffer
1722 (if (boundp 'erc-modified-channels-alist)
1723 (buffer-name (caar (last erc-modified-channels-alist)))
1726 (or enabled (iswitchb-mode -1)))))
1728 (defun erc-channel-list (proc)
1729 "Return a list of channel buffers.
1730 PROC is the process for the server connection. If PROC is nil, return
1731 all channel buffers on all servers."
1734 (and (erc-default-target)
1735 (erc-channel-p (erc-default-target))))
1738 (defun erc-buffer-list-with-nick (nick proc)
1739 "Return buffers containing NICK in the `erc-channel-users' list."
1740 (with-current-buffer (process-buffer proc)
1741 (let ((user (gethash (erc-downcase nick) erc-server-users)))
1743 (erc-server-user-buffers user)
1746 ;; Some local variables
1748 (defvar erc-default-recipients nil
1749 "List of default recipients of the current buffer.")
1750 (make-variable-buffer-local 'erc-default-recipients)
1752 (defvar erc-session-user-full-name nil
1753 "Full name of the user on the current server.")
1754 (make-variable-buffer-local 'erc-session-user-full-name)
1756 (defvar erc-channel-user-limit nil
1757 "Limit of users per channel.")
1758 (make-variable-buffer-local 'erc-channel-user-limit)
1760 (defvar erc-channel-key nil
1761 "Key needed to join channel.")
1762 (make-variable-buffer-local 'erc-channel-key)
1764 (defvar erc-invitation nil
1765 "Last invitation channel.")
1766 (make-variable-buffer-local 'erc-invitation)
1768 (defvar erc-away nil
1769 "Non-nil indicates that we are away.
1771 Use `erc-away-time' to access this if you might be in a channel
1772 buffer rather than a server buffer.")
1773 (make-variable-buffer-local 'erc-away)
1775 (defvar erc-channel-list nil
1776 "Server channel list.")
1777 (make-variable-buffer-local 'erc-channel-list)
1779 (defvar erc-bad-nick nil
1780 "Non-nil indicates that we got a `nick in use' error while connecting.")
1781 (make-variable-buffer-local 'erc-bad-nick)
1783 (defvar erc-logged-in nil
1784 "Non-nil indicates that we are logged in.")
1785 (make-variable-buffer-local 'erc-logged-in)
1787 (defvar erc-default-nicks nil
1788 "The local copy of `erc-nick' - the list of nicks to choose from.")
1789 (make-variable-buffer-local 'erc-default-nicks)
1791 (defvar erc-nick-change-attempt-count 0
1792 "Used to keep track of how many times an attempt at changing nick is made.")
1793 (make-variable-buffer-local 'erc-nick-change-attempt-count)
1795 (defun erc-migrate-modules (mods)
1796 "Migrate old names of ERC modules to new ones."
1797 ;; modify `transforms' to specify what needs to be changed
1798 ;; each item is in the format '(old . new)
1799 (let ((transforms '((pcomplete . completion))))
1801 (mapcar (lambda (m) (or (cdr (assoc m transforms)) m))
1804 (defcustom erc-modules '(netsplit fill button match track completion readonly
1805 networks ring autojoin noncommands irccontrols
1806 move-to-prompt stamp menu list)
1807 "A list of modules which ERC should enable.
1808 If you set the value of this without using `customize' remember to call
1809 \(erc-update-modules) after you change it. When using `customize', modules
1810 removed from the list will be disabled."
1812 ;; replace outdated names with their newer equivalents
1813 (erc-migrate-modules (symbol-value sym)))
1814 :set (lambda (sym val)
1815 ;; disable modules which have just been removed
1816 (when (and (boundp 'erc-modules) erc-modules val)
1817 (dolist (module erc-modules)
1818 (unless (member module val)
1819 (let ((f (intern-soft (format "erc-%s-mode" module))))
1820 (when (and (fboundp f) (boundp f) (symbol-value f))
1821 (message "Disabling `erc-%s'" module)
1824 ;; this test is for the case where erc hasn't been loaded yet
1825 (when (fboundp 'erc-update-modules)
1826 (erc-update-modules)))
1830 (const :tag "autoaway: Set away status automatically" autoaway)
1831 (const :tag "autojoin: Join channels automatically" autojoin)
1832 (const :tag "button: Buttonize URLs, nicknames, and other text" button)
1833 (const :tag "capab: Mark unidentified users on servers supporting CAPAB"
1835 (const :tag "completion: Complete nicknames and commands (programmable)"
1837 (const :tag "hecomplete: Complete nicknames and commands (obsolete, use \"completion\")" hecomplete)
1838 (const :tag "dcc: Provide Direct Client-to-Client support" dcc)
1839 (const :tag "fill: Wrap long lines" fill)
1840 (const :tag "identd: Launch an identd server on port 8113" identd)
1841 (const :tag "irccontrols: Highlight or remove IRC control characters"
1843 (const :tag "keep-place: Leave point above un-viewed text" keep-place)
1844 (const :tag "list: List channels in a separate buffer" list)
1845 (const :tag "log: Save buffers in logs" log)
1846 (const :tag "match: Highlight pals, fools, and other keywords" match)
1847 (const :tag "menu: Display a menu in ERC buffers" menu)
1848 (const :tag "move-to-prompt: Move to the prompt when typing text"
1850 (const :tag "netsplit: Detect netsplits" netsplit)
1851 (const :tag "networks: Provide data about IRC networks" networks)
1852 (const :tag "noncommands: Don't display non-IRC commands after evaluation"
1855 "notify: Notify when the online status of certain users changes"
1857 (const :tag "notifications: Send notifications on PRIVMSG or nickname mentions"
1859 (const :tag "page: Process CTCP PAGE requests from IRC" page)
1860 (const :tag "readonly: Make displayed lines read-only" readonly)
1861 (const :tag "replace: Replace text in messages" replace)
1862 (const :tag "ring: Enable an input history" ring)
1863 (const :tag "scrolltobottom: Scroll to the bottom of the buffer"
1865 (const :tag "services: Identify to Nickserv (IRC Services) automatically"
1867 (const :tag "smiley: Convert smileys to pretty icons" smiley)
1868 (const :tag "sound: Play sounds when you receive CTCP SOUND requests"
1870 (const :tag "stamp: Add timestamps to messages" stamp)
1871 (const :tag "spelling: Check spelling" spelling)
1872 (const :tag "track: Track channel activity in the mode-line" track)
1873 (const :tag "truncate: Truncate buffers to a certain size" truncate)
1874 (const :tag "unmorse: Translate morse code in messages" unmorse)
1875 (const :tag "xdcc: Act as an XDCC file-server" xdcc)
1876 (repeat :tag "Others" :inline t symbol))
1879 (defun erc-update-modules ()
1880 "Run this to enable erc-foo-mode for all modules in `erc-modules'."
1882 (dolist (mod erc-modules)
1883 (setq req (concat "erc-" (symbol-name mod)))
1885 ;; yuck. perhaps we should bring the filenames into sync?
1886 ((string= req "erc-capab-identify")
1887 (setq req "erc-capab"))
1888 ((string= req "erc-completion")
1889 (setq req "erc-pcomplete"))
1890 ((string= req "erc-pcomplete")
1891 (setq mod 'completion))
1892 ((string= req "erc-autojoin")
1893 (setq req "erc-join")))
1895 (require (intern req))
1897 (let ((sym (intern-soft (concat "erc-" (symbol-name mod) "-mode"))))
1900 (error "`%s' is not a known ERC module" mod))))))
1902 (defun erc-setup-buffer (buffer)
1903 "Consults `erc-join-buffer' to find out how to display `BUFFER'."
1904 (pcase erc-join-buffer
1906 (if (active-minibuffer-window)
1907 (display-buffer buffer)
1908 (switch-to-buffer-other-window buffer)))
1910 (display-buffer buffer))
1914 (when (or (not erc-reuse-frames)
1915 (not (get-buffer-window buffer t)))
1916 (let ((frame (make-frame (or erc-frame-alist
1917 default-frame-alist))))
1919 (select-frame frame))
1920 (switch-to-buffer buffer)
1921 (when erc-frame-dedicated-flag
1922 (set-window-dedicated-p (selected-window) t))))
1924 (if (active-minibuffer-window)
1925 (display-buffer buffer)
1926 (switch-to-buffer buffer)))))
1928 (defun erc-open (&optional server port nick full-name
1929 connect passwd tgt-list channel process)
1930 "Connect to SERVER on PORT as NICK with FULL-NAME.
1932 If CONNECT is non-nil, connect to the server. Otherwise assume
1933 already connected and just create a separate buffer for the new
1936 Use PASSWD as user password on the server. If TGT-LIST is
1937 non-nil, use it to initialize `erc-default-recipients'.
1939 Returns the buffer for the given server or channel."
1940 (let ((server-announced-name (when (and (boundp 'erc-session-server)
1941 (string= server erc-session-server))
1942 erc-server-announced-name))
1943 (connected-p (unless connect erc-server-connected))
1944 (buffer (erc-get-buffer-create server port channel))
1945 (old-buffer (current-buffer))
1948 (when connect (run-hook-with-args 'erc-before-connect server port nick))
1949 (erc-update-modules)
1951 (setq old-point (point))
1953 (setq erc-server-announced-name server-announced-name)
1954 (setq erc-server-connected connected-p)
1955 ;; connection parameters
1956 (setq erc-server-process process)
1957 (setq erc-insert-marker (make-marker))
1958 (setq erc-input-marker (make-marker))
1959 ;; go to the end of the buffer and open a new line
1960 ;; (the buffer may have existed)
1961 (goto-char (point-max))
1963 (when (get-text-property (point) 'erc-prompt)
1964 (setq continued-session t)
1965 (set-marker erc-input-marker
1966 (or (next-single-property-change (point) 'erc-prompt)
1968 (unless continued-session
1969 (goto-char (point-max))
1971 (set-marker erc-insert-marker (point))
1972 ;; stack of default recipients
1973 (setq erc-default-recipients tgt-list)
1974 (setq erc-server-current-nick nil)
1975 ;; Initialize erc-server-users and erc-channel-users
1977 (progn ;; server buffer
1978 (setq erc-server-users
1979 (make-hash-table :test 'equal))
1980 (setq erc-channel-users nil))
1981 (progn ;; target buffer
1982 (setq erc-server-users nil)
1983 (setq erc-channel-users
1984 (make-hash-table :test 'equal))))
1985 ;; clear last incomplete line read
1986 (setq erc-server-filter-data nil)
1987 (setq erc-channel-topic "")
1988 ;; limit on the number of users on the channel (mode +l)
1989 (setq erc-channel-user-limit nil)
1990 (setq erc-channel-key nil)
1991 ;; last active buffer, defaults to this one
1992 (erc-set-active-buffer buffer)
1993 ;; last invitation channel
1994 (setq erc-invitation nil)
1995 ;; Server channel list
1996 (setq erc-channel-list ())
1997 ;; login-time 'nick in use' error
1998 (setq erc-bad-nick nil)
1999 ;; whether we have logged in
2000 (setq erc-logged-in nil)
2001 ;; The local copy of `erc-nick' - the list of nicks to choose
2002 (setq erc-default-nicks (if (consp erc-nick) erc-nick (list erc-nick)))
2004 (setq erc-session-password
2009 (auth-source-search :host server
2013 :require '(:secret)))
2015 (if (functionp secret)
2018 ;; debug output buffer
2021 (get-buffer-create (concat "*ERC-DEBUG: " server "*"))))
2023 (unless continued-session
2024 (goto-char (point-max))
2026 (if continued-session
2027 (goto-char old-point)
2028 (set-marker erc-insert-marker (point))
2029 (erc-display-prompt)
2030 (goto-char (point-max)))
2032 (erc-determine-parameters server port nick full-name)
2034 ;; Saving log file on exit
2035 (run-hook-with-args 'erc-connect-pre-hook buffer)
2038 (erc-server-connect erc-session-server erc-session-port buffer))
2039 (erc-update-mode-line)
2041 ;; Now display the buffer in a window as per user wishes.
2042 (unless (eq buffer old-buffer)
2044 ;; we can't log to debug buffer, it may not exist yet
2045 (message "erc: old buffer %s, switching to %s"
2047 (erc-setup-buffer buffer))
2051 (defun erc-initialize-log-marker (buffer)
2052 "Initialize the `erc-last-saved-position' marker to a sensible position.
2053 BUFFER is the current buffer."
2054 (with-current-buffer buffer
2055 (setq erc-last-saved-position (make-marker))
2056 (move-marker erc-last-saved-position
2057 (1- (marker-position erc-insert-marker)))))
2059 ;; interactive startup
2061 (defvar erc-server-history-list nil
2062 "IRC server interactive selection history list.")
2064 (defvar erc-nick-history-list nil
2065 "Nickname interactive selection history list.")
2067 (defun erc-already-logged-in (server port nick)
2068 "Return the buffers corresponding to a NICK on PORT of a session SERVER.
2069 This is determined by looking for the appropriate buffer and checking
2070 whether the connection is still alive.
2071 If no buffer matches, return nil."
2074 (and (erc-server-process-alive)
2075 (string= erc-session-server server)
2076 (erc-port-equal erc-session-port port)
2077 (erc-current-nick-p nick)))))
2079 (defcustom erc-before-connect nil
2080 "Hook called before connecting to a server.
2081 This hook gets executed before `erc' actually invokes `erc-mode'
2082 with your input data. The functions in here get called with three
2083 parameters, SERVER, PORT and NICK."
2087 (defcustom erc-after-connect nil
2088 "Hook called after connecting to a server.
2089 This hook gets executed when an end of MOTD has been received. All
2090 functions in here get called with the parameters SERVER and NICK."
2095 (defun erc-select-read-args ()
2096 "Prompt the user for values of nick, server, port, and password."
2097 (let (user-input server port nick passwd)
2098 (setq user-input (read-from-minibuffer
2100 (erc-compute-server) nil nil 'erc-server-history-list))
2102 (if (string-match "\\(.*\\):\\(.*\\)\\'" user-input)
2103 (setq port (erc-string-to-port (match-string 2 user-input))
2104 user-input (match-string 1 user-input))
2106 (erc-string-to-port (read-from-minibuffer
2107 "IRC port: " (erc-port-to-string
2108 (erc-compute-port))))))
2110 (if (string-match "\\`\\(.*\\)@\\(.*\\)" user-input)
2111 (setq nick (match-string 1 user-input)
2112 user-input (match-string 2 user-input))
2114 (if (erc-already-logged-in server port nick)
2115 (read-from-minibuffer
2116 (erc-format-message 'nick-in-use ?n nick)
2118 nil nil 'erc-nick-history-list)
2119 (read-from-minibuffer
2120 "Nickname: " (erc-compute-nick nick)
2121 nil nil 'erc-nick-history-list))))
2123 (setq server user-input)
2125 (setq passwd (if erc-prompt-for-password
2126 (if (and erc-password
2127 (y-or-n-p "Use the default password? "))
2129 (read-passwd "Password: "))
2131 (when (and passwd (string= "" passwd))
2134 (while (erc-already-logged-in server port nick)
2135 ;; hmm, this is a problem when using multiple connections to a bnc
2136 ;; with the same nick. Currently this code prevents using more than one
2137 ;; bnc with the same nick. actually it would be nice to have
2138 ;; bncs transparent, so that erc-compute-buffer-name displays
2139 ;; the server one is connected to.
2140 (setq nick (read-from-minibuffer
2141 (erc-format-message 'nick-in-use ?n nick)
2143 nil nil 'erc-nick-history-list)))
2144 (list :server server :port port :nick nick :password passwd)))
2147 (cl-defun erc (&key (server (erc-compute-server))
2148 (port (erc-compute-port))
2149 (nick (erc-compute-nick))
2151 (full-name (erc-compute-full-name)))
2152 "ERC is a powerful, modular, and extensible IRC client.
2153 This function is the main entry point for ERC.
2155 It permits you to select connection parameters, and then starts ERC.
2157 Non-interactively, it takes the keyword arguments
2158 (server (erc-compute-server))
2159 (port (erc-compute-port))
2160 (nick (erc-compute-nick))
2162 (full-name (erc-compute-full-name)))
2164 That is, if called with
2166 (erc :server \"irc.freenode.net\" :full-name \"Harry S Truman\")
2168 then the server and full-name will be set to those values, whereas
2169 `erc-compute-port', `erc-compute-nick' and `erc-compute-full-name' will
2170 be invoked for the values of the other parameters."
2171 (interactive (erc-select-read-args))
2172 (erc-open server port nick full-name t password))
2175 (defalias 'erc-select 'erc)
2176 (defalias 'erc-ssl 'erc-tls)
2179 (defun erc-tls (&rest r)
2180 "Interactively select TLS connection parameters and run ERC.
2181 Arguments are the same as for `erc'."
2182 (interactive (erc-select-read-args))
2183 (let ((erc-server-connect-function 'erc-open-tls-stream))
2186 (defun erc-open-tls-stream (name buffer host port)
2187 "Open an TLS stream to an IRC server.
2188 The process will be given the name NAME, its target buffer will be
2189 BUFFER. HOST and PORT specify the connection target."
2190 (open-network-stream name buffer host port
2193 ;;; Displaying error messages
2195 (defun erc-error (&rest args)
2196 "Pass ARGS to `format', and display the result as an error message.
2197 If `debug-on-error' is set to non-nil, then throw a real error with this
2198 message instead, to make debugging easier."
2200 (apply #'error args)
2201 (apply #'message args)
2204 ;;; Debugging the protocol
2206 (defvar erc-debug-irc-protocol nil
2207 "If non-nil, log all IRC protocol traffic to the buffer \"*erc-protocol*\".
2209 The buffer is created if it doesn't exist.
2211 NOTE: If this variable is non-nil, and you kill the only
2212 visible \"*erc-protocol*\" buffer, it will be recreated shortly,
2213 but you won't see it.
2215 WARNING: Do not set this variable directly! Instead, use the
2216 function `erc-toggle-debug-irc-protocol' to toggle its value.")
2218 (declare-function erc-network-name "erc-networks" ())
2220 (defun erc-log-irc-protocol (string &optional outbound)
2221 "Append STRING to the buffer *erc-protocol*.
2223 This only has any effect if `erc-debug-irc-protocol' is non-nil.
2225 The buffer is created if it doesn't exist.
2227 If OUTBOUND is non-nil, STRING is being sent to the IRC server
2228 and appears in face `erc-input-face' in the buffer."
2229 (when erc-debug-irc-protocol
2230 (let ((network-name (or (ignore-errors (erc-network-name))
2232 (with-current-buffer (get-buffer-create "*erc-protocol*")
2234 (goto-char (point-max))
2235 (let ((inhibit-read-only t))
2236 (insert (if (not outbound)
2237 ;; Cope with the fact that string might
2238 ;; contain multiple lines of text.
2239 (let ((lines (delete "" (split-string string
2242 (dolist (line lines)
2243 (setq result (concat result network-name
2247 (concat network-name " >> " string
2250 (1- (length string))))
2252 'face 'erc-input-face)))))
2253 (let ((orig-win (selected-window))
2254 (debug-buffer-window (get-buffer-window (current-buffer) t)))
2255 (when debug-buffer-window
2256 (select-window debug-buffer-window)
2257 (when (= 1 (count-lines (point) (point-max)))
2258 (goto-char (point-max))
2260 (select-window orig-win)))))))
2262 (defun erc-toggle-debug-irc-protocol (&optional arg)
2263 "Toggle the value of `erc-debug-irc-protocol'.
2265 If ARG is non-nil, show the *erc-protocol* buffer."
2267 (let* ((buf (get-buffer-create "*erc-protocol*")))
2268 (with-current-buffer buf
2269 (erc-view-mode-enter)
2270 (when (null (current-local-map))
2271 (let ((inhibit-read-only t))
2272 (insert (erc-make-notice "This buffer displays all IRC protocol traffic exchanged with each server.\n"))
2273 (insert (erc-make-notice "Kill this buffer to terminate protocol logging.\n\n")))
2274 (use-local-map (make-sparse-keymap))
2275 (local-set-key (kbd "t") 'erc-toggle-debug-irc-protocol))
2276 (add-hook 'kill-buffer-hook
2277 #'(lambda () (setq erc-debug-irc-protocol nil))
2279 (goto-char (point-max))
2280 (let ((inhibit-read-only t))
2281 (insert (erc-make-notice
2282 (format "IRC protocol logging %s at %s -- Press `t' to toggle logging.\n"
2283 (if erc-debug-irc-protocol "disabled" "enabled")
2284 (current-time-string))))))
2285 (setq erc-debug-irc-protocol (not erc-debug-irc-protocol))
2287 (not (get-buffer-window "*erc-protocol*" t)))
2288 (display-buffer buf t))
2289 (message "IRC protocol traffic logging %s (see buffer *erc-protocol*)."
2290 (if erc-debug-irc-protocol "enabled" "disabled"))))
2296 (defun erc-send-action (tgt str &optional force)
2297 "Send CTCP ACTION information described by STR to TGT."
2298 (erc-send-ctcp-message tgt (format "ACTION %s" str) force)
2299 (erc-display-message
2300 nil 'input (current-buffer)
2301 'ACTION ?n (erc-current-nick) ?a str ?u "" ?h ""))
2303 ;; Display interface
2305 (defun erc-string-invisible-p (string)
2306 "Check whether STRING is invisible or not.
2307 I.e. any char in it has the `invisible' property set."
2308 (text-property-any 0 (length string) 'invisible t string))
2310 (defcustom erc-remove-parsed-property t
2311 "Whether to remove the erc-parsed text property after displaying a message.
2313 The default is to remove it, since it causes ERC to take up extra
2314 memory. If you have code that relies on this property, then set
2315 this option to nil."
2319 (defun erc-display-line-1 (string buffer)
2320 "Display STRING in `erc-mode' BUFFER.
2321 Auxiliary function used in `erc-display-line'. The line gets filtered to
2322 interpret the control characters. Then, `erc-insert-pre-hook' gets called.
2323 If `erc-insert-this' is still t, STRING gets inserted into the buffer.
2324 Afterwards, `erc-insert-modify' and `erc-insert-post-hook' get called.
2325 If STRING is nil, the function does nothing."
2327 (with-current-buffer (or buffer (process-buffer erc-server-process))
2328 (let ((insert-position (or (marker-position erc-insert-marker)
2330 (let ((string string) ;; FIXME! Can this be removed?
2331 (buffer-undo-list t)
2332 (inhibit-read-only t))
2333 (unless (string-match "\n$" string)
2334 (setq string (concat string "\n"))
2335 (when (erc-string-invisible-p string)
2336 (erc-put-text-properties 0 (length string)
2337 '(invisible intangible) string)))
2338 (erc-log (concat "erc-display-line: " string
2339 (format "(%S)" string) " in buffer "
2340 (format "%s" buffer)))
2341 (setq erc-insert-this t)
2342 (run-hook-with-args 'erc-insert-pre-hook string)
2343 (if (null erc-insert-this)
2344 ;; Leave erc-insert-this set to t as much as possible. Fran
2345 ;; Litterio <franl> has seen erc-insert-this set to nil while
2346 ;; erc-send-pre-hook is running, which should never happen. This
2348 (setq erc-insert-this t)
2349 (save-excursion ;; to restore point in the new buffer
2352 (goto-char insert-position)
2353 (insert-before-markers string)
2354 ;; run insertion hook, with point at restored location
2356 (narrow-to-region insert-position (point))
2357 (run-hooks 'erc-insert-modify-hook)
2358 (run-hooks 'erc-insert-post-hook)
2359 (when erc-remove-parsed-property
2360 (remove-text-properties (point-min) (point-max)
2361 '(erc-parsed nil))))))))
2362 (erc-update-undo-list (- (or (marker-position erc-insert-marker)
2364 insert-position))))))
2366 (defun erc-update-undo-list (shift)
2367 ;; Translate buffer positions in buffer-undo-list by SHIFT.
2368 (unless (or (zerop shift) (atom buffer-undo-list))
2369 (let ((list buffer-undo-list) elt)
2371 (setq elt (car list))
2372 (cond ((integerp elt) ; POSITION
2373 (cl-incf (car list) shift))
2374 ((or (atom elt) ; nil, EXTENT
2375 ;; (eq t (car elt)) ; (t . TIME)
2376 (markerp (car elt))) ; (MARKER . DISTANCE)
2378 ((integerp (car elt)) ; (BEGIN . END)
2379 (cl-incf (car elt) shift)
2380 (cl-incf (cdr elt) shift))
2381 ((stringp (car elt)) ; (TEXT . POSITION)
2382 (cl-incf (cdr elt) (* (if (natnump (cdr elt)) 1 -1) shift)))
2383 ((null (car elt)) ; (nil PROPERTY VALUE BEG . END)
2384 (let ((cons (nthcdr 3 elt)))
2385 (cl-incf (car cons) shift)
2386 (cl-incf (cdr cons) shift)))
2387 ((and (featurep 'xemacs)
2388 (extentp (car elt))) ; (EXTENT START END)
2389 (cl-incf (nth 1 elt) shift)
2390 (cl-incf (nth 2 elt) shift)))
2391 (setq list (cdr list))))))
2393 (defvar erc-valid-nick-regexp "[]a-zA-Z^[;\\`_{}|][]^[;\\`_{}|a-zA-Z0-9-]*"
2394 "Regexp which matches all valid characters in a IRC nickname.")
2396 (defun erc-is-valid-nick-p (nick)
2397 "Check if NICK is a valid IRC nickname."
2398 (string-match (concat "^" erc-valid-nick-regexp "$") nick))
2400 (defun erc-display-line (string &optional buffer)
2401 "Display STRING in the ERC BUFFER.
2402 All screen output must be done through this function. If BUFFER is nil
2403 or omitted, the default ERC buffer for the `erc-session-server' is used.
2404 The BUFFER can be an actual buffer, a list of buffers, 'all or 'active.
2405 If BUFFER = 'all, the string is displayed in all the ERC buffers for the
2406 current session. 'active means the current active buffer
2407 \(`erc-active-buffer'). If the buffer can't be resolved, the current
2408 buffer is used. `erc-display-line-1' is used to display STRING.
2410 If STRING is nil, the function does nothing."
2411 (let ((inhibit-point-motion-hooks t)
2414 ((bufferp buffer) (list buffer))
2415 ((listp buffer) buffer)
2416 ((processp buffer) (list (process-buffer buffer)))
2418 ;; Hmm, or all of the same session server?
2419 (erc-buffer-list nil erc-server-process))
2420 ((and (eq 'active buffer) (erc-active-buffer))
2421 (list (erc-active-buffer)))
2422 ((erc-server-buffer-live-p)
2423 (list (process-buffer erc-server-process)))
2424 (t (list (current-buffer)))))
2425 (when (buffer-live-p buf)
2426 (erc-display-line-1 string buf)
2427 (push buf new-bufs)))
2428 (when (null new-bufs)
2429 (erc-display-line-1 string (if (erc-server-buffer-live-p)
2430 (process-buffer erc-server-process)
2431 (current-buffer))))))
2433 (defun erc-display-message-highlight (type string)
2434 "Highlight STRING according to TYPE, where erc-TYPE-face is an ERC face.
2436 See also `erc-make-notice'."
2437 (cond ((eq type 'notice)
2438 (erc-make-notice string))
2440 (erc-put-text-property
2442 'face (or (intern-soft
2443 (concat "erc-" (symbol-name type) "-face"))
2448 (defvar erc-lurker-state nil
2449 "Track the time of the last PRIVMSG for each (server,nick) pair.
2451 This is implemented as a hash of hashes, where the outer key is
2452 the canonicalized server name (as returned by
2453 `erc-canonicalize-server-name') and the outer value is a hash
2454 table mapping nicks (as returned by `erc-lurker-maybe-trim') to
2455 the times of their most recently received PRIVMSG on any channel
2456 on the given server.")
2458 (defcustom erc-lurker-trim-nicks t
2459 "If t, trim trailing `erc-lurker-ignore-chars' from nicks.
2461 This causes e.g. nick and nick` to be considered as the same
2462 individual for activity tracking and lurkiness detection
2467 (defcustom erc-lurker-ignore-chars "`_"
2468 "Characters at the end of a nick to strip for activity tracking purposes.
2470 See also `erc-lurker-trim-nicks'."
2474 (defun erc-lurker-maybe-trim (nick)
2475 "Maybe trim trailing `erc-lurker-ignore-chars' from NICK.
2477 Returns NICK unmodified unless `erc-lurker-trim-nicks' is
2479 (if erc-lurker-trim-nicks
2480 (replace-regexp-in-string
2482 (mapconcat (lambda (char)
2483 (regexp-quote (char-to-string char)))
2484 erc-lurker-ignore-chars ""))
2488 (defcustom erc-lurker-hide-list nil
2489 "List of IRC type messages to hide when sent by lurkers.
2491 A typical value would be '(\"JOIN\" \"PART\" \"QUIT\").
2492 See also `erc-lurker-p' and `erc-hide-list'."
2494 :type 'erc-message-type)
2496 (defcustom erc-lurker-threshold-time (* 60 60 24) ; 24h by default
2497 "Nicks from which no PRIVMSGs have been received within this
2498 interval (in units of seconds) are considered lurkers by
2499 `erc-lurker-p' and as a result their messages of types in
2500 `erc-lurker-hide-list' will be hidden."
2504 (defun erc-lurker-initialize ()
2505 "Initialize ERC lurker tracking functionality.
2507 This function adds `erc-lurker-update-status' to
2508 `erc-insert-pre-hook' in order to record the time of each nick's
2509 most recent PRIVMSG as well as initializing the state variable
2510 storing this information."
2511 (setq erc-lurker-state (make-hash-table :test 'equal))
2512 (add-hook 'erc-insert-pre-hook 'erc-lurker-update-status))
2514 (defun erc-lurker-cleanup ()
2515 "Remove all last PRIVMSG state older than `erc-lurker-threshold-time'.
2517 This should be called regularly to avoid excessive resource
2518 consumption for long-lived IRC or Emacs sessions."
2520 (lambda (server hash)
2522 (lambda (nick last-PRIVMSG-time)
2524 (> (float-time (time-subtract
2527 erc-lurker-threshold-time)
2528 (remhash nick hash)))
2530 (if (zerop (hash-table-count hash))
2531 (remhash server erc-lurker-state)))
2534 (defvar erc-lurker-cleanup-count 0
2535 "Internal counter variable for use with `erc-lurker-cleanup-interval'.")
2537 (defvar erc-lurker-cleanup-interval 100
2538 "Frequency of cleaning up stale erc-lurker state.
2540 `erc-lurker-update-status' calls `erc-lurker-cleanup' once for
2541 every `erc-lurker-cleanup-interval' updates to
2542 `erc-lurker-state'. This is designed to limit the memory
2543 consumption of lurker state during long Emacs sessions and/or ERC
2544 sessions with large numbers of incoming PRIVMSGs.")
2546 (defun erc-lurker-update-status (_message)
2547 "Update `erc-lurker-state' if necessary.
2549 This function is called from `erc-insert-pre-hook'. If the
2550 current message is a PRIVMSG, update `erc-lurker-state' to
2551 reflect the fact that its sender has issued a PRIVMSG at the
2552 current time. Otherwise, take no action.
2554 This function depends on the fact that `erc-display-message'
2555 dynamically binds `parsed', which is used to check if the current
2556 message is a PRIVMSG and to determine its sender. See also
2557 `erc-lurker-trim-nicks' and `erc-lurker-ignore-chars'.
2559 In order to limit memory consumption, this function also calls
2560 `erc-lurker-cleanup' once every `erc-lurker-cleanup-interval'
2561 updates of `erc-lurker-state'."
2562 (when (and (boundp 'parsed) (erc-response-p parsed))
2563 (let* ((command (erc-response.command parsed))
2565 (erc-lurker-maybe-trim
2566 (car (erc-parse-user (erc-response.sender parsed)))))
2568 (erc-canonicalize-server-name erc-server-announced-name)))
2569 (when (equal command "PRIVMSG")
2570 (when (>= (cl-incf erc-lurker-cleanup-count)
2571 erc-lurker-cleanup-interval)
2572 (setq erc-lurker-cleanup-count 0)
2573 (erc-lurker-cleanup))
2574 (unless (gethash server erc-lurker-state)
2575 (puthash server (make-hash-table :test 'equal) erc-lurker-state))
2576 (puthash sender (current-time)
2577 (gethash server erc-lurker-state))))))
2579 (defun erc-lurker-p (nick)
2580 "Predicate indicating NICK's lurking status on the current server.
2582 Lurking is the condition where NICK has issued no PRIVMSG on this
2583 server within `erc-lurker-threshold-time'. See also
2584 `erc-lurker-trim-nicks' and `erc-lurker-ignore-chars'."
2585 (unless erc-lurker-state (erc-lurker-initialize))
2587 (erc-canonicalize-server-name erc-server-announced-name))
2589 (gethash (erc-lurker-maybe-trim nick)
2590 (gethash server erc-lurker-state (make-hash-table)))))
2591 (or (null last-PRIVMSG-time)
2593 (time-subtract (current-time) last-PRIVMSG-time))
2594 erc-lurker-threshold-time))))
2596 (defcustom erc-common-server-suffixes
2597 '(("openprojects.net$" . "OPN")
2598 ("freenode.net$" . "freenode")
2599 ("oftc.net$" . "OFTC"))
2600 "Alist of common server name suffixes.
2601 This variable is used in mode-line display to save screen
2602 real estate. Set it to nil if you want to avoid changing
2603 displayed hostnames."
2604 :group 'erc-mode-line-and-header
2607 (defun erc-canonicalize-server-name (server)
2608 "Return the canonical network name for SERVER if any,
2609 otherwise `erc-server-announced-name'. SERVER is matched against
2610 `erc-common-server-suffixes'."
2612 (or (cdar (erc-remove-if-not
2613 (lambda (net) (string-match (car net) server))
2614 erc-common-server-suffixes))
2615 erc-server-announced-name)))
2617 (defun erc-hide-current-message-p (parsed)
2618 "Predicate indicating whether the parsed ERC response PARSED should be hidden.
2620 Messages are always hidden if the message type of PARSED appears in
2621 `erc-hide-list'. In addition, messages whose type is a member of
2622 `erc-lurker-hide-list' are hidden if `erc-lurker-p' returns true."
2623 (let* ((command (erc-response.command parsed))
2624 (sender (car (erc-parse-user (erc-response.sender parsed)))))
2625 (or (member command erc-hide-list)
2626 (and (member command erc-lurker-hide-list) (erc-lurker-p sender)))))
2628 (defun erc-display-message (parsed type buffer msg &rest args)
2629 "Display MSG in BUFFER.
2631 ARGS, PARSED, and TYPE are used to format MSG sensibly.
2633 See also `erc-format-message' and `erc-display-line'."
2634 (let ((string (if (symbolp msg)
2635 (apply 'erc-format-message msg args)
2642 (mapc (lambda (type)
2644 (erc-display-message-highlight type string)))
2648 (erc-display-message-highlight type string))))
2650 (if (not (erc-response-p parsed))
2651 (erc-display-line string buffer)
2652 (unless (erc-hide-current-message-p parsed)
2653 (erc-put-text-property 0 (length string) 'erc-parsed parsed string)
2654 (erc-put-text-property 0 (length string) 'rear-sticky t string)
2655 (erc-display-line string buffer)))))
2657 (defun erc-message-type-member (position list)
2658 "Return non-nil if the erc-parsed text-property at POSITION is in LIST.
2660 This function relies on the erc-parsed text-property being
2662 (let ((prop-val (erc-get-parsed-vector position)))
2663 (and prop-val (member (erc-response.command prop-val) list))))
2665 (defvar erc-send-input-line-function 'erc-send-input-line)
2666 (make-variable-buffer-local 'erc-send-input-line-function)
2668 (defun erc-send-input-line (target line &optional force)
2669 "Send LINE to TARGET.
2671 See also `erc-server-send'."
2672 (setq line (format "PRIVMSG %s :%s"
2674 ;; If the line is empty, we still want to
2675 ;; send it - i.e. an empty pasted line.
2676 (if (string= line "\n")
2679 (erc-server-send line force target))
2681 (defun erc-get-arglist (fun)
2682 "Return the argument list of a function without the parens."
2683 (let ((arglist (format "%S" (erc-function-arglist fun))))
2684 (if (string-match "^(\\(.*\\))$" arglist)
2685 (match-string 1 arglist)
2688 (defun erc-command-no-process-p (str)
2689 "Return non-nil if STR is an ERC command that can be run when the process
2690 is not alive, nil otherwise."
2691 (let ((fun (erc-extract-command-from-line str)))
2694 (get (car fun) 'process-not-needed))))
2696 (defun erc-command-name (cmd)
2697 "For CMD being the function name of a ERC command, something like
2698 erc-cmd-FOO, this returns a string /FOO."
2699 (let ((command-name (symbol-name cmd)))
2700 (if (string-match "^erc-cmd-\\(.*\\)$" command-name)
2701 (concat "/" (match-string 1 command-name))
2704 (defun erc-process-input-line (line &optional force no-command)
2705 "Translate LINE to an RFC1459 command and send it based.
2706 Returns non-nil if the command is actually sent to the server, and nil
2709 If the command in the LINE is not bound as a function `erc-cmd-<COMMAND>',
2710 it is passed to `erc-cmd-default'. If LINE is not a command (i.e. doesn't
2711 start with /<COMMAND>) then it is sent as a message.
2713 An optional FORCE argument forces sending the line when flood
2714 protection is in effect. The optional NO-COMMAND argument prohibits
2715 this function from interpreting the line as a command."
2716 (let ((command-list (erc-extract-command-from-line line)))
2717 (if (and command-list
2719 (let* ((cmd (nth 0 command-list))
2720 (args (nth 1 command-list)))
2725 (wrong-number-of-arguments
2726 (erc-display-message nil 'error (current-buffer) 'incorrect-args
2727 ?c (erc-command-name cmd)
2728 ?u (or (erc-get-arglist cmd)
2731 (or (documentation cmd) "")))
2733 (let ((r (erc-default-target)))
2735 (funcall erc-send-input-line-function r line force)
2736 (erc-display-message nil 'error (current-buffer) 'no-target)
2739 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2740 ;; Input commands handlers
2741 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2743 (defun erc-cmd-AMSG (line)
2744 "Send LINE to all channels of the current server that you are on."
2745 (interactive "sSend to all channels you're on: ")
2746 (setq line (erc-trim-string line))
2747 (erc-with-all-buffers-of-server nil
2749 (erc-channel-p (erc-default-target)))
2750 (erc-send-message line)))
2751 (put 'erc-cmd-AMSG 'do-not-parse-args t)
2753 (defun erc-cmd-SAY (line)
2754 "Send LINE to the current query or channel as a message, not a command.
2756 Use this when you want to send a message with a leading '/'. Note
2757 that since multi-line messages are never a command, you don't
2758 need this when pasting multiple lines of text."
2759 (if (string-match "^\\s-*$" line)
2761 (string-match "^ ?\\(.*\\)" line)
2762 (erc-process-input-line (match-string 1 line) nil t)))
2763 (put 'erc-cmd-SAY 'do-not-parse-args t)
2765 (defun erc-cmd-SET (line)
2766 "Set the variable named by the first word in LINE to some VALUE.
2767 VALUE is computed by evaluating the rest of LINE in Lisp."
2769 ((string-match "^\\s-*\\(\\S-+\\)\\s-+\\(.*\\)$" line)
2770 (let ((var (read (concat "erc-" (match-string 1 line))))
2771 (val (read (match-string 2 line))))
2774 (set var (eval val))
2775 (erc-display-message
2776 nil nil 'active (format "Set %S to %S" var val))
2778 (setq var (read (match-string 1 line)))
2781 (set var (eval val))
2782 (erc-display-message
2783 nil nil 'active (format "Set %S to %S" var val))
2785 (erc-display-message nil 'error 'active 'variable-not-bound)
2787 ((string-match "^\\s-*$" line)
2789 (concat "Available user variables:\n"
2794 (let ((val (symbol-value var)))
2795 (concat (format "%S:" var)
2797 (concat "\n" (pp-to-string val))
2798 (format " %S\n" val)))))
2799 (apropos-internal "^erc-" 'custom-variable-p))))
2800 (current-buffer)) t)
2802 (defalias 'erc-cmd-VAR 'erc-cmd-SET)
2803 (defalias 'erc-cmd-VARIABLE 'erc-cmd-SET)
2804 (put 'erc-cmd-SET 'do-not-parse-args t)
2805 (put 'erc-cmd-SET 'process-not-needed t)
2807 (defun erc-cmd-default (line)
2810 Commands for which no erc-cmd-xxx exists, are tunneled through
2811 this function. LINE is sent to the server verbatim, and
2812 therefore has to contain the command itself as well."
2813 (erc-log (format "cmd: DEFAULT: %s" line))
2814 (erc-server-send (substring line 1))
2817 (defun erc-cmd-IGNORE (&optional user)
2818 "Ignore USER. This should be a regexp matching nick!user@host.
2819 If no USER argument is specified, list the contents of `erc-ignore-list'."
2821 (let ((quoted (regexp-quote user)))
2822 (when (and (not (string= user quoted))
2823 (y-or-n-p (format "Use regexp-quoted form (%s) instead? "
2827 (erc-make-notice (format "Now ignoring %s" user))
2829 (erc-with-server-buffer (add-to-list 'erc-ignore-list user)))
2830 (if (null (erc-with-server-buffer erc-ignore-list))
2831 (erc-display-line (erc-make-notice "Ignore list is empty") 'active)
2832 (erc-display-line (erc-make-notice "Ignore list:") 'active)
2833 (mapc #'(lambda (item)
2834 (erc-display-line (erc-make-notice item)
2836 (erc-with-server-buffer erc-ignore-list))))
2839 (defun erc-cmd-UNIGNORE (user)
2840 "Remove the user specified in USER from the ignore list."
2841 (let ((ignored-nick (car (erc-with-server-buffer
2842 (erc-member-ignore-case (regexp-quote user)
2843 erc-ignore-list)))))
2844 (unless ignored-nick
2845 (if (setq ignored-nick (erc-ignored-user-p user))
2846 (unless (y-or-n-p (format "Remove this regexp (%s)? "
2848 (setq ignored-nick nil))
2850 (erc-make-notice (format "%s is not currently ignored!" user))
2854 (erc-make-notice (format "No longer ignoring %s" user))
2856 (erc-with-server-buffer
2857 (setq erc-ignore-list (delete ignored-nick erc-ignore-list)))))
2860 (defun erc-cmd-CLEAR ()
2861 "Clear the window content."
2864 (put 'erc-cmd-CLEAR 'process-not-needed t)
2866 (defun erc-cmd-OPS ()
2867 "Show the ops in the current channel."
2870 (if erc-channel-users
2871 (maphash (lambda (_nick user-data)
2872 (let ((cuser (cdr user-data)))
2874 (erc-channel-user-op cuser))
2875 (setq ops (cons (erc-server-user-nickname
2879 (setq ops (sort ops 'string-lessp))
2881 (erc-display-message
2882 nil 'notice (current-buffer) 'ops
2883 ?i (length ops) ?s (if (> (length ops) 1) "s" "")
2884 ?o (mapconcat 'identity ops " "))
2885 (erc-display-message nil 'notice (current-buffer) 'ops-none)))
2888 (defun erc-cmd-COUNTRY (tld)
2889 "Display the country associated with the top level domain TLD."
2890 (require 'mail-extr)
2891 (let ((co (ignore-errors (what-domain tld))))
2893 (erc-display-message
2894 nil 'notice 'active 'country ?c co ?d tld)
2895 (erc-display-message
2896 nil 'notice 'active 'country-unknown ?d tld))
2898 (put 'erc-cmd-COUNTRY 'process-not-needed t)
2900 (defun erc-cmd-AWAY (line)
2901 "Mark the user as being away, the reason being indicated by LINE.
2902 If no reason is given, unset away status."
2903 (when (string-match "^\\s-*\\(.*\\)$" line)
2904 (let ((reason (match-string 1 line)))
2905 (erc-log (format "cmd: AWAY: %s" reason))
2907 (if (string= reason "")
2909 (concat "AWAY :" reason))))
2911 (put 'erc-cmd-AWAY 'do-not-parse-args t)
2913 (defun erc-cmd-GAWAY (line)
2914 "Mark the user as being away everywhere, the reason being indicated by LINE."
2915 ;; on all server buffers.
2916 (erc-with-all-buffers-of-server nil
2917 #'erc-open-server-buffer-p
2918 (erc-cmd-AWAY line)))
2919 (put 'erc-cmd-GAWAY 'do-not-parse-args t)
2921 (defun erc-cmd-CTCP (nick cmd &rest args)
2922 "Send a Client To Client Protocol message to NICK.
2924 CMD is the CTCP command, possible values being ECHO, FINGER, CLIENTINFO, TIME,
2925 VERSION and so on. It is called with ARGS."
2926 (let ((str (concat cmd
2928 (concat " " (mapconcat #'identity args " "))))))
2929 (erc-log (format "cmd: CTCP [%s]: [%s]" nick str))
2930 (erc-send-ctcp-message nick str)
2933 (defun erc-cmd-HELP (&optional func)
2934 "Popup help information.
2936 If FUNC contains a valid function or variable, help about that
2937 will be displayed. If FUNC is empty, display an apropos about
2938 ERC commands. Otherwise, do `apropos' in the ERC namespace
2942 To find out about erc and bbdb, do
2945 For help about the WHOIS command, do:
2948 For a list of user commands (/join /part, ...):
2951 (let* ((sym (or (let ((sym (intern-soft
2952 (concat "erc-cmd-" (upcase func)))))
2953 (if (and sym (or (boundp sym) (fboundp sym)))
2956 (let ((sym (intern-soft func)))
2957 (if (and sym (or (boundp sym) (fboundp sym)))
2960 (let ((sym (intern-soft (concat "erc-" func))))
2961 (if (and sym (or (boundp sym) (fboundp sym)))
2966 ((boundp sym) (describe-variable sym))
2967 ((fboundp sym) (describe-function sym))
2969 (apropos-command (concat "erc-.*" func) nil
2972 (get x 'custom-type))))
2974 (apropos "erc-cmd-")
2975 (message "Type C-h m to get additional information about keybindings.")
2978 (defalias 'erc-cmd-H 'erc-cmd-HELP)
2979 (put 'erc-cmd-HELP 'process-not-needed t)
2981 (defun erc-cmd-JOIN (channel &optional key)
2982 "Join the channel given in CHANNEL, optionally with KEY.
2983 If CHANNEL is specified as \"-invite\", join the channel to which you
2984 were most recently invited. See also `invitation'."
2986 (if (string= (upcase channel) "-INVITE")
2988 (setq chnl erc-invitation)
2989 (erc-display-message nil 'error (current-buffer) 'no-invitation))
2990 (setq chnl (erc-ensure-channel-name channel)))
2992 ;; Prevent double joining of same channel on same server.
2993 (let ((joined-channels
2994 (mapcar #'(lambda (chanbuf)
2995 (with-current-buffer chanbuf (erc-default-target)))
2996 (erc-channel-list erc-server-process))))
2997 (if (erc-member-ignore-case chnl joined-channels)
2998 (switch-to-buffer (car (erc-member-ignore-case chnl
3000 (erc-log (format "cmd: JOIN: %s" chnl))
3001 (erc-server-send (if (and chnl key)
3002 (format "JOIN %s %s" chnl key)
3003 (format "JOIN %s" chnl)))))))
3006 (defalias 'erc-cmd-CHANNEL 'erc-cmd-JOIN)
3007 (defalias 'erc-cmd-J 'erc-cmd-JOIN)
3009 (defvar erc-channel-new-member-names nil
3010 "If non-nil, a names list is currently being received.
3012 If non-nil, this variable is a hash-table that associates
3013 received nicks with t.")
3014 (make-variable-buffer-local 'erc-channel-new-member-names)
3016 (defun erc-cmd-NAMES (&optional channel)
3017 "Display the users in CHANNEL.
3018 If CHANNEL is not specified, display the users in the current channel.
3019 This function clears the channel name list first, then sends the
3021 (let ((tgt (or (and (erc-channel-p channel) channel)
3022 (erc-default-target))))
3023 (if (and tgt (erc-channel-p tgt))
3025 (erc-log (format "cmd: DEFAULT: NAMES %s" tgt))
3028 (erc-channel-begin-receiving-names))
3029 (erc-server-send (concat "NAMES " tgt)))
3030 (erc-display-message nil 'error (current-buffer) 'no-default-channel)))
3032 (defalias 'erc-cmd-N 'erc-cmd-NAMES)
3034 (defun erc-cmd-KICK (target &optional reason-or-nick &rest reasonwords)
3035 "Kick the user indicated in LINE from the current channel.
3036 LINE has the format: \"#CHANNEL NICK REASON\" or \"NICK REASON\"."
3037 (let ((reasonstring (mapconcat 'identity reasonwords " ")))
3038 (if (string= "" reasonstring)
3039 (setq reasonstring (format "Kicked by %s" (erc-current-nick))))
3040 (if (erc-channel-p target)
3041 (let ((nick reason-or-nick))
3042 (erc-log (format "cmd: KICK: %s/%s: %s" nick target reasonstring))
3043 (erc-server-send (format "KICK %s %s :%s" target nick reasonstring)
3047 (let ((ch (erc-default-target)))
3048 (setq reasonstring (concat
3049 (if reason-or-nick (concat reason-or-nick " "))
3054 (format "cmd: KICK: %s/%s: %s" target ch reasonstring))
3056 (format "KICK %s %s :%s" ch target reasonstring) nil ch))
3057 (erc-display-message nil 'error (current-buffer)
3058 'no-default-channel))
3061 (defvar erc-script-args nil)
3063 (defun erc-cmd-LOAD (line)
3064 "Load the script provided in the LINE.
3065 If LINE continues beyond the file name, the rest of
3066 it is put in a (local) variable `erc-script-args',
3067 which can be used in Emacs Lisp scripts.
3069 The optional FORCE argument is ignored here - you can't force loading
3070 a script after exceeding the flood threshold."
3072 ((string-match "^\\s-*\\(\\S-+\\)\\(.*\\)$" line)
3073 (let* ((file-to-find (match-string 1 line))
3074 (erc-script-args (match-string 2 line))
3075 (file (erc-find-file file-to-find erc-script-path)))
3076 (erc-log (format "cmd: LOAD: %s" file-to-find))
3079 (erc-display-message nil 'error (current-buffer)
3080 'cannot-find-file ?f file-to-find))
3081 ((not (file-readable-p file))
3082 (erc-display-message nil 'error (current-buffer)
3083 'cannot-read-file ?f file))
3085 (message "Loading \'%s\'..." file)
3086 (erc-load-script file)
3087 (message "Loading \'%s\'...done" file))))
3091 (defun erc-cmd-WHOIS (user &optional server)
3092 "Display whois information for USER.
3094 If SERVER is non-nil, use that, rather than the current server."
3095 ;; FIXME: is the above docstring correct? -- Lawrence 2004-01-08
3096 (let ((send (if server
3097 (format "WHOIS %s %s" user server)
3098 (format "WHOIS %s" user))))
3099 (erc-log (format "cmd: %s" send))
3100 (erc-server-send send)
3102 (defalias 'erc-cmd-WI 'erc-cmd-WHOIS)
3104 (defun erc-cmd-WHOAMI ()
3105 "Display whois information about yourself."
3106 (erc-cmd-WHOIS (erc-current-nick))
3109 (defun erc-cmd-IDLE (nick)
3110 "Show the length of time NICK has been idle."
3111 (let ((origbuf (current-buffer))
3113 (erc-with-server-buffer
3114 (push (cons (erc-once-with-server-event
3115 311 (lambda (_proc parsed)
3117 (nth 1 (erc-response.command-args
3119 'erc-server-311-functions)
3121 (push (cons (erc-once-with-server-event
3122 312 (lambda (_proc parsed)
3124 (nth 1 (erc-response.command-args
3126 'erc-server-312-functions)
3128 (push (cons (erc-once-with-server-event
3129 318 (lambda (_proc parsed)
3131 (nth 1 (erc-response.command-args
3133 'erc-server-318-functions)
3135 (push (cons (erc-once-with-server-event
3136 319 (lambda (_proc parsed)
3138 (nth 1 (erc-response.command-args
3140 'erc-server-319-functions)
3142 (push (cons (erc-once-with-server-event
3143 320 (lambda (_proc parsed)
3145 (nth 1 (erc-response.command-args
3147 'erc-server-320-functions)
3149 (push (cons (erc-once-with-server-event
3150 330 (lambda (_proc parsed)
3152 (nth 1 (erc-response.command-args
3154 'erc-server-330-functions)
3156 (push (cons (erc-once-with-server-event
3158 (lambda (_proc parsed)
3162 (erc-response.command-args parsed)))))
3165 (format "%s has been idle for %s."
3166 (erc-string-no-properties nick)
3167 (erc-seconds-to-string idleseconds)))
3170 'erc-server-317-functions)
3173 ;; Send the WHOIS command.
3174 (erc-cmd-WHOIS nick)
3176 ;; Remove the uninterned symbols from the server hooks that did not run.
3177 (run-at-time 20 nil (lambda (buf symlist)
3178 (with-current-buffer buf
3179 (dolist (sym symlist)
3180 (let ((hooksym (cdr sym))
3181 (funcsym (car sym)))
3182 (remove-hook hooksym funcsym t)))))
3183 (current-buffer) symlist)))
3186 (defun erc-cmd-DESCRIBE (line)
3187 "Pose some action to a certain user.
3188 LINE has the format \"USER ACTION\"."
3191 "^\\s-*\\(\\S-+\\)\\s-\\(.*\\)$" line)
3192 (let ((dst (match-string 1 line))
3193 (s (match-string 2 line)))
3194 (erc-log (format "cmd: DESCRIBE: [%s] %s" dst s))
3195 (erc-send-action dst s))
3198 (put 'erc-cmd-DESCRIBE 'do-not-parse-args t)
3200 (defun erc-cmd-ME (line)
3201 "Send LINE as an action."
3203 ((string-match "^\\s-\\(.*\\)$" line)
3204 (let ((s (match-string 1 line)))
3205 (erc-log (format "cmd: ME: %s" s))
3206 (erc-send-action (erc-default-target) s))
3209 (put 'erc-cmd-ME 'do-not-parse-args t)
3211 (defun erc-cmd-ME\'S (line)
3212 "Do a /ME command, but add the string \" 's\" to the beginning."
3213 (erc-cmd-ME (concat " 's" line)))
3214 (put 'erc-cmd-ME\'S 'do-not-parse-args t)
3216 (defun erc-cmd-LASTLOG (line)
3217 "Show all lines in the current buffer matching the regexp LINE.
3219 If a match spreads across multiple lines, all those lines are shown.
3221 The lines are shown in a buffer named `*Occur*'.
3222 It serves as a menu to find any of the occurrences in this buffer.
3223 \\[describe-mode] in that buffer will explain how.
3225 If LINE contains upper case characters (excluding those preceded by `\'),
3226 the matching is case-sensitive."
3229 (put 'erc-cmd-LASTLOG 'do-not-parse-args t)
3230 (put 'erc-cmd-LASTLOG 'process-not-needed t)
3232 (defun erc-send-message (line &optional force)
3233 "Send LINE to the current channel or user and display it.
3235 See also `erc-message' and `erc-display-line'."
3236 (erc-message "PRIVMSG" (concat (erc-default-target) " " line) force)
3238 (concat (erc-format-my-nick) line)
3240 ;; FIXME - treat multiline, run hooks, or remove me?
3243 (defun erc-cmd-MODE (line)
3244 "Change or display the mode value of a channel or user.
3245 The first word specifies the target. The rest is the mode string
3248 If only one word is given, display the mode of that target.
3250 A list of valid mode strings for Freenode may be found at
3251 URL `http://freenode.net/using_the_network.shtml'."
3253 ((string-match "^\\s-\\(.*\\)$" line)
3254 (let ((s (match-string 1 line)))
3255 (erc-log (format "cmd: MODE: %s" s))
3256 (erc-server-send (concat "MODE " line)))
3259 (put 'erc-cmd-MODE 'do-not-parse-args t)
3261 (defun erc-cmd-NOTICE (channel-or-user &rest message)
3262 "Send a notice to the channel or user given as the first word.
3263 The rest is the message to send."
3264 (erc-message "NOTICE" (concat channel-or-user " "
3265 (mapconcat #'identity message " "))))
3267 (defun erc-cmd-MSG (line)
3268 "Send a message to the channel or user given as the first word in LINE.
3270 The rest of LINE is the message to send."
3271 (erc-message "PRIVMSG" line))
3273 (defalias 'erc-cmd-M 'erc-cmd-MSG)
3274 (put 'erc-cmd-MSG 'do-not-parse-args t)
3276 (defun erc-cmd-SQUERY (line)
3277 "Send a Service Query to the service given as the first word in LINE.
3279 The rest of LINE is the message to send."
3280 (erc-message "SQUERY" line))
3282 (defun erc-cmd-NICK (nick)
3283 "Change current nickname to NICK."
3284 (erc-log (format "cmd: NICK: %s (erc-bad-nick: %S)" nick erc-bad-nick))
3285 (let ((nicklen (cdr (assoc "NICKLEN" (erc-with-server-buffer
3286 erc-server-parameters)))))
3287 (and nicklen (> (length nick) (string-to-number nicklen))
3288 (erc-display-message
3289 nil 'notice 'active 'nick-too-long
3290 ?i (length nick) ?l nicklen)))
3291 (erc-server-send (format "NICK %s" nick))
3293 (erc-set-current-nick nick)
3294 (erc-update-mode-line)
3295 (setq erc-bad-nick nil)))
3298 (defun erc-cmd-PART (line)
3299 "When LINE is an empty string, leave the current channel.
3300 Otherwise leave the channel indicated by LINE."
3302 ((string-match "^\\s-*\\([&#+!]\\S-+\\)\\s-?\\(.*\\)$" line)
3303 (let* ((ch (match-string 1 line))
3304 (msg (match-string 2 line))
3305 (reason (funcall erc-part-reason (if (equal msg "") nil msg))))
3306 (erc-log (format "cmd: PART: %s: %s" ch reason))
3307 (erc-server-send (if (string= reason "")
3308 (format "PART %s" ch)
3309 (format "PART %s :%s" ch reason))
3312 ((string-match "^\\s-*\\(.*\\)$" line)
3313 (let* ((ch (erc-default-target))
3314 (msg (match-string 1 line))
3315 (reason (funcall erc-part-reason (if (equal msg "") nil msg))))
3316 (if (and ch (erc-channel-p ch))
3318 (erc-log (format "cmd: PART: %s: %s" ch reason))
3319 (erc-server-send (if (string= reason "")
3320 (format "PART %s" ch)
3321 (format "PART %s :%s" ch reason))
3323 (erc-display-message nil 'error (current-buffer) 'no-target)))
3326 (put 'erc-cmd-PART 'do-not-parse-args t)
3328 (defalias 'erc-cmd-LEAVE 'erc-cmd-PART)
3330 (defun erc-cmd-PING (recipient)
3332 (let ((time (format "%f" (erc-current-time))))
3333 (erc-log (format "cmd: PING: %s" time))
3334 (erc-cmd-CTCP recipient "PING" time)))
3336 (defun erc-cmd-QUOTE (line)
3337 "Send LINE directly to the server.
3338 All the text given as argument is sent to the sever as unmodified,
3339 just as you provided it. Use this command with care!"
3341 ((string-match "^ ?\\(.+\\)$" line)
3342 (erc-server-send (match-string 1 line)))
3344 (put 'erc-cmd-QUOTE 'do-not-parse-args t)
3346 (defcustom erc-query-display 'window
3347 "Indicates how to display query buffers when using the /QUERY
3348 command to talk to someone.
3350 The default behavior is to display the message in a new window
3351 and bring it to the front. See the documentation for
3352 `erc-join-buffer' for a description of the available choices.
3354 See also `erc-auto-query' to decide how private messages from
3355 other people should be displayed."
3357 :type '(choice (const :tag "Split window and select" window)
3358 (const :tag "Split window, don't select" window-noselect)
3359 (const :tag "New frame" frame)
3360 (const :tag "Bury in new buffer" bury)
3361 (const :tag "Use current buffer" buffer)
3362 (const :tag "Use current buffer" t)))
3364 (defun erc-cmd-QUERY (&optional user)
3365 "Open a query with USER.
3366 The type of query window/frame/etc will depend on the value of
3367 `erc-query-display'.
3369 If USER is omitted, close the current query buffer if one exists
3370 - except this is broken now ;-)"
3372 (list (read-from-minibuffer "Start a query with: " nil)))
3373 (let ((session-buffer (erc-server-buffer))
3374 (erc-join-buffer erc-query-display))
3376 (erc-query user session-buffer)
3377 ;; currently broken, evil hack to display help anyway
3378 ;(erc-delete-query))))
3379 (signal 'wrong-number-of-arguments ""))))
3380 (defalias 'erc-cmd-Q 'erc-cmd-QUERY)
3382 (defun erc-quit-reason-normal (&optional s)
3383 "Normal quit message.
3385 If S is non-nil, it will be used as the quit reason."
3387 (format "\C-bERC\C-b %s (IRC client for Emacs)"; - \C-b%s\C-b"
3388 erc-version-string) ; erc-official-location)
3391 (defun erc-quit-reason-zippy (&optional s)
3392 "Zippy quit message.
3394 If S is non-nil, it will be used as the quit reason."
3397 (erc-replace-regexp-in-string "\n" "" (yow))
3398 (erc-quit-reason-normal))))
3400 (make-obsolete 'erc-quit-reason-zippy "it will be removed." "24.4")
3402 (defun erc-quit-reason-various (s)
3403 "Choose a quit reason based on S (a string)."
3404 (when (featurep 'xemacs) (require 'poe))
3405 (let ((res (car (assoc-default (or s "")
3406 erc-quit-reason-various-alist 'string-match))))
3408 ((functionp res) (funcall res))
3411 (t (erc-quit-reason-normal)))))
3413 (defun erc-part-reason-normal (&optional s)
3414 "Normal part message.
3416 If S is non-nil, it will be used as the quit reason."
3418 (format "\C-bERC\C-b %s (IRC client for Emacs)"; - \C-b%s\C-b"
3419 erc-version-string) ; erc-official-location)
3422 (defun erc-part-reason-zippy (&optional s)
3423 "Zippy part message.
3425 If S is non-nil, it will be used as the quit reason."
3428 (erc-replace-regexp-in-string "\n" "" (yow))
3429 (erc-part-reason-normal))))
3431 (make-obsolete 'erc-part-reason-zippy "it will be removed." "24.4")
3433 (defun erc-part-reason-various (s)
3434 "Choose a part reason based on S (a string)."
3435 (when (featurep 'xemacs) (require 'poe))
3436 (let ((res (car (assoc-default (or s "")
3437 erc-part-reason-various-alist 'string-match))))
3439 ((functionp res) (funcall res))
3442 (t (erc-part-reason-normal)))))
3444 (defun erc-cmd-QUIT (reason)
3445 "Disconnect from the current server.
3446 If REASON is omitted, display a default quit message, otherwise display
3447 the message given by REASON."
3451 ((string-match "^\\s-*\\(.*\\)$" reason)
3452 (let* ((s (match-string 1 reason))
3453 (buffer (erc-server-buffer))
3454 (reason (funcall erc-quit-reason (if (equal s "") nil s)))
3456 (with-current-buffer (if (and buffer
3460 (erc-log (format "cmd: QUIT: %s" reason))
3461 (setq erc-server-quitting t)
3462 (erc-set-active-buffer (erc-server-buffer))
3463 (setq server-proc erc-server-process)
3464 (erc-server-send (format "QUIT :%s" reason)))
3465 (run-hook-with-args 'erc-quit-hook server-proc)
3466 (when erc-kill-queries-on-quit
3467 (erc-kill-query-buffers server-proc))
3468 ;; if the process has not been killed within 4 seconds, kill it
3471 (when (and (processp proc)
3472 (memq (process-status proc) '(run open)))
3473 (delete-process proc)))
3478 (defalias 'erc-cmd-BYE 'erc-cmd-QUIT)
3479 (defalias 'erc-cmd-EXIT 'erc-cmd-QUIT)
3480 (defalias 'erc-cmd-SIGNOFF 'erc-cmd-QUIT)
3481 (put 'erc-cmd-QUIT 'do-not-parse-args t)
3482 (put 'erc-cmd-QUIT 'process-not-needed t)
3484 (defun erc-cmd-GQUIT (reason)
3485 "Disconnect from all servers at once with the same quit REASON."
3486 (erc-with-all-buffers-of-server nil #'erc-open-server-buffer-p
3487 (erc-cmd-QUIT reason))
3488 (when erc-kill-queries-on-quit
3489 ;; if the query buffers have not been killed within 4 seconds,
3494 (dolist (buffer (erc-buffer-list (lambda (buf)
3495 (not (erc-server-buffer-p buf)))))
3496 (kill-buffer buffer)))))
3499 (defalias 'erc-cmd-GQ 'erc-cmd-GQUIT)
3500 (put 'erc-cmd-GQUIT 'do-not-parse-args t)
3501 (put 'erc-cmd-GQUIT 'process-not-needed t)
3503 (defun erc-cmd-RECONNECT ()
3504 "Try to reconnect to the current IRC server."
3505 (let ((buffer (erc-server-buffer))
3507 (unless (buffer-live-p buffer)
3508 (setq buffer (current-buffer)))
3509 (with-current-buffer buffer
3510 (setq erc-server-quitting nil)
3511 (setq erc-server-reconnecting t)
3512 (setq erc-server-reconnect-count 0)
3513 (setq process (get-buffer-process (erc-server-buffer)))
3515 (delete-process process)
3516 (erc-server-reconnect))
3517 (setq erc-server-reconnecting nil)))
3519 (put 'erc-cmd-RECONNECT 'process-not-needed t)
3521 (defun erc-cmd-SERVER (server)
3522 "Connect to SERVER, leaving existing connection intact."
3523 (erc-log (format "cmd: SERVER: %s" server))
3525 (erc :server server :nick (erc-current-nick))
3527 (erc-error "Cannot find host %s." server)))
3529 (put 'erc-cmd-SERVER 'process-not-needed t)
3531 (defvar motif-version-string)
3532 (defvar gtk-version-string)
3534 (defun erc-cmd-SV ()
3535 "Say the current ERC and Emacs version into channel."
3536 (erc-send-message (format "I'm using ERC %s with %s %s (%s%s) of %s."
3538 (if (featurep 'xemacs) "XEmacs" "GNU Emacs")
3540 system-configuration
3542 (cond ((featurep 'motif)
3543 (concat ", " (substring
3544 motif-version-string 4)))
3546 (concat ", GTK+ Version "
3547 gtk-version-string))
3548 ((featurep 'x-toolkit) ", X toolkit")
3550 (if (and (boundp 'x-toolkit-scroll-bars)
3551 (memq x-toolkit-scroll-bars
3553 (format ", %s scroll bars"
3554 (capitalize (symbol-name
3555 x-toolkit-scroll-bars)))
3557 (if (featurep 'multi-tty) ", multi-tty" ""))
3558 erc-emacs-build-time))
3561 (defun erc-cmd-SM ()
3562 "Say the current ERC modes into channel."
3563 (erc-send-message (format "I'm using the following modules: %s!"
3567 (defun erc-cmd-DEOP (&rest people)
3568 "Remove the operator setting from user(s) given in PEOPLE."
3569 (when (> (length people) 0)
3570 (erc-server-send (concat "MODE " (erc-default-target)
3572 (make-string (length people) ?o)
3574 (mapconcat 'identity people " ")))
3577 (defun erc-cmd-OP (&rest people)
3578 "Add the operator setting to users(s) given in PEOPLE."
3579 (when (> (length people) 0)
3580 (erc-server-send (concat "MODE " (erc-default-target)
3582 (make-string (length people) ?o)
3584 (mapconcat 'identity people " ")))
3587 (defun erc-cmd-TIME (&optional line)
3588 "Request the current time and date from the current server."
3590 ((and line (string-match "^\\s-*\\(.*\\)$" line))
3591 (let ((args (match-string 1 line)))
3592 (erc-log (format "cmd: TIME: %s" args))
3593 (erc-server-send (concat "TIME " args)))
3595 (t (erc-server-send "TIME"))))
3596 (defalias 'erc-cmd-DATE 'erc-cmd-TIME)
3598 (defun erc-cmd-TOPIC (topic)
3599 "Set or request the topic for a channel.
3600 LINE has the format: \"#CHANNEL TOPIC\", \"#CHANNEL\", \"TOPIC\"
3601 or the empty string.
3603 If no #CHANNEL is given, the default channel is used. If TOPIC is
3604 given, the channel topic is modified, otherwise the current topic will
3607 ;; /topic #channel TOPIC
3608 ((string-match "^\\s-*\\([&#+!]\\S-+\\)\\s-\\(.*\\)$" topic)
3609 (let ((ch (match-string 1 topic))
3610 (topic (match-string 2 topic)))
3611 (erc-log (format "cmd: TOPIC [%s]: %s" ch topic))
3612 (erc-server-send (format "TOPIC %s :%s" ch topic) nil ch))
3615 ((string-match "^\\s-*\\([&#+!]\\S-+\\)" topic)
3616 (let ((ch (match-string 1 topic)))
3617 (erc-server-send (format "TOPIC %s" ch) nil ch)
3620 ((string-match "^\\s-*$" topic)
3621 (let ((ch (erc-default-target)))
3622 (erc-server-send (format "TOPIC %s" ch) nil ch)
3625 ((string-match "^\\s-*\\(.*\\)$" topic)
3626 (let ((ch (erc-default-target))
3627 (topic (match-string 1 topic)))
3628 (if (and ch (erc-channel-p ch))
3630 (erc-log (format "cmd: TOPIC [%s]: %s" ch topic))
3631 (erc-server-send (format "TOPIC %s :%s" ch topic) nil ch))
3632 (erc-display-message nil 'error (current-buffer) 'no-target)))
3635 (defalias 'erc-cmd-T 'erc-cmd-TOPIC)
3636 (put 'erc-cmd-TOPIC 'do-not-parse-args t)
3638 (defun erc-cmd-APPENDTOPIC (topic)
3639 "Append TOPIC to the current channel topic, separated by a space."
3640 (let ((oldtopic erc-channel-topic))
3641 ;; display help when given no arguments
3642 (when (string-match "^\\s-*$" topic)
3643 (signal 'wrong-number-of-arguments nil))
3644 ;; strip trailing ^O
3645 (when (string-match "\\(.*\\)\C-o" oldtopic)
3646 (erc-cmd-TOPIC (concat (match-string 1 oldtopic) topic)))))
3647 (defalias 'erc-cmd-AT 'erc-cmd-APPENDTOPIC)
3648 (put 'erc-cmd-APPENDTOPIC 'do-not-parse-args t)
3650 (defun erc-cmd-CLEARTOPIC (&optional channel)
3651 "Clear the topic for a CHANNEL.
3652 If CHANNEL is not specified, clear the topic for the default channel."
3653 (interactive "sClear topic of channel (RET is current channel): ")
3654 (let ((chnl (or (and (erc-channel-p channel) channel) (erc-default-target))))
3656 (erc-server-send (format "TOPIC %s :" chnl))
3661 (defvar erc-channel-banlist nil
3662 "A list of bans seen for the current channel.
3664 Each ban is an alist of the form:
3667 The property `received-from-server' indicates whether
3668 or not the ban list has been requested from the server.")
3669 (make-variable-buffer-local 'erc-channel-banlist)
3670 (put 'erc-channel-banlist 'received-from-server nil)
3672 (defun erc-cmd-BANLIST ()
3673 "Pretty-print the contents of `erc-channel-banlist'.
3675 The ban list is fetched from the server if necessary."
3676 (let ((chnl (erc-default-target))
3677 (chnl-name (buffer-name)))
3680 ((not (erc-channel-p chnl))
3681 (erc-display-line (erc-make-notice "You're not on a channel\n")
3684 ((not (get 'erc-channel-banlist 'received-from-server))
3685 (let ((old-367-hook erc-server-367-functions))
3686 (setq erc-server-367-functions 'erc-banlist-store
3687 erc-channel-banlist nil)
3688 ;; fetch the ban list then callback
3689 (erc-with-server-buffer
3690 (erc-once-with-server-event
3692 (lambda (_proc _parsed)
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 (lambda (_proc _parsed)
3764 (with-current-buffer chnl
3765 (put 'erc-channel-banlist 'received-from-server t)
3766 (setq erc-server-367-functions old-367-hook)
3769 (erc-server-send (format "MODE %s b" chnl)))))
3771 (t (let ((bans (mapcar 'cdr erc-channel-banlist)))
3773 ;; Glob the bans into groups of three, and carry out the unban.
3774 ;; eg. /mode #foo -bbb a*!*@* b*!*@* c*!*@*
3778 (format "MODE %s -%s %s" (erc-default-target)
3779 (make-string (length x) ?b)
3780 (mapconcat 'identity x " "))))
3781 (erc-group-list bans 3))))
3784 (defalias 'erc-cmd-MUB 'erc-cmd-MASSUNBAN)
3786 ;;;; End of IRC commands
3788 (defun erc-ensure-channel-name (channel)
3789 "Return CHANNEL if it is a valid channel name.
3790 Eventually add a # in front of it, if that turns it into a valid channel name."
3791 (if (erc-channel-p channel)
3793 (concat "#" channel)))
3795 (defun erc-grab-region (start end)
3796 "Copy the region between START and END in a recreatable format.
3798 Converts all the IRC text properties in each line of the region
3799 into control codes and writes them to a separate buffer. The
3800 resulting text may be used directly as a script to generate this
3803 (erc-set-active-buffer (current-buffer))
3805 (let* ((cb (current-buffer))
3806 (buf (generate-new-buffer erc-grab-buffer-name))
3807 (region (buffer-substring start end))
3808 (lines (erc-split-multiline-safe region)))
3810 (dolist (line lines)
3811 (insert (concat line "\n")))
3813 (switch-to-buffer-other-window buf)))
3814 (message "erc-grab-region doesn't grab colors etc. anymore. If you use this, please tell the maintainers.")
3817 (defun erc-display-prompt (&optional buffer pos prompt face)
3818 "Display PROMPT in BUFFER at position POS.
3819 Display an ERC prompt in BUFFER.
3821 If PROMPT is nil, one is constructed with the function `erc-prompt'.
3822 If BUFFER is nil, the `current-buffer' is used.
3823 If POS is nil, PROMPT will be displayed at `point'.
3824 If FACE is non-nil, it will be used to propertize the prompt. If it is nil,
3825 `erc-prompt-face' will be used."
3826 (let* ((prompt (or prompt (erc-prompt)))
3828 (ob (current-buffer)))
3829 ;; We cannot use save-excursion because we move point, therefore
3830 ;; we resort to the ol' ob trick to restore this.
3831 (when (and buffer (bufferp buffer))
3832 (set-buffer buffer))
3834 ;; now save excursion again to store where point and mark are
3835 ;; in the current buffer
3837 (setq pos (or pos (point)))
3840 ;; Do not extend the text properties when typing at the end
3841 ;; of the prompt, but stuff typed in front of the prompt
3842 ;; shall remain part of the prompt.
3843 (setq prompt (erc-propertize prompt
3844 'start-open t ; XEmacs
3845 'rear-nonsticky t ; Emacs
3850 (erc-put-text-property 0 (1- (length prompt))
3851 'face (or face 'erc-prompt-face)
3854 ;; Set the input marker
3855 (set-marker erc-input-marker (point)))
3857 ;; Now we are back at the old position. If the prompt was
3858 ;; inserted here or before us, advance point by the length of
3860 (when (or (not pos) (<= (point) pos))
3862 ;; Clear the undo buffer now, so the user can undo his stuff,
3863 ;; but not the stuff we did. Sneaky!
3864 (setq buffer-undo-list nil)
3867 ;; interactive operations
3869 (defun erc-input-message ()
3870 "Read input from the minibuffer."
3872 (let ((minibuffer-allow-text-properties t)
3873 (read-map minibuffer-local-map))
3874 (insert (read-from-minibuffer "Message: "
3875 (string (if (featurep 'xemacs)
3877 last-command-event)) read-map))
3878 (erc-send-current-line)))
3880 (defvar erc-action-history-list ()
3881 "History list for interactive action input.")
3883 (defun erc-input-action ()
3884 "Interactively input a user action and send it to IRC."
3886 (erc-set-active-buffer (current-buffer))
3887 (let ((action (read-from-minibuffer
3888 "Action: " nil nil nil 'erc-action-history-list)))
3889 (if (not (string-match "^\\s-*$" action))
3890 (erc-send-action (erc-default-target) action))))
3892 (defun erc-join-channel (channel &optional key)
3895 If `point' is at the beginning of a channel name, use that as default."
3898 (let ((chnl (if (looking-at "\\([&#+!][^ \n]+\\)") (match-string 1) ""))
3899 (table (when (erc-server-buffer-live-p)
3900 (set-buffer (process-buffer erc-server-process))
3902 (completing-read "Join channel: " table nil nil nil nil chnl))
3903 (when (or current-prefix-arg erc-prompt-for-channel-key)
3904 (read-from-minibuffer "Channel key (RET for none): " nil))))
3905 (erc-cmd-JOIN channel (when (>= (length key) 1) key)))
3907 (defun erc-part-from-channel (reason)
3908 "Part from the current channel and prompt for a REASON."
3911 (if (and (boundp 'reason) (stringp reason) (not (string= reason "")))
3913 (read-from-minibuffer (concat "Reason for leaving " (erc-default-target)
3915 (erc-cmd-PART (concat (erc-default-target)" " reason)))
3917 (defun erc-set-topic (topic)
3918 "Prompt for a TOPIC for the current channel."
3921 (read-from-minibuffer
3922 (concat "Set topic of " (erc-default-target) ": ")
3923 (when erc-channel-topic
3924 (let ((ss (split-string erc-channel-topic "\C-o")))
3925 (cons (apply 'concat (if (cdr ss) (butlast ss) ss))
3927 (let ((topic-list (split-string topic "\C-o"))) ; strip off the topic setter
3928 (erc-cmd-TOPIC (concat (erc-default-target) " " (car topic-list)))))
3930 (defun erc-set-channel-limit (&optional limit)
3931 "Set a LIMIT for the current channel. Remove limit if nil.
3932 Prompt for one if called interactively."
3933 (interactive (list (read-from-minibuffer
3934 (format "Limit for %s (RET to remove limit): "
3935 (erc-default-target)))))
3936 (let ((tgt (erc-default-target)))
3937 (erc-server-send (if (and limit (>= (length limit) 1))
3938 (format "MODE %s +l %s" tgt limit)
3939 (format "MODE %s -l" tgt)))))
3941 (defun erc-set-channel-key (&optional key)
3942 "Set a KEY for the current channel. Remove key if nil.
3943 Prompt for one if called interactively."
3944 (interactive (list (read-from-minibuffer
3945 (format "Key for %s (RET to remove key): "
3946 (erc-default-target)))))
3947 (let ((tgt (erc-default-target)))
3948 (erc-server-send (if (and key (>= (length key) 1))
3949 (format "MODE %s +k %s" tgt key)
3950 (format "MODE %s -k" tgt)))))
3952 (defun erc-quit-server (reason)
3953 "Disconnect from current server after prompting for REASON.
3954 `erc-quit-reason' works with this just like with `erc-cmd-QUIT'."
3955 (interactive (list (read-from-minibuffer
3956 (format "Reason for quitting %s: "
3957 (or erc-server-announced-name
3958 erc-session-server)))))
3959 (erc-cmd-QUIT reason))
3961 ;; Movement of point
3964 "Move `point' to the beginning of the current line.
3966 This places `point' just after the prompt, or at the beginning of the line."
3969 (when (get-text-property (point) 'erc-prompt)
3970 (goto-char erc-input-marker))
3973 (defun erc-kill-input ()
3974 "Kill current input line using `erc-bol' followed by `kill-line'."
3976 (when (and (erc-bol)
3977 (/= (point) (point-max))) ;; Prevent a (ding) and an error when
3978 ;; there's nothing to kill
3979 (if (boundp 'erc-input-ring-index)
3980 (setq erc-input-ring-index nil))
3983 (defun erc-complete-word-at-point ()
3984 (run-hook-with-args-until-success 'erc-complete-functions))
3986 (define-obsolete-function-alias 'erc-complete-word 'completion-at-point "24.1")
3988 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3990 ;; IRC SERVER INPUT HANDLING
3992 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3994 ;;;; New Input parsing
3996 ; Stolen from ZenIRC. I just wanna test this code, so here is
3999 (defcustom erc-default-server-hook '(erc-debug-missing-hooks
4000 erc-default-server-handler)
4001 "Default for server messages which aren't covered by `erc-server-hooks'."
4002 :group 'erc-server-hooks
4005 (defun erc-default-server-handler (proc parsed)
4006 "Default server handler.
4008 Displays PROC and PARSED appropriately using `erc-display-message'."
4009 (erc-display-message
4016 (setq res (append res (list x)))))
4021 (defvar erc-server-vectors
4022 '(["msgtype" "sender" "to" "arg1" "arg2" "arg3" "..."])
4023 "List of received server messages which ERC does not specifically handle.
4024 See `erc-debug-missing-hooks'.")
4025 ;(make-variable-buffer-local 'erc-server-vectors)
4027 (defun erc-debug-missing-hooks (_proc parsed)
4028 "Add PARSED server message ERC does not yet handle to `erc-server-vectors'.
4029 These vectors can be helpful when adding new server message handlers to ERC.
4030 See `erc-default-server-hook'."
4031 (nconc erc-server-vectors (list parsed))
4034 (defun erc-query (target server)
4035 "Open a query buffer on TARGET, using SERVER.
4036 To change how this query window is displayed, use `let' to bind
4037 `erc-join-buffer' before calling this."
4039 (buffer-live-p server)
4040 (set-buffer server))
4041 (error "Couldn't switch to server buffer"))
4042 (let ((buf (erc-open erc-session-server
4045 erc-session-user-full-name
4050 erc-server-process)))
4052 (error "Couldn't open query window"))
4053 (erc-update-mode-line)
4056 (defcustom erc-auto-query 'window-noselect
4057 "If non-nil, create a query buffer each time you receive a private message.
4058 If the buffer doesn't already exist, it is created.
4060 This can be set to a symbol, to control how the new query window
4061 should appear. The default behavior is to display the buffer in
4062 a new window, but not to select it. See the documentation for
4063 `erc-join-buffer' for a description of the available choices."
4065 :type '(choice (const :tag "Don't create query window" nil)
4066 (const :tag "Split window and select" window)
4067 (const :tag "Split window, don't select" window-noselect)
4068 (const :tag "New frame" frame)
4069 (const :tag "Bury in new buffer" bury)
4070 (const :tag "Use current buffer" buffer)
4071 (const :tag "Use current buffer" t)))
4073 (defcustom erc-query-on-unjoined-chan-privmsg t
4074 "If non-nil create query buffer on receiving any PRIVMSG at all.
4075 This includes PRIVMSGs directed to channels. If you are using an IRC
4076 bouncer, such as dircproxy, to keep a log of channels when you are
4077 disconnected, you should set this option to t."
4081 (defcustom erc-format-query-as-channel-p t
4082 "If non-nil, format text from others in a query buffer like in a channel,
4083 otherwise format like a private message."
4087 (defcustom erc-minibuffer-notice nil
4088 "If non-nil, print ERC notices for the user in the minibuffer.
4089 Only happens when the session buffer isn't visible."
4093 (defcustom erc-minibuffer-ignored nil
4094 "If non-nil, print a message in the minibuffer if we ignored something."
4098 (defun erc-wash-quit-reason (reason nick login host)
4099 "Remove duplicate text from quit REASON.
4100 Specifically in relation to NICK (user@host) information. Returns REASON
4101 unmodified if nothing can be removed.
4102 E.g. \"Read error to Nick [user@some.host]: 110\" would be shortened to
4103 \"Read error: 110\". The same applies for \"Ping Timeout\"."
4104 (setq nick (regexp-quote nick)
4105 login (regexp-quote login)
4106 host (regexp-quote host))
4107 (or (when (string-match (concat "^\\(Read error\\) to "
4108 nick "\\[" host "\\]: "
4109 "\\(.+\\)$") reason)
4110 (concat (match-string 1 reason) ": " (match-string 2 reason)))
4111 (when (string-match (concat "^\\(Ping timeout\\) for "
4112 nick "\\[" host "\\]$") reason)
4113 (match-string 1 reason))
4116 (defun erc-nickname-in-use (nick reason)
4117 "If NICK is unavailable, tell the user the REASON.
4119 See also `erc-display-error-notice'."
4120 (if (or (not erc-try-new-nick-p)
4121 ;; how many default-nicks are left + one more try...
4122 (eq erc-nick-change-attempt-count
4123 (if (consp erc-nick)
4124 (+ (length erc-nick) 1)
4126 (erc-display-error-notice
4128 (format "Nickname %s is %s, try another." nick reason))
4129 (setq erc-nick-change-attempt-count (+ erc-nick-change-attempt-count 1))
4130 (let ((newnick (nth 1 erc-default-nicks))
4131 (nicklen (cdr (assoc "NICKLEN"
4132 (erc-with-server-buffer
4133 erc-server-parameters)))))
4134 (setq erc-bad-nick t)
4135 ;; try to use a different nick
4136 (if erc-default-nicks
4137 (setq erc-default-nicks (cdr erc-default-nicks)))
4139 (setq newnick (concat (truncate-string-to-width
4141 (if (and erc-server-connected nicklen)
4142 (- (string-to-number nicklen)
4143 (length erc-nick-uniquifier))
4144 ;; rfc2812 max nick length = 9
4145 ;; we must assume this is the
4146 ;; server's setting if we haven't
4147 ;; established a connection yet
4148 (- 9 (length erc-nick-uniquifier))))
4149 erc-nick-uniquifier)))
4150 (erc-cmd-NICK newnick)
4151 (erc-display-error-notice
4153 (format "Nickname %s is %s, trying %s"
4154 nick reason newnick)))))
4158 (defgroup erc-server-hooks nil
4159 "Server event callbacks.
4160 Every server event - like numeric replies - has its own hook.
4161 Those hooks are all called using `run-hook-with-args-until-success'.
4162 They receive as first argument the process object from where the event
4164 and as second argument the event parsed as a vector."
4167 (defun erc-display-server-message (_proc parsed)
4168 "Display the message sent by the server as a notice."
4169 (erc-display-message
4170 parsed 'notice 'active (erc-response.contents parsed)))
4172 (defun erc-auto-query (proc parsed)
4173 ;; FIXME: This needs more documentation, unless it's not a user function --
4174 ;; Lawrence 2004-01-08
4175 "Put this on `erc-server-PRIVMSG-functions'."
4176 (when erc-auto-query
4177 (let* ((nick (car (erc-parse-user (erc-response.sender parsed))))
4178 (target (car (erc-response.command-args parsed)))
4179 (msg (erc-response.contents parsed))
4180 (query (if (not erc-query-on-unjoined-chan-privmsg)
4182 (if (erc-current-nick-p target)
4185 (and (not (erc-ignored-user-p (erc-response.sender parsed)))
4186 (or erc-query-on-unjoined-chan-privmsg
4187 (string= target (erc-current-nick)))
4188 (not (erc-get-buffer query proc))
4189 (not (erc-is-message-ctcp-and-not-action-p msg))
4190 (let ((erc-query-display erc-auto-query))
4191 (erc-cmd-QUERY query))
4194 (defun erc-is-message-ctcp-p (message)
4195 "Check if MESSAGE is a CTCP message or not."
4196 (string-match "^\C-a\\([^\C-a]*\\)\C-a?$" message))
4198 (defun erc-is-message-ctcp-and-not-action-p (message)
4199 "Check if MESSAGE is a CTCP message or not."
4200 (and (erc-is-message-ctcp-p message)
4201 (not (string-match "^\C-a\\ACTION.*\C-a$" message))))
4203 (defun erc-format-privmessage (nick msg privp msgp)
4204 "Format a PRIVMSG in an insertable fashion."
4205 (let* ((mark-s (if msgp (if privp "*" "<") "-"))
4206 (mark-e (if msgp (if privp "*" ">") "-"))
4207 (str (format "%s%s%s %s" mark-s nick mark-e msg))
4208 (nick-face (if privp 'erc-nick-msg-face 'erc-nick-default-face))
4209 (msg-face (if privp 'erc-direct-msg-face 'erc-default-face)))
4210 ;; add text properties to text before the nick, the nick and after the nick
4211 (erc-put-text-property 0 (length mark-s) 'face msg-face str)
4212 (erc-put-text-property (length mark-s) (+ (length mark-s) (length nick))
4213 'face nick-face str)
4214 (erc-put-text-property (+ (length mark-s) (length nick)) (length str)
4218 (defcustom erc-format-nick-function 'erc-format-nick
4219 "Function to format a nickname for message display."
4223 (defun erc-format-nick (&optional user _channel-data)
4224 "Return the nickname of USER.
4225 See also `erc-format-nick-function'."
4226 (let ((nick (erc-server-user-nickname user)))
4227 (concat (erc-propertize
4228 (erc-get-user-mode-prefix nick)
4229 'face 'erc-nick-prefix-face) nick)))
4231 (defun erc-get-user-mode-prefix (user)
4233 (cond ((erc-channel-user-owner-p user)
4234 (erc-propertize "~" 'help-echo "owner"))
4235 ((erc-channel-user-admin-p user)
4236 (erc-propertize "&" 'help-echo "admin"))
4237 ((erc-channel-user-op-p user)
4238 (erc-propertize "@" 'help-echo "operator"))
4239 ((erc-channel-user-halfop-p user)
4240 (erc-propertize "%" 'help-echo "half-op"))
4241 ((erc-channel-user-voice-p user)
4242 (erc-propertize "+" 'help-echo "voice"))
4245 (defun erc-format-@nick (&optional user channel-data)
4246 "Format the nickname of USER showing if USER has a voice, is an
4247 operator, half-op, admin or owner. Owners have \"~\", admins have
4248 \"&\", operators have \"@\" and users with voice have \"+\" as a
4249 prefix. Use CHANNEL-DATA to determine op and voice status. See
4250 also `erc-format-nick-function'."
4252 (let ((nick (erc-server-user-nickname user)))
4253 (concat (erc-propertize
4254 (erc-get-user-mode-prefix nick)
4255 'face 'erc-nick-prefix-face) nick nick))))
4257 (defun erc-format-my-nick ()
4258 "Return the beginning of this user's message, correctly propertized."
4259 (if erc-show-my-nick
4262 (nick (erc-current-nick))
4263 (mode (erc-get-user-mode-prefix nick)))
4265 (erc-propertize open 'face 'erc-default-face)
4266 (erc-propertize mode 'face 'erc-my-nick-prefix-face)
4267 (erc-propertize nick 'face 'erc-my-nick-face)
4268 (erc-propertize close 'face 'erc-default-face)))
4269 (let ((prefix "> "))
4270 (erc-propertize prefix 'face 'erc-default-face))))
4272 (defun erc-echo-notice-in-default-buffer (s parsed buffer _sender)
4273 "Echos a private notice in the default buffer, namely the
4274 target buffer specified by BUFFER, or there is no target buffer,
4275 the server buffer. This function is designed to be added to
4276 either `erc-echo-notice-hook' or `erc-echo-notice-always-hook',
4277 and always returns t."
4278 (erc-display-message parsed nil buffer s)
4281 (defun erc-echo-notice-in-target-buffer (s parsed buffer _sender)
4282 "Echos a private notice in BUFFER, if BUFFER is non-nil. This
4283 function is designed to be added to either `erc-echo-notice-hook'
4284 or `erc-echo-notice-always-hook', and returns non-nil if BUFFER
4287 (progn (erc-display-message parsed nil buffer s) t)
4290 (defun erc-echo-notice-in-minibuffer (s _parsed _buffer _sender)
4291 "Echos a private notice in the minibuffer. This function is
4292 designed to be added to either `erc-echo-notice-hook' or
4293 `erc-echo-notice-always-hook', and always returns t."
4294 (message "%s" (concat "NOTICE: " s))
4297 (defun erc-echo-notice-in-server-buffer (s parsed _buffer _sender)
4298 "Echos a private notice in the server buffer. This function is
4299 designed to be added to either `erc-echo-notice-hook' or
4300 `erc-echo-notice-always-hook', and always returns t."
4301 (erc-display-message parsed nil nil s)
4304 (defun erc-echo-notice-in-active-non-server-buffer (s parsed _buffer _sender)
4305 "Echos a private notice in the active buffer if the active
4306 buffer is not the server buffer. This function is designed to be
4307 added to either `erc-echo-notice-hook' or
4308 `erc-echo-notice-always-hook', and returns non-nil if the active
4309 buffer is not the server buffer."
4310 (if (not (eq (erc-server-buffer) (erc-active-buffer)))
4311 (progn (erc-display-message parsed nil 'active s) t)
4314 (defun erc-echo-notice-in-active-buffer (s parsed _buffer _sender)
4315 "Echos a private notice in the active buffer. This function is
4316 designed to be added to either `erc-echo-notice-hook' or
4317 `erc-echo-notice-always-hook', and always returns t."
4318 (erc-display-message parsed nil 'active s)
4321 (defun erc-echo-notice-in-user-buffers (s parsed _buffer sender)
4322 "Echos a private notice in all of the buffers for which SENDER
4323 is a member. This function is designed to be added to either
4324 `erc-echo-notice-hook' or `erc-echo-notice-always-hook', and
4325 returns non-nil if there is at least one buffer for which the
4328 See also: `erc-echo-notice-in-first-user-buffer',
4329 `erc-buffer-list-with-nick'."
4330 (let ((buffers (erc-buffer-list-with-nick sender erc-server-process)))
4332 (progn (erc-display-message parsed nil buffers s) t)
4335 (defun erc-echo-notice-in-user-and-target-buffers (s parsed buffer sender)
4336 "Echos a private notice in BUFFER and in all of the buffers for
4337 which SENDER is a member. This function is designed to be added
4338 to either `erc-echo-notice-hook' or
4339 `erc-echo-notice-always-hook', and returns non-nil if there is
4340 at least one buffer for which the sender is a member or the
4343 See also: `erc-echo-notice-in-user-buffers',
4344 `erc-buffer-list-with-nick'."
4345 (let ((buffers (erc-buffer-list-with-nick sender erc-server-process)))
4346 (unless (memq buffer buffers) (push buffer buffers))
4347 (if buffers ;FIXME: How could it be nil?
4348 (progn (erc-display-message parsed nil buffers s) t)
4351 (defun erc-echo-notice-in-first-user-buffer (s parsed _buffer sender)
4352 "Echos a private notice in one of the buffers for which SENDER
4353 is a member. This function is designed to be added to either
4354 `erc-echo-notice-hook' or `erc-echo-notice-always-hook', and
4355 returns non-nil if there is at least one buffer for which the
4358 See also: `erc-echo-notice-in-user-buffers',
4359 `erc-buffer-list-with-nick'."
4360 (let ((buffers (erc-buffer-list-with-nick sender erc-server-process)))
4362 (progn (erc-display-message parsed nil (car buffers) s) t)
4365 ;;; Ban manipulation
4367 (defun erc-banlist-store (proc parsed)
4368 "Record ban entries for a channel."
4369 (pcase-let ((`(,channel ,mask ,whoset)
4370 (cdr (erc-response.command-args parsed))))
4371 ;; Determine to which buffer the message corresponds
4372 (let ((buffer (erc-get-buffer channel proc)))
4373 (with-current-buffer buffer
4374 (unless (member (cons whoset mask) erc-channel-banlist)
4375 (setq erc-channel-banlist (cons (cons whoset mask)
4376 erc-channel-banlist))))))
4379 (defun erc-banlist-finished (proc parsed)
4380 "Record that we have received the banlist."
4381 (let* ((channel (nth 1 (erc-response.command-args parsed)))
4382 (buffer (erc-get-buffer channel proc)))
4383 (with-current-buffer buffer
4384 (put 'erc-channel-banlist 'received-from-server t)))
4385 t) ; suppress the 'end of banlist' message
4387 (defun erc-banlist-update (proc parsed)
4388 "Check MODE commands for bans and update the banlist appropriately."
4389 ;; FIXME: Possibly incorrect. -- Lawrence 2004-05-11
4390 (let* ((tgt (car (erc-response.command-args parsed)))
4391 (mode (erc-response.contents parsed))
4392 (whoset (erc-response.sender parsed))
4393 (buffer (erc-get-buffer tgt proc)))
4395 (with-current-buffer buffer
4396 (cond ((not (get 'erc-channel-banlist 'received-from-server)) nil)
4397 ((string-match "^\\([+-]\\)b" mode)
4400 ((string-match "^-" mode)
4401 ;; Remove the unbanned masks from the ban list
4402 (setq erc-channel-banlist
4405 (member (upcase (cdr y))
4407 (cdr (split-string mode)))))
4408 erc-channel-banlist)))
4409 ((string-match "^+" mode)
4410 ;; Add the banned mask(s) to the ban list
4413 (unless (member (cons whoset mask) erc-channel-banlist)
4414 (setq erc-channel-banlist
4415 (cons (cons whoset mask) erc-channel-banlist))))
4416 (cdr (split-string mode))))))))))
4419 ;; used for the banlist cmds
4420 (defun erc-group-list (list n)
4421 "Group LIST into sublists of length N."
4422 (cond ((null list) nil)
4423 ((null (nthcdr n list)) (list list))
4424 (t (cons (erc-subseq list 0 n) (erc-group-list (nthcdr n list) n)))))
4429 (defun erc-handle-login ()
4430 "Handle the logging in process of connection."
4431 (unless erc-logged-in
4432 (setq erc-logged-in t)
4433 (message "Logging in as \'%s\'... done" (erc-current-nick))
4434 ;; execute a startup script
4435 (let ((f (erc-select-startup-file)))
4437 (erc-load-script f)))))
4439 (defun erc-connection-established (proc parsed)
4440 "Run just after connection.
4442 Set user modes and run `erc-after-connect' hook."
4443 (with-current-buffer (process-buffer proc)
4444 (unless erc-server-connected ; only once per session
4445 (let ((server (or erc-server-announced-name
4446 (erc-response.sender parsed)))
4447 (nick (car (erc-response.command-args parsed)))
4448 (buffer (process-buffer proc)))
4449 (setq erc-server-connected t)
4450 (erc-update-mode-line)
4451 (erc-set-initial-user-mode nick buffer)
4452 (erc-server-setup-periodical-ping buffer)
4453 (run-hook-with-args 'erc-after-connect server nick)))))
4455 (defun erc-set-initial-user-mode (nick buffer)
4456 "If `erc-user-mode' is non-nil for NICK, set the user modes.
4457 The server buffer is given by BUFFER."
4458 (with-current-buffer buffer
4460 (let ((mode (if (functionp erc-user-mode)
4461 (funcall erc-user-mode)
4463 (when (stringp mode)
4464 (erc-log (format "changing mode for %s to %s" nick mode))
4465 (erc-server-send (format "MODE %s %s" nick mode)))))))
4467 (defun erc-display-error-notice (parsed string)
4468 "Display STRING as an error notice.
4470 See also `erc-display-message'."
4471 (erc-display-message
4472 parsed '(notice error) 'active string))
4474 (defun erc-process-ctcp-query (proc parsed nick login host)
4475 ;; FIXME: This needs a proper docstring -- Lawrence 2004-01-08
4476 "Process a CTCP query."
4477 (let ((queries (delete "" (split-string (erc-response.contents parsed)
4479 (if (> (length queries) 4)
4480 (erc-display-message
4481 parsed (list 'notice 'error) proc 'ctcp-too-many)
4482 (if (= 0 (length queries))
4483 (erc-display-message
4484 parsed (list 'notice 'error) proc
4485 'ctcp-empty ?n nick)
4487 (let* ((type (upcase (car (split-string (car queries)))))
4488 (hook (intern-soft (concat "erc-ctcp-query-" type "-hook"))))
4489 (if (and hook (boundp hook))
4490 (if (string-equal type "ACTION")
4491 (run-hook-with-args-until-success
4492 hook proc parsed nick login host
4493 (car (erc-response.command-args parsed))
4496 (if (erc-current-nick-p
4497 (car (erc-response.command-args parsed)))
4498 (erc-display-message
4499 parsed 'error 'active 'ctcp-request
4500 ?n nick ?u login ?h host ?r (car queries))
4501 (erc-display-message
4502 parsed 'error 'active 'ctcp-request-to
4503 ?n nick ?u login ?h host ?r (car queries)
4504 ?t (car (erc-response.command-args parsed)))))
4505 (run-hook-with-args-until-success
4506 hook proc nick login host
4507 (car (erc-response.command-args parsed))
4509 (erc-display-message
4510 parsed (list 'notice 'error) proc
4512 (setq queries (cdr queries)))))))
4514 (defvar erc-ctcp-query-ACTION-hook '(erc-ctcp-query-ACTION))
4516 (defun erc-ctcp-query-ACTION (proc parsed nick login host to msg)
4517 "Respond to a CTCP ACTION query."
4518 (when (string-match "^ACTION\\s-\\(.*\\)\\s-*$" msg)
4519 (let ((s (match-string 1 msg))
4520 (buf (or (erc-get-buffer to proc)
4521 (erc-get-buffer nick proc)
4522 (process-buffer proc))))
4523 (erc-display-message
4525 'ACTION ?n nick ?u login ?h host ?a s))))
4527 (defvar erc-ctcp-query-CLIENTINFO-hook '(erc-ctcp-query-CLIENTINFO))
4529 (defun erc-ctcp-query-CLIENTINFO (_proc nick _login _host _to msg)
4530 "Respond to a CTCP CLIENTINFO query."
4531 (when (string-match "^CLIENTINFO\\(\\s-*\\|\\s-+.*\\)$" msg)
4532 (let ((s (erc-client-info (erc-trim-string (match-string 1 msg)))))
4533 (unless erc-disable-ctcp-replies
4534 (erc-send-ctcp-notice nick (format "CLIENTINFO %s" s)))))
4537 (defvar erc-ctcp-query-ECHO-hook '(erc-ctcp-query-ECHO))
4538 (defun erc-ctcp-query-ECHO (_proc nick _login _host _to msg)
4539 "Respond to a CTCP ECHO query."
4540 (when (string-match "^ECHO\\s-+\\(.*\\)\\s-*$" msg)
4541 (let ((s (match-string 1 msg)))
4542 (unless erc-disable-ctcp-replies
4543 (erc-send-ctcp-notice nick (format "ECHO %s" s)))))
4546 (defvar erc-ctcp-query-FINGER-hook '(erc-ctcp-query-FINGER))
4547 (defun erc-ctcp-query-FINGER (_proc nick _login _host _to _msg)
4548 "Respond to a CTCP FINGER query."
4549 (unless erc-disable-ctcp-replies
4550 (let ((s (if erc-anonymous-login
4551 (format "FINGER I'm %s." (erc-current-nick))
4552 (format "FINGER %s (%s@%s)."
4556 (ns (erc-time-diff erc-server-last-sent-time (erc-current-time))))
4558 (setq s (concat s " Idle for " (erc-sec-to-time ns))))
4559 (erc-send-ctcp-notice nick s)))
4562 (defvar erc-ctcp-query-PING-hook '(erc-ctcp-query-PING))
4563 (defun erc-ctcp-query-PING (_proc nick _login _host _to msg)
4564 "Respond to a CTCP PING query."
4565 (when (string-match "^PING\\s-+\\(.*\\)" msg)
4566 (unless erc-disable-ctcp-replies
4567 (let ((arg (match-string 1 msg)))
4568 (erc-send-ctcp-notice nick (format "PING %s" arg)))))
4571 (defvar erc-ctcp-query-TIME-hook '(erc-ctcp-query-TIME))
4572 (defun erc-ctcp-query-TIME (_proc nick _login _host _to _msg)
4573 "Respond to a CTCP TIME query."
4574 (unless erc-disable-ctcp-replies
4575 (erc-send-ctcp-notice nick (format "TIME %s" (current-time-string))))
4578 (defvar erc-ctcp-query-USERINFO-hook '(erc-ctcp-query-USERINFO))
4579 (defun erc-ctcp-query-USERINFO (_proc nick _login _host _to _msg)
4580 "Respond to a CTCP USERINFO query."
4581 (unless erc-disable-ctcp-replies
4582 (erc-send-ctcp-notice nick (format "USERINFO %s" erc-user-information)))
4585 (defvar erc-ctcp-query-VERSION-hook '(erc-ctcp-query-VERSION))
4586 (defun erc-ctcp-query-VERSION (_proc nick _login _host _to _msg)
4587 "Respond to a CTCP VERSION query."
4588 (unless erc-disable-ctcp-replies
4589 (erc-send-ctcp-notice
4591 "VERSION \C-bERC\C-b %s - an IRC client for emacs (\C-b%s\C-b)"
4593 erc-official-location)))
4596 (defun erc-process-ctcp-reply (proc parsed nick login host msg)
4597 "Process MSG as a CTCP reply."
4598 (let* ((type (car (split-string msg)))
4599 (hook (intern (concat "erc-ctcp-reply-" type "-hook"))))
4601 (run-hook-with-args-until-success
4602 hook proc nick login host
4603 (car (erc-response.command-args parsed)) msg)
4604 (erc-display-message
4605 parsed 'notice 'active
4606 'CTCP-UNKNOWN ?n nick ?u login ?h host ?m msg))))
4608 (defvar erc-ctcp-reply-ECHO-hook '(erc-ctcp-reply-ECHO))
4609 (defun erc-ctcp-reply-ECHO (_proc nick _login _host _to msg)
4610 "Handle a CTCP ECHO reply."
4611 (when (string-match "^ECHO\\s-+\\(.*\\)\\s-*$" msg)
4612 (let ((message (match-string 1 msg)))
4613 (erc-display-message
4614 nil '(notice action) 'active
4615 'CTCP-ECHO ?n nick ?m message)))
4618 (defvar erc-ctcp-reply-CLIENTINFO-hook '(erc-ctcp-reply-CLIENTINFO))
4619 (defun erc-ctcp-reply-CLIENTINFO (_proc nick _login _host _to msg)
4620 "Handle a CTCP CLIENTINFO reply."
4621 (when (string-match "^CLIENTINFO\\s-+\\(.*\\)\\s-*$" msg)
4622 (let ((message (match-string 1 msg)))
4623 (erc-display-message
4625 'CTCP-CLIENTINFO ?n nick ?m message)))
4628 (defvar erc-ctcp-reply-FINGER-hook '(erc-ctcp-reply-FINGER))
4629 (defun erc-ctcp-reply-FINGER (_proc nick _login _host _to msg)
4630 "Handle a CTCP FINGER reply."
4631 (when (string-match "^FINGER\\s-+\\(.*\\)\\s-*$" msg)
4632 (let ((message (match-string 1 msg)))
4633 (erc-display-message
4635 'CTCP-FINGER ?n nick ?m message)))
4638 (defvar erc-ctcp-reply-PING-hook '(erc-ctcp-reply-PING))
4639 (defun erc-ctcp-reply-PING (_proc nick _login _host _to msg)
4640 "Handle a CTCP PING reply."
4641 (if (not (string-match "^PING\\s-+\\([0-9.]+\\)" msg))
4643 (let ((time (match-string 1 msg)))
4645 (let ((delta (erc-time-diff (string-to-number time)
4646 (erc-current-time))))
4647 (erc-display-message
4650 ?t (erc-sec-to-time delta)))
4652 (erc-display-message
4654 'bad-ping-response ?n nick ?t time))))))
4656 (defvar erc-ctcp-reply-TIME-hook '(erc-ctcp-reply-TIME))
4657 (defun erc-ctcp-reply-TIME (_proc nick _login _host _to msg)
4658 "Handle a CTCP TIME reply."
4659 (when (string-match "^TIME\\s-+\\(.*\\)\\s-*$" msg)
4660 (let ((message (match-string 1 msg)))
4661 (erc-display-message
4663 'CTCP-TIME ?n nick ?m message)))
4666 (defvar erc-ctcp-reply-VERSION-hook '(erc-ctcp-reply-VERSION))
4667 (defun erc-ctcp-reply-VERSION (_proc nick _login _host _to msg)
4668 "Handle a CTCP VERSION reply."
4669 (when (string-match "^VERSION\\s-+\\(.*\\)\\s-*$" msg)
4670 (let ((message (match-string 1 msg)))
4671 (erc-display-message
4673 'CTCP-VERSION ?n nick ?m message)))
4676 (defun erc-process-away (proc away-p)
4677 "Toggle the away status of the user depending on the value of AWAY-P.
4679 If nil, set the user as away.
4680 If non-nil, return from being away."
4681 (let ((sessionbuf (process-buffer proc)))
4683 (with-current-buffer sessionbuf
4684 (when erc-away-nickname
4685 (erc-log (format "erc-process-away: away-nick: %s, away-p: %s"
4686 erc-away-nickname away-p))
4687 (erc-cmd-NICK (if away-p
4692 (setq erc-away (current-time)))
4694 (let ((away-time erc-away))
4695 ;; away must be set to NIL BEFORE sending anything to prevent
4696 ;; an infinite recursion
4698 (with-current-buffer (erc-active-buffer)
4699 (when erc-public-away-p
4701 (erc-default-target)
4703 (format "is back (gone for %s)"
4706 (erc-emacs-time-to-erc-time away-time)
4707 (erc-current-time))))
4709 (erc-update-mode-line)))
4711 ;;;; List of channel members handling
4713 (defun erc-channel-begin-receiving-names ()
4716 Used when a channel names list is about to be received. Should
4717 be called with the current buffer set to the channel buffer.
4719 See also `erc-channel-end-receiving-names'."
4720 (setq erc-channel-new-member-names (make-hash-table :test 'equal)))
4722 (defun erc-channel-end-receiving-names ()
4725 Used to fix `erc-channel-users' after a channel names list has been
4726 received. Should be called with the current buffer set to the
4729 See also `erc-channel-begin-receiving-names'."
4730 (maphash (lambda (nick _user)
4731 (if (null (gethash nick erc-channel-new-member-names))
4732 (erc-remove-channel-user nick)))
4734 (setq erc-channel-new-member-names nil))
4736 (defun erc-parse-prefix ()
4737 "Return an alist of valid prefix character types and their representations.
4738 Example: (operator) o => @, (voiced) v => +."
4739 (let ((str (or (cdr (assoc "PREFIX" (erc-with-server-buffer
4740 erc-server-parameters)))
4741 ;; provide a sane default
4744 (when (string-match "^(\\([^)]+\\))\\(.+\\)$" str)
4745 (setq types (match-string 1 str)
4746 chars (match-string 2 str))
4747 (let ((len (min (length types) (length chars)))
4751 (setq alist (cons (cons (elt types i) (elt chars i))
4756 (defun erc-channel-receive-names (names-string)
4757 "This function is for internal use only.
4759 Update `erc-channel-users' according to NAMES-STRING.
4760 NAMES-STRING is a string listing some of the names on the
4762 (let* ((prefix (erc-parse-prefix))
4763 (voice-ch (cdr (assq ?v prefix)))
4764 (op-ch (cdr (assq ?o prefix)))
4765 (hop-ch (cdr (assq ?h prefix)))
4766 (adm-ch (cdr (assq ?a prefix)))
4767 (own-ch (cdr (assq ?q prefix)))
4768 names name op voice halfop admin owner)
4769 (setq names (delete "" (split-string names-string)))
4770 (let ((erc-channel-members-changed-hook nil))
4771 (dolist (item names)
4773 (setq name item op 'off voice 'off halfop 'off admin 'off owner 'off)
4774 (if (rassq (elt item 0) prefix)
4775 (cond ((= (length item) 1)
4777 ((eq (elt item 0) voice-ch)
4778 (setq name (substring item 1)
4780 ((eq (elt item 0) hop-ch)
4781 (setq name (substring item 1)
4783 ((eq (elt item 0) op-ch)
4784 (setq name (substring item 1)
4786 ((eq (elt item 0) adm-ch)
4787 (setq name (substring item 1)
4789 ((eq (elt item 0) own-ch)
4790 (setq name (substring item 1)
4792 (t (setq name (substring item 1)))))
4794 (puthash (erc-downcase name) t
4795 erc-channel-new-member-names)
4796 (erc-update-current-channel-member
4797 name name t voice halfop op admin owner)))))
4798 (run-hooks 'erc-channel-members-changed-hook)))
4801 (defcustom erc-channel-members-changed-hook nil
4802 "This hook is called every time the variable `channel-members' changes.
4803 The buffer where the change happened is current while this hook is called."
4807 (defun erc-update-user-nick (nick &optional new-nick
4808 host login full-name info)
4809 "Update the stored user information for the user with nickname NICK.
4811 See also: `erc-update-user'."
4812 (erc-update-user (erc-get-server-user nick) new-nick
4813 host login full-name info))
4815 (defun erc-update-user (user &optional new-nick
4816 host login full-name info)
4817 "Update user info for USER. USER must be an erc-server-user
4818 struct. Any of NEW-NICK, HOST, LOGIN, FULL-NAME, INFO which are
4819 non-nil and not equal to the existing values for USER are used to
4820 replace the stored values in USER.
4822 If, and only if, a change is made,
4823 `erc-channel-members-changed-hook' is run for each channel for
4824 which USER is a member, and t is returned."
4828 (not (equal (erc-server-user-nickname user)
4831 (erc-change-user-nickname user new-nick))
4833 (not (equal (erc-server-user-host user) host)))
4835 (setf (erc-server-user-host user) host))
4837 (not (equal (erc-server-user-login user) login)))
4839 (setf (erc-server-user-login user) login))
4840 (when (and full-name
4841 (not (equal (erc-server-user-full-name user)
4844 (setf (erc-server-user-full-name user) full-name))
4846 (not (equal (erc-server-user-info user) info)))
4848 (setf (erc-server-user-info user) info))
4850 (dolist (buf (erc-server-user-buffers user))
4851 (if (buffer-live-p buf)
4852 (with-current-buffer buf
4853 (run-hooks 'erc-channel-members-changed-hook))))))
4856 (defun erc-update-current-channel-member
4857 (nick new-nick &optional add voice halfop op admin owner host login full-name info
4858 update-message-time)
4859 "Update the stored user information for the user with nickname NICK.
4860 `erc-update-user' is called to handle changes to nickname,
4861 HOST, LOGIN, FULL-NAME, and INFO. If VOICE HALFOP OP ADMIN or OWNER
4862 are non-nil, they must be equal to either `on' or `off', in which
4863 case the status of the user in the current channel is changed accordingly.
4864 If UPDATE-MESSAGE-TIME is non-nil, the last-message-time of the user
4865 in the current channel is set to (current-time).
4867 If ADD is non-nil, the user will be added with the specified
4868 information if it is not already present in the user or channel
4871 If, and only if, changes are made, or the user is added,
4872 `erc-channel-members-updated-hook' is run, and t is returned.
4874 See also: `erc-update-user' and `erc-update-channel-member'."
4875 (let* (changed user-changed
4876 (channel-data (erc-get-channel-user nick))
4877 (cuser (cdr channel-data))
4878 (user (if channel-data (car channel-data)
4879 (erc-get-server-user nick))))
4882 (erc-log (format "update-member: user = %S, cuser = %S" user cuser))
4884 (not (eq (erc-channel-user-voice cuser) voice)))
4886 (setf (erc-channel-user-voice cuser)
4887 (cond ((eq voice 'on) t)
4888 ((eq voice 'off) nil)
4891 (not (eq (erc-channel-user-halfop cuser) halfop)))
4893 (setf (erc-channel-user-halfop cuser)
4894 (cond ((eq halfop 'on) t)
4895 ((eq halfop 'off) nil)
4898 (not (eq (erc-channel-user-op cuser) op)))
4900 (setf (erc-channel-user-op cuser)
4901 (cond ((eq op 'on) t)
4905 (not (eq (erc-channel-user-admin cuser) admin)))
4907 (setf (erc-channel-user-admin cuser)
4908 (cond ((eq admin 'on) t)
4909 ((eq admin 'off) nil)
4912 (not (eq (erc-channel-user-owner cuser) owner)))
4914 (setf (erc-channel-user-owner cuser)
4915 (cond ((eq owner 'on) t)
4916 ((eq owner 'off) nil)
4918 (when update-message-time
4919 (setf (erc-channel-user-last-message-time cuser) (current-time)))
4921 (erc-update-user user new-nick
4922 host login full-name info)))
4926 (setq user (make-erc-server-user
4929 :full-name full-name
4932 :buffers (list (current-buffer))))
4933 (erc-add-server-user nick user))
4934 (setf (erc-server-user-buffers user)
4935 (cons (current-buffer)
4936 (erc-server-user-buffers user))))
4937 (setq cuser (make-erc-channel-user
4938 :voice (cond ((eq voice 'on) t)
4939 ((eq voice 'off) nil)
4941 :halfop (cond ((eq halfop 'on) t)
4942 ((eq halfop 'off) nil)
4944 :op (cond ((eq op 'on) t)
4947 :admin (cond ((eq admin 'on) t)
4948 ((eq admin 'off) nil)
4950 :owner (cond ((eq owner 'on) t)
4951 ((eq owner 'off) nil)
4954 (if update-message-time (current-time))))
4955 (puthash (erc-downcase nick) (cons user cuser)
4958 (when (and changed (null user-changed))
4959 (run-hooks 'erc-channel-members-changed-hook))
4960 (or changed user-changed add)))
4962 (defun erc-update-channel-member (channel nick new-nick
4963 &optional add voice halfop op admin owner host login
4964 full-name info update-message-time)
4965 "Update user and channel information for the user with
4966 nickname NICK in channel CHANNEL.
4968 See also: `erc-update-current-channel-member'."
4971 (erc-update-current-channel-member nick new-nick add voice halfop op admin owner host
4972 login full-name info
4973 update-message-time)))
4975 (defun erc-remove-current-channel-member (nick)
4976 "Remove NICK from current channel membership list.
4977 Runs `erc-channel-members-changed-hook'."
4978 (let ((channel-data (erc-get-channel-user nick)))
4980 (erc-remove-channel-user nick)
4981 (run-hooks 'erc-channel-members-changed-hook))))
4983 (defun erc-remove-channel-member (channel nick)
4984 "Remove NICK from CHANNEL's membership list.
4986 See also `erc-remove-current-channel-member'."
4989 (erc-remove-current-channel-member nick)))
4991 (defun erc-update-channel-topic (channel topic &optional modify)
4992 "Find a buffer for CHANNEL and set the TOPIC for it.
4994 If optional MODIFY is 'append or 'prepend, then append or prepend the
4995 TOPIC string to the current topic."
4996 (erc-with-buffer (channel)
4997 (cond ((eq modify 'append)
4998 (setq erc-channel-topic (concat erc-channel-topic topic)))
4999 ((eq modify 'prepend)
5000 (setq erc-channel-topic (concat topic erc-channel-topic)))
5001 (t (setq erc-channel-topic topic)))
5002 (erc-update-mode-line-buffer (current-buffer))))
5004 (defun erc-set-modes (tgt mode-string)
5005 "Set the modes for the TGT provided as MODE-STRING."
5006 (let* ((modes (erc-parse-modes mode-string))
5007 (add-modes (nth 0 modes))
5008 ;; list of triples: (mode-char 'on/'off argument)
5009 (arg-modes (nth 2 modes)))
5010 (cond ((erc-channel-p tgt); channel modes
5011 (let ((buf (and erc-server-process
5012 (erc-get-buffer tgt erc-server-process))))
5014 (with-current-buffer buf
5015 (setq erc-channel-modes add-modes)
5016 (setq erc-channel-user-limit nil)
5017 (setq erc-channel-key nil)
5019 (let ((mode (nth 0 (car arg-modes)))
5020 (onoff (nth 1 (car arg-modes)))
5021 (arg (nth 2 (car arg-modes))))
5022 (cond ((string-match "^[Ll]" mode)
5023 (erc-update-channel-limit tgt onoff arg))
5024 ((string-match "^[Kk]" mode)
5025 (erc-update-channel-key tgt onoff arg))
5027 (setq arg-modes (cdr arg-modes)))
5028 (erc-update-mode-line-buffer buf)))))
5029 ;; we do not keep our nick's modes yet
5030 ;;(t (setq erc-user-modes add-modes))
5034 (defun erc-sort-strings (list-of-strings)
5035 "Sort LIST-OF-STRINGS in lexicographic order.
5038 (sort (copy-sequence list-of-strings) 'string<))
5040 (defun erc-parse-modes (mode-string)
5041 "Parse MODE-STRING into a list.
5043 Returns a list of three elements:
5045 (ADD-MODES REMOVE-MODES ARG-MODES).
5047 The add-modes and remove-modes are lists of single-character strings
5048 for modes without parameters to add and remove respectively. The
5049 arg-modes is a list of triples of the form:
5051 (MODE-CHAR ON/OFF ARGUMENT)."
5052 (if (string-match "^\\s-*\\(\\S-+\\)\\(\\s-.*$\\|$\\)" mode-string)
5053 (let ((chars (mapcar 'char-to-string (match-string 1 mode-string)))
5054 ;; arguments in channel modes
5055 (args-str (match-string 2 mode-string))
5059 (arg-modes nil); list of triples: (mode-char 'on/'off argument)
5061 ;; make the argument list
5062 (while (string-match "^\\s-*\\(\\S-+\\)\\(\\s-+.*$\\|$\\)" args-str)
5063 (setq args (cons (match-string 1 args-str) args))
5064 (setq args-str (match-string 2 args-str)))
5065 (setq args (nreverse args))
5066 ;; collect what modes changed, and match them with arguments
5068 (cond ((string= (car chars) "+") (setq add-p t))
5069 ((string= (car chars) "-") (setq add-p nil))
5070 ((string-match "^[qaovhbQAOVHB]" (car chars))
5071 (setq arg-modes (cons (list (car chars)
5073 (if args (car args) nil))
5075 (if args (setq args (cdr args))))
5076 ((string-match "^[LlKk]" (car chars))
5077 (setq arg-modes (cons (list (car chars)
5079 (if (and add-p args)
5082 (if (and add-p args) (setq args (cdr args))))
5083 (add-p (setq add-modes (cons (car chars) add-modes)))
5084 (t (setq remove-modes (cons (car chars) remove-modes))))
5085 (setq chars (cdr chars)))
5086 (setq add-modes (nreverse add-modes))
5087 (setq remove-modes (nreverse remove-modes))
5088 (setq arg-modes (nreverse arg-modes))
5089 (list add-modes remove-modes arg-modes))
5092 (defun erc-update-modes (tgt mode-string &optional nick host login)
5093 "Update the mode information for TGT, provided as MODE-STRING.
5094 Optional arguments: NICK, HOST and LOGIN - the attributes of the
5095 person who changed the modes."
5096 ;; FIXME: neither of nick, host, and login are used!
5097 (let* ((modes (erc-parse-modes mode-string))
5098 (add-modes (nth 0 modes))
5099 (remove-modes (nth 1 modes))
5100 ;; list of triples: (mode-char 'on/'off argument)
5101 (arg-modes (nth 2 modes)))
5102 ;; now parse the modes changes and do the updates
5103 (cond ((erc-channel-p tgt); channel modes
5104 (let ((buf (and erc-server-process
5105 (erc-get-buffer tgt erc-server-process))))
5107 ;; FIXME! This used to have an original buffer
5108 ;; variable, but it never switched back to the original
5109 ;; buffer. Is this wanted behavior?
5111 (if (not (boundp 'erc-channel-modes))
5112 (setq erc-channel-modes nil))
5114 (setq erc-channel-modes (delete (car remove-modes)
5116 remove-modes (cdr remove-modes)))
5118 (setq erc-channel-modes (cons (car add-modes)
5120 add-modes (cdr add-modes)))
5121 (setq erc-channel-modes (erc-sort-strings erc-channel-modes))
5123 (let ((mode (nth 0 (car arg-modes)))
5124 (onoff (nth 1 (car arg-modes)))
5125 (arg (nth 2 (car arg-modes))))
5126 (cond ((string-match "^[Vv]" mode)
5127 (erc-update-channel-member tgt arg arg nil onoff))
5128 ((string-match "^[hH]" mode)
5129 (erc-update-channel-member tgt arg arg nil nil onoff))
5130 ((string-match "^[oO]" mode)
5131 (erc-update-channel-member tgt arg arg nil nil nil onoff))
5132 ((string-match "^[aA]" mode)
5133 (erc-update-channel-member tgt arg arg nil nil nil nil onoff))
5134 ((string-match "^[qQ]" mode)
5135 (erc-update-channel-member tgt arg arg nil nil nil nil nil onoff))
5136 ((string-match "^[Ll]" mode)
5137 (erc-update-channel-limit tgt onoff arg))
5138 ((string-match "^[Kk]" mode)
5139 (erc-update-channel-key tgt onoff arg))
5140 (t nil)); only ops are tracked now
5141 (setq arg-modes (cdr arg-modes))))
5142 (erc-update-mode-line buf))))
5143 ;; nick modes - ignored at this point
5146 (defun erc-update-channel-limit (channel onoff n)
5147 ;; FIXME: what does ONOFF actually do? -- Lawrence 2004-01-08
5148 "Update CHANNEL's user limit to N."
5149 (if (or (not (eq onoff 'on))
5150 (and (stringp n) (string-match "^[0-9]+$" n)))
5153 (cond ((eq onoff 'on) (setq erc-channel-user-limit (string-to-number n)))
5154 (t (setq erc-channel-user-limit nil))))))
5156 (defun erc-update-channel-key (channel onoff key)
5157 "Update CHANNEL's key to KEY if ONOFF is 'on or to nil if it's 'off."
5160 (cond ((eq onoff 'on) (setq erc-channel-key key))
5161 (t (setq erc-channel-key nil)))))
5163 (defun erc-handle-user-status-change (type nlh &optional l)
5164 "Handle changes in any user's status.
5166 So far, only nick change is handled.
5168 Generally, the TYPE argument is a symbol describing the change type, NLH is
5169 a list containing the original nickname, login name and hostname for the user,
5170 and L is a list containing additional TYPE-specific arguments.
5172 So far the following TYPE/L pairs are supported:
5176 nickname change 'nick (NEW-NICK)"
5177 (erc-log (format "user-change: type: %S nlh: %S l: %S" type nlh l))
5185 (defun erc-highlight-notice (s)
5186 "Highlight notice message S and return it.
5187 See also variable `erc-notice-highlight-type'."
5189 ((eq erc-notice-highlight-type 'prefix)
5190 (erc-put-text-property 0 (length erc-notice-prefix)
5191 'face 'erc-notice-face s)
5193 ((eq erc-notice-highlight-type 'all)
5194 (erc-put-text-property 0 (length s) 'face 'erc-notice-face s)
5198 (defun erc-make-notice (message)
5199 "Notify the user of MESSAGE."
5200 (when erc-minibuffer-notice
5201 (message "%s" message))
5202 (erc-highlight-notice (concat erc-notice-prefix message)))
5204 (defun erc-highlight-error (s)
5205 "Highlight error message S and return it."
5206 (erc-put-text-property 0 (length s) 'face 'erc-error-face s)
5209 (defun erc-put-text-property (start end property value &optional object)
5210 "Set text-property for an object (usually a string).
5211 START and END define the characters covered.
5212 PROPERTY is the text-property set, usually the symbol `face'.
5213 VALUE is the value for the text-property, usually a face symbol such as
5214 the face `bold' or `erc-pal-face'.
5215 OBJECT is a string which will be modified and returned.
5216 OBJECT is modified without being copied first.
5218 You can redefine or `defadvice' this function in order to add
5219 EmacsSpeak support."
5220 (put-text-property start end property value object))
5222 (defun erc-list (thing)
5223 "Return THING if THING is a list, or a list with THING as its element."
5228 (defun erc-parse-user (string)
5229 "Parse STRING as a user specification (nick!login@host).
5231 Return a list of the three separate tokens."
5233 ((string-match "^\\([^!\n]*\\)!\\([^@\n]*\\)@\\(.*\\)$" string)
5234 (list (match-string 1 string)
5235 (match-string 2 string)
5236 (match-string 3 string)))
5237 ;; Some bogus bouncers send Nick!(null), try to live with that.
5238 ((string-match "^\\([^!\n]*\\)!\\(.*\\)$" string)
5239 (list (match-string 1 string)
5241 (match-string 2 string)))
5243 (list string "" ""))))
5245 (defun erc-extract-nick (string)
5246 "Return the nick corresponding to a user specification STRING.
5248 See also `erc-parse-user'."
5249 (car (erc-parse-user string)))
5251 (defun erc-put-text-properties (start end properties
5252 &optional object value-list)
5253 "Set text-properties for OBJECT.
5255 START and END describe positions in OBJECT.
5256 If VALUE-LIST is nil, set each property in PROPERTIES to t, else set
5257 each property to the corresponding value in VALUE-LIST."
5259 (setq value-list (mapcar (lambda (_x) t)
5261 (while (and properties value-list)
5262 (erc-put-text-property
5263 start end (pop properties) (pop value-list) object)))
5265 ;;; Input area handling:
5267 (defun erc-beg-of-input-line ()
5268 "Return the value of `point' at the beginning of the input line.
5270 Specifically, return the position of `erc-insert-marker'."
5271 (or (and (boundp 'erc-insert-marker)
5272 (markerp erc-insert-marker))
5273 (error "erc-insert-marker has no value, please report a bug"))
5274 (marker-position erc-insert-marker))
5276 (defun erc-end-of-input-line ()
5277 "Return the value of `point' at the end of the input line."
5280 (defvar erc-last-input-time 0
5281 "Time of last call to `erc-send-current-line'.
5282 If that function has never been called, the value is 0.")
5284 (defcustom erc-accidental-paste-threshold-seconds nil
5285 "Minimum time, in seconds, before sending new lines via IRC.
5286 If the value is a number, `erc-send-current-line' signals an error
5287 if its previous invocation was fewer than this many seconds ago.
5288 This is useful so that if you accidentally enter large amounts of text
5289 into the ERC buffer, that text is not sent to the IRC server.
5291 If the value is nil, `erc-send-current-line' always considers any
5292 submitted line to be intentional."
5295 :type '(choice number (other :tag "disabled" nil)))
5297 (defun erc-send-current-line ()
5298 "Parse current line and send it to IRC."
5300 (let ((now (float-time)))
5301 (if (or (not erc-accidental-paste-threshold-seconds)
5302 (< erc-accidental-paste-threshold-seconds
5303 (- now erc-last-input-time)))
5306 (if (< (point) (erc-beg-of-input-line))
5307 (erc-error "Point is not in the input area")
5308 (let ((inhibit-read-only t)
5309 (str (erc-user-input))
5310 (old-buf (current-buffer)))
5311 (if (and (not (erc-server-buffer-live-p))
5312 (not (erc-command-no-process-p str)))
5313 (erc-error "ERC: No process running")
5314 (erc-set-active-buffer (current-buffer))
5315 ;; Kill the input and the prompt
5316 (delete-region (erc-beg-of-input-line)
5317 (erc-end-of-input-line))
5319 (erc-send-input str)
5320 ;; Fix the buffer if the command didn't kill it
5321 (when (buffer-live-p old-buf)
5322 (with-current-buffer old-buf
5325 (goto-char (point-max))
5326 (when (processp erc-server-process)
5327 (set-marker (process-mark erc-server-process) (point)))
5328 (set-marker erc-insert-marker (point))
5329 (let ((buffer-modified (buffer-modified-p)))
5330 (erc-display-prompt)
5331 (set-buffer-modified-p buffer-modified))))))
5333 ;; Only when last hook has been run...
5334 (run-hook-with-args 'erc-send-completed-hook str))))
5335 (setq erc-last-input-time now))
5336 (switch-to-buffer "*ERC Accidental Paste Overflow*")
5337 (lwarn 'erc :warning
5338 "You seem to have accidentally pasted some text!"))))
5340 (defun erc-user-input ()
5341 "Return the input of the user in the current buffer."
5342 (buffer-substring-no-properties
5344 (erc-end-of-input-line)))
5346 (defvar erc-command-regexp "^/\\([A-Za-z']+\\)\\(\\s-+.*\\|\\s-*\\)$"
5347 "Regular expression used for matching commands in ERC.")
5349 (defun erc-send-input (input)
5350 "Treat INPUT as typed in by the user. It is assumed that the input
5351 and the prompt is already deleted.
5352 This returns non-nil only if we actually send anything."
5353 ;; Handle different kinds of inputs
5355 ;; Ignore empty input
5356 ((if erc-send-whitespace-lines
5358 (string-match "\\`[ \t\r\f\n]*\\'" input))
5359 (when erc-warn-about-blank-lines
5360 (message "Blank line - ignoring...")
5365 (erc-insert-this t))
5366 (setq erc-send-this t)
5367 (run-hook-with-args 'erc-send-pre-hook input)
5369 (if (or (string-match "\n" str)
5370 (not (string-match erc-command-regexp str)))
5375 ;; Insert what has to be inserted for this.
5376 (erc-display-msg line)
5377 (erc-process-input-line (concat line "\n")
5378 (null erc-flood-protect) t))
5379 (or (and erc-flood-protect (erc-split-line line))
5381 (split-string str "\n"))
5382 ;; Insert the prompt along with the command.
5383 (erc-display-command str)
5384 (erc-process-input-line (concat str "\n") t nil))
5387 (defun erc-display-command (line)
5388 (when erc-insert-this
5389 (let ((insert-position (point)))
5390 (unless erc-hide-prompt
5391 (erc-display-prompt nil nil (erc-command-indicator)
5392 (and (erc-command-indicator)
5393 'erc-command-indicator-face)))
5394 (let ((beg (point)))
5396 (erc-put-text-property beg (point)
5397 'face 'erc-command-indicator-face)
5399 (when (processp erc-server-process)
5400 (set-marker (process-mark erc-server-process) (point)))
5401 (set-marker erc-insert-marker (point))
5404 (narrow-to-region insert-position (point))
5405 (run-hooks 'erc-send-modify-hook)
5406 (run-hooks 'erc-send-post-hook))))))
5408 (defun erc-display-msg (line)
5409 "Display LINE as a message of the user to the current target at the
5411 (when erc-insert-this
5412 (let ((insert-position (point)))
5413 (insert (erc-format-my-nick))
5414 (let ((beg (point)))
5416 (erc-put-text-property beg (point)
5417 'face 'erc-input-face))
5419 (when (processp erc-server-process)
5420 (set-marker (process-mark erc-server-process) (point)))
5421 (set-marker erc-insert-marker (point))
5424 (narrow-to-region insert-position (point))
5425 (run-hooks 'erc-send-modify-hook)
5426 (run-hooks 'erc-send-post-hook))))))
5428 (defun erc-command-symbol (command)
5429 "Return the ERC command symbol for COMMAND if it exists and is bound."
5430 (let ((cmd (intern-soft (format "erc-cmd-%s" (upcase command)))))
5431 (when (fboundp cmd) cmd)))
5433 (defun erc-extract-command-from-line (line)
5434 "Extract command and args from the input LINE.
5435 If no command was given, return nil. If command matches, return a
5436 list of the form: (command args) where both elements are strings."
5437 (when (string-match erc-command-regexp line)
5438 (let* ((cmd (erc-command-symbol (match-string 1 line)))
5439 ;; note: return is nil, we apply this simply for side effects
5440 (_canon-defun (while (and cmd (symbolp (symbol-function cmd)))
5441 (setq cmd (symbol-function cmd))))
5442 (cmd-fun (or cmd #'erc-cmd-default))
5444 (if (get cmd-fun 'do-not-parse-args)
5445 (format "%s" (match-string 2 line))
5446 (delete "" (split-string (erc-trim-string
5447 (match-string 2 line)) " ")))
5449 (list cmd-fun arg))))
5451 (defun erc-split-multiline-safe (string)
5452 "Split STRING, containing multiple lines and return them in a list.
5453 Do it only for STRING as the complete input, do not carry unfinished
5454 strings over to the next call."
5459 (let ((i (string-match "\r?\n" string i0))
5460 (s (substring string i0)))
5461 (cond (i (setq l (cons (substring string i0 i) l))
5462 (setq i0 (match-end 0)))
5464 (setq l (cons s l))(setq doit nil))
5465 (t (setq doit nil)))))
5470 (defun erc-set-current-nick (nick)
5471 "Set the current nickname to NICK."
5472 (with-current-buffer (if (buffer-live-p (erc-server-buffer))
5475 (setq erc-server-current-nick nick)))
5477 (defun erc-current-nick ()
5478 "Return the current nickname."
5479 (with-current-buffer (if (buffer-live-p (erc-server-buffer))
5482 erc-server-current-nick))
5484 (defun erc-current-nick-p (nick)
5485 "Return non-nil if NICK is the current nickname."
5486 (erc-nick-equal-p nick (erc-current-nick)))
5488 (defun erc-nick-equal-p (nick1 nick2)
5489 "Return non-nil if NICK1 and NICK2 are the same.
5491 This matches strings according to the IRC protocol's case convention.
5493 See also `erc-downcase'."
5494 (string= (erc-downcase nick1)
5495 (erc-downcase nick2)))
5497 ;; default target handling
5499 (defun erc-default-target ()
5500 "Return the current default target (as a character string) or nil if none."
5501 (let ((tgt (car erc-default-recipients)))
5504 ((listp tgt) (cdr tgt))
5507 (defun erc-add-default-channel (channel)
5508 "Add CHANNEL to the default channel list."
5509 (let ((chl (downcase channel)))
5510 (setq erc-default-recipients
5511 (cons chl erc-default-recipients))))
5513 (defun erc-delete-default-channel (channel &optional buffer)
5514 "Delete CHANNEL from the default channel list."
5515 (with-current-buffer (if (and buffer
5519 (setq erc-default-recipients (delete (downcase channel)
5520 erc-default-recipients))))
5522 (defun erc-add-query (nickname)
5523 "Add QUERY'd NICKNAME to the default channel list.
5525 The previous default target of QUERY type gets removed."
5526 (let ((d1 (car erc-default-recipients))
5527 (d2 (cdr erc-default-recipients))
5528 (qt (cons 'QUERY (downcase nickname))))
5529 (setq erc-default-recipients (cons qt (if (and (listp d1)
5530 (eq (car d1) 'QUERY))
5532 erc-default-recipients)))))
5534 (defun erc-delete-query ()
5535 "Delete the topmost target if it is a QUERY."
5537 (let ((d1 (car erc-default-recipients))
5538 (d2 (cdr erc-default-recipients)))
5540 (eq (car d1) 'QUERY))
5541 (setq erc-default-recipients d2)
5542 (error "Current target is not a QUERY"))))
5544 (defun erc-ignored-user-p (spec)
5545 "Return non-nil if SPEC matches something in `erc-ignore-list'.
5547 Takes a full SPEC of a user in the form \"nick!login@host\", and
5548 matches against all the regexp's in `erc-ignore-list'. If any
5549 match, returns that regexp."
5551 (dolist (ignored (erc-with-server-buffer erc-ignore-list))
5552 (if (string-match ignored spec)
5553 (throw 'found ignored)))))
5555 (defun erc-ignored-reply-p (msg tgt proc)
5556 ;; FIXME: this docstring needs fixing -- Lawrence 2004-01-08
5557 "Return non-nil if MSG matches something in `erc-ignore-reply-list'.
5559 Takes a message MSG to a channel and returns non-nil if the addressed
5560 user matches any regexp in `erc-ignore-reply-list'."
5561 (let ((target-nick (erc-message-target msg)))
5562 (if (not target-nick)
5564 (erc-with-buffer (tgt proc)
5565 (let ((user (erc-get-server-user target-nick)))
5567 (erc-list-match erc-ignore-reply-list
5568 (erc-user-spec user))))))))
5570 (defun erc-message-target (msg)
5571 "Return the addressed target in MSG.
5573 The addressed target is the string before the first colon in MSG."
5574 (if (string-match "^\\([^: \n]*\\):" msg)
5575 (match-string 1 msg)
5578 (defun erc-user-spec (user)
5579 "Create a nick!user@host spec from a user struct."
5580 (let ((nick (erc-server-user-nickname user))
5581 (host (erc-server-user-host user))
5582 (login (erc-server-user-login user)))
5583 (concat (or nick "")
5589 (defun erc-list-match (lst str)
5590 "Return non-nil if any regexp in LST matches STR."
5591 (memq nil (mapcar (lambda (regexp)
5592 (not (string-match regexp str)))
5597 (defun erc-toggle-ctcp-autoresponse (&optional arg)
5598 "Toggle automatic CTCP replies (like VERSION and PING).
5600 If ARG is positive, turns CTCP replies on.
5602 If ARG is non-nil and not positive, turns CTCP replies off."
5604 (cond ((and (numberp arg) (> arg 0))
5605 (setq erc-disable-ctcp-replies t))
5606 (arg (setq erc-disable-ctcp-replies nil))
5607 (t (setq erc-disable-ctcp-replies (not erc-disable-ctcp-replies))))
5608 (message "ERC CTCP replies are %s" (if erc-disable-ctcp-replies "OFF" "ON")))
5610 (defun erc-toggle-flood-control (&optional arg)
5611 "Toggle use of flood control on sent messages.
5613 If ARG is positive, use flood control.
5614 If ARG is non-nil and not positive, do not use flood control.
5616 See `erc-server-flood-margin' for an explanation of the available
5617 flood control parameters."
5619 (cond ((and (numberp arg) (> arg 0))
5620 (setq erc-flood-protect t))
5621 (arg (setq erc-flood-protect nil))
5622 (t (setq erc-flood-protect (not erc-flood-protect))))
5623 (message "ERC flood control is %s"
5624 (cond (erc-flood-protect "ON")
5627 ;; Some useful channel and nick commands for fast key bindings
5629 (defun erc-invite-only-mode (&optional arg)
5630 "Turn on the invite only mode (+i) for the current channel.
5632 If ARG is non-nil, turn this mode off (-i).
5634 This command is sent even if excess flood is detected."
5636 (erc-set-active-buffer (current-buffer))
5637 (let ((tgt (erc-default-target)))
5638 (if (or (not tgt) (not (erc-channel-p tgt)))
5639 (erc-display-message nil 'error (current-buffer) 'no-target)
5640 (erc-load-irc-script-lines
5641 (list (concat "/mode " tgt (if arg " -i" " +i")))
5644 (defun erc-get-channel-mode-from-keypress (key)
5645 "Read a key sequence and call the corresponding channel mode function.
5646 After doing C-c C-o, type in a channel mode letter.
5649 RET lets you type more than one mode at a time.
5650 If \"l\" is pressed, `erc-set-channel-limit' gets called.
5651 If \"k\" is pressed, `erc-set-channel-key' gets called.
5652 Anything else will be sent to `erc-toggle-channel-mode'."
5653 (interactive "kChannel mode (RET to set more than one): ")
5654 (when (featurep 'xemacs)
5655 (setq key (char-to-string (event-to-character (aref key 0)))))
5656 (cond ((equal key "\C-g")
5659 (erc-insert-mode-command))
5661 (call-interactively 'erc-set-channel-limit))
5663 (call-interactively 'erc-set-channel-key))
5664 (t (erc-toggle-channel-mode key))))
5666 (defun erc-toggle-channel-mode (mode &optional channel)
5667 "Toggle channel MODE.
5669 If CHANNEL is non-nil, toggle MODE for that channel, otherwise use
5670 `erc-default-target'."
5672 (erc-set-active-buffer (current-buffer))
5673 (let ((tgt (or channel (erc-default-target))))
5674 (if (or (null tgt) (null (erc-channel-p tgt)))
5675 (erc-display-message nil 'error 'active 'no-target)
5676 (let* ((active (member mode erc-channel-modes))
5677 (newstate (if active "OFF" "ON")))
5678 (erc-log (format "%s: Toggle mode %s %s" tgt mode newstate))
5679 (message "Toggle channel mode %s %s" mode newstate)
5680 (erc-server-send (format "MODE %s %s%s"
5681 tgt (if active "-" "+") mode))))))
5683 (defun erc-insert-mode-command ()
5684 "Insert the line \"/mode <current target> \" at `point'."
5686 (let ((tgt (erc-default-target)))
5687 (if tgt (insert (concat "/mode " tgt " "))
5688 (erc-display-message nil 'error (current-buffer) 'no-target))))
5690 (defun erc-channel-names ()
5691 "Run \"/names #channel\" in the current channel."
5693 (erc-set-active-buffer (current-buffer))
5694 (let ((tgt (erc-default-target)))
5695 (if tgt (erc-load-irc-script-lines (list (concat "/names " tgt)))
5696 (erc-display-message nil 'error (current-buffer) 'no-target))))
5698 (defun erc-remove-text-properties-region (start end &optional object)
5699 "Clears the region (START,END) in OBJECT from all colors, etc."
5702 (let ((inhibit-read-only t))
5703 (set-text-properties start end nil object))))
5704 (put 'erc-remove-text-properties-region 'disabled t)
5706 ;; script execution and startup
5708 (defun erc-find-file (file &optional path)
5709 "Search for a FILE in the filesystem.
5710 First the `default-directory' is searched for FILE, then any directories
5711 specified in the list PATH.
5713 If FILE is found, return the path to it."
5714 (let ((filepath file))
5715 (if (file-readable-p filepath) filepath
5717 (progn (setq filepath (expand-file-name file (car path)))
5718 (not (file-readable-p filepath))))
5719 (setq path (cdr path)))
5720 (if path filepath nil))))
5722 (defun erc-select-startup-file ()
5723 "Select an ERC startup file.
5724 See also `erc-startup-file-list'."
5726 (dolist (f erc-startup-file-list)
5727 (setq f (convert-standard-filename f))
5728 (when (file-readable-p f)
5729 (throw 'found f)))))
5731 (defun erc-find-script-file (file)
5732 "Search for FILE in `default-directory', and any in `erc-script-path'."
5733 (erc-find-file file erc-script-path))
5735 (defun erc-load-script (file)
5736 "Load a script from FILE.
5738 FILE must be the full name, it is not searched in the
5739 `erc-script-path'. If the filename ends with `.el', then load it
5740 as an Emacs Lisp program. Otherwise, treat it as a regular IRC
5742 (erc-log (concat "erc-load-script: " file))
5744 ((string-match "\\.el\\'" file)
5747 (erc-load-irc-script file))))
5749 (defun erc-process-script-line (line &optional args)
5750 "Process an IRC script LINE.
5752 Does script-specific substitutions (script arguments, current nick,
5753 server, etc.) in LINE and returns it.
5755 Substitutions are: %C and %c = current target (channel or nick),
5756 %S %s = current server, %N %n = my current nick, and %x is x verbatim,
5757 where x is any other character;
5758 $* = the entire argument string, $1 = the first argument, $2 = the second,
5760 (if (not args) (setq args ""))
5761 (let* ((arg-esc-regexp "\\(\\$\\(\\*\\|[1-9][0-9]*\\)\\)\\([^0-9]\\|$\\)")
5762 (percent-regexp "\\(%.\\)")
5763 (esc-regexp (concat arg-esc-regexp "\\|" percent-regexp))
5764 (tgt (erc-default-target))
5765 (server (and (boundp 'erc-session-server) erc-session-server))
5766 (nick (erc-current-nick))
5771 (if (not tgt) (setq tgt ""))
5772 (if (not server) (setq server ""))
5773 (if (not nick) (setq nick ""))
5774 ;; First, compute the argument list
5776 (while (string-match "^\\s-*\\(\\S-+\\)\\(\\s-+.*$\\|$\\)" tmp)
5777 (setq arg-list (cons (match-string 1 tmp) arg-list))
5778 (setq tmp (match-string 2 tmp)))
5779 (setq arg-list (nreverse arg-list))
5780 (setq arg-num (length arg-list))
5781 ;; now do the substitution
5782 (setq tmp (string-match esc-regexp line))
5784 ;;(message "beginning of while: tmp=%S" tmp)
5785 (let* ((hd (substring line 0 tmp))
5788 (tail (substring line tmp)))
5789 (cond ((string-match (concat "^" arg-esc-regexp) tail)
5790 (setq esc (match-string 1 tail))
5791 (setq tail (substring tail (match-end 1))))
5792 ((string-match (concat "^" percent-regexp) tail)
5793 (setq esc (match-string 1 tail))
5794 (setq tail (substring tail (match-end 1)))))
5795 ;;(message "hd=%S, esc=%S, tail=%S, arg-num=%S" hd esc tail arg-num)
5796 (setq res (concat res hd))
5798 (cond ((string= esc "") "")
5799 ((string-match "^\\$\\*$" esc) args)
5800 ((string-match "^\\$\\([0-9]+\\)$" esc)
5801 (let ((n (string-to-number (match-string 1 esc))))
5802 (message "n = %S, integerp(n)=%S" n (integerp n))
5803 (if (<= n arg-num) (nth (1- n) arg-list) "")))
5804 ((string-match "^%[Cc]$" esc) tgt)
5805 ((string-match "^%[Ss]$" esc) server)
5806 ((string-match "^%[Nn]$" esc) nick)
5807 ((string-match "^%\\(.\\)$" esc) (match-string 1 esc))
5808 (t (erc-log (format "BUG in erc-process-script-line: bad escape sequence: %S\n" esc))
5809 (message "BUG IN ERC: esc=%S" esc)
5812 (setq tmp (string-match esc-regexp line))
5813 (setq res (concat res subst))
5814 ;;(message "end of while: line=%S, res=%S, tmp=%S" line res tmp)
5816 (setq res (concat res line))
5819 (defun erc-load-irc-script (file &optional force)
5820 "Load an IRC script from FILE."
5821 (erc-log (concat "erc-load-script: " file))
5822 (let ((str (with-temp-buffer
5823 (insert-file-contents file)
5825 (erc-load-irc-script-lines (erc-split-multiline-safe str) force)))
5827 (defun erc-load-irc-script-lines (lines &optional force noexpand)
5828 "Load IRC script LINES (a list of strings).
5830 If optional NOEXPAND is non-nil, do not expand script-specific
5831 sequences, process the lines verbatim. Use this for multiline
5833 (let* ((cb (current-buffer))
5835 (sp (or (erc-command-indicator) (erc-prompt)))
5836 (args (and (boundp 'erc-script-args) erc-script-args)))
5837 (if (and args (string-match "^ " args))
5838 (setq args (substring args 1)))
5839 ;; prepare the prompt string for echo
5840 (erc-put-text-property 0 (length sp)
5841 'face 'erc-command-indicator-face sp)
5843 (setq s (car lines))
5844 (erc-log (concat "erc-load-script: CMD: " s))
5845 (unless (string-match "^\\s-*$" s)
5846 (let ((line (if noexpand s (erc-process-script-line s args))))
5847 (if (and (erc-process-input-line line force)
5850 (erc-put-text-property 0 (length line)
5851 'face 'erc-input-face line)
5852 (erc-display-line (concat sp line) cb)))))
5853 (setq lines (cdr lines)))))
5858 "Perform user authentication at the IRC server."
5859 (erc-log (format "login: nick: %s, user: %s %s %s :%s"
5862 (or erc-system-name (system-name))
5864 erc-session-user-full-name))
5865 (if erc-session-password
5866 (erc-server-send (format "PASS %s" erc-session-password))
5867 (message "Logging in without password"))
5868 (erc-server-send (format "NICK %s" (erc-current-nick)))
5870 (format "USER %s %s %s :%s"
5872 (if erc-anonymous-login erc-email-userid (user-login-name))
5874 erc-session-user-full-name))
5875 (erc-update-mode-line))
5877 ;; connection properties' heuristics
5879 (defun erc-determine-parameters (&optional server port nick name)
5880 "Determine the connection and authentication parameters.
5881 Sets the buffer local variables:
5883 - `erc-session-connector'
5884 - `erc-session-server'
5885 - `erc-session-port'
5886 - `erc-session-full-name'
5887 - `erc-server-current-nick'"
5888 (setq erc-session-connector erc-server-connect-function
5889 erc-session-server (erc-compute-server server)
5890 erc-session-port (or port erc-default-port)
5891 erc-session-user-full-name (erc-compute-full-name name))
5892 (erc-set-current-nick (erc-compute-nick nick)))
5894 (defun erc-compute-server (&optional server)
5895 "Return an IRC server name.
5897 This tries a number of increasingly more default methods until a
5898 non-nil value is found.
5900 - SERVER (the argument passed to this function)
5901 - The `erc-server' option
5902 - The value of the IRCSERVER environment variable
5903 - The `erc-default-server' variable"
5906 (getenv "IRCSERVER")
5907 erc-default-server))
5909 (defun erc-compute-nick (&optional nick)
5910 "Return user's IRC nick.
5912 This tries a number of increasingly more default methods until a
5913 non-nil value is found.
5915 - NICK (the argument passed to this function)
5916 - The `erc-nick' option
5917 - The value of the IRCNICK environment variable
5918 - The result from the `user-login-name' function"
5920 (if (consp erc-nick) (car erc-nick) erc-nick)
5925 (defun erc-compute-full-name (&optional full-name)
5926 "Return user's full name.
5928 This tries a number of increasingly more default methods until a
5929 non-nil value is found.
5931 - FULL-NAME (the argument passed to this function)
5932 - The `erc-user-full-name' option
5933 - The value of the IRCNAME environment variable
5934 - The result from the `user-full-name' function"
5938 (if erc-anonymous-login "unknown" nil)
5941 (defun erc-compute-port (&optional port)
5942 "Return a port for an IRC server.
5944 This tries a number of increasingly more default methods until a
5945 non-nil value is found.
5947 - PORT (the argument passed to this function)
5948 - The `erc-port' option
5949 - The `erc-default-port' variable"
5950 (or port erc-port erc-default-port))
5954 (defun erc-string-to-emacs-time (string)
5955 "Convert the long number represented by STRING into an Emacs format.
5956 Returns a list of the form (HIGH LOW), compatible with Emacs time format."
5957 (let* ((n (string-to-number (concat string ".0"))))
5958 (list (truncate (/ n 65536))
5959 (truncate (mod n 65536)))))
5961 (defun erc-emacs-time-to-erc-time (time)
5962 "Convert Emacs TIME to a number of seconds since the epoch."
5964 (+ (* (nth 0 time) 65536.0) (nth 1 time))))
5965 ; (round (+ (* (nth 0 tm) 65536.0) (nth 1 tm))))
5967 (defun erc-current-time ()
5968 "Return the `current-time' as a number of seconds since the epoch.
5970 See also `erc-emacs-time-to-erc-time'."
5971 (erc-emacs-time-to-erc-time (current-time)))
5973 (defun erc-time-diff (t1 t2)
5974 "Return the time difference in seconds between T1 and T2."
5977 (defun erc-time-gt (t1 t2)
5978 "Check whether T1 > T2."
5981 (defun erc-sec-to-time (ns)
5982 "Convert NS to a time string HH:MM.SS."
5983 (setq ns (truncate ns))
5984 (format "%02d:%02d.%02d"
5989 (defun erc-seconds-to-string (seconds)
5990 "Convert a number of SECONDS into an English phrase."
5991 (let (days hours minutes format-args output)
5992 (setq days (/ seconds 86400)
5993 seconds (% seconds 86400)
5994 hours (/ seconds 3600)
5995 seconds (% seconds 3600)
5996 minutes (/ seconds 60)
5997 seconds (% seconds 60)
5998 format-args (if (> days 0)
5999 `("%d days, %d hours, %d minutes, %d seconds"
6000 ,days ,hours ,minutes ,seconds)
6002 `("%d hours, %d minutes, %d seconds"
6003 ,hours ,minutes ,seconds)
6005 `("%d minutes, %d seconds" ,minutes ,seconds)
6006 `("%d seconds" ,seconds))))
6007 output (apply 'format format-args))
6008 ;; Change all "1 units" to "1 unit".
6009 (while (string-match "\\([^0-9]\\|^\\)1 \\S-+\\(s\\)" output)
6010 (setq output (erc-replace-match-subexpression-in-string
6011 "" output (match-string 2 output) 2 (match-beginning 2))))
6017 (defconst erc-clientinfo-alist
6018 '(("ACTION" . "is used to inform about one's current activity")
6019 ("CLIENTINFO" . "gives help on CTCP commands supported by client")
6020 ("ECHO" . "echoes its arguments back")
6021 ("FINGER" . "shows user's name, location, and idle time")
6022 ("PING" . "measures delay between peers")
6023 ("TIME" . "shows client-side time")
6024 ("USERINFO" . "shows information provided by a user")
6025 ("VERSION" . "shows client type and version"))
6026 "Alist of CTCP CLIENTINFO for ERC commands.")
6028 (defun erc-client-info (s)
6029 "Return CTCP CLIENTINFO on command S.
6030 If S is nil or an empty string then return general CLIENTINFO."
6031 (if (or (not s) (string= s ""))
6035 (concat (car e) " "))
6036 erc-clientinfo-alist))
6037 ": use CLIENTINFO <COMMAND> to get more specific information")
6038 (let ((h (assoc (upcase s) erc-clientinfo-alist)))
6040 (concat s " " (cdr h))
6041 (concat s ": unknown command")))))
6045 (defun erc-directory-writable-p (dir)
6046 "Determine whether DIR is a writable directory.
6047 If it doesn't exist, create it."
6048 (unless (file-attributes dir) (make-directory dir))
6049 (or (file-accessible-directory-p dir) (error "Cannot access %s" dir)))
6051 (defun erc-kill-query-buffers (process)
6052 "Kill all buffers of PROCESS."
6053 ;; here, we only want to match the channel buffers, to avoid
6054 ;; "selecting killed buffers" b0rkage.
6055 (erc-with-all-buffers-of-server process
6057 (not (erc-server-buffer-p)))
6058 (kill-buffer (current-buffer))))
6060 (defun erc-nick-at-point ()
6061 "Give information about the nickname at `point'.
6063 If called interactively, give a human readable message in the
6064 minibuffer. If called programmatically, return the corresponding
6065 entry of `channel-members'."
6067 (require 'thingatpt)
6068 (let* ((word (word-at-point))
6069 (channel-data (erc-get-channel-user word))
6070 (cuser (cdr channel-data))
6071 (user (if channel-data
6073 (erc-get-server-user word)))
6074 host login full-name nick voice halfop op admin owner)
6076 (setq nick (erc-server-user-nickname user)
6077 host (erc-server-user-host user)
6078 login (erc-server-user-login user)
6079 full-name (erc-server-user-full-name user))
6081 (setq voice (erc-channel-user-voice cuser)
6082 halfop (erc-channel-user-halfop cuser)
6083 op (erc-channel-user-op cuser)
6084 admin (erc-channel-user-admin cuser)
6085 owner (erc-channel-user-owner cuser))))
6086 (if (called-interactively-p 'interactive)
6087 (message "%s is %s@%s%s%s"
6089 (if full-name (format " (%s)" full-name) "")
6090 (if (or voice halfop op admin owner)
6091 (format " and is +%s%s on %s"
6097 (erc-default-target))
6101 (defun erc-away-time ()
6102 "Return non-nil if the current ERC process is set away.
6104 In particular, the time that we were set away is returned.
6105 See `current-time' for details on the time format."
6106 (erc-with-server-buffer erc-away))
6108 ;; Mode line handling
6110 (defcustom erc-mode-line-format "%S %a"
6111 "A string to be formatted and shown in the mode-line in `erc-mode'.
6113 The string is formatted using `format-spec' and the result is set as the value
6114 of `mode-line-buffer-identification'.
6116 The following characters are replaced:
6117 %a: String indicating away status or \"\" if you are not away
6118 %l: The estimated lag time to the server
6119 %m: The modes of the channel
6120 %n: The current nick name
6121 %N: The name of the network
6122 %o: The topic of the channel
6123 %p: The session port
6124 %t: The name of the target (channel, nickname, or servername:port)
6125 %s: In the server-buffer, this gets filled with the value of
6126 `erc-server-announced-name', in a channel, the value of
6127 (erc-default-target) also get concatenated.
6128 %S: In the server-buffer, this gets filled with the value of
6129 `erc-network', in a channel, the value of (erc-default-target)
6130 also get concatenated."
6131 :group 'erc-mode-line-and-header
6134 (defcustom erc-header-line-format "%n on %t (%m,%l) %o"
6135 "A string to be formatted and shown in the header-line in `erc-mode'.
6136 Only used starting in Emacs 21.
6138 Set this to nil if you do not want the header line to be
6141 See `erc-mode-line-format' for which characters are can be used."
6142 :group 'erc-mode-line-and-header
6143 :set (lambda (sym val)
6145 (when (fboundp 'erc-update-mode-line)
6146 (erc-update-mode-line nil)))
6147 :type '(choice (const :tag "Disabled" nil)
6150 (defcustom erc-header-line-uses-tabbar-p nil
6151 "Use tabbar mode instead of the header line to display the header."
6152 :group 'erc-mode-line-and-header
6155 (defcustom erc-header-line-uses-help-echo-p t
6156 "Show the contents of the header line in the echo area or as a tooltip
6157 when you move point into the header line."
6158 :group 'erc-mode-line-and-header
6161 (defcustom erc-header-line-face-method nil
6162 "Determine what method to use when colorizing the header line text.
6164 If nil, don't colorize the header text.
6165 If given a function, call it and use the resulting face name.
6166 Otherwise, use the `erc-header-line' face."
6167 :group 'erc-mode-line-and-header
6168 :type '(choice (const :tag "Don't colorize" nil)
6169 (const :tag "Use the erc-header-line face" t)
6170 (function :tag "Call a function")))
6172 (defcustom erc-show-channel-key-p t
6173 "Show the channel key in the header line."
6174 :group 'erc-paranoia
6177 (defcustom erc-mode-line-away-status-format
6178 "(AWAY since %a %b %d %H:%M) "
6179 "When you're away on a server, this is shown in the mode line.
6180 This should be a string with substitution variables recognized by
6181 `format-time-string'."
6182 :group 'erc-mode-line-and-header
6185 (defun erc-shorten-server-name (server-name)
6186 "Shorten SERVER-NAME according to `erc-common-server-suffixes'."
6187 (if (stringp server-name)
6189 (insert server-name)
6190 (let ((alist erc-common-server-suffixes))
6192 (goto-char (point-min))
6193 (if (re-search-forward (caar alist) nil t)
6194 (replace-match (cdar alist)))
6195 (setq alist (cdr alist))))
6198 (defun erc-format-target ()
6199 "Return the name of the target (channel or nickname or servername:port)."
6200 (let ((target (erc-default-target)))
6202 (concat (erc-shorten-server-name
6203 (or erc-server-announced-name
6204 erc-session-server))
6205 ":" (erc-port-to-string erc-session-port)))))
6207 (defun erc-format-target-and/or-server ()
6208 "Return the server name or the current target and server name combined."
6209 (let ((server-name (erc-shorten-server-name
6210 (or erc-server-announced-name
6211 erc-session-server))))
6212 (cond ((erc-default-target)
6213 (concat (erc-string-no-properties (erc-default-target))
6215 (server-name server-name)
6216 (t (buffer-name (current-buffer))))))
6218 (defun erc-format-network ()
6219 "Return the name of the network we are currently on."
6220 (let ((network (and (fboundp 'erc-network-name) (erc-network-name))))
6221 (if (and network (symbolp network))
6222 (symbol-name network)
6225 (defun erc-format-target-and/or-network ()
6226 "Return the network or the current target and network combined.
6227 If the name of the network is not available, then use the
6228 shortened server name instead."
6229 (let ((network-name (or (and (fboundp 'erc-network-name) (erc-network-name))
6230 (erc-shorten-server-name
6231 (or erc-server-announced-name
6232 erc-session-server)))))
6233 (when (and network-name (symbolp network-name))
6234 (setq network-name (symbol-name network-name)))
6235 (cond ((erc-default-target)
6236 (concat (erc-string-no-properties (erc-default-target))
6238 (network-name network-name)
6239 (t (buffer-name (current-buffer))))))
6241 (defun erc-format-away-status ()
6242 "Return a formatted `erc-mode-line-away-status-format'
6243 if `erc-away' is non-nil."
6244 (let ((a (erc-away-time)))
6246 (format-time-string erc-mode-line-away-status-format a)
6249 (defun erc-format-channel-modes ()
6250 "Return the current channel's modes."
6251 (concat (apply 'concat
6252 "+" erc-channel-modes)
6253 (cond ((and erc-channel-user-limit erc-channel-key)
6254 (if erc-show-channel-key-p
6255 (format "lk %.0f %s" erc-channel-user-limit
6257 (format "kl %.0f" erc-channel-user-limit)))
6258 (erc-channel-user-limit
6259 ;; Emacs has no bignums
6260 (format "l %.0f" erc-channel-user-limit))
6262 (if erc-show-channel-key-p
6263 (format "k %s" erc-channel-key)
6267 (defun erc-format-lag-time ()
6268 "Return the estimated lag time to server, `erc-server-lag'."
6269 (let ((lag (erc-with-server-buffer erc-server-lag)))
6270 (cond (lag (format "lag:%.0f" lag))
6273 ;; erc-goodies is required at end of this file.
6274 (declare-function erc-controls-strip "erc-goodies" (str))
6276 (defvar tabbar--local-hlf)
6278 (defun erc-update-mode-line-buffer (buffer)
6279 "Update the mode line in a single ERC buffer BUFFER."
6280 (with-current-buffer buffer
6281 (let ((spec (format-spec-make
6282 ?a (erc-format-away-status)
6283 ?l (erc-format-lag-time)
6284 ?m (erc-format-channel-modes)
6285 ?n (or (erc-current-nick) "")
6286 ?N (erc-format-network)
6287 ?o (or (erc-controls-strip erc-channel-topic) "")
6288 ?p (erc-port-to-string erc-session-port)
6289 ?s (erc-format-target-and/or-server)
6290 ?S (erc-format-target-and/or-network)
6291 ?t (erc-format-target)))
6292 (process-status (cond ((and (erc-server-process-alive)
6293 (not erc-server-connected))
6295 ((erc-server-process-alive)
6299 (face (cond ((eq erc-header-line-face-method nil)
6301 ((functionp erc-header-line-face-method)
6302 (funcall erc-header-line-face-method))
6304 'erc-header-line))))
6305 (cond ((featurep 'xemacs)
6306 (setq modeline-buffer-identification
6307 (list (format-spec erc-mode-line-format spec)))
6308 (setq modeline-process (list process-status)))
6310 (setq mode-line-buffer-identification
6311 (list (format-spec erc-mode-line-format spec)))
6312 (setq mode-line-process (list process-status))))
6313 (when (boundp 'header-line-format)
6314 (let ((header (if erc-header-line-format
6315 (format-spec erc-header-line-format spec)
6317 (cond (erc-header-line-uses-tabbar-p
6318 (set (make-local-variable 'tabbar--local-hlf)
6320 (kill-local-variable 'header-line-format))
6322 (setq header-line-format nil))
6323 (erc-header-line-uses-help-echo-p
6324 (let ((help-echo (with-temp-buffer
6326 (fill-region (point-min) (point-max))
6328 (setq header-line-format
6329 (erc-replace-regexp-in-string
6333 (erc-propertize header 'help-echo help-echo
6335 (erc-propertize header 'help-echo help-echo))))))
6336 (t (setq header-line-format
6338 (erc-propertize header 'face face)
6340 (if (featurep 'xemacs)
6342 (force-mode-line-update))))
6344 (defun erc-update-mode-line (&optional buffer)
6345 "Update the mode line in BUFFER.
6347 If BUFFER is nil, update the mode line in all ERC buffers."
6348 (if (and buffer (bufferp buffer))
6349 (erc-update-mode-line-buffer buffer)
6350 (dolist (buf (erc-buffer-list))
6351 (when (buffer-live-p buf)
6352 (erc-update-mode-line-buffer buf)))))
6356 (defun erc-port-to-string (p)
6357 "Convert port P to a string.
6358 P may be an integer or a service name."
6363 (defun erc-string-to-port (s)
6364 "Convert string S to either an integer port number or a service name."
6367 (let ((n (string-to-number s)))
6372 (defun erc-version (&optional here)
6373 "Show the version number of ERC in the minibuffer.
6374 If optional argument HERE is non-nil, insert version number at point."
6376 (let ((version-string
6377 (format "ERC %s (GNU Emacs %s)" erc-version-string emacs-version)))
6379 (insert version-string)
6380 (if (called-interactively-p 'interactive)
6381 (message "%s" version-string)
6384 (defun erc-modes (&optional here)
6385 "Show the active ERC modes in the minibuffer.
6386 If optional argument HERE is non-nil, insert version number at point."
6389 (mapconcat 'identity
6390 (let (modes (case-fold-search nil))
6391 (dolist (var (apropos-internal "^erc-.*mode$"))
6392 (when (and (boundp var)
6394 (setq modes (cons (symbol-name var)
6400 (if (called-interactively-p 'interactive)
6401 (message "%s" string)
6404 (defun erc-trim-string (s)
6405 "Trim leading and trailing spaces off S."
6407 ((not (stringp s)) nil)
6408 ((string-match "^\\s-*$" s)
6410 ((string-match "^\\s-*\\(.*\\S-\\)\\s-*$" s)
6415 (defun erc-arrange-session-in-multiple-windows ()
6416 "Open a window for every non-server buffer related to `erc-session-server'.
6418 All windows are opened in the current frame."
6420 (unless erc-server-process
6421 (error "No erc-server-process found in current buffer"))
6422 (let ((bufs (erc-buffer-list nil erc-server-process)))
6424 (delete-other-windows)
6425 (switch-to-buffer (car bufs))
6426 (setq bufs (cdr bufs))
6430 (switch-to-buffer (car bufs))
6431 (setq bufs (cdr bufs))
6432 (balance-windows)))))
6434 (defun erc-popup-input-buffer ()
6435 "Provide an input buffer."
6437 (let ((buffer-name (generate-new-buffer-name "*ERC input*"))
6442 (list (symbol-name e)))
6443 (apropos-internal "-mode$" 'commandp))
6445 (pop-to-buffer (make-indirect-buffer (current-buffer) buffer-name))
6447 (narrow-to-region (point) (point))
6448 (shrink-window-if-larger-than-buffer)))
6452 (defun erc-make-message-variable-name (catalog entry)
6453 "Create a variable name corresponding to CATALOG's ENTRY."
6454 (intern (concat "erc-message-"
6455 (symbol-name catalog) "-" (symbol-name entry))))
6457 (defun erc-define-catalog-entry (catalog entry format-spec)
6458 "Set CATALOG's ENTRY to FORMAT-SPEC."
6459 (set (erc-make-message-variable-name catalog entry)
6462 (defun erc-define-catalog (catalog entries)
6463 "Define a CATALOG according to ENTRIES."
6464 (dolist (entry entries)
6465 (erc-define-catalog-entry catalog (car entry) (cdr entry))))
6469 '((bad-ping-response . "Unexpected PING response from %n (time %t)")
6470 (bad-syntax . "Error occurred - incorrect usage?\n%c %u\n%d")
6471 (incorrect-args . "Incorrect arguments. Usage:\n%c %u\n%d")
6472 (cannot-find-file . "Cannot find file %f")
6473 (cannot-read-file . "Cannot read file %f")
6474 (connect . "Connecting to %S:%p... ")
6476 (country-unknown . "%d: No such domain")
6477 (ctcp-empty . "Illegal empty CTCP query received from %n. Ignoring.")
6478 (ctcp-request . "==> CTCP request from %n (%u@%h): %r")
6479 (ctcp-request-to . "==> CTCP request from %n (%u@%h) to %t: %r")
6480 (ctcp-too-many . "Too many CTCP queries in single message. Ignoring")
6481 (flood-ctcp-off . "FLOOD PROTECTION: Automatic CTCP responses turned off.")
6483 . "FLOOD PROTECTION: Switched to Strict Flood Control mode.")
6484 (disconnected . "\n\nConnection failed! Re-establishing connection...\n")
6485 (disconnected-noreconnect
6486 . "\n\nConnection failed! Not re-establishing connection.\n")
6487 (finished . "\n\n*** ERC finished ***\n")
6488 (terminated . "\n\n*** ERC terminated: %e\n")
6489 (login . "Logging in as \'%n\'...")
6490 (nick-in-use . "%n is in use. Choose new nickname: ")
6492 . "WARNING: Nick length (%i) exceeds max NICKLEN(%l) defined by server")
6493 (no-default-channel . "No default channel")
6494 (no-invitation . "You've got no invitation")
6495 (no-target . "No target")
6496 (ops . "%i operator%s: %o")
6497 (ops-none . "No operators in this channel.")
6498 (undefined-ctcp . "Undefined CTCP query received. Silently ignored")
6499 (variable-not-bound . "Variable not bound!")
6500 (ACTION . "* %n %a")
6501 (CTCP-CLIENTINFO . "Client info for %n: %m")
6502 (CTCP-ECHO . "Echo %n: %m")
6503 (CTCP-FINGER . "Finger info for %n: %m")
6504 (CTCP-PING . "Ping time to %n is %t")
6505 (CTCP-TIME . "Time by %n is %m")
6506 (CTCP-UNKNOWN . "Unknown CTCP message from %n (%u@%h): %m")
6507 (CTCP-VERSION . "Version for %n is %m")
6508 (ERROR . "==> ERROR from %s: %c\n")
6509 (INVITE . "%n (%u@%h) invites you to channel %c")
6510 (JOIN . "%n (%u@%h) has joined channel %c")
6511 (JOIN-you . "You have joined channel %c")
6512 (KICK . "%n (%u@%h) has kicked %k off channel %c: %r")
6513 (KICK-you . "You have been kicked off channel %c by %n (%u@%h): %r")
6514 (KICK-by-you . "You have kicked %k off channel %c: %r")
6515 (MODE . "%n (%u@%h) has changed mode for %t to %m")
6516 (MODE-nick . "%n has changed mode for %t to %m")
6517 (NICK . "%n (%u@%h) is now known as %N")
6518 (NICK-you . "Your new nickname is %N")
6519 (PART . erc-message-english-PART)
6520 (PING . "PING from server (last: %s sec. ago)")
6521 (PONG . "PONG from %h (%i second%s)")
6522 (QUIT . "%n (%u@%h) has quit: %r")
6523 (TOPIC . "%n (%u@%h) has set the topic for %c: \"%T\"")
6524 (WALLOPS . "Wallops from %n: %m")
6525 (s004 . "%s %v %U %C")
6526 (s221 . "User modes for %n: %m")
6527 (s252 . "%i operator(s) online")
6528 (s253 . "%i unknown connection(s)")
6529 (s254 . "%i channels formed")
6531 (s301 . "%n is AWAY: %r")
6532 (s303 . "Is online: %n")
6536 (s311 . "%n is %f (%u@%h)")
6537 (s312 . "%n is/was on server %s (%c)")
6538 (s313 . "%n is an IRC operator")
6539 (s314 . "%n was %f (%u@%h)")
6540 (s317 . "%n has been idle for %i")
6541 (s317-on-since . "%n has been idle for %i, on since %t")
6542 (s319 . "%n is on channel(s): %c")
6543 (s320 . "%n is an identified user")
6544 (s321 . "Channel Users Topic")
6545 (s322 . "%c [%u] %t")
6546 (s324 . "%c modes: %m")
6547 (s328 . "%c URL: %u")
6548 (s329 . "%c was created on %t")
6550 (s331 . "No topic is set for %c")
6551 (s332 . "Topic for %c: %T")
6552 (s333 . "%c: topic set by %n, %t")
6553 (s341 . "Inviting %n to channel %c")
6554 (s352 . "%-11c %-10n %-4a %u@%h (%f)")
6555 (s353 . "Users on %c: %u")
6556 (s367 . "Ban for %b on %c")
6557 (s367-set-by . "Ban for %b on %c set by %s on %t")
6558 (s368 . "Banlist of %c ends.")
6559 (s379 . "%c: Forwarded to %f")
6560 (s391 . "The time at %s is %t")
6561 (s401 . "%n: No such nick/channel")
6562 (s403 . "%c: No such channel")
6563 (s404 . "%c: Cannot send to channel")
6564 (s405 . "%c: You have joined too many channels")
6565 (s406 . "%n: There was no such nickname")
6566 (s412 . "No text to send")
6567 (s421 . "%c: Unknown command")
6568 (s431 . "No nickname given")
6569 (s432 . "%n is an erroneous nickname")
6570 (s442 . "%c: You're not on that channel")
6571 (s445 . "SUMMON has been disabled")
6572 (s446 . "USERS has been disabled")
6573 (s451 . "You have not registered")
6574 (s461 . "%c: not enough parameters")
6575 (s462 . "Unauthorized command (already registered)")
6576 (s463 . "Your host isn't among the privileged")
6577 (s464 . "Password incorrect")
6578 (s465 . "You are banned from this server")
6579 (s474 . "You can't join %c because you're banned (+b)")
6580 (s475 . "You must specify the correct channel key (+k) to join %c")
6581 (s481 . "Permission Denied - You're not an IRC operator")
6582 (s482 . "You need to be a channel operator of %c to do that")
6583 (s483 . "You can't kill a server!")
6584 (s484 . "Your connection is restricted!")
6585 (s485 . "You're not the original channel operator")
6586 (s491 . "No O-lines for your host")
6587 (s501 . "Unknown MODE flag")
6588 (s502 . "You can't change modes for other users")
6591 (defun erc-message-english-PART (&rest args)
6592 "Format a proper PART message.
6594 This function is an example on what could be done with formatting
6596 (let ((nick (cadr (memq ?n args)))
6597 (user (cadr (memq ?u args)))
6598 (host (cadr (memq ?h args)))
6599 (channel (cadr (memq ?c args)))
6600 (reason (cadr (memq ?r args))))
6601 (if (string= nick (erc-current-nick))
6602 (format "You have left channel %s" channel)
6603 (format "%s (%s@%s) has left channel %s%s"
6604 nick user host channel
6605 (if (not (string= reason ""))
6607 (erc-replace-regexp-in-string "%" "%%" reason))
6611 (defvar erc-current-message-catalog 'english)
6612 (make-variable-buffer-local 'erc-current-message-catalog)
6614 (defun erc-retrieve-catalog-entry (entry &optional catalog)
6615 "Retrieve ENTRY from CATALOG.
6617 If CATALOG is nil, `erc-current-message-catalog' is used.
6619 If ENTRY is nil in CATALOG, it is retrieved from the fallback,
6621 (unless catalog (setq catalog erc-current-message-catalog))
6622 (let ((var (erc-make-message-variable-name catalog entry)))
6625 (when (boundp (erc-make-message-variable-name 'english entry))
6626 (symbol-value (erc-make-message-variable-name 'english entry))))))
6628 (defun erc-format-message (msg &rest args)
6629 "Format MSG according to ARGS.
6631 See also `format-spec'."
6632 (when (eq (logand (length args) 1) 1) ; oddp
6633 (error "Obscure usage of this function appeared"))
6634 (let ((entry (erc-retrieve-catalog-entry msg)))
6636 (error "No format spec for message %s" msg))
6637 (when (functionp entry)
6638 (setq entry (apply entry args)))
6639 (format-spec entry (apply 'format-spec-make args))))
6641 ;;; Various hook functions
6643 (add-hook 'kill-buffer-hook 'erc-kill-buffer-function)
6645 (defcustom erc-kill-server-hook '(erc-kill-server)
6646 "Invoked whenever a server buffer is killed via `kill-buffer'."
6650 (defcustom erc-kill-channel-hook '(erc-kill-channel)
6651 "Invoked whenever a channel-buffer is killed via `kill-buffer'."
6655 (defcustom erc-kill-buffer-hook nil
6656 "Hook run whenever a non-server or channel buffer is killed.
6658 See also `kill-buffer'."
6662 (defun erc-kill-buffer-function ()
6663 "Function to call when an ERC buffer is killed.
6664 This function should be on `kill-buffer-hook'.
6665 When the current buffer is in `erc-mode', this function will run
6666 one of the following hooks:
6667 `erc-kill-server-hook' if the server buffer was killed,
6668 `erc-kill-channel-hook' if a channel buffer was killed,
6669 or `erc-kill-buffer-hook' if any other buffer."
6670 (when (eq major-mode 'erc-mode)
6671 (erc-remove-channel-users)
6673 ((eq (erc-server-buffer) (current-buffer))
6674 (run-hooks 'erc-kill-server-hook))
6675 ((erc-channel-p (erc-default-target))
6676 (run-hooks 'erc-kill-channel-hook))
6678 (run-hooks 'erc-kill-buffer-hook)))))
6680 (defun erc-kill-server ()
6681 "Sends a QUIT command to the server when the server buffer is killed.
6682 This function should be on `erc-kill-server-hook'."
6683 (when (erc-server-process-alive)
6684 (setq erc-server-quitting t)
6685 (erc-server-send (format "QUIT :%s" (funcall erc-quit-reason nil)))))
6687 (defun erc-kill-channel ()
6688 "Sends a PART command to the server when the channel buffer is killed.
6689 This function should be on `erc-kill-channel-hook'."
6690 (when (erc-server-process-alive)
6691 (let ((tgt (erc-default-target)))
6692 (erc-server-send (format "PART %s :%s" tgt
6693 (funcall erc-part-reason nil))
6696 ;;; Dealing with `erc-parsed'
6698 (defun erc-find-parsed-property ()
6699 "Find the next occurrence of the `erc-parsed' text property."
6700 (text-property-not-all (point-min) (point-max) 'erc-parsed nil))
6702 (defun erc-restore-text-properties ()
6703 "Restore the property 'erc-parsed for the region."
6704 (let ((parsed-posn (erc-find-parsed-property)))
6706 (point-min) (point-max)
6707 'erc-parsed (when parsed-posn (erc-get-parsed-vector parsed-posn)))))
6709 (defun erc-get-parsed-vector (point)
6710 "Return the whole parsed vector on POINT."
6711 (get-text-property point 'erc-parsed))
6713 (defun erc-get-parsed-vector-nick (vect)
6714 "Return nickname in the parsed vector VECT."
6715 (let* ((untreated-nick (and vect (erc-response.sender vect)))
6716 (maybe-nick (when untreated-nick
6717 (car (split-string untreated-nick "!")))))
6718 (when (and (not (null maybe-nick))
6719 (erc-is-valid-nick-p maybe-nick))
6722 (defun erc-get-parsed-vector-type (vect)
6723 "Return message type in the parsed vector VECT."
6725 (erc-response.command vect)))
6727 ;; Teach url.el how to open irc:// URLs with ERC.
6728 ;; To activate, customize `url-irc-function' to `url-irc-erc'.
6731 (defun erc-handle-irc-url (host port channel user password)
6732 "Use ERC to IRC on HOST:PORT in CHANNEL as USER with PASSWORD.
6733 If ERC is already connected to HOST:PORT, simply /join CHANNEL.
6734 Otherwise, connect to HOST:PORT as USER and /join CHANNEL."
6735 (let ((server-buffer
6736 (car (erc-buffer-filter
6738 (and (string-equal erc-session-server host)
6739 (= erc-session-port port)
6740 (erc-open-server-buffer-p)))))))
6741 (with-current-buffer (or server-buffer (current-buffer))
6742 (if (and server-buffer channel)
6743 (erc-cmd-JOIN channel)
6744 (erc-open host port (or user (erc-compute-nick)) (erc-compute-full-name)
6745 (not server-buffer) password nil channel
6747 (get-buffer-process server-buffer)))))))
6751 ;; Deprecated. We might eventually stop requiring the goodies automatically.
6752 ;; IMPORTANT: This require must appear _after_ the above (provide 'erc) to
6753 ;; avoid a recursive require error when byte-compiling the entire package.
6754 (require 'erc-goodies)
6756 ;;; erc.el ends here
6759 ;; outline-regexp: ";;+"
6760 ;; indent-tabs-mode: t