Update copyright year to 2015
[emacs.git] / lisp / erc / erc.el
blob7b9a3eb862088ac483896394fd9073e34274af1c
1 ;; erc.el --- An Emacs Internet Relay Chat client -*- lexical-binding:t -*-
3 ;; Copyright (C) 1997-2015 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 (kwhite@gnu.org)
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/>.
32 ;;; Commentary:
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.
45 ;; Installation:
47 ;; Put erc.el in your load-path, and put (require 'erc) in your .emacs.
49 ;; Configuration:
51 ;; Use M-x customize-group RET erc RET to get an overview
52 ;; of all the variables you can tweak.
54 ;; Usage:
56 ;; To connect to an IRC server, do
58 ;; M-x erc RET
60 ;; After you are connected to a server, you can use C-h m or have a look at
61 ;; the ERC menu.
63 ;;; History:
66 (defconst erc-version-string (format "\C-bERC\C-b (IRC client for Emacs %s)" emacs-version)
67 "ERC version. This is used by function `erc-version'.")
69 ;;; Code:
71 (eval-when-compile (require 'cl-lib))
72 (require 'font-lock)
73 (require 'pp)
74 (require 'thingatpt)
75 (require 'auth-source)
76 (require 'erc-compat)
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.")
82 (defgroup erc nil
83 "Emacs Internet Relay Chat client."
84 :link '(url-link "http://www.emacswiki.org/cgi-bin/wiki/ERC")
85 :link '(custom-manual "(erc) Top")
86 :prefix "erc-"
87 :group 'applications)
89 (defgroup erc-buffers nil
90 "Creating new ERC buffers"
91 :group 'erc)
93 (defgroup erc-display nil
94 "Settings for how various things are displayed"
95 :group 'erc)
97 (defgroup erc-mode-line-and-header nil
98 "Displaying information in the mode-line and header"
99 :group 'erc-display)
101 (defgroup erc-ignore nil
102 "Ignoring certain messages"
103 :group 'erc)
105 (defgroup erc-lurker nil
106 "Hide specified message types sent by lurkers"
107 :version "24.3"
108 :group 'erc-ignore)
110 (defgroup erc-query nil
111 "Using separate buffers for private discussions"
112 :group 'erc)
114 (defgroup erc-quit-and-part nil
115 "Quitting and parting channels"
116 :group 'erc)
118 (defgroup erc-paranoia nil
119 "Know what is sent and received; control the display of sensitive data."
120 :group 'erc)
122 (defgroup erc-scripts nil
123 "Running scripts at startup and with /LOAD"
124 :group 'erc)
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."
145 :group 'erc
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."
153 :group 'erc
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."
167 :group 'erc
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."
174 :group 'erc
175 :type 'string)
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."
182 :group 'erc
183 :type 'boolean)
185 (defcustom erc-user-full-name nil
186 "User full name.
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."
192 :group 'erc
193 :type '(choice (const :tag "No name" nil)
194 (string :tag "Name")
195 (function :tag "Get from function"))
196 :set (lambda (sym val)
197 (set sym (if (functionp val) (funcall val) val))))
199 (defcustom erc-rename-buffers nil
200 "When this is set to t, buffers will be renamed to network name if available"
201 :group 'erc
202 :type 'boolean)
204 (defvar erc-password nil
205 "Password to use when authenticating to an IRC server.
206 It is not strictly necessary to provide this, since ERC will
207 prompt you for it.")
209 (defcustom erc-user-mode nil
210 "Initial user modes to be set after a connection is established."
211 :group 'erc
212 :type '(choice (const nil) string function))
215 (defcustom erc-prompt-for-password t
216 "Asks before using the default password, or whether to enter a new one."
217 :group 'erc
218 :type 'boolean)
220 (defcustom erc-warn-about-blank-lines t
221 "Warn the user if they attempt to send a blank line."
222 :group 'erc
223 :type 'boolean)
225 (defcustom erc-send-whitespace-lines nil
226 "If set to non-nil, send lines consisting of only whitespace."
227 :group 'erc
228 :type 'boolean)
230 (defcustom erc-hide-prompt nil
231 "If non-nil, do not display the prompt for commands.
233 \(A command is any input starting with a '/').
235 See also the variables `erc-prompt' and `erc-command-indicator'."
236 :group 'erc-display
237 :type 'boolean)
239 ;; tunable GUI stuff
241 (defcustom erc-show-my-nick t
242 "If non-nil, display one's own nickname when sending a message.
244 If non-nil, \"<nickname>\" will be shown.
245 If nil, only \"> \" will be shown."
246 :group 'erc-display
247 :type 'boolean)
249 (define-widget 'erc-message-type 'set
250 "A set of standard IRC Message types."
251 :args '((const "JOIN")
252 (const "KICK")
253 (const "NICK")
254 (const "PART")
255 (const "QUIT")
256 (const "MODE")
257 (repeat :inline t :tag "Others" (string :tag "IRC Message Type"))))
259 (defcustom erc-hide-list nil
260 "List of IRC type messages to hide.
261 A typical value would be '(\"JOIN\" \"PART\" \"QUIT\")."
262 :group 'erc-ignore
263 :type 'erc-message-type)
265 (defvar erc-session-password nil
266 "The password used for the current session.")
267 (make-variable-buffer-local 'erc-session-password)
269 (defcustom erc-disconnected-hook nil
270 "Run this hook with arguments (NICK IP REASON) when disconnected.
271 This happens before automatic reconnection. Note, that
272 `erc-server-QUIT-functions' might not be run when we disconnect,
273 simply because we do not necessarily receive the QUIT event."
274 :group 'erc-hooks
275 :type 'hook)
277 (defcustom erc-complete-functions nil
278 "These functions get called when the user hits TAB in ERC.
279 Each function in turn is called until one returns non-nil to
280 indicate it has handled the input."
281 :group 'erc-hooks
282 :type 'hook)
284 (defcustom erc-join-hook nil
285 "Hook run when we join a channel. Hook functions are called
286 without arguments, with the current buffer set to the buffer of
287 the new channel.
289 See also `erc-server-JOIN-functions', `erc-part-hook'."
290 :group 'erc-hooks
291 :type 'hook)
293 (defcustom erc-quit-hook nil
294 "Hook run when processing a quit command directed at our nick.
296 The hook receives one argument, the current PROCESS.
297 See also `erc-server-QUIT-functions' and `erc-disconnected-hook'."
298 :group 'erc-hooks
299 :type 'hook)
301 (defcustom erc-part-hook nil
302 "Hook run when processing a PART message directed at our nick.
304 The hook receives one argument, the current BUFFER.
305 See also `erc-server-QUIT-functions', `erc-quit-hook' and
306 `erc-disconnected-hook'."
307 :group 'erc-hooks
308 :type 'hook)
310 (defcustom erc-kick-hook nil
311 "Hook run when processing a KICK message directed at our nick.
313 The hook receives one argument, the current BUFFER.
314 See also `erc-server-PART-functions' and `erc-part-hook'."
315 :group 'erc-hooks
316 :type 'hook)
318 (defcustom erc-nick-changed-functions nil
319 "List of functions run when your nick was successfully changed.
321 Each function should accept two arguments, NEW-NICK and OLD-NICK."
322 :group 'erc-hooks
323 :type 'hook)
325 (defcustom erc-connect-pre-hook '(erc-initialize-log-marker)
326 "Hook called just before `erc' calls `erc-connect'.
327 Functions are passed a buffer as the first argument."
328 :group 'erc-hooks
329 :type 'hook)
332 (defvar erc-channel-users nil
333 "A hash table of members in the current channel, which
334 associates nicknames with cons cells of the form:
335 \(USER . MEMBER-DATA) where USER is a pointer to an
336 erc-server-user struct, and MEMBER-DATA is a pointer to an
337 erc-channel-user struct.")
338 (make-variable-buffer-local 'erc-channel-users)
340 (defvar erc-server-users nil
341 "A hash table of users on the current server, which associates
342 nicknames with erc-server-user struct instances.")
343 (make-variable-buffer-local 'erc-server-users)
345 (defun erc-downcase (string)
346 "Convert STRING to IRC standard conforming downcase."
347 (let ((s (downcase string))
348 (c '((?\[ . ?\{)
349 (?\] . ?\})
350 (?\\ . ?\|)
351 (?~ . ?^))))
352 (save-match-data
353 (while (string-match "[]\\[~]" s)
354 (aset s (match-beginning 0)
355 (cdr (assq (aref s (match-beginning 0)) c)))))
358 (defmacro erc-with-server-buffer (&rest body)
359 "Execute BODY in the current ERC server buffer.
360 If no server buffer exists, return nil."
361 (declare (indent 0) (debug (body)))
362 (let ((buffer (make-symbol "buffer")))
363 `(let ((,buffer (erc-server-buffer)))
364 (when (buffer-live-p ,buffer)
365 (with-current-buffer ,buffer
366 ,@body)))))
368 (cl-defstruct (erc-server-user (:type vector) :named)
369 ;; User data
370 nickname host login full-name info
371 ;; Buffers
373 ;; This is an alist of the form (BUFFER . CHANNEL-DATA), where
374 ;; CHANNEL-DATA is either nil or an erc-channel-user struct.
375 (buffers nil)
378 (cl-defstruct (erc-channel-user (:type vector) :named)
379 voice halfop op admin owner
380 ;; Last message time (in the form of the return value of
381 ;; (current-time)
383 ;; This is useful for ordered name completion.
384 (last-message-time nil))
386 (defsubst erc-get-channel-user (nick)
387 "Find the (USER . CHANNEL-DATA) element corresponding to NICK
388 in the current buffer's `erc-channel-users' hash table."
389 (gethash (erc-downcase nick) erc-channel-users))
391 (defsubst erc-get-server-user (nick)
392 "Find the USER corresponding to NICK in the current server's
393 `erc-server-users' hash table."
394 (erc-with-server-buffer
395 (gethash (erc-downcase nick) erc-server-users)))
397 (defsubst erc-add-server-user (nick user)
398 "This function is for internal use only.
400 Adds USER with nickname NICK to the `erc-server-users' hash table."
401 (erc-with-server-buffer
402 (puthash (erc-downcase nick) user erc-server-users)))
404 (defsubst erc-remove-server-user (nick)
405 "This function is for internal use only.
407 Removes the user with nickname NICK from the `erc-server-users'
408 hash table. This user is not removed from the
409 `erc-channel-users' lists of other buffers.
411 See also: `erc-remove-user'."
412 (erc-with-server-buffer
413 (remhash (erc-downcase nick) erc-server-users)))
415 (defun erc-change-user-nickname (user new-nick)
416 "This function is for internal use only.
418 Changes the nickname of USER to NEW-NICK in the
419 `erc-server-users' hash table. The `erc-channel-users' lists of
420 other buffers are also changed."
421 (let ((nick (erc-server-user-nickname user)))
422 (setf (erc-server-user-nickname user) new-nick)
423 (erc-with-server-buffer
424 (remhash (erc-downcase nick) erc-server-users)
425 (puthash (erc-downcase new-nick) user erc-server-users))
426 (dolist (buf (erc-server-user-buffers user))
427 (if (buffer-live-p buf)
428 (with-current-buffer buf
429 (let ((cdata (erc-get-channel-user nick)))
430 (remhash (erc-downcase nick) erc-channel-users)
431 (puthash (erc-downcase new-nick) cdata
432 erc-channel-users)))))))
434 (defun erc-remove-channel-user (nick)
435 "This function is for internal use only.
437 Removes the user with nickname NICK from the `erc-channel-users'
438 list for this channel. If this user is not in the
439 `erc-channel-users' list of any other buffers, the user is also
440 removed from the server's `erc-server-users' list.
442 See also: `erc-remove-server-user' and `erc-remove-user'."
443 (let ((channel-data (erc-get-channel-user nick)))
444 (when channel-data
445 (let ((user (car channel-data)))
446 (setf (erc-server-user-buffers user)
447 (delq (current-buffer)
448 (erc-server-user-buffers user)))
449 (remhash (erc-downcase nick) erc-channel-users)
450 (if (null (erc-server-user-buffers user))
451 (erc-remove-server-user nick))))))
453 (defun erc-remove-user (nick)
454 "This function is for internal use only.
456 Removes the user with nickname NICK from the `erc-server-users'
457 list as well as from all `erc-channel-users' lists.
459 See also: `erc-remove-server-user' and
460 `erc-remove-channel-user'."
461 (let ((user (erc-get-server-user nick)))
462 (when user
463 (let ((buffers (erc-server-user-buffers user)))
464 (dolist (buf buffers)
465 (if (buffer-live-p buf)
466 (with-current-buffer buf
467 (remhash (erc-downcase nick) erc-channel-users)
468 (run-hooks 'erc-channel-members-changed-hook)))))
469 (erc-remove-server-user nick))))
471 (defun erc-remove-channel-users ()
472 "This function is for internal use only.
474 Removes all users in the current channel. This is called by
475 `erc-server-PART' and `erc-server-QUIT'."
476 (when (and erc-server-connected
477 (erc-server-process-alive)
478 (hash-table-p erc-channel-users))
479 (maphash (lambda (nick _cdata)
480 (erc-remove-channel-user nick))
481 erc-channel-users)
482 (clrhash erc-channel-users)))
484 (defsubst erc-channel-user-owner-p (nick)
485 "Return non-nil if NICK is an owner of the current channel."
486 (and nick
487 (hash-table-p erc-channel-users)
488 (let ((cdata (erc-get-channel-user nick)))
489 (and cdata (cdr cdata)
490 (erc-channel-user-owner (cdr cdata))))))
492 (defsubst erc-channel-user-admin-p (nick)
493 "Return non-nil if NICK is an admin in the current channel."
494 (and nick
495 (hash-table-p erc-channel-users)
496 (let ((cdata (erc-get-channel-user nick)))
497 (and cdata (cdr cdata)
498 (erc-channel-user-admin (cdr cdata))))))
500 (defsubst erc-channel-user-op-p (nick)
501 "Return non-nil if NICK is an operator in the current channel."
502 (and nick
503 (hash-table-p erc-channel-users)
504 (let ((cdata (erc-get-channel-user nick)))
505 (and cdata (cdr cdata)
506 (erc-channel-user-op (cdr cdata))))))
508 (defsubst erc-channel-user-halfop-p (nick)
509 "Return non-nil if NICK is a half-operator in the current channel."
510 (and nick
511 (hash-table-p erc-channel-users)
512 (let ((cdata (erc-get-channel-user nick)))
513 (and cdata (cdr cdata)
514 (erc-channel-user-halfop (cdr cdata))))))
516 (defsubst erc-channel-user-voice-p (nick)
517 "Return non-nil if NICK has voice in the current channel."
518 (and nick
519 (hash-table-p erc-channel-users)
520 (let ((cdata (erc-get-channel-user nick)))
521 (and cdata (cdr cdata)
522 (erc-channel-user-voice (cdr cdata))))))
524 (defun erc-get-channel-user-list ()
525 "Return a list of users in the current channel. Each element
526 of the list is of the form (USER . CHANNEL-DATA), where USER is
527 an erc-server-user struct, and CHANNEL-DATA is either nil or an
528 erc-channel-user struct.
530 See also: `erc-sort-channel-users-by-activity'"
531 (let (users)
532 (if (hash-table-p erc-channel-users)
533 (maphash (lambda (_nick cdata)
534 (setq users (cons cdata users)))
535 erc-channel-users))
536 users))
538 (defun erc-get-server-nickname-list ()
539 "Return a list of known nicknames on the current server."
540 (erc-with-server-buffer
541 (let (nicks)
542 (when (hash-table-p erc-server-users)
543 (maphash (lambda (_n user)
544 (setq nicks
545 (cons (erc-server-user-nickname user)
546 nicks)))
547 erc-server-users)
548 nicks))))
550 (defun erc-get-channel-nickname-list ()
551 "Return a list of known nicknames on the current channel."
552 (let (nicks)
553 (when (hash-table-p erc-channel-users)
554 (maphash (lambda (_n cdata)
555 (setq nicks
556 (cons (erc-server-user-nickname (car cdata))
557 nicks)))
558 erc-channel-users)
559 nicks)))
561 (defun erc-get-server-nickname-alist ()
562 "Return an alist of known nicknames on the current server."
563 (erc-with-server-buffer
564 (let (nicks)
565 (when (hash-table-p erc-server-users)
566 (maphash (lambda (_n user)
567 (setq nicks
568 (cons (cons (erc-server-user-nickname user) nil)
569 nicks)))
570 erc-server-users)
571 nicks))))
573 (defun erc-get-channel-nickname-alist ()
574 "Return an alist of known nicknames on the current channel."
575 (let (nicks)
576 (when (hash-table-p erc-channel-users)
577 (maphash (lambda (_n cdata)
578 (setq nicks
579 (cons (cons (erc-server-user-nickname (car cdata)) nil)
580 nicks)))
581 erc-channel-users)
582 nicks)))
584 (defun erc-sort-channel-users-by-activity (list)
585 "Sort LIST such that users which have spoken most recently are listed first.
586 LIST must be of the form (USER . CHANNEL-DATA).
588 See also: `erc-get-channel-user-list'."
589 (sort list
590 (lambda (x y)
591 (when (and (cdr x) (cdr y))
592 (let ((tx (erc-channel-user-last-message-time (cdr x)))
593 (ty (erc-channel-user-last-message-time (cdr y))))
594 (and tx
595 (or (not ty)
596 (time-less-p ty tx))))))))
598 (defun erc-sort-channel-users-alphabetically (list)
599 "Sort LIST so that users' nicknames are in alphabetical order.
600 LIST must be of the form (USER . CHANNEL-DATA).
602 See also: `erc-get-channel-user-list'."
603 (sort list
604 (lambda (x y)
605 (when (and (cdr x) (cdr y))
606 (let ((nickx (downcase (erc-server-user-nickname (car x))))
607 (nicky (downcase (erc-server-user-nickname (car y)))))
608 (and nickx
609 (or (not nicky)
610 (string-lessp nickx nicky))))))))
612 (defvar erc-channel-topic nil
613 "A topic string for the channel. Should only be used in channel-buffers.")
614 (make-variable-buffer-local 'erc-channel-topic)
616 (defvar erc-channel-modes nil
617 "List of strings representing channel modes.
618 E.g. '(\"i\" \"m\" \"s\" \"b Quake!*@*\")
619 \(not sure the ban list will be here, but why not)")
620 (make-variable-buffer-local 'erc-channel-modes)
622 (defvar erc-insert-marker nil
623 "The place where insertion of new text in erc buffers should happen.")
624 (make-variable-buffer-local 'erc-insert-marker)
626 (defvar erc-input-marker nil
627 "The marker where input should be inserted.")
628 (make-variable-buffer-local 'erc-input-marker)
630 (defun erc-string-no-properties (string)
631 "Return a copy of STRING will all text-properties removed."
632 (let ((newstring (copy-sequence string)))
633 (set-text-properties 0 (length newstring) nil newstring)
634 newstring))
636 (defcustom erc-prompt "ERC>"
637 "Prompt used by ERC. Trailing whitespace is not required."
638 :group 'erc-display
639 :type '(choice string function))
641 (defun erc-prompt ()
642 "Return the input prompt as a string.
644 See also the variable `erc-prompt'."
645 (let ((prompt (if (functionp erc-prompt)
646 (funcall erc-prompt)
647 erc-prompt)))
648 (if (> (length prompt) 0)
649 (concat prompt " ")
650 prompt)))
652 (defcustom erc-command-indicator nil
653 "Indicator used by ERC for showing commands.
655 If non-nil, this will be used in the ERC buffer to indicate
656 commands (i.e., input starting with a '/').
658 If nil, the prompt will be constructed from the variable `erc-prompt'."
659 :group 'erc-display
660 :type '(choice (const nil) string function))
662 (defun erc-command-indicator ()
663 "Return the command indicator prompt as a string.
665 This only has any meaning if the variable `erc-command-indicator' is non-nil."
666 (and erc-command-indicator
667 (let ((prompt (if (functionp erc-command-indicator)
668 (funcall erc-command-indicator)
669 erc-command-indicator)))
670 (if (> (length prompt) 0)
671 (concat prompt " ")
672 prompt))))
674 (defcustom erc-notice-prefix "*** "
675 "Prefix for all notices."
676 :group 'erc-display
677 :type 'string)
679 (defcustom erc-notice-highlight-type 'all
680 "Determines how to highlight notices.
681 See `erc-notice-prefix'.
683 The following values are allowed:
685 'prefix - highlight notice prefix only
686 'all - highlight the entire notice
688 Any other value disables notice's highlighting altogether."
689 :group 'erc-display
690 :type '(choice (const :tag "highlight notice prefix only" prefix)
691 (const :tag "highlight the entire notice" all)
692 (const :tag "don't highlight notices at all" nil)))
694 (defcustom erc-echo-notice-hook nil
695 "List of functions to call to echo a private notice.
696 Each function is called with four arguments, the string
697 to display, the parsed server message, the target buffer (or
698 nil), and the sender. The functions are called in order, until a
699 function evaluates to non-nil. These hooks are called after
700 those specified in `erc-echo-notice-always-hook'.
702 See also: `erc-echo-notice-always-hook',
703 `erc-echo-notice-in-default-buffer',
704 `erc-echo-notice-in-target-buffer',
705 `erc-echo-notice-in-minibuffer',
706 `erc-echo-notice-in-server-buffer',
707 `erc-echo-notice-in-active-non-server-buffer',
708 `erc-echo-notice-in-active-buffer',
709 `erc-echo-notice-in-user-buffers',
710 `erc-echo-notice-in-user-and-target-buffers',
711 `erc-echo-notice-in-first-user-buffer'"
712 :group 'erc-hooks
713 :type 'hook
714 :options '(erc-echo-notice-in-default-buffer
715 erc-echo-notice-in-target-buffer
716 erc-echo-notice-in-minibuffer
717 erc-echo-notice-in-server-buffer
718 erc-echo-notice-in-active-non-server-buffer
719 erc-echo-notice-in-active-buffer
720 erc-echo-notice-in-user-buffers
721 erc-echo-notice-in-user-and-target-buffers
722 erc-echo-notice-in-first-user-buffer))
724 (defcustom erc-echo-notice-always-hook
725 '(erc-echo-notice-in-default-buffer)
726 "List of functions to call to echo a private notice.
727 Each function is called with four arguments, the string
728 to display, the parsed server message, the target buffer (or
729 nil), and the sender. The functions are called in order, and all
730 functions are called. These hooks are called before those
731 specified in `erc-echo-notice-hook'.
733 See also: `erc-echo-notice-hook',
734 `erc-echo-notice-in-default-buffer',
735 `erc-echo-notice-in-target-buffer',
736 `erc-echo-notice-in-minibuffer',
737 `erc-echo-notice-in-server-buffer',
738 `erc-echo-notice-in-active-non-server-buffer',
739 `erc-echo-notice-in-active-buffer',
740 `erc-echo-notice-in-user-buffers',
741 `erc-echo-notice-in-user-and-target-buffers',
742 `erc-echo-notice-in-first-user-buffer'"
743 :group 'erc-hooks
744 :type 'hook
745 :options '(erc-echo-notice-in-default-buffer
746 erc-echo-notice-in-target-buffer
747 erc-echo-notice-in-minibuffer
748 erc-echo-notice-in-server-buffer
749 erc-echo-notice-in-active-non-server-buffer
750 erc-echo-notice-in-active-buffer
751 erc-echo-notice-in-user-buffers
752 erc-echo-notice-in-user-and-target-buffers
753 erc-echo-notice-in-first-user-buffer))
755 ;; other tunable parameters
757 (defcustom erc-whowas-on-nosuchnick nil
758 "If non-nil, do a whowas on a nick if no such nick."
759 :group 'erc
760 :type 'boolean)
762 (defcustom erc-verbose-server-ping nil
763 "If non-nil, show every time you get a PING or PONG from the server."
764 :group 'erc-paranoia
765 :type 'boolean)
767 (defcustom erc-public-away-p nil
768 "Let others know you are back when you are no longer marked away.
769 This happens in this form:
770 * <nick> is back (gone for <time>)
772 Many consider it impolite to do so automatically."
773 :group 'erc
774 :type 'boolean)
776 (defcustom erc-away-nickname nil
777 "The nickname to take when you are marked as being away."
778 :group 'erc
779 :type '(choice (const nil)
780 string))
782 (defcustom erc-paranoid nil
783 "If non-nil, then all incoming CTCP requests will be shown."
784 :group 'erc-paranoia
785 :type 'boolean)
787 (defcustom erc-disable-ctcp-replies nil
788 "Disable replies to CTCP requests that require a reply.
789 If non-nil, then all incoming CTCP requests that normally require
790 an automatic reply (like VERSION or PING) will be ignored. Good to
791 set if some hacker is trying to flood you away."
792 :group 'erc-paranoia
793 :type 'boolean)
795 (defcustom erc-anonymous-login t
796 "Be paranoid, don't give away your machine name."
797 :group 'erc-paranoia
798 :type 'boolean)
800 (defcustom erc-prompt-for-channel-key nil
801 "Prompt for channel key when using `erc-join-channel' interactively."
802 :group 'erc
803 :type 'boolean)
805 (defcustom erc-email-userid "user"
806 "Use this as your email user ID."
807 :group 'erc
808 :type 'string)
810 (defcustom erc-system-name nil
811 "Use this as the name of your system.
812 If nil, ERC will call `system-name' to get this information."
813 :group 'erc
814 :type '(choice (const :tag "Default system name" nil)
815 string))
817 (defcustom erc-ignore-list nil
818 "List of regexps matching user identifiers to ignore.
820 A user identifier has the form \"nick!login@host\". If an
821 identifier matches, the message from the person will not be
822 processed."
823 :group 'erc-ignore
824 :type '(repeat regexp))
825 (make-variable-buffer-local 'erc-ignore-list)
827 (defcustom erc-ignore-reply-list nil
828 "List of regexps matching user identifiers to ignore completely.
830 This differs from `erc-ignore-list' in that it also ignores any
831 messages directed at the user.
833 A user identifier has the form \"nick!login@host\".
835 If an identifier matches, or a message is addressed to a nick
836 whose identifier matches, the message will not be processed.
838 CAVEAT: ERC doesn't know about the user and host of anyone who
839 was already in the channel when you joined, but never said
840 anything, so it won't be able to match the user and host of those
841 people. You can update the ERC internal info using /WHO *."
842 :group 'erc-ignore
843 :type '(repeat regexp))
845 (defvar erc-flood-protect t
846 "If non-nil, flood protection is enabled.
847 Flooding is sending too much information to the server in too
848 short of an interval, which may cause the server to terminate the
849 connection.
851 See `erc-server-flood-margin' for other flood-related parameters.")
853 ;; Script parameters
855 (defcustom erc-startup-file-list
856 (list (concat erc-user-emacs-directory ".ercrc.el")
857 (concat erc-user-emacs-directory ".ercrc")
858 "~/.ercrc.el" "~/.ercrc" ".ercrc.el" ".ercrc")
859 "List of files to try for a startup script.
860 The first existent and readable one will get executed.
862 If the filename ends with `.el' it is presumed to be an Emacs Lisp
863 script and it gets (load)ed. Otherwise it is treated as a bunch of
864 regular IRC commands."
865 :group 'erc-scripts
866 :type '(repeat file))
868 (defcustom erc-script-path nil
869 "List of directories to look for a script in /load command.
870 The script is first searched in the current directory, then in each
871 directory in the list."
872 :group 'erc-scripts
873 :type '(repeat directory))
875 (defcustom erc-script-echo t
876 "If non-nil, echo the IRC script commands locally."
877 :group 'erc-scripts
878 :type 'boolean)
880 (defvar erc-last-saved-position nil
881 "A marker containing the position the current buffer was last saved at.")
882 (make-variable-buffer-local 'erc-last-saved-position)
884 (defcustom erc-kill-buffer-on-part nil
885 "Kill the channel buffer on PART.
886 This variable should probably stay nil, as ERC can reuse buffers if
887 you rejoin them later."
888 :group 'erc-quit-and-part
889 :type 'boolean)
891 (defcustom erc-kill-queries-on-quit nil
892 "Kill all query (also channel) buffers of this server on QUIT.
893 See the variable `erc-kill-buffer-on-part' for details."
894 :group 'erc-quit-and-part
895 :type 'boolean)
897 (defcustom erc-kill-server-buffer-on-quit nil
898 "Kill the server buffer of the process on QUIT."
899 :group 'erc-quit-and-part
900 :type 'boolean)
902 (defcustom erc-quit-reason-various-alist nil
903 "Alist of possible arguments to the /quit command.
905 Each element has the form:
906 (REGEXP RESULT)
908 If REGEXP matches the argument to /quit, then its relevant RESULT
909 will be used. RESULT may be either a string, or a function. If
910 a function, it should return the quit message as a string.
912 If no elements match, then the empty string is used.
914 As an example:
915 (setq erc-quit-reason-various-alist
916 '((\"xmms\" dme:now-playing)
917 (\"version\" erc-quit-reason-normal)
918 (\"home\" \"Gone home !\")
919 (\"^$\" \"Default Reason\")))
920 If the user types \"/quit home\", then \"Gone home !\" will be used
921 as the quit message."
922 :group 'erc-quit-and-part
923 :type '(repeat (list regexp (choice (string) (function)))))
925 (defcustom erc-part-reason-various-alist nil
926 "Alist of possible arguments to the /part command.
928 Each element has the form:
929 (REGEXP RESULT)
931 If REGEXP matches the argument to /part, then its relevant RESULT
932 will be used. RESULT may be either a string, or a function. If
933 a function, it should return the part message as a string.
935 If no elements match, then the empty string is used.
937 As an example:
938 (setq erc-part-reason-various-alist
939 '((\"xmms\" dme:now-playing)
940 (\"version\" erc-part-reason-normal)
941 (\"home\" \"Gone home !\")
942 (\"^$\" \"Default Reason\")))
943 If the user types \"/part home\", then \"Gone home !\" will be used
944 as the part message."
945 :group 'erc-quit-and-part
946 :type '(repeat (list regexp (choice (string) (function)))))
948 (defcustom erc-quit-reason 'erc-quit-reason-normal
949 "A function which returns the reason for quitting.
951 The function is passed a single argument, the string typed by the
952 user after \"/quit\"."
953 :group 'erc-quit-and-part
954 :type '(choice (const erc-quit-reason-normal)
955 (const erc-quit-reason-various)
956 (symbol)))
958 (defcustom erc-part-reason 'erc-part-reason-normal
959 "A function which returns the reason for parting a channel.
961 The function is passed a single argument, the string typed by the
962 user after \"/PART\"."
963 :group 'erc-quit-and-part
964 :type '(choice (const erc-part-reason-normal)
965 (const erc-part-reason-various)
966 (symbol)))
968 (defvar erc-grab-buffer-name "*erc-grab*"
969 "The name of the buffer created by `erc-grab-region'.")
971 ;; variables available for IRC scripts
973 (defvar erc-user-information "ERC User"
974 "USER_INFORMATION IRC variable.")
976 ;; Hooks
978 (defgroup erc-hooks nil
979 "Hook variables for fancy customizations of ERC."
980 :group 'erc)
982 (defcustom erc-mode-hook nil
983 "Hook run after `erc-mode' setup is finished."
984 :group 'erc-hooks
985 :type 'hook
986 :options '(erc-add-scroll-to-bottom))
988 (defcustom erc-timer-hook nil
989 "Put functions which should get called more or less periodically here.
990 The idea is that servers always play ping pong with the client, and so there
991 is no need for any idle-timer games with Emacs."
992 :group 'erc-hooks
993 :type 'hook)
995 (defcustom erc-insert-pre-hook nil
996 "Hook called first when some text is inserted through `erc-display-line'.
997 It gets called with one argument, STRING.
998 To be able to modify the inserted text, use `erc-insert-modify-hook' instead.
999 Filtering functions can set `erc-insert-this' to nil to avoid
1000 display of that particular string at all."
1001 :group 'erc-hooks
1002 :type 'hook)
1004 (defcustom erc-send-pre-hook nil
1005 "Hook called first when some text is sent through `erc-send-current-line'.
1006 It gets called with one argument, STRING.
1008 To change the text that will be sent, set the variable `str' which is
1009 used in `erc-send-current-line'.
1011 To change the text inserted into the buffer without changing the text
1012 that will be sent, use `erc-send-modify-hook' instead.
1014 Filtering functions can set `erc-send-this' to nil to avoid sending of
1015 that particular string at all and `erc-insert-this' to prevent
1016 inserting that particular string into the buffer.
1018 Note that it's useless to set `erc-send-this' to nil and
1019 `erc-insert-this' to t. ERC is sane enough to not insert the text
1020 anyway."
1021 :group 'erc-hooks
1022 :type 'hook)
1024 (defvar erc-insert-this t
1025 "Insert the text into the target buffer or not.
1026 Functions on `erc-insert-pre-hook' can set this variable to nil
1027 if they wish to avoid insertion of a particular string.")
1029 (defvar erc-send-this t
1030 "Send the text to the target or not.
1031 Functions on `erc-send-pre-hook' can set this variable to nil
1032 if they wish to avoid sending of a particular string.")
1034 (defcustom erc-insert-modify-hook ()
1035 "Insertion hook for functions that will change the text's appearance.
1036 This hook is called just after `erc-insert-pre-hook' when the value
1037 of `erc-insert-this' is t.
1038 While this hook is run, narrowing is in effect and `current-buffer' is
1039 the buffer where the text got inserted. One possible value to add here
1040 is `erc-fill'."
1041 :group 'erc-hooks
1042 :type 'hook)
1044 (defcustom erc-insert-post-hook nil
1045 "This hook is called just after `erc-insert-modify-hook'.
1046 At this point, all modifications from prior hook functions are done."
1047 :group 'erc-hooks
1048 :type 'hook
1049 :options '(erc-truncate-buffer
1050 erc-make-read-only
1051 erc-save-buffer-in-logs))
1053 (defcustom erc-send-modify-hook nil
1054 "Sending hook for functions that will change the text's appearance.
1055 This hook is called just after `erc-send-pre-hook' when the values
1056 of `erc-send-this' and `erc-insert-this' are both t.
1057 While this hook is run, narrowing is in effect and `current-buffer' is
1058 the buffer where the text got inserted.
1060 Note that no function in this hook can change the appearance of the
1061 text that is sent. Only changing the sent text's appearance on the
1062 sending user's screen is possible. One possible value to add here
1063 is `erc-fill'."
1064 :group 'erc-hooks
1065 :type 'hook)
1067 (defcustom erc-send-post-hook nil
1068 "This hook is called just after `erc-send-modify-hook'.
1069 At this point, all modifications from prior hook functions are done.
1070 NOTE: The functions on this hook are called _before_ sending a command
1071 to the server.
1073 This function is called with narrowing, ala `erc-send-modify-hook'."
1074 :group 'erc-hooks
1075 :type 'hook
1076 :options '(erc-make-read-only))
1078 (defcustom erc-send-completed-hook
1079 (when (fboundp 'emacspeak-auditory-icon)
1080 (list (byte-compile
1081 (lambda (_str)
1082 (emacspeak-auditory-icon 'select-object)))))
1083 "Hook called after a message has been parsed by ERC.
1085 The single argument to the functions is the unmodified string
1086 which the local user typed."
1087 :group 'erc-hooks
1088 :type 'hook)
1089 ;; mode-specific tables
1091 (defvar erc-mode-syntax-table
1092 (let ((syntax-table (make-syntax-table)))
1093 (modify-syntax-entry ?\" ". " syntax-table)
1094 (modify-syntax-entry ?\\ ". " syntax-table)
1095 (modify-syntax-entry ?' "w " syntax-table)
1096 ;; Make dabbrev-expand useful for nick names
1097 (modify-syntax-entry ?< "." syntax-table)
1098 (modify-syntax-entry ?> "." syntax-table)
1099 syntax-table)
1100 "Syntax table used while in ERC mode.")
1102 (defvar erc-mode-abbrev-table nil
1103 "Abbrev table used while in ERC mode.")
1104 (define-abbrev-table 'erc-mode-abbrev-table ())
1106 (defvar erc-mode-map
1107 (let ((map (make-sparse-keymap)))
1108 (define-key map "\C-m" 'erc-send-current-line)
1109 (define-key map "\C-a" 'erc-bol)
1110 (define-key map [home] 'erc-bol)
1111 (define-key map "\C-c\C-a" 'erc-bol)
1112 (define-key map "\C-c\C-b" 'erc-iswitchb)
1113 (define-key map "\C-c\C-c" 'erc-toggle-interpret-controls)
1114 (define-key map "\C-c\C-d" 'erc-input-action)
1115 (define-key map "\C-c\C-e" 'erc-toggle-ctcp-autoresponse)
1116 (define-key map "\C-c\C-f" 'erc-toggle-flood-control)
1117 (define-key map "\C-c\C-i" 'erc-invite-only-mode)
1118 (define-key map "\C-c\C-j" 'erc-join-channel)
1119 (define-key map "\C-c\C-n" 'erc-channel-names)
1120 (define-key map "\C-c\C-o" 'erc-get-channel-mode-from-keypress)
1121 (define-key map "\C-c\C-p" 'erc-part-from-channel)
1122 (define-key map "\C-c\C-q" 'erc-quit-server)
1123 (define-key map "\C-c\C-r" 'erc-remove-text-properties-region)
1124 (define-key map "\C-c\C-t" 'erc-set-topic)
1125 (define-key map "\C-c\C-u" 'erc-kill-input)
1126 (define-key map "\C-c\C-x" 'erc-quit-server)
1127 (define-key map "\M-\t" 'ispell-complete-word)
1128 (define-key map "\t" 'completion-at-point)
1130 ;; Suppress `font-lock-fontify-block' key binding since it
1131 ;; destroys face properties.
1132 (define-key map [remap font-lock-fontify-block] 'undefined)
1134 map)
1135 "ERC keymap.")
1137 ;; Faces
1139 ; Honestly, I have a horrible sense of color and the "defaults" below
1140 ; are supposed to be really bad. But colors ARE required in IRC to
1141 ; convey different parts of conversation. If you think you know better
1142 ; defaults - send them to me.
1144 ;; Now colors are a bit nicer, at least to my eyes.
1145 ;; You may still want to change them to better fit your background.-- S.B.
1147 (defgroup erc-faces nil
1148 "Faces for ERC."
1149 :group 'erc)
1151 (defface erc-default-face '((t))
1152 "ERC default face."
1153 :group 'erc-faces)
1155 (defface erc-nick-prefix-face '((t :inherit erc-nick-default-face :weight bold))
1156 "ERC face used for user mode prefix."
1157 :group 'erc-faces)
1159 (defface erc-my-nick-prefix-face '((t :inherit erc-nick-default-face :weight bold))
1160 "ERC face used for my user mode prefix."
1161 :group 'erc-faces)
1163 (defface erc-direct-msg-face '((t :foreground "IndianRed"))
1164 "ERC face used for messages you receive in the main erc buffer."
1165 :group 'erc-faces)
1167 (defface erc-header-line
1168 '((t :foreground "grey20" :background "grey90"))
1169 "ERC face used for the header line.
1171 This will only be used if `erc-header-line-face-method' is non-nil."
1172 :group 'erc-faces)
1174 (defface erc-input-face '((t :foreground "brown"))
1175 "ERC face used for your input."
1176 :group 'erc-faces)
1178 (defface erc-prompt-face
1179 '((t :weight bold :foreground "Black" :background "lightBlue2"))
1180 "ERC face for the prompt."
1181 :group 'erc-faces)
1183 (defface erc-command-indicator-face
1184 '((t :weight bold))
1185 "ERC face for the command indicator.
1186 See the variable `erc-command-indicator'."
1187 :group 'erc-faces)
1189 (defface erc-notice-face
1190 '((default :weight bold)
1191 (((class color) (min-colors 88)) :foreground "SlateBlue")
1192 (t :foreground "blue"))
1193 "ERC face for notices."
1194 :group 'erc-faces)
1196 (defface erc-action-face '((t :weight bold))
1197 "ERC face for actions generated by /ME."
1198 :group 'erc-faces)
1200 (defface erc-error-face '((t :foreground "red"))
1201 "ERC face for errors."
1202 :group 'erc-faces)
1204 ;; same default color as `erc-input-face'
1205 (defface erc-my-nick-face '((t :weight bold :foreground "brown"))
1206 "ERC face for your current nickname in messages sent by you.
1207 See also `erc-show-my-nick'."
1208 :group 'erc-faces)
1210 (defface erc-nick-default-face '((t :weight bold))
1211 "ERC nickname default face."
1212 :group 'erc-faces)
1214 (defface erc-nick-msg-face '((t :weight bold :foreground "IndianRed"))
1215 "ERC nickname face for private messages."
1216 :group 'erc-faces)
1218 ;; Debugging support
1220 (defvar erc-log-p nil
1221 "When set to t, generate debug messages in a separate debug buffer.")
1223 (defvar erc-debug-log-file (expand-file-name "ERC.debug")
1224 "Debug log file name.")
1226 (defvar erc-dbuf nil)
1227 (make-variable-buffer-local 'erc-dbuf)
1229 (defmacro define-erc-module (name alias doc enable-body disable-body
1230 &optional local-p)
1231 "Define a new minor mode using ERC conventions.
1232 Symbol NAME is the name of the module.
1233 Symbol ALIAS is the alias to use, or nil.
1234 DOC is the documentation string to use for the minor mode.
1235 ENABLE-BODY is a list of expressions used to enable the mode.
1236 DISABLE-BODY is a list of expressions used to disable the mode.
1237 If LOCAL-P is non-nil, the mode will be created as a buffer-local
1238 mode, rather than a global one.
1240 This will define a minor mode called erc-NAME-mode, possibly
1241 an alias erc-ALIAS-mode, as well as the helper functions
1242 erc-NAME-enable, and erc-NAME-disable.
1244 Example:
1246 ;;;###autoload (autoload 'erc-replace-mode \"erc-replace\")
1247 (define-erc-module replace nil
1248 \"This mode replaces incoming text according to `erc-replace-alist'.\"
1249 ((add-hook 'erc-insert-modify-hook
1250 'erc-replace-insert))
1251 ((remove-hook 'erc-insert-modify-hook
1252 'erc-replace-insert)))"
1253 (declare (doc-string 3))
1254 (let* ((sn (symbol-name name))
1255 (mode (intern (format "erc-%s-mode" (downcase sn))))
1256 (group (intern (format "erc-%s" (downcase sn))))
1257 (enable (intern (format "erc-%s-enable" (downcase sn))))
1258 (disable (intern (format "erc-%s-disable" (downcase sn)))))
1259 `(progn
1260 (erc-define-minor-mode
1261 ,mode
1262 ,(format "Toggle ERC %S mode.
1263 With a prefix argument ARG, enable %s if ARG is positive,
1264 and disable it otherwise. If called from Lisp, enable the mode
1265 if ARG is omitted or nil.
1266 %s" name name doc)
1267 nil nil nil
1268 :global ,(not local-p) :group (quote ,group)
1269 (if ,mode
1270 (,enable)
1271 (,disable)))
1272 (defun ,enable ()
1273 ,(format "Enable ERC %S mode."
1274 name)
1275 (interactive)
1276 (add-to-list 'erc-modules (quote ,name))
1277 (setq ,mode t)
1278 ,@enable-body)
1279 (defun ,disable ()
1280 ,(format "Disable ERC %S mode."
1281 name)
1282 (interactive)
1283 (setq erc-modules (delq (quote ,name) erc-modules))
1284 (setq ,mode nil)
1285 ,@disable-body)
1286 ,(when (and alias (not (eq name alias)))
1287 `(defalias
1288 (quote
1289 ,(intern
1290 (format "erc-%s-mode"
1291 (downcase (symbol-name alias)))))
1292 (quote
1293 ,mode)))
1294 ;; For find-function and find-variable.
1295 (put ',mode 'definition-name ',name)
1296 (put ',enable 'definition-name ',name)
1297 (put ',disable 'definition-name ',name))))
1299 (defun erc-once-with-server-event (event f)
1300 "Run function F the next time EVENT occurs in the `current-buffer'.
1302 You should make sure that `current-buffer' is a server buffer.
1304 This function temporarily adds a function to EVENT's hook to call F with
1305 two arguments (`proc' and `parsed'). After F is called, the function is
1306 removed from EVENT's hook. F should return either nil
1307 or t, where nil indicates that the other functions on EVENT's hook
1308 should be run too, and t indicates that other functions should
1309 not be run.
1311 Please be sure to use this function in server-buffers. In
1312 channel-buffers it may not work at all, as it uses the LOCAL
1313 argument of `add-hook' and `remove-hook' to ensure multiserver
1314 capabilities."
1315 (unless (erc-server-buffer-p)
1316 (error
1317 "You should only run `erc-once-with-server-event' in a server buffer"))
1318 (let ((fun (make-symbol "fun"))
1319 (hook (erc-get-hook event)))
1320 (put fun 'erc-original-buffer (current-buffer))
1321 (fset fun (lambda (proc parsed)
1322 (with-current-buffer (get fun 'erc-original-buffer)
1323 (remove-hook hook fun t))
1324 (fmakunbound fun)
1325 (funcall f proc parsed)))
1326 (add-hook hook fun nil t)
1327 fun))
1329 (defsubst erc-log (string)
1330 "Logs STRING if logging is on (see `erc-log-p')."
1331 (when erc-log-p
1332 (erc-log-aux string)))
1334 (defun erc-server-buffer ()
1335 "Return the server buffer for the current buffer's process.
1336 The buffer-local variable `erc-server-process' is used to find
1337 the process buffer."
1338 (and (erc-server-buffer-live-p)
1339 (process-buffer erc-server-process)))
1341 (defun erc-server-buffer-live-p ()
1342 "Return t if the server buffer has not been killed."
1343 (and (processp erc-server-process)
1344 (buffer-live-p (process-buffer erc-server-process))))
1346 (defun erc-server-buffer-p (&optional buffer)
1347 "Return non-nil if argument BUFFER is an ERC server buffer.
1349 If BUFFER is nil, the current buffer is used."
1350 (with-current-buffer (or buffer (current-buffer))
1351 (and (eq major-mode 'erc-mode)
1352 (null (erc-default-target)))))
1354 (defun erc-open-server-buffer-p (&optional buffer)
1355 "Return non-nil if argument BUFFER is an ERC server buffer that
1356 has an open IRC process.
1358 If BUFFER is nil, the current buffer is used."
1359 (and (erc-server-buffer-p buffer)
1360 (erc-server-process-alive buffer)))
1362 (defun erc-query-buffer-p (&optional buffer)
1363 "Return non-nil if BUFFER is an ERC query buffer.
1364 If BUFFER is nil, the current buffer is used."
1365 (with-current-buffer (or buffer (current-buffer))
1366 (let ((target (erc-default-target)))
1367 (and (eq major-mode 'erc-mode)
1368 target
1369 (not (memq (aref target 0) '(?# ?& ?+ ?!)))))))
1371 (defun erc-ison-p (nick)
1372 "Return non-nil if NICK is online."
1373 (interactive "sNick: ")
1374 (erc-with-server-buffer
1375 (let ((erc-online-p 'unknown))
1376 (erc-once-with-server-event
1378 (lambda (_proc parsed)
1379 (let ((ison (split-string (aref parsed 3))))
1380 (setq erc-online-p (car (erc-member-ignore-case nick ison)))
1381 t)))
1382 (erc-server-send (format "ISON %s" nick))
1383 (while (eq erc-online-p 'unknown) (accept-process-output))
1384 (if (called-interactively-p 'interactive)
1385 (message "%s is %sonline"
1386 (or erc-online-p nick)
1387 (if erc-online-p "" "not "))
1388 erc-online-p))))
1390 (defun erc-log-aux (string)
1391 "Do the debug logging of STRING."
1392 (let ((cb (current-buffer))
1393 (point 1)
1394 (was-eob nil)
1395 (session-buffer (erc-server-buffer)))
1396 (if session-buffer
1397 (progn
1398 (set-buffer session-buffer)
1399 (if (not (and erc-dbuf (bufferp erc-dbuf) (buffer-live-p erc-dbuf)))
1400 (progn
1401 (setq erc-dbuf (get-buffer-create
1402 (concat "*ERC-DEBUG: "
1403 erc-session-server "*")))))
1404 (set-buffer erc-dbuf)
1405 (setq point (point))
1406 (setq was-eob (eobp))
1407 (goto-char (point-max))
1408 (insert (concat "** " string "\n"))
1409 (if was-eob (goto-char (point-max))
1410 (goto-char point))
1411 (set-buffer cb))
1412 (message "ERC: ** %s" string))))
1414 ;; Last active buffer, to print server messages in the right place
1416 (defvar erc-active-buffer nil
1417 "The current active buffer, the one where the user typed the last command.
1418 Defaults to the server buffer, and should only be set in the
1419 server buffer.")
1420 (make-variable-buffer-local 'erc-active-buffer)
1422 (defun erc-active-buffer ()
1423 "Return the value of `erc-active-buffer' for the current server.
1424 Defaults to the server buffer."
1425 (erc-with-server-buffer
1426 (if (buffer-live-p erc-active-buffer)
1427 erc-active-buffer
1428 (setq erc-active-buffer (current-buffer)))))
1430 (defun erc-set-active-buffer (buffer)
1431 "Set the value of `erc-active-buffer' to BUFFER."
1432 (cond ((erc-server-buffer)
1433 (with-current-buffer (erc-server-buffer)
1434 (setq erc-active-buffer buffer)))
1435 (t (setq erc-active-buffer buffer))))
1437 ;; Mode activation routines
1439 (define-derived-mode erc-mode fundamental-mode "ERC"
1440 "Major mode for Emacs IRC."
1441 (setq local-abbrev-table erc-mode-abbrev-table)
1442 (when (boundp 'next-line-add-newlines)
1443 (set (make-local-variable 'next-line-add-newlines) nil))
1444 (setq line-move-ignore-invisible t)
1445 (set (make-local-variable 'paragraph-separate)
1446 (concat "\C-l\\|\\(^" (regexp-quote (erc-prompt)) "\\)"))
1447 (set (make-local-variable 'paragraph-start)
1448 (concat "\\(" (regexp-quote (erc-prompt)) "\\)"))
1449 (add-hook 'completion-at-point-functions 'erc-complete-word-at-point nil t))
1451 ;; activation
1453 (defconst erc-default-server "irc.freenode.net"
1454 "IRC server to use if it cannot be detected otherwise.")
1456 (defconst erc-default-port 6667
1457 "IRC port to use if it cannot be detected otherwise.")
1459 (defcustom erc-join-buffer 'buffer
1460 "Determines how to display a newly created IRC buffer.
1462 The available choices are:
1464 'window - in another window,
1465 'window-noselect - in another window, but don't select that one,
1466 'frame - in another frame,
1467 'bury - bury it in a new buffer,
1468 'buffer - in place of the current buffer,
1469 any other value - in place of the current buffer."
1470 :group 'erc-buffers
1471 :type '(choice (const :tag "Split window and select" window)
1472 (const :tag "Split window, don't select" window-noselect)
1473 (const :tag "New frame" frame)
1474 (const :tag "Bury in new buffer" bury)
1475 (const :tag "Use current buffer" buffer)
1476 (const :tag "Use current buffer" t)))
1478 (defcustom erc-frame-alist nil
1479 "Alist of frame parameters for creating erc frames.
1480 A value of nil means to use `default-frame-alist'."
1481 :group 'erc-buffers
1482 :type '(repeat (cons :format "%v"
1483 (symbol :tag "Parameter")
1484 (sexp :tag "Value"))))
1486 (defcustom erc-frame-dedicated-flag nil
1487 "Non-nil means the erc frames are dedicated to that buffer.
1488 This only has effect when `erc-join-buffer' is set to `frame'."
1489 :group 'erc-buffers
1490 :type 'boolean)
1492 (defcustom erc-reuse-frames t
1493 "Determines whether new frames are always created.
1494 Non-nil means that a new frame is not created to display an ERC
1495 buffer if there is already a window displaying it. This only has
1496 effect when `erc-join-buffer' is set to `frame'."
1497 :group 'erc-buffers
1498 :type 'boolean)
1500 (defun erc-channel-p (channel)
1501 "Return non-nil if CHANNEL seems to be an IRC channel name."
1502 (cond ((stringp channel)
1503 (memq (aref channel 0) '(?# ?& ?+ ?!)))
1504 ((and (bufferp channel) (buffer-live-p channel))
1505 (with-current-buffer channel
1506 (erc-channel-p (erc-default-target))))
1507 (t nil)))
1509 (defcustom erc-reuse-buffers t
1510 "If nil, create new buffers on joining a channel/query.
1511 If non-nil, a new buffer will only be created when you join
1512 channels with same names on different servers, or have query buffers
1513 open with nicks of the same name on different servers. Otherwise,
1514 the existing buffers will be reused."
1515 :group 'erc-buffers
1516 :type 'boolean)
1518 (defun erc-normalize-port (port)
1519 "Normalize the port specification PORT to integer form.
1520 PORT may be an integer, a string or a symbol. If it is a string or a
1521 symbol, it may have these values:
1522 * irc -> 194
1523 * ircs -> 994
1524 * ircd -> 6667
1525 * ircd-dalnet -> 7000"
1526 (cond
1527 ((symbolp port)
1528 (erc-normalize-port (symbol-name port)))
1529 ((stringp port)
1530 (let ((port-nr (string-to-number port)))
1531 (cond
1532 ((> port-nr 0)
1533 port-nr)
1534 ((string-equal port "irc")
1535 194)
1536 ((string-equal port "ircs")
1537 994)
1538 ((string-equal port "ircd")
1539 6667)
1540 ((string-equal port "ircd-dalnet")
1541 7000)
1543 nil))))
1544 ((numberp port)
1545 port)
1547 nil)))
1549 (defun erc-port-equal (a b)
1550 "Check whether ports A and B are equal."
1551 (= (erc-normalize-port a) (erc-normalize-port b)))
1553 (defun erc-generate-new-buffer-name (server port target)
1554 "Create a new buffer name based on the arguments."
1555 (when (numberp port) (setq port (number-to-string port)))
1556 (let ((buf-name (or target
1557 (or (let ((name (concat server ":" port)))
1558 (when (> (length name) 1)
1559 name))
1560 ;; This fallback should in fact never happen
1561 "*erc-server-buffer*")))
1562 buffer-name)
1563 ;; Reuse existing buffers, but not if the buffer is a connected server
1564 ;; buffer and not if its associated with a different server than the
1565 ;; current ERC buffer.
1566 ;; if buf-name is taken by a different connection (or by something !erc)
1567 ;; then see if "buf-name/server" meets the same criteria
1568 (dolist (candidate (list buf-name (concat buf-name "/" server)))
1569 (if (and (not buffer-name)
1570 erc-reuse-buffers
1571 (get-buffer candidate)
1572 (or target
1573 (with-current-buffer (get-buffer candidate)
1574 (and (erc-server-buffer-p)
1575 (not (erc-server-process-alive)))))
1576 (with-current-buffer (get-buffer candidate)
1577 (and (string= erc-session-server server)
1578 (erc-port-equal erc-session-port port))))
1579 (setq buffer-name candidate)))
1580 ;; if buffer-name is unset, neither candidate worked out for us,
1581 ;; fallback to the old <N> uniquification method:
1582 (or buffer-name (generate-new-buffer-name buf-name)) ))
1584 (defun erc-get-buffer-create (server port target)
1585 "Create a new buffer based on the arguments."
1586 (get-buffer-create (erc-generate-new-buffer-name server port target)))
1589 (defun erc-member-ignore-case (string list)
1590 "Return non-nil if STRING is a member of LIST.
1592 All strings are compared according to IRC protocol case rules, see
1593 `erc-downcase'."
1594 (setq string (erc-downcase string))
1595 (catch 'result
1596 (while list
1597 (if (string= string (erc-downcase (car list)))
1598 (throw 'result list)
1599 (setq list (cdr list))))))
1601 (defmacro erc-with-buffer (spec &rest body)
1602 "Execute BODY in the buffer associated with SPEC.
1604 SPEC should have the form
1606 (TARGET [PROCESS])
1608 If TARGET is a buffer, use it. Otherwise, use the buffer
1609 matching TARGET in the process specified by PROCESS.
1611 If PROCESS is nil, use the current `erc-server-process'.
1612 See `erc-get-buffer' for details.
1614 See also `with-current-buffer'.
1616 \(fn (TARGET [PROCESS]) BODY...)"
1617 (declare (indent 1) (debug ((form &optional form) body)))
1618 (let ((buf (make-symbol "buf"))
1619 (proc (make-symbol "proc"))
1620 (target (make-symbol "target"))
1621 (process (make-symbol "process")))
1622 `(let* ((,target ,(car spec))
1623 (,process ,(cadr spec))
1624 (,buf (if (bufferp ,target)
1625 ,target
1626 (let ((,proc (or ,process
1627 (and (processp erc-server-process)
1628 erc-server-process))))
1629 (if (and ,target ,proc)
1630 (erc-get-buffer ,target ,proc))))))
1631 (when (buffer-live-p ,buf)
1632 (with-current-buffer ,buf
1633 ,@body)))))
1635 (defun erc-get-buffer (target &optional proc)
1636 "Return the buffer matching TARGET in the process PROC.
1637 If PROC is not supplied, all processes are searched."
1638 (let ((downcased-target (erc-downcase target)))
1639 (catch 'buffer
1640 (erc-buffer-filter
1641 (lambda ()
1642 (let ((current (erc-default-target)))
1643 (and (stringp current)
1644 (string-equal downcased-target (erc-downcase current))
1645 (throw 'buffer (current-buffer)))))
1646 proc))))
1648 (defun erc-buffer-filter (predicate &optional proc)
1649 "Return a list of `erc-mode' buffers matching certain criteria.
1650 PREDICATE is a function executed with each buffer, if it returns t, that buffer
1651 is considered a valid match.
1653 PROC is either an `erc-server-process', identifying a certain
1654 server connection, or nil which means all open connections."
1655 (save-excursion
1656 (delq
1658 (mapcar (lambda (buf)
1659 (when (buffer-live-p buf)
1660 (with-current-buffer buf
1661 (and (eq major-mode 'erc-mode)
1662 (or (not proc)
1663 (eq proc erc-server-process))
1664 (funcall predicate)
1665 buf))))
1666 (buffer-list)))))
1668 (defun erc-buffer-list (&optional predicate proc)
1669 "Return a list of ERC buffers.
1670 PREDICATE is a function which executes with every buffer satisfying
1671 the predicate. If PREDICATE is passed as nil, return a list of all ERC
1672 buffers. If PROC is given, the buffers local variable `erc-server-process'
1673 needs to match PROC."
1674 (unless predicate
1675 (setq predicate (lambda () t)))
1676 (erc-buffer-filter predicate proc))
1678 (defmacro erc-with-all-buffers-of-server (process pred &rest forms)
1679 "Execute FORMS in all buffers which have same process as this server.
1680 FORMS will be evaluated in all buffers having the process PROCESS and
1681 where PRED matches or in all buffers of the server process if PRED is
1682 nil."
1683 (declare (indent 1) (debug (form form body)))
1684 ;; Make the evaluation have the correct order
1685 (let ((pre (make-symbol "pre"))
1686 (pro (make-symbol "pro")))
1687 `(let* ((,pro ,process)
1688 (,pre ,pred)
1689 (res (mapcar (lambda (buffer)
1690 (with-current-buffer buffer
1691 ,@forms))
1692 (erc-buffer-list ,pre
1693 ,pro))))
1694 ;; Silence the byte-compiler by binding the result of mapcar to
1695 ;; a variable.
1696 res)))
1698 ;; (iswitchb-mode) will autoload iswitchb.el
1699 (defvar iswitchb-temp-buflist)
1700 (declare-function iswitchb-read-buffer "iswitchb"
1701 (prompt &optional default require-match start matches-set))
1702 (defvar iswitchb-make-buflist-hook)
1704 (defun erc-iswitchb (&optional arg)
1705 "Use `iswitchb-read-buffer' to prompt for a ERC buffer to switch to.
1706 When invoked with prefix argument, use all erc buffers. Without prefix
1707 ARG, allow only buffers related to same session server.
1708 If `erc-track-mode' is in enabled, put the last element of
1709 `erc-modified-channels-alist' in front of the buffer list.
1711 Due to some yet unresolved reason, global function `iswitchb-mode'
1712 needs to be active for this function to work."
1713 (interactive "P")
1714 (let ((enabled (bound-and-true-p iswitchb-mode)))
1715 (or enabled (iswitchb-mode 1))
1716 (unwind-protect
1717 (let ((iswitchb-make-buflist-hook
1718 (lambda ()
1719 (setq iswitchb-temp-buflist
1720 (mapcar 'buffer-name
1721 (erc-buffer-list
1723 (when arg erc-server-process)))))))
1724 (switch-to-buffer
1725 (iswitchb-read-buffer
1726 "Switch-to: "
1727 (if (boundp 'erc-modified-channels-alist)
1728 (buffer-name (caar (last erc-modified-channels-alist)))
1729 nil)
1730 t)))
1731 (or enabled (iswitchb-mode -1)))))
1733 (defun erc-channel-list (proc)
1734 "Return a list of channel buffers.
1735 PROC is the process for the server connection. If PROC is nil, return
1736 all channel buffers on all servers."
1737 (erc-buffer-filter
1738 (lambda ()
1739 (and (erc-default-target)
1740 (erc-channel-p (erc-default-target))))
1741 proc))
1743 (defun erc-buffer-list-with-nick (nick proc)
1744 "Return buffers containing NICK in the `erc-channel-users' list."
1745 (with-current-buffer (process-buffer proc)
1746 (let ((user (gethash (erc-downcase nick) erc-server-users)))
1747 (if user
1748 (erc-server-user-buffers user)
1749 nil))))
1751 ;; Some local variables
1753 (defvar erc-default-recipients nil
1754 "List of default recipients of the current buffer.")
1755 (make-variable-buffer-local 'erc-default-recipients)
1757 (defvar erc-session-user-full-name nil
1758 "Full name of the user on the current server.")
1759 (make-variable-buffer-local 'erc-session-user-full-name)
1761 (defvar erc-channel-user-limit nil
1762 "Limit of users per channel.")
1763 (make-variable-buffer-local 'erc-channel-user-limit)
1765 (defvar erc-channel-key nil
1766 "Key needed to join channel.")
1767 (make-variable-buffer-local 'erc-channel-key)
1769 (defvar erc-invitation nil
1770 "Last invitation channel.")
1771 (make-variable-buffer-local 'erc-invitation)
1773 (defvar erc-away nil
1774 "Non-nil indicates that we are away.
1776 Use `erc-away-time' to access this if you might be in a channel
1777 buffer rather than a server buffer.")
1778 (make-variable-buffer-local 'erc-away)
1780 (defvar erc-channel-list nil
1781 "Server channel list.")
1782 (make-variable-buffer-local 'erc-channel-list)
1784 (defvar erc-bad-nick nil
1785 "Non-nil indicates that we got a `nick in use' error while connecting.")
1786 (make-variable-buffer-local 'erc-bad-nick)
1788 (defvar erc-logged-in nil
1789 "Non-nil indicates that we are logged in.")
1790 (make-variable-buffer-local 'erc-logged-in)
1792 (defvar erc-default-nicks nil
1793 "The local copy of `erc-nick' - the list of nicks to choose from.")
1794 (make-variable-buffer-local 'erc-default-nicks)
1796 (defvar erc-nick-change-attempt-count 0
1797 "Used to keep track of how many times an attempt at changing nick is made.")
1798 (make-variable-buffer-local 'erc-nick-change-attempt-count)
1800 (defun erc-migrate-modules (mods)
1801 "Migrate old names of ERC modules to new ones."
1802 ;; modify `transforms' to specify what needs to be changed
1803 ;; each item is in the format '(old . new)
1804 (let ((transforms '((pcomplete . completion))))
1805 (erc-delete-dups
1806 (mapcar (lambda (m) (or (cdr (assoc m transforms)) m))
1807 mods))))
1809 (defcustom erc-modules '(netsplit fill button match track completion readonly
1810 networks ring autojoin noncommands irccontrols
1811 move-to-prompt stamp menu list)
1812 "A list of modules which ERC should enable.
1813 If you set the value of this without using `customize' remember to call
1814 \(erc-update-modules) after you change it. When using `customize', modules
1815 removed from the list will be disabled."
1816 :get (lambda (sym)
1817 ;; replace outdated names with their newer equivalents
1818 (erc-migrate-modules (symbol-value sym)))
1819 :set (lambda (sym val)
1820 ;; disable modules which have just been removed
1821 (when (and (boundp 'erc-modules) erc-modules val)
1822 (dolist (module erc-modules)
1823 (unless (member module val)
1824 (let ((f (intern-soft (format "erc-%s-mode" module))))
1825 (when (and (fboundp f) (boundp f) (symbol-value f))
1826 (message "Disabling `erc-%s'" module)
1827 (funcall f 0))))))
1828 (set sym val)
1829 ;; this test is for the case where erc hasn't been loaded yet
1830 (when (fboundp 'erc-update-modules)
1831 (erc-update-modules)))
1832 :type
1833 '(set
1834 :greedy t
1835 (const :tag "autoaway: Set away status automatically" autoaway)
1836 (const :tag "autojoin: Join channels automatically" autojoin)
1837 (const :tag "button: Buttonize URLs, nicknames, and other text" button)
1838 (const :tag "capab: Mark unidentified users on servers supporting CAPAB"
1839 capab-identify)
1840 (const :tag "completion: Complete nicknames and commands (programmable)"
1841 completion)
1842 (const :tag "hecomplete: Complete nicknames and commands (obsolete, use \"completion\")" hecomplete)
1843 (const :tag "dcc: Provide Direct Client-to-Client support" dcc)
1844 (const :tag "fill: Wrap long lines" fill)
1845 (const :tag "identd: Launch an identd server on port 8113" identd)
1846 (const :tag "irccontrols: Highlight or remove IRC control characters"
1847 irccontrols)
1848 (const :tag "keep-place: Leave point above un-viewed text" keep-place)
1849 (const :tag "list: List channels in a separate buffer" list)
1850 (const :tag "log: Save buffers in logs" log)
1851 (const :tag "match: Highlight pals, fools, and other keywords" match)
1852 (const :tag "menu: Display a menu in ERC buffers" menu)
1853 (const :tag "move-to-prompt: Move to the prompt when typing text"
1854 move-to-prompt)
1855 (const :tag "netsplit: Detect netsplits" netsplit)
1856 (const :tag "networks: Provide data about IRC networks" networks)
1857 (const :tag "noncommands: Don't display non-IRC commands after evaluation"
1858 noncommands)
1859 (const :tag
1860 "notify: Notify when the online status of certain users changes"
1861 notify)
1862 (const :tag "notifications: Send notifications on PRIVMSG or nickname mentions"
1863 notifications)
1864 (const :tag "page: Process CTCP PAGE requests from IRC" page)
1865 (const :tag "readonly: Make displayed lines read-only" readonly)
1866 (const :tag "replace: Replace text in messages" replace)
1867 (const :tag "ring: Enable an input history" ring)
1868 (const :tag "scrolltobottom: Scroll to the bottom of the buffer"
1869 scrolltobottom)
1870 (const :tag "services: Identify to Nickserv (IRC Services) automatically"
1871 services)
1872 (const :tag "smiley: Convert smileys to pretty icons" smiley)
1873 (const :tag "sound: Play sounds when you receive CTCP SOUND requests"
1874 sound)
1875 (const :tag "stamp: Add timestamps to messages" stamp)
1876 (const :tag "spelling: Check spelling" spelling)
1877 (const :tag "track: Track channel activity in the mode-line" track)
1878 (const :tag "truncate: Truncate buffers to a certain size" truncate)
1879 (const :tag "unmorse: Translate morse code in messages" unmorse)
1880 (const :tag "xdcc: Act as an XDCC file-server" xdcc)
1881 (repeat :tag "Others" :inline t symbol))
1882 :group 'erc)
1884 (defun erc-update-modules ()
1885 "Run this to enable erc-foo-mode for all modules in `erc-modules'."
1886 (let (req)
1887 (dolist (mod erc-modules)
1888 (setq req (concat "erc-" (symbol-name mod)))
1889 (cond
1890 ;; yuck. perhaps we should bring the filenames into sync?
1891 ((string= req "erc-capab-identify")
1892 (setq req "erc-capab"))
1893 ((string= req "erc-completion")
1894 (setq req "erc-pcomplete"))
1895 ((string= req "erc-pcomplete")
1896 (setq mod 'completion))
1897 ((string= req "erc-autojoin")
1898 (setq req "erc-join")))
1899 (condition-case nil
1900 (require (intern req))
1901 (error nil))
1902 (let ((sym (intern-soft (concat "erc-" (symbol-name mod) "-mode"))))
1903 (if (fboundp sym)
1904 (funcall sym 1)
1905 (error "`%s' is not a known ERC module" mod))))))
1907 (defun erc-setup-buffer (buffer)
1908 "Consults `erc-join-buffer' to find out how to display `BUFFER'."
1909 (pcase erc-join-buffer
1910 (`window
1911 (if (active-minibuffer-window)
1912 (display-buffer buffer)
1913 (switch-to-buffer-other-window buffer)))
1914 (`window-noselect
1915 (display-buffer buffer))
1916 (`bury
1917 nil)
1918 (`frame
1919 (when (or (not erc-reuse-frames)
1920 (not (get-buffer-window buffer t)))
1921 (let ((frame (make-frame (or erc-frame-alist
1922 default-frame-alist))))
1923 (raise-frame frame)
1924 (select-frame frame))
1925 (switch-to-buffer buffer)
1926 (when erc-frame-dedicated-flag
1927 (set-window-dedicated-p (selected-window) t))))
1929 (if (active-minibuffer-window)
1930 (display-buffer buffer)
1931 (switch-to-buffer buffer)))))
1933 (defun erc-open (&optional server port nick full-name
1934 connect passwd tgt-list channel process)
1935 "Connect to SERVER on PORT as NICK with FULL-NAME.
1937 If CONNECT is non-nil, connect to the server. Otherwise assume
1938 already connected and just create a separate buffer for the new
1939 target CHANNEL.
1941 Use PASSWD as user password on the server. If TGT-LIST is
1942 non-nil, use it to initialize `erc-default-recipients'.
1944 Returns the buffer for the given server or channel."
1945 (let ((server-announced-name (when (and (boundp 'erc-session-server)
1946 (string= server erc-session-server))
1947 erc-server-announced-name))
1948 (connected-p (unless connect erc-server-connected))
1949 (buffer (erc-get-buffer-create server port channel))
1950 (old-buffer (current-buffer))
1951 old-point
1952 continued-session)
1953 (when connect (run-hook-with-args 'erc-before-connect server port nick))
1954 (erc-update-modules)
1955 (set-buffer buffer)
1956 (setq old-point (point))
1957 (erc-mode)
1958 (setq erc-server-announced-name server-announced-name)
1959 (setq erc-server-connected connected-p)
1960 ;; connection parameters
1961 (setq erc-server-process process)
1962 (setq erc-insert-marker (make-marker))
1963 (setq erc-input-marker (make-marker))
1964 ;; go to the end of the buffer and open a new line
1965 ;; (the buffer may have existed)
1966 (goto-char (point-max))
1967 (forward-line 0)
1968 (when (get-text-property (point) 'erc-prompt)
1969 (setq continued-session t)
1970 (set-marker erc-input-marker
1971 (or (next-single-property-change (point) 'erc-prompt)
1972 (point-max))))
1973 (unless continued-session
1974 (goto-char (point-max))
1975 (insert "\n"))
1976 (set-marker erc-insert-marker (point))
1977 ;; stack of default recipients
1978 (setq erc-default-recipients tgt-list)
1979 (setq erc-server-current-nick nil)
1980 ;; Initialize erc-server-users and erc-channel-users
1981 (if connect
1982 (progn ;; server buffer
1983 (setq erc-server-users
1984 (make-hash-table :test 'equal))
1985 (setq erc-channel-users nil))
1986 (progn ;; target buffer
1987 (setq erc-server-users nil)
1988 (setq erc-channel-users
1989 (make-hash-table :test 'equal))))
1990 ;; clear last incomplete line read
1991 (setq erc-server-filter-data nil)
1992 (setq erc-channel-topic "")
1993 ;; limit on the number of users on the channel (mode +l)
1994 (setq erc-channel-user-limit nil)
1995 (setq erc-channel-key nil)
1996 ;; last active buffer, defaults to this one
1997 (erc-set-active-buffer buffer)
1998 ;; last invitation channel
1999 (setq erc-invitation nil)
2000 ;; Server channel list
2001 (setq erc-channel-list ())
2002 ;; login-time 'nick in use' error
2003 (setq erc-bad-nick nil)
2004 ;; whether we have logged in
2005 (setq erc-logged-in nil)
2006 ;; The local copy of `erc-nick' - the list of nicks to choose
2007 (setq erc-default-nicks (if (consp erc-nick) erc-nick (list erc-nick)))
2008 ;; password stuff
2009 (setq erc-session-password
2010 (or passwd
2011 (let ((secret
2012 (plist-get
2013 (nth 0
2014 (auth-source-search :host server
2015 :max 1
2016 :user nick
2017 :port port
2018 :require '(:secret)))
2019 :secret)))
2020 (if (functionp secret)
2021 (funcall secret)
2022 secret))))
2023 ;; debug output buffer
2024 (setq erc-dbuf
2025 (when erc-log-p
2026 (get-buffer-create (concat "*ERC-DEBUG: " server "*"))))
2027 ;; set up prompt
2028 (unless continued-session
2029 (goto-char (point-max))
2030 (insert "\n"))
2031 (if continued-session
2032 (goto-char old-point)
2033 (set-marker erc-insert-marker (point))
2034 (erc-display-prompt)
2035 (goto-char (point-max)))
2037 (erc-determine-parameters server port nick full-name)
2039 ;; Saving log file on exit
2040 (run-hook-with-args 'erc-connect-pre-hook buffer)
2042 (when connect
2043 (erc-server-connect erc-session-server erc-session-port buffer))
2044 (erc-update-mode-line)
2046 ;; Now display the buffer in a window as per user wishes.
2047 (unless (eq buffer old-buffer)
2048 (when erc-log-p
2049 ;; we can't log to debug buffer, it may not exist yet
2050 (message "erc: old buffer %s, switching to %s"
2051 old-buffer buffer))
2052 (erc-setup-buffer buffer))
2054 buffer))
2056 (defun erc-initialize-log-marker (buffer)
2057 "Initialize the `erc-last-saved-position' marker to a sensible position.
2058 BUFFER is the current buffer."
2059 (with-current-buffer buffer
2060 (unless (markerp erc-last-saved-position)
2061 (setq erc-last-saved-position (make-marker))
2062 (move-marker erc-last-saved-position
2063 (1- (marker-position erc-insert-marker))))))
2065 ;; interactive startup
2067 (defvar erc-server-history-list nil
2068 "IRC server interactive selection history list.")
2070 (defvar erc-nick-history-list nil
2071 "Nickname interactive selection history list.")
2073 (defun erc-already-logged-in (server port nick)
2074 "Return the buffers corresponding to a NICK on PORT of a session SERVER.
2075 This is determined by looking for the appropriate buffer and checking
2076 whether the connection is still alive.
2077 If no buffer matches, return nil."
2078 (erc-buffer-list
2079 (lambda ()
2080 (and (erc-server-process-alive)
2081 (string= erc-session-server server)
2082 (erc-port-equal erc-session-port port)
2083 (erc-current-nick-p nick)))))
2085 (defcustom erc-before-connect nil
2086 "Hook called before connecting to a server.
2087 This hook gets executed before `erc' actually invokes `erc-mode'
2088 with your input data. The functions in here get called with three
2089 parameters, SERVER, PORT and NICK."
2090 :group 'erc-hooks
2091 :type 'hook)
2093 (defcustom erc-after-connect nil
2094 "Hook called after connecting to a server.
2095 This hook gets executed when an end of MOTD has been received. All
2096 functions in here get called with the parameters SERVER and NICK."
2097 :group 'erc-hooks
2098 :type 'hook)
2100 ;;;###autoload
2101 (defun erc-select-read-args ()
2102 "Prompt the user for values of nick, server, port, and password."
2103 (let (user-input server port nick passwd)
2104 (setq user-input (read-from-minibuffer
2105 "IRC server: "
2106 (erc-compute-server) nil nil 'erc-server-history-list))
2108 (if (string-match "\\(.*\\):\\(.*\\)\\'" user-input)
2109 (setq port (erc-string-to-port (match-string 2 user-input))
2110 user-input (match-string 1 user-input))
2111 (setq port
2112 (erc-string-to-port (read-from-minibuffer
2113 "IRC port: " (erc-port-to-string
2114 (erc-compute-port))))))
2116 (if (string-match "\\`\\(.*\\)@\\(.*\\)" user-input)
2117 (setq nick (match-string 1 user-input)
2118 user-input (match-string 2 user-input))
2119 (setq nick
2120 (if (erc-already-logged-in server port nick)
2121 (read-from-minibuffer
2122 (erc-format-message 'nick-in-use ?n nick)
2123 nick
2124 nil nil 'erc-nick-history-list)
2125 (read-from-minibuffer
2126 "Nickname: " (erc-compute-nick nick)
2127 nil nil 'erc-nick-history-list))))
2129 (setq server user-input)
2131 (setq passwd (if erc-prompt-for-password
2132 (if (and erc-password
2133 (y-or-n-p "Use the default password? "))
2134 erc-password
2135 (read-passwd "Password: "))
2136 erc-password))
2137 (when (and passwd (string= "" passwd))
2138 (setq passwd nil))
2140 (while (erc-already-logged-in server port nick)
2141 ;; hmm, this is a problem when using multiple connections to a bnc
2142 ;; with the same nick. Currently this code prevents using more than one
2143 ;; bnc with the same nick. actually it would be nice to have
2144 ;; bncs transparent, so that erc-compute-buffer-name displays
2145 ;; the server one is connected to.
2146 (setq nick (read-from-minibuffer
2147 (erc-format-message 'nick-in-use ?n nick)
2148 nick
2149 nil nil 'erc-nick-history-list)))
2150 (list :server server :port port :nick nick :password passwd)))
2152 ;;;###autoload
2153 (cl-defun erc (&key (server (erc-compute-server))
2154 (port (erc-compute-port))
2155 (nick (erc-compute-nick))
2156 password
2157 (full-name (erc-compute-full-name)))
2158 "ERC is a powerful, modular, and extensible IRC client.
2159 This function is the main entry point for ERC.
2161 It permits you to select connection parameters, and then starts ERC.
2163 Non-interactively, it takes the keyword arguments
2164 (server (erc-compute-server))
2165 (port (erc-compute-port))
2166 (nick (erc-compute-nick))
2167 password
2168 (full-name (erc-compute-full-name)))
2170 That is, if called with
2172 (erc :server \"irc.freenode.net\" :full-name \"Harry S Truman\")
2174 then the server and full-name will be set to those values, whereas
2175 `erc-compute-port', `erc-compute-nick' and `erc-compute-full-name' will
2176 be invoked for the values of the other parameters."
2177 (interactive (erc-select-read-args))
2178 (erc-open server port nick full-name t password))
2180 ;;;###autoload
2181 (defalias 'erc-select 'erc)
2182 (defalias 'erc-ssl 'erc-tls)
2184 ;;;###autoload
2185 (defun erc-tls (&rest r)
2186 "Interactively select TLS connection parameters and run ERC.
2187 Arguments are the same as for `erc'."
2188 (interactive (erc-select-read-args))
2189 (let ((erc-server-connect-function 'erc-open-tls-stream))
2190 (apply 'erc r)))
2192 (defun erc-open-tls-stream (name buffer host port)
2193 "Open an TLS stream to an IRC server.
2194 The process will be given the name NAME, its target buffer will be
2195 BUFFER. HOST and PORT specify the connection target."
2196 (open-network-stream name buffer host port
2197 :type 'tls))
2199 ;;; Displaying error messages
2201 (defun erc-error (&rest args)
2202 "Pass ARGS to `format', and display the result as an error message.
2203 If `debug-on-error' is set to non-nil, then throw a real error with this
2204 message instead, to make debugging easier."
2205 (if debug-on-error
2206 (apply #'error args)
2207 (apply #'message args)
2208 (beep)))
2210 ;;; Debugging the protocol
2212 (defvar erc-debug-irc-protocol nil
2213 "If non-nil, log all IRC protocol traffic to the buffer \"*erc-protocol*\".
2215 The buffer is created if it doesn't exist.
2217 NOTE: If this variable is non-nil, and you kill the only
2218 visible \"*erc-protocol*\" buffer, it will be recreated shortly,
2219 but you won't see it.
2221 WARNING: Do not set this variable directly! Instead, use the
2222 function `erc-toggle-debug-irc-protocol' to toggle its value.")
2224 (declare-function erc-network-name "erc-networks" ())
2226 (defun erc-log-irc-protocol (string &optional outbound)
2227 "Append STRING to the buffer *erc-protocol*.
2229 This only has any effect if `erc-debug-irc-protocol' is non-nil.
2231 The buffer is created if it doesn't exist.
2233 If OUTBOUND is non-nil, STRING is being sent to the IRC server
2234 and appears in face `erc-input-face' in the buffer."
2235 (when erc-debug-irc-protocol
2236 (let ((network-name (or (ignore-errors (erc-network-name))
2237 "???")))
2238 (with-current-buffer (get-buffer-create "*erc-protocol*")
2239 (save-excursion
2240 (goto-char (point-max))
2241 (let ((inhibit-read-only t))
2242 (insert (if (not outbound)
2243 ;; Cope with the fact that string might
2244 ;; contain multiple lines of text.
2245 (let ((lines (delete "" (split-string string
2246 "\n\\|\r\n")))
2247 (result ""))
2248 (dolist (line lines)
2249 (setq result (concat result network-name
2250 " << " line "\n")))
2251 result)
2252 (erc-propertize
2253 (concat network-name " >> " string
2254 (if (/= ?\n
2255 (aref string
2256 (1- (length string))))
2257 "\n"))
2258 'face 'erc-input-face)))))
2259 (let ((orig-win (selected-window))
2260 (debug-buffer-window (get-buffer-window (current-buffer) t)))
2261 (when debug-buffer-window
2262 (select-window debug-buffer-window)
2263 (when (= 1 (count-lines (point) (point-max)))
2264 (goto-char (point-max))
2265 (recenter -1))
2266 (select-window orig-win)))))))
2268 (defun erc-toggle-debug-irc-protocol (&optional arg)
2269 "Toggle the value of `erc-debug-irc-protocol'.
2271 If ARG is non-nil, show the *erc-protocol* buffer."
2272 (interactive "P")
2273 (let* ((buf (get-buffer-create "*erc-protocol*")))
2274 (with-current-buffer buf
2275 (erc-view-mode-enter)
2276 (when (null (current-local-map))
2277 (let ((inhibit-read-only t))
2278 (insert (erc-make-notice "This buffer displays all IRC protocol traffic exchanged with each server.\n"))
2279 (insert (erc-make-notice "Kill this buffer to terminate protocol logging.\n\n")))
2280 (use-local-map (make-sparse-keymap))
2281 (local-set-key (kbd "t") 'erc-toggle-debug-irc-protocol))
2282 (add-hook 'kill-buffer-hook
2283 #'(lambda () (setq erc-debug-irc-protocol nil))
2284 nil 'local)
2285 (goto-char (point-max))
2286 (let ((inhibit-read-only t))
2287 (insert (erc-make-notice
2288 (format "IRC protocol logging %s at %s -- Press `t' to toggle logging.\n"
2289 (if erc-debug-irc-protocol "disabled" "enabled")
2290 (current-time-string))))))
2291 (setq erc-debug-irc-protocol (not erc-debug-irc-protocol))
2292 (if (and arg
2293 (not (get-buffer-window "*erc-protocol*" t)))
2294 (display-buffer buf t))
2295 (message "IRC protocol traffic logging %s (see buffer *erc-protocol*)."
2296 (if erc-debug-irc-protocol "enabled" "disabled"))))
2298 ;;; I/O interface
2300 ;; send interface
2302 (defun erc-send-action (tgt str &optional force)
2303 "Send CTCP ACTION information described by STR to TGT."
2304 (erc-send-ctcp-message tgt (format "ACTION %s" str) force)
2305 (erc-display-message
2306 nil 'input (current-buffer)
2307 'ACTION ?n (erc-current-nick) ?a str ?u "" ?h ""))
2309 ;; Display interface
2311 (defun erc-string-invisible-p (string)
2312 "Check whether STRING is invisible or not.
2313 I.e. any char in it has the `invisible' property set."
2314 (text-property-any 0 (length string) 'invisible t string))
2316 (defcustom erc-remove-parsed-property t
2317 "Whether to remove the erc-parsed text property after displaying a message.
2319 The default is to remove it, since it causes ERC to take up extra
2320 memory. If you have code that relies on this property, then set
2321 this option to nil."
2322 :type 'boolean
2323 :group 'erc)
2325 (defun erc-display-line-1 (string buffer)
2326 "Display STRING in `erc-mode' BUFFER.
2327 Auxiliary function used in `erc-display-line'. The line gets filtered to
2328 interpret the control characters. Then, `erc-insert-pre-hook' gets called.
2329 If `erc-insert-this' is still t, STRING gets inserted into the buffer.
2330 Afterwards, `erc-insert-modify' and `erc-insert-post-hook' get called.
2331 If STRING is nil, the function does nothing."
2332 (when string
2333 (with-current-buffer (or buffer (process-buffer erc-server-process))
2334 (let ((insert-position (or (marker-position erc-insert-marker)
2335 (point-max))))
2336 (let ((string string) ;; FIXME! Can this be removed?
2337 (buffer-undo-list t)
2338 (inhibit-read-only t))
2339 (unless (string-match "\n$" string)
2340 (setq string (concat string "\n"))
2341 (when (erc-string-invisible-p string)
2342 (erc-put-text-properties 0 (length string)
2343 '(invisible intangible) string)))
2344 (erc-log (concat "erc-display-line: " string
2345 (format "(%S)" string) " in buffer "
2346 (format "%s" buffer)))
2347 (setq erc-insert-this t)
2348 (run-hook-with-args 'erc-insert-pre-hook string)
2349 (if (null erc-insert-this)
2350 ;; Leave erc-insert-this set to t as much as possible. Fran
2351 ;; Litterio <franl> has seen erc-insert-this set to nil while
2352 ;; erc-send-pre-hook is running, which should never happen. This
2353 ;; may cure it.
2354 (setq erc-insert-this t)
2355 (save-excursion ;; to restore point in the new buffer
2356 (save-restriction
2357 (widen)
2358 (goto-char insert-position)
2359 (insert-before-markers string)
2360 ;; run insertion hook, with point at restored location
2361 (save-restriction
2362 (narrow-to-region insert-position (point))
2363 (run-hooks 'erc-insert-modify-hook)
2364 (run-hooks 'erc-insert-post-hook)
2365 (when erc-remove-parsed-property
2366 (remove-text-properties (point-min) (point-max)
2367 '(erc-parsed nil))))))))
2368 (erc-update-undo-list (- (or (marker-position erc-insert-marker)
2369 (point-max))
2370 insert-position))))))
2372 (defun erc-update-undo-list (shift)
2373 ;; Translate buffer positions in buffer-undo-list by SHIFT.
2374 (unless (or (zerop shift) (atom buffer-undo-list))
2375 (let ((list buffer-undo-list) elt)
2376 (while list
2377 (setq elt (car list))
2378 (cond ((integerp elt) ; POSITION
2379 (cl-incf (car list) shift))
2380 ((or (atom elt) ; nil, EXTENT
2381 ;; (eq t (car elt)) ; (t . TIME)
2382 (markerp (car elt))) ; (MARKER . DISTANCE)
2383 nil)
2384 ((integerp (car elt)) ; (BEGIN . END)
2385 (cl-incf (car elt) shift)
2386 (cl-incf (cdr elt) shift))
2387 ((stringp (car elt)) ; (TEXT . POSITION)
2388 (cl-incf (cdr elt) (* (if (natnump (cdr elt)) 1 -1) shift)))
2389 ((null (car elt)) ; (nil PROPERTY VALUE BEG . END)
2390 (let ((cons (nthcdr 3 elt)))
2391 (cl-incf (car cons) shift)
2392 (cl-incf (cdr cons) shift)))
2393 ((and (featurep 'xemacs)
2394 (extentp (car elt))) ; (EXTENT START END)
2395 (cl-incf (nth 1 elt) shift)
2396 (cl-incf (nth 2 elt) shift)))
2397 (setq list (cdr list))))))
2399 (defvar erc-valid-nick-regexp "[]a-zA-Z^[;\\`_{}|][]^[;\\`_{}|a-zA-Z0-9-]*"
2400 "Regexp which matches all valid characters in a IRC nickname.")
2402 (defun erc-is-valid-nick-p (nick)
2403 "Check if NICK is a valid IRC nickname."
2404 (string-match (concat "^" erc-valid-nick-regexp "$") nick))
2406 (defun erc-display-line (string &optional buffer)
2407 "Display STRING in the ERC BUFFER.
2408 All screen output must be done through this function. If BUFFER is nil
2409 or omitted, the default ERC buffer for the `erc-session-server' is used.
2410 The BUFFER can be an actual buffer, a list of buffers, 'all or 'active.
2411 If BUFFER = 'all, the string is displayed in all the ERC buffers for the
2412 current session. 'active means the current active buffer
2413 \(`erc-active-buffer'). If the buffer can't be resolved, the current
2414 buffer is used. `erc-display-line-1' is used to display STRING.
2416 If STRING is nil, the function does nothing."
2417 (let ((inhibit-point-motion-hooks t)
2418 new-bufs)
2419 (dolist (buf (cond
2420 ((bufferp buffer) (list buffer))
2421 ((listp buffer) buffer)
2422 ((processp buffer) (list (process-buffer buffer)))
2423 ((eq 'all buffer)
2424 ;; Hmm, or all of the same session server?
2425 (erc-buffer-list nil erc-server-process))
2426 ((and (eq 'active buffer) (erc-active-buffer))
2427 (list (erc-active-buffer)))
2428 ((erc-server-buffer-live-p)
2429 (list (process-buffer erc-server-process)))
2430 (t (list (current-buffer)))))
2431 (when (buffer-live-p buf)
2432 (erc-display-line-1 string buf)
2433 (push buf new-bufs)))
2434 (when (null new-bufs)
2435 (erc-display-line-1 string (if (erc-server-buffer-live-p)
2436 (process-buffer erc-server-process)
2437 (current-buffer))))))
2439 (defun erc-display-message-highlight (type string)
2440 "Highlight STRING according to TYPE, where erc-TYPE-face is an ERC face.
2442 See also `erc-make-notice'."
2443 (cond ((eq type 'notice)
2444 (erc-make-notice string))
2446 (erc-put-text-property
2447 0 (length string)
2448 'face (or (intern-soft
2449 (concat "erc-" (symbol-name type) "-face"))
2450 "erc-default-face")
2451 string)
2452 string)))
2454 (defvar erc-lurker-state nil
2455 "Track the time of the last PRIVMSG for each (server,nick) pair.
2457 This is implemented as a hash of hashes, where the outer key is
2458 the canonicalized server name (as returned by
2459 `erc-canonicalize-server-name') and the outer value is a hash
2460 table mapping nicks (as returned by `erc-lurker-maybe-trim') to
2461 the times of their most recently received PRIVMSG on any channel
2462 on the given server.")
2464 (defcustom erc-lurker-trim-nicks t
2465 "If t, trim trailing `erc-lurker-ignore-chars' from nicks.
2467 This causes e.g. nick and nick` to be considered as the same
2468 individual for activity tracking and lurkiness detection
2469 purposes."
2470 :group 'erc-lurker
2471 :type 'boolean)
2473 (defcustom erc-lurker-ignore-chars "`_"
2474 "Characters at the end of a nick to strip for activity tracking purposes.
2476 See also `erc-lurker-trim-nicks'."
2477 :group 'erc-lurker
2478 :type 'string)
2480 (defun erc-lurker-maybe-trim (nick)
2481 "Maybe trim trailing `erc-lurker-ignore-chars' from NICK.
2483 Returns NICK unmodified unless `erc-lurker-trim-nicks' is
2484 non-nil."
2485 (if erc-lurker-trim-nicks
2486 (replace-regexp-in-string
2487 (format "[%s]"
2488 (mapconcat (lambda (char)
2489 (regexp-quote (char-to-string char)))
2490 erc-lurker-ignore-chars ""))
2491 "" nick)
2492 nick))
2494 (defcustom erc-lurker-hide-list nil
2495 "List of IRC type messages to hide when sent by lurkers.
2497 A typical value would be '(\"JOIN\" \"PART\" \"QUIT\").
2498 See also `erc-lurker-p' and `erc-hide-list'."
2499 :group 'erc-lurker
2500 :type 'erc-message-type)
2502 (defcustom erc-lurker-threshold-time (* 60 60 24) ; 24h by default
2503 "Nicks from which no PRIVMSGs have been received within this
2504 interval (in units of seconds) are considered lurkers by
2505 `erc-lurker-p' and as a result their messages of types in
2506 `erc-lurker-hide-list' will be hidden."
2507 :group 'erc-lurker
2508 :type 'integer)
2510 (defun erc-lurker-initialize ()
2511 "Initialize ERC lurker tracking functionality.
2513 This function adds `erc-lurker-update-status' to
2514 `erc-insert-pre-hook' in order to record the time of each nick's
2515 most recent PRIVMSG as well as initializing the state variable
2516 storing this information."
2517 (setq erc-lurker-state (make-hash-table :test 'equal))
2518 (add-hook 'erc-insert-pre-hook 'erc-lurker-update-status))
2520 (defun erc-lurker-cleanup ()
2521 "Remove all last PRIVMSG state older than `erc-lurker-threshold-time'.
2523 This should be called regularly to avoid excessive resource
2524 consumption for long-lived IRC or Emacs sessions."
2525 (maphash
2526 (lambda (server hash)
2527 (maphash
2528 (lambda (nick last-PRIVMSG-time)
2529 (when
2530 (> (float-time (time-subtract
2531 (current-time)
2532 last-PRIVMSG-time))
2533 erc-lurker-threshold-time)
2534 (remhash nick hash)))
2535 hash)
2536 (if (zerop (hash-table-count hash))
2537 (remhash server erc-lurker-state)))
2538 erc-lurker-state))
2540 (defvar erc-lurker-cleanup-count 0
2541 "Internal counter variable for use with `erc-lurker-cleanup-interval'.")
2543 (defvar erc-lurker-cleanup-interval 100
2544 "Frequency of cleaning up stale erc-lurker state.
2546 `erc-lurker-update-status' calls `erc-lurker-cleanup' once for
2547 every `erc-lurker-cleanup-interval' updates to
2548 `erc-lurker-state'. This is designed to limit the memory
2549 consumption of lurker state during long Emacs sessions and/or ERC
2550 sessions with large numbers of incoming PRIVMSGs.")
2552 (defun erc-lurker-update-status (_message)
2553 "Update `erc-lurker-state' if necessary.
2555 This function is called from `erc-insert-pre-hook'. If the
2556 current message is a PRIVMSG, update `erc-lurker-state' to
2557 reflect the fact that its sender has issued a PRIVMSG at the
2558 current time. Otherwise, take no action.
2560 This function depends on the fact that `erc-display-message'
2561 dynamically binds `parsed', which is used to check if the current
2562 message is a PRIVMSG and to determine its sender. See also
2563 `erc-lurker-trim-nicks' and `erc-lurker-ignore-chars'.
2565 In order to limit memory consumption, this function also calls
2566 `erc-lurker-cleanup' once every `erc-lurker-cleanup-interval'
2567 updates of `erc-lurker-state'."
2568 (when (and (boundp 'parsed) (erc-response-p parsed))
2569 (let* ((command (erc-response.command parsed))
2570 (sender
2571 (erc-lurker-maybe-trim
2572 (car (erc-parse-user (erc-response.sender parsed)))))
2573 (server
2574 (erc-canonicalize-server-name erc-server-announced-name)))
2575 (when (equal command "PRIVMSG")
2576 (when (>= (cl-incf erc-lurker-cleanup-count)
2577 erc-lurker-cleanup-interval)
2578 (setq erc-lurker-cleanup-count 0)
2579 (erc-lurker-cleanup))
2580 (unless (gethash server erc-lurker-state)
2581 (puthash server (make-hash-table :test 'equal) erc-lurker-state))
2582 (puthash sender (current-time)
2583 (gethash server erc-lurker-state))))))
2585 (defun erc-lurker-p (nick)
2586 "Predicate indicating NICK's lurking status on the current server.
2588 Lurking is the condition where NICK has issued no PRIVMSG on this
2589 server within `erc-lurker-threshold-time'. See also
2590 `erc-lurker-trim-nicks' and `erc-lurker-ignore-chars'."
2591 (unless erc-lurker-state (erc-lurker-initialize))
2592 (let* ((server
2593 (erc-canonicalize-server-name erc-server-announced-name))
2594 (last-PRIVMSG-time
2595 (gethash (erc-lurker-maybe-trim nick)
2596 (gethash server erc-lurker-state (make-hash-table)))))
2597 (or (null last-PRIVMSG-time)
2598 (> (float-time
2599 (time-subtract (current-time) last-PRIVMSG-time))
2600 erc-lurker-threshold-time))))
2602 (defcustom erc-common-server-suffixes
2603 '(("openprojects.net$" . "OPN")
2604 ("freenode.net$" . "freenode")
2605 ("oftc.net$" . "OFTC"))
2606 "Alist of common server name suffixes.
2607 This variable is used in mode-line display to save screen
2608 real estate. Set it to nil if you want to avoid changing
2609 displayed hostnames."
2610 :group 'erc-mode-line-and-header
2611 :type 'alist)
2613 (defun erc-canonicalize-server-name (server)
2614 "Return the canonical network name for SERVER if any,
2615 otherwise `erc-server-announced-name'. SERVER is matched against
2616 `erc-common-server-suffixes'."
2617 (when server
2618 (or (cdar (erc-remove-if-not
2619 (lambda (net) (string-match (car net) server))
2620 erc-common-server-suffixes))
2621 erc-server-announced-name)))
2623 (defun erc-hide-current-message-p (parsed)
2624 "Predicate indicating whether the parsed ERC response PARSED should be hidden.
2626 Messages are always hidden if the message type of PARSED appears in
2627 `erc-hide-list'. In addition, messages whose type is a member of
2628 `erc-lurker-hide-list' are hidden if `erc-lurker-p' returns true."
2629 (let* ((command (erc-response.command parsed))
2630 (sender (car (erc-parse-user (erc-response.sender parsed)))))
2631 (or (member command erc-hide-list)
2632 (and (member command erc-lurker-hide-list) (erc-lurker-p sender)))))
2634 (defun erc-display-message (parsed type buffer msg &rest args)
2635 "Display MSG in BUFFER.
2637 ARGS, PARSED, and TYPE are used to format MSG sensibly.
2639 See also `erc-format-message' and `erc-display-line'."
2640 (let ((string (if (symbolp msg)
2641 (apply 'erc-format-message msg args)
2642 msg)))
2643 (setq string
2644 (cond
2645 ((null type)
2646 string)
2647 ((listp type)
2648 (mapc (lambda (type)
2649 (setq string
2650 (erc-display-message-highlight type string)))
2651 type)
2652 string)
2653 ((symbolp type)
2654 (erc-display-message-highlight type string))))
2656 (if (not (erc-response-p parsed))
2657 (erc-display-line string buffer)
2658 (unless (erc-hide-current-message-p parsed)
2659 (erc-put-text-property 0 (length string) 'erc-parsed parsed string)
2660 (erc-put-text-property 0 (length string) 'rear-sticky t string)
2661 (erc-display-line string buffer)))))
2663 (defun erc-message-type-member (position list)
2664 "Return non-nil if the erc-parsed text-property at POSITION is in LIST.
2666 This function relies on the erc-parsed text-property being
2667 present."
2668 (let ((prop-val (erc-get-parsed-vector position)))
2669 (and prop-val (member (erc-response.command prop-val) list))))
2671 (defvar erc-send-input-line-function 'erc-send-input-line)
2672 (make-variable-buffer-local 'erc-send-input-line-function)
2674 (defun erc-send-input-line (target line &optional force)
2675 "Send LINE to TARGET.
2677 See also `erc-server-send'."
2678 (setq line (format "PRIVMSG %s :%s"
2679 target
2680 ;; If the line is empty, we still want to
2681 ;; send it - i.e. an empty pasted line.
2682 (if (string= line "\n")
2683 " \n"
2684 line)))
2685 (erc-server-send line force target))
2687 (defun erc-get-arglist (fun)
2688 "Return the argument list of a function without the parens."
2689 (let ((arglist (format "%S" (erc-function-arglist fun))))
2690 (if (string-match "^(\\(.*\\))$" arglist)
2691 (match-string 1 arglist)
2692 arglist)))
2694 (defun erc-command-no-process-p (str)
2695 "Return non-nil if STR is an ERC command that can be run when the process
2696 is not alive, nil otherwise."
2697 (let ((fun (erc-extract-command-from-line str)))
2698 (and fun
2699 (symbolp (car fun))
2700 (get (car fun) 'process-not-needed))))
2702 (defun erc-command-name (cmd)
2703 "For CMD being the function name of a ERC command, something like
2704 erc-cmd-FOO, this returns a string /FOO."
2705 (let ((command-name (symbol-name cmd)))
2706 (if (string-match "^erc-cmd-\\(.*\\)$" command-name)
2707 (concat "/" (match-string 1 command-name))
2708 command-name)))
2710 (defun erc-process-input-line (line &optional force no-command)
2711 "Translate LINE to an RFC1459 command and send it based.
2712 Returns non-nil if the command is actually sent to the server, and nil
2713 otherwise.
2715 If the command in the LINE is not bound as a function `erc-cmd-<COMMAND>',
2716 it is passed to `erc-cmd-default'. If LINE is not a command (i.e. doesn't
2717 start with /<COMMAND>) then it is sent as a message.
2719 An optional FORCE argument forces sending the line when flood
2720 protection is in effect. The optional NO-COMMAND argument prohibits
2721 this function from interpreting the line as a command."
2722 (let ((command-list (erc-extract-command-from-line line)))
2723 (if (and command-list
2724 (not no-command))
2725 (let* ((cmd (nth 0 command-list))
2726 (args (nth 1 command-list)))
2727 (condition-case nil
2728 (if (listp args)
2729 (apply cmd args)
2730 (funcall cmd args))
2731 (wrong-number-of-arguments
2732 (erc-display-message nil 'error (current-buffer) 'incorrect-args
2733 ?c (erc-command-name cmd)
2734 ?u (or (erc-get-arglist cmd)
2736 ?d (format "%s\n"
2737 (or (documentation cmd) "")))
2738 nil)))
2739 (let ((r (erc-default-target)))
2740 (if r
2741 (funcall erc-send-input-line-function r line force)
2742 (erc-display-message nil 'error (current-buffer) 'no-target)
2743 nil)))))
2745 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2746 ;; Input commands handlers
2747 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2749 (defun erc-cmd-AMSG (line)
2750 "Send LINE to all channels of the current server that you are on."
2751 (interactive "sSend to all channels you're on: ")
2752 (setq line (erc-trim-string line))
2753 (erc-with-all-buffers-of-server nil
2754 (lambda ()
2755 (erc-channel-p (erc-default-target)))
2756 (erc-send-message line)))
2757 (put 'erc-cmd-AMSG 'do-not-parse-args t)
2759 (defun erc-cmd-SAY (line)
2760 "Send LINE to the current query or channel as a message, not a command.
2762 Use this when you want to send a message with a leading '/'. Note
2763 that since multi-line messages are never a command, you don't
2764 need this when pasting multiple lines of text."
2765 (if (string-match "^\\s-*$" line)
2767 (string-match "^ ?\\(.*\\)" line)
2768 (erc-process-input-line (match-string 1 line) nil t)))
2769 (put 'erc-cmd-SAY 'do-not-parse-args t)
2771 (defun erc-cmd-SET (line)
2772 "Set the variable named by the first word in LINE to some VALUE.
2773 VALUE is computed by evaluating the rest of LINE in Lisp."
2774 (cond
2775 ((string-match "^\\s-*\\(\\S-+\\)\\s-+\\(.*\\)$" line)
2776 (let ((var (read (concat "erc-" (match-string 1 line))))
2777 (val (read (match-string 2 line))))
2778 (if (boundp var)
2779 (progn
2780 (set var (eval val))
2781 (erc-display-message
2782 nil nil 'active (format "Set %S to %S" var val))
2784 (setq var (read (match-string 1 line)))
2785 (if (boundp var)
2786 (progn
2787 (set var (eval val))
2788 (erc-display-message
2789 nil nil 'active (format "Set %S to %S" var val))
2791 (erc-display-message nil 'error 'active 'variable-not-bound)
2792 nil))))
2793 ((string-match "^\\s-*$" line)
2794 (erc-display-line
2795 (concat "Available user variables:\n"
2796 (apply
2797 'concat
2798 (mapcar
2799 (lambda (var)
2800 (let ((val (symbol-value var)))
2801 (concat (format "%S:" var)
2802 (if (consp val)
2803 (concat "\n" (pp-to-string val))
2804 (format " %S\n" val)))))
2805 (apropos-internal "^erc-" 'custom-variable-p))))
2806 (current-buffer))
2808 (t nil)))
2809 (defalias 'erc-cmd-VAR 'erc-cmd-SET)
2810 (defalias 'erc-cmd-VARIABLE 'erc-cmd-SET)
2811 (put 'erc-cmd-SET 'do-not-parse-args t)
2812 (put 'erc-cmd-SET 'process-not-needed t)
2814 (defun erc-cmd-default (line)
2815 "Fallback command.
2817 Commands for which no erc-cmd-xxx exists, are tunneled through
2818 this function. LINE is sent to the server verbatim, and
2819 therefore has to contain the command itself as well."
2820 (erc-log (format "cmd: DEFAULT: %s" line))
2821 (erc-server-send (substring line 1))
2824 (defun erc-cmd-IGNORE (&optional user)
2825 "Ignore USER. This should be a regexp matching nick!user@host.
2826 If no USER argument is specified, list the contents of `erc-ignore-list'."
2827 (if user
2828 (let ((quoted (regexp-quote user)))
2829 (when (and (not (string= user quoted))
2830 (y-or-n-p (format "Use regexp-quoted form (%s) instead? "
2831 quoted)))
2832 (setq user quoted))
2833 (erc-display-line
2834 (erc-make-notice (format "Now ignoring %s" user))
2835 'active)
2836 (erc-with-server-buffer (add-to-list 'erc-ignore-list user)))
2837 (if (null (erc-with-server-buffer erc-ignore-list))
2838 (erc-display-line (erc-make-notice "Ignore list is empty") 'active)
2839 (erc-display-line (erc-make-notice "Ignore list:") 'active)
2840 (mapc #'(lambda (item)
2841 (erc-display-line (erc-make-notice item)
2842 'active))
2843 (erc-with-server-buffer erc-ignore-list))))
2846 (defun erc-cmd-UNIGNORE (user)
2847 "Remove the user specified in USER from the ignore list."
2848 (let ((ignored-nick (car (erc-with-server-buffer
2849 (erc-member-ignore-case (regexp-quote user)
2850 erc-ignore-list)))))
2851 (unless ignored-nick
2852 (if (setq ignored-nick (erc-ignored-user-p user))
2853 (unless (y-or-n-p (format "Remove this regexp (%s)? "
2854 ignored-nick))
2855 (setq ignored-nick nil))
2856 (erc-display-line
2857 (erc-make-notice (format "%s is not currently ignored!" user))
2858 'active)))
2859 (when ignored-nick
2860 (erc-display-line
2861 (erc-make-notice (format "No longer ignoring %s" user))
2862 'active)
2863 (erc-with-server-buffer
2864 (setq erc-ignore-list (delete ignored-nick erc-ignore-list)))))
2867 (defun erc-cmd-CLEAR ()
2868 "Clear the window content."
2869 (recenter 0)
2871 (put 'erc-cmd-CLEAR 'process-not-needed t)
2873 (defun erc-cmd-OPS ()
2874 "Show the ops in the current channel."
2875 (interactive)
2876 (let ((ops nil))
2877 (if erc-channel-users
2878 (maphash (lambda (_nick user-data)
2879 (let ((cuser (cdr user-data)))
2880 (if (and cuser
2881 (erc-channel-user-op cuser))
2882 (setq ops (cons (erc-server-user-nickname
2883 (car user-data))
2884 ops)))))
2885 erc-channel-users))
2886 (setq ops (sort ops 'string-lessp))
2887 (if ops
2888 (erc-display-message
2889 nil 'notice (current-buffer) 'ops
2890 ?i (length ops) ?s (if (> (length ops) 1) "s" "")
2891 ?o (mapconcat 'identity ops " "))
2892 (erc-display-message nil 'notice (current-buffer) 'ops-none)))
2895 (defun erc-cmd-COUNTRY (tld)
2896 "Display the country associated with the top level domain TLD."
2897 (require 'mail-extr)
2898 (let ((co (ignore-errors (what-domain tld))))
2899 (if co
2900 (erc-display-message
2901 nil 'notice 'active 'country ?c co ?d tld)
2902 (erc-display-message
2903 nil 'notice 'active 'country-unknown ?d tld))
2905 (put 'erc-cmd-COUNTRY 'process-not-needed t)
2907 (defun erc-cmd-AWAY (line)
2908 "Mark the user as being away, the reason being indicated by LINE.
2909 If no reason is given, unset away status."
2910 (when (string-match "^\\s-*\\(.*\\)$" line)
2911 (let ((reason (match-string 1 line)))
2912 (erc-log (format "cmd: AWAY: %s" reason))
2913 (erc-server-send
2914 (if (string= reason "")
2915 "AWAY"
2916 (concat "AWAY :" reason))))
2918 (put 'erc-cmd-AWAY 'do-not-parse-args t)
2920 (defun erc-cmd-GAWAY (line)
2921 "Mark the user as being away everywhere, the reason being indicated by LINE."
2922 ;; on all server buffers.
2923 (erc-with-all-buffers-of-server nil
2924 #'erc-open-server-buffer-p
2925 (erc-cmd-AWAY line)))
2926 (put 'erc-cmd-GAWAY 'do-not-parse-args t)
2928 (defun erc-cmd-CTCP (nick cmd &rest args)
2929 "Send a Client To Client Protocol message to NICK.
2931 CMD is the CTCP command, possible values being ECHO, FINGER, CLIENTINFO, TIME,
2932 VERSION and so on. It is called with ARGS."
2933 (let ((str (concat cmd
2934 (when args
2935 (concat " " (mapconcat #'identity args " "))))))
2936 (erc-log (format "cmd: CTCP [%s]: [%s]" nick str))
2937 (erc-send-ctcp-message nick str)
2940 (defun erc-cmd-HELP (&optional func)
2941 "Popup help information.
2943 If FUNC contains a valid function or variable, help about that
2944 will be displayed. If FUNC is empty, display an apropos about
2945 ERC commands. Otherwise, do `apropos' in the ERC namespace
2946 \(\"erc-.*LINE\"\).
2948 Examples:
2949 To find out about erc and bbdb, do
2950 /help bbdb.*
2952 For help about the WHOIS command, do:
2953 /help whois
2955 For a list of user commands (/join /part, ...):
2956 /help."
2957 (if func
2958 (let* ((sym (or (let ((sym (intern-soft
2959 (concat "erc-cmd-" (upcase func)))))
2960 (if (and sym (or (boundp sym) (fboundp sym)))
2962 nil))
2963 (let ((sym (intern-soft func)))
2964 (if (and sym (or (boundp sym) (fboundp sym)))
2966 nil))
2967 (let ((sym (intern-soft (concat "erc-" func))))
2968 (if (and sym (or (boundp sym) (fboundp sym)))
2970 nil)))))
2971 (if sym
2972 (cond
2973 ((boundp sym) (describe-variable sym))
2974 ((fboundp sym) (describe-function sym))
2975 (t nil))
2976 (apropos-command (concat "erc-.*" func) nil
2977 (lambda (x)
2978 (or (commandp x)
2979 (get x 'custom-type))))
2981 (apropos "erc-cmd-")
2982 (message "Type C-h m to get additional information about keybindings.")
2985 (defalias 'erc-cmd-H 'erc-cmd-HELP)
2986 (put 'erc-cmd-HELP 'process-not-needed t)
2988 (defun erc-cmd-JOIN (channel &optional key)
2989 "Join the channel given in CHANNEL, optionally with KEY.
2990 If CHANNEL is specified as \"-invite\", join the channel to which you
2991 were most recently invited. See also `invitation'."
2992 (let (chnl)
2993 (if (string= (upcase channel) "-INVITE")
2994 (if erc-invitation
2995 (setq chnl erc-invitation)
2996 (erc-display-message nil 'error (current-buffer) 'no-invitation))
2997 (setq chnl (erc-ensure-channel-name channel)))
2998 (when chnl
2999 ;; Prevent double joining of same channel on same server.
3000 (let ((joined-channels
3001 (mapcar #'(lambda (chanbuf)
3002 (with-current-buffer chanbuf (erc-default-target)))
3003 (erc-channel-list erc-server-process))))
3004 (if (erc-member-ignore-case chnl joined-channels)
3005 (switch-to-buffer (car (erc-member-ignore-case chnl
3006 joined-channels)))
3007 (erc-log (format "cmd: JOIN: %s" chnl))
3008 (erc-server-send (if (and chnl key)
3009 (format "JOIN %s %s" chnl key)
3010 (format "JOIN %s" chnl)))))))
3013 (defalias 'erc-cmd-CHANNEL 'erc-cmd-JOIN)
3014 (defalias 'erc-cmd-J 'erc-cmd-JOIN)
3016 (defvar erc-channel-new-member-names nil
3017 "If non-nil, a names list is currently being received.
3019 If non-nil, this variable is a hash-table that associates
3020 received nicks with t.")
3021 (make-variable-buffer-local 'erc-channel-new-member-names)
3023 (defun erc-cmd-NAMES (&optional channel)
3024 "Display the users in CHANNEL.
3025 If CHANNEL is not specified, display the users in the current channel.
3026 This function clears the channel name list first, then sends the
3027 command."
3028 (let ((tgt (or (and (erc-channel-p channel) channel)
3029 (erc-default-target))))
3030 (if (and tgt (erc-channel-p tgt))
3031 (progn
3032 (erc-log (format "cmd: DEFAULT: NAMES %s" tgt))
3033 (erc-with-buffer
3034 (tgt)
3035 (erc-channel-begin-receiving-names))
3036 (erc-server-send (concat "NAMES " tgt)))
3037 (erc-display-message nil 'error (current-buffer) 'no-default-channel)))
3039 (defalias 'erc-cmd-N 'erc-cmd-NAMES)
3041 (defun erc-cmd-KICK (target &optional reason-or-nick &rest reasonwords)
3042 "Kick the user indicated in LINE from the current channel.
3043 LINE has the format: \"#CHANNEL NICK REASON\" or \"NICK REASON\"."
3044 (let ((reasonstring (mapconcat 'identity reasonwords " ")))
3045 (if (string= "" reasonstring)
3046 (setq reasonstring (format "Kicked by %s" (erc-current-nick))))
3047 (if (erc-channel-p target)
3048 (let ((nick reason-or-nick))
3049 (erc-log (format "cmd: KICK: %s/%s: %s" nick target reasonstring))
3050 (erc-server-send (format "KICK %s %s :%s" target nick reasonstring)
3051 nil target)
3053 (when target
3054 (let ((ch (erc-default-target)))
3055 (setq reasonstring (concat
3056 (if reason-or-nick (concat reason-or-nick " "))
3057 reasonstring))
3058 (if ch
3059 (progn
3060 (erc-log
3061 (format "cmd: KICK: %s/%s: %s" target ch reasonstring))
3062 (erc-server-send
3063 (format "KICK %s %s :%s" ch target reasonstring) nil ch))
3064 (erc-display-message nil 'error (current-buffer)
3065 'no-default-channel))
3066 t)))))
3068 (defvar erc-script-args nil)
3070 (defun erc-cmd-LOAD (line)
3071 "Load the script provided in the LINE.
3072 If LINE continues beyond the file name, the rest of
3073 it is put in a (local) variable `erc-script-args',
3074 which can be used in Emacs Lisp scripts.
3076 The optional FORCE argument is ignored here - you can't force loading
3077 a script after exceeding the flood threshold."
3078 (cond
3079 ((string-match "^\\s-*\\(\\S-+\\)\\(.*\\)$" line)
3080 (let* ((file-to-find (match-string 1 line))
3081 (erc-script-args (match-string 2 line))
3082 (file (erc-find-file file-to-find erc-script-path)))
3083 (erc-log (format "cmd: LOAD: %s" file-to-find))
3084 (cond
3085 ((not file)
3086 (erc-display-message nil 'error (current-buffer)
3087 'cannot-find-file ?f file-to-find))
3088 ((not (file-readable-p file))
3089 (erc-display-message nil 'error (current-buffer)
3090 'cannot-read-file ?f file))
3092 (message "Loading \'%s\'..." file)
3093 (erc-load-script file)
3094 (message "Loading \'%s\'...done" file))))
3096 (t nil)))
3098 (defun erc-cmd-WHOIS (user &optional server)
3099 "Display whois information for USER.
3101 If SERVER is non-nil, use that, rather than the current server."
3102 ;; FIXME: is the above docstring correct? -- Lawrence 2004-01-08
3103 (let ((send (if server
3104 (format "WHOIS %s %s" user server)
3105 (format "WHOIS %s" user))))
3106 (erc-log (format "cmd: %s" send))
3107 (erc-server-send send)
3109 (defalias 'erc-cmd-WI 'erc-cmd-WHOIS)
3111 (defun erc-cmd-WHOAMI ()
3112 "Display whois information about yourself."
3113 (erc-cmd-WHOIS (erc-current-nick))
3116 (defun erc-cmd-IDLE (nick)
3117 "Show the length of time NICK has been idle."
3118 (let ((origbuf (current-buffer))
3119 symlist)
3120 (erc-with-server-buffer
3121 (push (cons (erc-once-with-server-event
3122 311 (lambda (_proc parsed)
3123 (string= nick
3124 (nth 1 (erc-response.command-args
3125 parsed)))))
3126 'erc-server-311-functions)
3127 symlist)
3128 (push (cons (erc-once-with-server-event
3129 312 (lambda (_proc parsed)
3130 (string= nick
3131 (nth 1 (erc-response.command-args
3132 parsed)))))
3133 'erc-server-312-functions)
3134 symlist)
3135 (push (cons (erc-once-with-server-event
3136 318 (lambda (_proc parsed)
3137 (string= nick
3138 (nth 1 (erc-response.command-args
3139 parsed)))))
3140 'erc-server-318-functions)
3141 symlist)
3142 (push (cons (erc-once-with-server-event
3143 319 (lambda (_proc parsed)
3144 (string= nick
3145 (nth 1 (erc-response.command-args
3146 parsed)))))
3147 'erc-server-319-functions)
3148 symlist)
3149 (push (cons (erc-once-with-server-event
3150 320 (lambda (_proc parsed)
3151 (string= nick
3152 (nth 1 (erc-response.command-args
3153 parsed)))))
3154 'erc-server-320-functions)
3155 symlist)
3156 (push (cons (erc-once-with-server-event
3157 330 (lambda (_proc parsed)
3158 (string= nick
3159 (nth 1 (erc-response.command-args
3160 parsed)))))
3161 'erc-server-330-functions)
3162 symlist)
3163 (push (cons (erc-once-with-server-event
3165 (lambda (_proc parsed)
3166 (let ((idleseconds
3167 (string-to-number
3168 (cl-third
3169 (erc-response.command-args parsed)))))
3170 (erc-display-line
3171 (erc-make-notice
3172 (format "%s has been idle for %s."
3173 (erc-string-no-properties nick)
3174 (erc-seconds-to-string idleseconds)))
3175 origbuf)
3176 t)))
3177 'erc-server-317-functions)
3178 symlist)
3180 ;; Send the WHOIS command.
3181 (erc-cmd-WHOIS nick)
3183 ;; Remove the uninterned symbols from the server hooks that did not run.
3184 (run-at-time 20 nil (lambda (buf symlist)
3185 (with-current-buffer buf
3186 (dolist (sym symlist)
3187 (let ((hooksym (cdr sym))
3188 (funcsym (car sym)))
3189 (remove-hook hooksym funcsym t)))))
3190 (current-buffer) symlist)))
3193 (defun erc-cmd-DESCRIBE (line)
3194 "Pose some action to a certain user.
3195 LINE has the format \"USER ACTION\"."
3196 (cond
3197 ((string-match
3198 "^\\s-*\\(\\S-+\\)\\s-\\(.*\\)$" line)
3199 (let ((dst (match-string 1 line))
3200 (s (match-string 2 line)))
3201 (erc-log (format "cmd: DESCRIBE: [%s] %s" dst s))
3202 (erc-send-action dst s))
3204 (t nil)))
3205 (put 'erc-cmd-DESCRIBE 'do-not-parse-args t)
3207 (defun erc-cmd-ME (line)
3208 "Send LINE as an action."
3209 (cond
3210 ((string-match "^\\s-\\(.*\\)$" line)
3211 (let ((s (match-string 1 line)))
3212 (erc-log (format "cmd: ME: %s" s))
3213 (erc-send-action (erc-default-target) s))
3215 (t nil)))
3216 (put 'erc-cmd-ME 'do-not-parse-args t)
3218 (defun erc-cmd-ME\'S (line)
3219 "Do a /ME command, but add the string \" 's\" to the beginning."
3220 (erc-cmd-ME (concat " 's" line)))
3221 (put 'erc-cmd-ME\'S 'do-not-parse-args t)
3223 (defun erc-cmd-LASTLOG (line)
3224 "Show all lines in the current buffer matching the regexp LINE.
3226 If a match spreads across multiple lines, all those lines are shown.
3228 The lines are shown in a buffer named `*Occur*'.
3229 It serves as a menu to find any of the occurrences in this buffer.
3230 \\[describe-mode] in that buffer will explain how.
3232 If LINE contains upper case characters (excluding those preceded by `\'),
3233 the matching is case-sensitive."
3234 (occur line)
3236 (put 'erc-cmd-LASTLOG 'do-not-parse-args t)
3237 (put 'erc-cmd-LASTLOG 'process-not-needed t)
3239 (defun erc-send-message (line &optional force)
3240 "Send LINE to the current channel or user and display it.
3242 See also `erc-message' and `erc-display-line'."
3243 (erc-message "PRIVMSG" (concat (erc-default-target) " " line) force)
3244 (erc-display-line
3245 (concat (erc-format-my-nick) line)
3246 (current-buffer))
3247 ;; FIXME - treat multiline, run hooks, or remove me?
3250 (defun erc-cmd-MODE (line)
3251 "Change or display the mode value of a channel or user.
3252 The first word specifies the target. The rest is the mode string
3253 to send.
3255 If only one word is given, display the mode of that target.
3257 A list of valid mode strings for Freenode may be found at
3258 URL `http://freenode.net/using_the_network.shtml'."
3259 (cond
3260 ((string-match "^\\s-\\(.*\\)$" line)
3261 (let ((s (match-string 1 line)))
3262 (erc-log (format "cmd: MODE: %s" s))
3263 (erc-server-send (concat "MODE " line)))
3265 (t nil)))
3266 (put 'erc-cmd-MODE 'do-not-parse-args t)
3268 (defun erc-cmd-NOTICE (channel-or-user &rest message)
3269 "Send a notice to the channel or user given as the first word.
3270 The rest is the message to send."
3271 (erc-message "NOTICE" (concat channel-or-user " "
3272 (mapconcat #'identity message " "))))
3274 (defun erc-cmd-MSG (line)
3275 "Send a message to the channel or user given as the first word in LINE.
3277 The rest of LINE is the message to send."
3278 (erc-message "PRIVMSG" line))
3280 (defalias 'erc-cmd-M 'erc-cmd-MSG)
3281 (put 'erc-cmd-MSG 'do-not-parse-args t)
3283 (defun erc-cmd-SQUERY (line)
3284 "Send a Service Query to the service given as the first word in LINE.
3286 The rest of LINE is the message to send."
3287 (erc-message "SQUERY" line))
3289 (defun erc-cmd-NICK (nick)
3290 "Change current nickname to NICK."
3291 (erc-log (format "cmd: NICK: %s (erc-bad-nick: %S)" nick erc-bad-nick))
3292 (let ((nicklen (cdr (assoc "NICKLEN" (erc-with-server-buffer
3293 erc-server-parameters)))))
3294 (and nicklen (> (length nick) (string-to-number nicklen))
3295 (erc-display-message
3296 nil 'notice 'active 'nick-too-long
3297 ?i (length nick) ?l nicklen)))
3298 (erc-server-send (format "NICK %s" nick))
3299 (cond (erc-bad-nick
3300 (erc-set-current-nick nick)
3301 (erc-update-mode-line)
3302 (setq erc-bad-nick nil)))
3305 (defun erc-cmd-PART (line)
3306 "When LINE is an empty string, leave the current channel.
3307 Otherwise leave the channel indicated by LINE."
3308 (cond
3309 ((string-match "^\\s-*\\([&#+!]\\S-+\\)\\s-?\\(.*\\)$" line)
3310 (let* ((ch (match-string 1 line))
3311 (msg (match-string 2 line))
3312 (reason (funcall erc-part-reason (if (equal msg "") nil msg))))
3313 (erc-log (format "cmd: PART: %s: %s" ch reason))
3314 (erc-server-send (if (string= reason "")
3315 (format "PART %s" ch)
3316 (format "PART %s :%s" ch reason))
3317 nil ch))
3319 ((string-match "^\\s-*\\(.*\\)$" line)
3320 (let* ((ch (erc-default-target))
3321 (msg (match-string 1 line))
3322 (reason (funcall erc-part-reason (if (equal msg "") nil msg))))
3323 (if (and ch (erc-channel-p ch))
3324 (progn
3325 (erc-log (format "cmd: PART: %s: %s" ch reason))
3326 (erc-server-send (if (string= reason "")
3327 (format "PART %s" ch)
3328 (format "PART %s :%s" ch reason))
3329 nil ch))
3330 (erc-display-message nil 'error (current-buffer) 'no-target)))
3332 (t nil)))
3333 (put 'erc-cmd-PART 'do-not-parse-args t)
3335 (defalias 'erc-cmd-LEAVE 'erc-cmd-PART)
3337 (defun erc-cmd-PING (recipient)
3338 "Ping RECIPIENT."
3339 (let ((time (format "%f" (erc-current-time))))
3340 (erc-log (format "cmd: PING: %s" time))
3341 (erc-cmd-CTCP recipient "PING" time)))
3343 (defun erc-cmd-QUOTE (line)
3344 "Send LINE directly to the server.
3345 All the text given as argument is sent to the sever as unmodified,
3346 just as you provided it. Use this command with care!"
3347 (cond
3348 ((string-match "^ ?\\(.+\\)$" line)
3349 (erc-server-send (match-string 1 line)))
3350 (t nil)))
3351 (put 'erc-cmd-QUOTE 'do-not-parse-args t)
3353 (defcustom erc-query-display 'window
3354 "Indicates how to display query buffers when using the /QUERY
3355 command to talk to someone.
3357 The default behavior is to display the message in a new window
3358 and bring it to the front. See the documentation for
3359 `erc-join-buffer' for a description of the available choices.
3361 See also `erc-auto-query' to decide how private messages from
3362 other people should be displayed."
3363 :group 'erc-query
3364 :type '(choice (const :tag "Split window and select" window)
3365 (const :tag "Split window, don't select" window-noselect)
3366 (const :tag "New frame" frame)
3367 (const :tag "Bury in new buffer" bury)
3368 (const :tag "Use current buffer" buffer)
3369 (const :tag "Use current buffer" t)))
3371 (defun erc-cmd-QUERY (&optional user)
3372 "Open a query with USER.
3373 The type of query window/frame/etc will depend on the value of
3374 `erc-query-display'.
3376 If USER is omitted, close the current query buffer if one exists
3377 - except this is broken now ;-)"
3378 (interactive
3379 (list (read-from-minibuffer "Start a query with: " nil)))
3380 (let ((session-buffer (erc-server-buffer))
3381 (erc-join-buffer erc-query-display))
3382 (if user
3383 (erc-query user session-buffer)
3384 ;; currently broken, evil hack to display help anyway
3385 ;(erc-delete-query))))
3386 (signal 'wrong-number-of-arguments ""))))
3387 (defalias 'erc-cmd-Q 'erc-cmd-QUERY)
3389 (defun erc-quit/part-reason-default ()
3390 "Default quit/part message."
3391 (format "\C-bERC\C-b (IRC client for Emacs %s)" emacs-version))
3394 (defun erc-quit-reason-normal (&optional s)
3395 "Normal quit message.
3397 If S is non-nil, it will be used as the quit reason."
3398 (or s (erc-quit/part-reason-default)))
3400 (defun erc-quit-reason-zippy (&optional s)
3401 "Zippy quit message.
3403 If S is non-nil, it will be used as the quit reason."
3404 (or s
3405 (if (fboundp 'yow)
3406 (erc-replace-regexp-in-string "\n" "" (yow))
3407 (erc-quit/part-reason-default))))
3409 (make-obsolete 'erc-quit-reason-zippy "it will be removed." "24.4")
3411 (defun erc-quit-reason-various (s)
3412 "Choose a quit reason based on S (a string)."
3413 (when (featurep 'xemacs) (require 'poe))
3414 (let ((res (car (assoc-default (or s "")
3415 erc-quit-reason-various-alist 'string-match))))
3416 (cond
3417 ((functionp res) (funcall res))
3418 ((stringp res) res)
3419 (s s)
3420 (t (erc-quit/part-reason-default)))))
3422 (defun erc-part-reason-normal (&optional s)
3423 "Normal part message.
3425 If S is non-nil, it will be used as the part reason."
3426 (or s (erc-quit/part-reason-default)))
3428 (defun erc-part-reason-zippy (&optional s)
3429 "Zippy part message.
3431 If S is non-nil, it will be used as the quit reason."
3432 (or s
3433 (if (fboundp 'yow)
3434 (erc-replace-regexp-in-string "\n" "" (yow))
3435 (erc-quit/part-reason-default))))
3437 (make-obsolete 'erc-part-reason-zippy "it will be removed." "24.4")
3439 (defun erc-part-reason-various (s)
3440 "Choose a part reason based on S (a string)."
3441 (when (featurep 'xemacs) (require 'poe))
3442 (let ((res (car (assoc-default (or s "")
3443 erc-part-reason-various-alist 'string-match))))
3444 (cond
3445 ((functionp res) (funcall res))
3446 ((stringp res) res)
3447 (s s)
3448 (t (erc-quit/part-reason-default)))))
3450 (defun erc-cmd-QUIT (reason)
3451 "Disconnect from the current server.
3452 If REASON is omitted, display a default quit message, otherwise display
3453 the message given by REASON."
3454 (unless reason
3455 (setq reason ""))
3456 (cond
3457 ((string-match "^\\s-*\\(.*\\)$" reason)
3458 (let* ((s (match-string 1 reason))
3459 (buffer (erc-server-buffer))
3460 (reason (funcall erc-quit-reason (if (equal s "") nil s)))
3461 server-proc)
3462 (with-current-buffer (if (and buffer
3463 (bufferp buffer))
3464 buffer
3465 (current-buffer))
3466 (erc-log (format "cmd: QUIT: %s" reason))
3467 (setq erc-server-quitting t)
3468 (erc-set-active-buffer (erc-server-buffer))
3469 (setq server-proc erc-server-process)
3470 (erc-server-send (format "QUIT :%s" reason)))
3471 (run-hook-with-args 'erc-quit-hook server-proc)
3472 (when erc-kill-queries-on-quit
3473 (erc-kill-query-buffers server-proc))
3474 ;; if the process has not been killed within 4 seconds, kill it
3475 (run-at-time 4 nil
3476 (lambda (proc)
3477 (when (and (processp proc)
3478 (memq (process-status proc) '(run open)))
3479 (delete-process proc)))
3480 server-proc))
3482 (t nil)))
3484 (defalias 'erc-cmd-BYE 'erc-cmd-QUIT)
3485 (defalias 'erc-cmd-EXIT 'erc-cmd-QUIT)
3486 (defalias 'erc-cmd-SIGNOFF 'erc-cmd-QUIT)
3487 (put 'erc-cmd-QUIT 'do-not-parse-args t)
3488 (put 'erc-cmd-QUIT 'process-not-needed t)
3490 (defun erc-cmd-GQUIT (reason)
3491 "Disconnect from all servers at once with the same quit REASON."
3492 (erc-with-all-buffers-of-server nil #'erc-open-server-buffer-p
3493 (erc-cmd-QUIT reason))
3494 (when erc-kill-queries-on-quit
3495 ;; if the query buffers have not been killed within 4 seconds,
3496 ;; kill them
3497 (run-at-time
3498 4 nil
3499 (lambda ()
3500 (dolist (buffer (erc-buffer-list (lambda (buf)
3501 (not (erc-server-buffer-p buf)))))
3502 (kill-buffer buffer)))))
3505 (defalias 'erc-cmd-GQ 'erc-cmd-GQUIT)
3506 (put 'erc-cmd-GQUIT 'do-not-parse-args t)
3507 (put 'erc-cmd-GQUIT 'process-not-needed t)
3509 (defun erc-cmd-RECONNECT ()
3510 "Try to reconnect to the current IRC server."
3511 (let ((buffer (erc-server-buffer))
3512 (process nil))
3513 (unless (buffer-live-p buffer)
3514 (setq buffer (current-buffer)))
3515 (with-current-buffer buffer
3516 (setq erc-server-quitting nil)
3517 (setq erc-server-reconnecting t)
3518 (setq erc-server-reconnect-count 0)
3519 (setq process (get-buffer-process (erc-server-buffer)))
3520 (if process
3521 (delete-process process)
3522 (erc-server-reconnect))
3523 (setq erc-server-reconnecting nil)))
3525 (put 'erc-cmd-RECONNECT 'process-not-needed t)
3527 (defun erc-cmd-SERVER (server)
3528 "Connect to SERVER, leaving existing connection intact."
3529 (erc-log (format "cmd: SERVER: %s" server))
3530 (condition-case nil
3531 (erc :server server :nick (erc-current-nick))
3532 (error
3533 (erc-error "Cannot find host %s." server)))
3535 (put 'erc-cmd-SERVER 'process-not-needed t)
3537 (defvar motif-version-string)
3538 (defvar gtk-version-string)
3540 (defun erc-cmd-SV ()
3541 "Say the current ERC and Emacs version into channel."
3542 (erc-send-message (format "I'm using ERC with %s %s (%s%s) of %s."
3543 (if (featurep 'xemacs) "XEmacs" "GNU Emacs")
3544 emacs-version
3545 system-configuration
3546 (concat
3547 (cond ((featurep 'motif)
3548 (concat ", " (substring
3549 motif-version-string 4)))
3550 ((featurep 'gtk)
3551 (concat ", GTK+ Version "
3552 gtk-version-string))
3553 ((featurep 'x-toolkit) ", X toolkit")
3554 (t ""))
3555 (if (and (boundp 'x-toolkit-scroll-bars)
3556 (memq x-toolkit-scroll-bars
3557 '(xaw xaw3d)))
3558 (format ", %s scroll bars"
3559 (capitalize (symbol-name
3560 x-toolkit-scroll-bars)))
3562 (if (featurep 'multi-tty) ", multi-tty" ""))
3563 erc-emacs-build-time))
3566 (defun erc-cmd-SM ()
3567 "Say the current ERC modes into channel."
3568 (erc-send-message (format "I'm using the following modules: %s!"
3569 (erc-modes)))
3572 (defun erc-cmd-DEOP (&rest people)
3573 "Remove the operator setting from user(s) given in PEOPLE."
3574 (when (> (length people) 0)
3575 (erc-server-send (concat "MODE " (erc-default-target)
3576 " -"
3577 (make-string (length people) ?o)
3579 (mapconcat 'identity people " ")))
3582 (defun erc-cmd-OP (&rest people)
3583 "Add the operator setting to users(s) given in PEOPLE."
3584 (when (> (length people) 0)
3585 (erc-server-send (concat "MODE " (erc-default-target)
3586 " +"
3587 (make-string (length people) ?o)
3589 (mapconcat 'identity people " ")))
3592 (defun erc-cmd-TIME (&optional line)
3593 "Request the current time and date from the current server."
3594 (cond
3595 ((and line (string-match "^\\s-*\\(.*\\)$" line))
3596 (let ((args (match-string 1 line)))
3597 (erc-log (format "cmd: TIME: %s" args))
3598 (erc-server-send (concat "TIME " args)))
3600 (t (erc-server-send "TIME"))))
3601 (defalias 'erc-cmd-DATE 'erc-cmd-TIME)
3603 (defun erc-cmd-TOPIC (topic)
3604 "Set or request the topic for a channel.
3605 LINE has the format: \"#CHANNEL TOPIC\", \"#CHANNEL\", \"TOPIC\"
3606 or the empty string.
3608 If no #CHANNEL is given, the default channel is used. If TOPIC is
3609 given, the channel topic is modified, otherwise the current topic will
3610 be displayed."
3611 (cond
3612 ;; /topic #channel TOPIC
3613 ((string-match "^\\s-*\\([&#+!]\\S-+\\)\\s-\\(.*\\)$" topic)
3614 (let ((ch (match-string 1 topic))
3615 (topic (match-string 2 topic)))
3616 (erc-log (format "cmd: TOPIC [%s]: %s" ch topic))
3617 (erc-server-send (format "TOPIC %s :%s" ch topic) nil ch))
3619 ;; /topic #channel
3620 ((string-match "^\\s-*\\([&#+!]\\S-+\\)" topic)
3621 (let ((ch (match-string 1 topic)))
3622 (erc-server-send (format "TOPIC %s" ch) nil ch)
3624 ;; /topic
3625 ((string-match "^\\s-*$" topic)
3626 (let ((ch (erc-default-target)))
3627 (erc-server-send (format "TOPIC %s" ch) nil ch)
3629 ;; /topic TOPIC
3630 ((string-match "^\\s-*\\(.*\\)$" topic)
3631 (let ((ch (erc-default-target))
3632 (topic (match-string 1 topic)))
3633 (if (and ch (erc-channel-p ch))
3634 (progn
3635 (erc-log (format "cmd: TOPIC [%s]: %s" ch topic))
3636 (erc-server-send (format "TOPIC %s :%s" ch topic) nil ch))
3637 (erc-display-message nil 'error (current-buffer) 'no-target)))
3639 (t nil)))
3640 (defalias 'erc-cmd-T 'erc-cmd-TOPIC)
3641 (put 'erc-cmd-TOPIC 'do-not-parse-args t)
3643 (defun erc-cmd-APPENDTOPIC (topic)
3644 "Append TOPIC to the current channel topic, separated by a space."
3645 (let ((oldtopic erc-channel-topic))
3646 ;; display help when given no arguments
3647 (when (string-match "^\\s-*$" topic)
3648 (signal 'wrong-number-of-arguments nil))
3649 ;; strip trailing ^O
3650 (when (string-match "\\(.*\\)\C-o" oldtopic)
3651 (erc-cmd-TOPIC (concat (match-string 1 oldtopic) topic)))))
3652 (defalias 'erc-cmd-AT 'erc-cmd-APPENDTOPIC)
3653 (put 'erc-cmd-APPENDTOPIC 'do-not-parse-args t)
3655 (defun erc-cmd-CLEARTOPIC (&optional channel)
3656 "Clear the topic for a CHANNEL.
3657 If CHANNEL is not specified, clear the topic for the default channel."
3658 (interactive "sClear topic of channel (RET is current channel): ")
3659 (let ((chnl (or (and (erc-channel-p channel) channel) (erc-default-target))))
3660 (when chnl
3661 (erc-server-send (format "TOPIC %s :" chnl))
3662 t)))
3664 ;;; Banlists
3666 (defvar erc-channel-banlist nil
3667 "A list of bans seen for the current channel.
3669 Each ban is an alist of the form:
3670 (WHOSET . MASK)
3672 The property `received-from-server' indicates whether
3673 or not the ban list has been requested from the server.")
3674 (make-variable-buffer-local 'erc-channel-banlist)
3675 (put 'erc-channel-banlist 'received-from-server nil)
3677 (defun erc-cmd-BANLIST ()
3678 "Pretty-print the contents of `erc-channel-banlist'.
3680 The ban list is fetched from the server if necessary."
3681 (let ((chnl (erc-default-target))
3682 (chnl-name (buffer-name)))
3684 (cond
3685 ((not (erc-channel-p chnl))
3686 (erc-display-line (erc-make-notice "You're not on a channel\n")
3687 'active))
3689 ((not (get 'erc-channel-banlist 'received-from-server))
3690 (let ((old-367-hook erc-server-367-functions))
3691 (setq erc-server-367-functions 'erc-banlist-store
3692 erc-channel-banlist nil)
3693 ;; fetch the ban list then callback
3694 (erc-with-server-buffer
3695 (erc-once-with-server-event
3697 (lambda (_proc _parsed)
3698 (with-current-buffer chnl-name
3699 (put 'erc-channel-banlist 'received-from-server t)
3700 (setq erc-server-367-functions old-367-hook)
3701 (erc-cmd-BANLIST)
3702 t)))
3703 (erc-server-send (format "MODE %s b" chnl)))))
3705 ((null erc-channel-banlist)
3706 (erc-display-line (erc-make-notice
3707 (format "No bans for channel: %s\n" chnl))
3708 'active)
3709 (put 'erc-channel-banlist 'received-from-server nil))
3712 (let* ((erc-fill-column (or (and (boundp 'erc-fill-column)
3713 erc-fill-column)
3714 (and (boundp 'fill-column)
3715 fill-column)
3716 (1- (window-width))))
3717 (separator (make-string erc-fill-column ?=))
3718 (fmt (concat
3719 "%-" (number-to-string (/ erc-fill-column 2)) "s"
3720 "%" (number-to-string (/ erc-fill-column 2)) "s")))
3722 (erc-display-line
3723 (erc-make-notice (format "Ban list for channel: %s\n"
3724 (erc-default-target)))
3725 'active)
3727 (erc-display-line separator 'active)
3728 (erc-display-line (format fmt "Ban Mask" "Banned By") 'active)
3729 (erc-display-line separator 'active)
3731 (mapc
3732 (lambda (x)
3733 (erc-display-line
3734 (format fmt
3735 (truncate-string-to-width (cdr x) (/ erc-fill-column 2))
3736 (if (car x)
3737 (truncate-string-to-width (car x) (/ erc-fill-column 2))
3738 ""))
3739 'active))
3740 erc-channel-banlist)
3742 (erc-display-line (erc-make-notice "End of Ban list")
3743 'active)
3744 (put 'erc-channel-banlist 'received-from-server nil)))))
3747 (defalias 'erc-cmd-BL 'erc-cmd-BANLIST)
3749 (defun erc-cmd-MASSUNBAN ()
3750 "Mass Unban.
3752 Unban all currently banned users in the current channel."
3753 (let ((chnl (erc-default-target)))
3754 (cond
3756 ((not (erc-channel-p chnl))
3757 (erc-display-line
3758 (erc-make-notice "You're not on a channel\n")
3759 'active))
3761 ((not (get 'erc-channel-banlist 'received-from-server))
3762 (let ((old-367-hook erc-server-367-functions))
3763 (setq erc-server-367-functions 'erc-banlist-store)
3764 ;; fetch the ban list then callback
3765 (erc-with-server-buffer
3766 (erc-once-with-server-event
3768 (lambda (_proc _parsed)
3769 (with-current-buffer chnl
3770 (put 'erc-channel-banlist 'received-from-server t)
3771 (setq erc-server-367-functions old-367-hook)
3772 (erc-cmd-MASSUNBAN)
3773 t)))
3774 (erc-server-send (format "MODE %s b" chnl)))))
3776 (t (let ((bans (mapcar 'cdr erc-channel-banlist)))
3777 (when bans
3778 ;; Glob the bans into groups of three, and carry out the unban.
3779 ;; eg. /mode #foo -bbb a*!*@* b*!*@* c*!*@*
3780 (mapc
3781 (lambda (x)
3782 (erc-server-send
3783 (format "MODE %s -%s %s" (erc-default-target)
3784 (make-string (length x) ?b)
3785 (mapconcat 'identity x " "))))
3786 (erc-group-list bans 3))))
3787 t))))
3789 (defalias 'erc-cmd-MUB 'erc-cmd-MASSUNBAN)
3791 ;;;; End of IRC commands
3793 (defun erc-ensure-channel-name (channel)
3794 "Return CHANNEL if it is a valid channel name.
3795 Eventually add a # in front of it, if that turns it into a valid channel name."
3796 (if (erc-channel-p channel)
3797 channel
3798 (concat "#" channel)))
3800 (defun erc-grab-region (start end)
3801 "Copy the region between START and END in a recreatable format.
3803 Converts all the IRC text properties in each line of the region
3804 into control codes and writes them to a separate buffer. The
3805 resulting text may be used directly as a script to generate this
3806 text again."
3807 (interactive "r")
3808 (erc-set-active-buffer (current-buffer))
3809 (save-excursion
3810 (let* ((cb (current-buffer))
3811 (buf (generate-new-buffer erc-grab-buffer-name))
3812 (region (buffer-substring start end))
3813 (lines (erc-split-multiline-safe region)))
3814 (set-buffer buf)
3815 (dolist (line lines)
3816 (insert (concat line "\n")))
3817 (set-buffer cb)
3818 (switch-to-buffer-other-window buf)))
3819 (message "erc-grab-region doesn't grab colors etc. anymore. If you use this, please tell the maintainers.")
3820 (ding))
3822 (defun erc-display-prompt (&optional buffer pos prompt face)
3823 "Display PROMPT in BUFFER at position POS.
3824 Display an ERC prompt in BUFFER.
3826 If PROMPT is nil, one is constructed with the function `erc-prompt'.
3827 If BUFFER is nil, the `current-buffer' is used.
3828 If POS is nil, PROMPT will be displayed at `point'.
3829 If FACE is non-nil, it will be used to propertize the prompt. If it is nil,
3830 `erc-prompt-face' will be used."
3831 (let* ((prompt (or prompt (erc-prompt)))
3832 (l (length prompt))
3833 (ob (current-buffer)))
3834 ;; We cannot use save-excursion because we move point, therefore
3835 ;; we resort to the ol' ob trick to restore this.
3836 (when (and buffer (bufferp buffer))
3837 (set-buffer buffer))
3839 ;; now save excursion again to store where point and mark are
3840 ;; in the current buffer
3841 (save-excursion
3842 (setq pos (or pos (point)))
3843 (goto-char pos)
3844 (when (> l 0)
3845 ;; Do not extend the text properties when typing at the end
3846 ;; of the prompt, but stuff typed in front of the prompt
3847 ;; shall remain part of the prompt.
3848 (setq prompt (erc-propertize prompt
3849 'start-open t ; XEmacs
3850 'rear-nonsticky t ; Emacs
3851 'erc-prompt t
3852 'field t
3853 'front-sticky t
3854 'read-only t))
3855 (erc-put-text-property 0 (1- (length prompt))
3856 'face (or face 'erc-prompt-face)
3857 prompt)
3858 (insert prompt))
3859 ;; Set the input marker
3860 (set-marker erc-input-marker (point)))
3862 ;; Now we are back at the old position. If the prompt was
3863 ;; inserted here or before us, advance point by the length of
3864 ;; the prompt.
3865 (when (or (not pos) (<= (point) pos))
3866 (forward-char l))
3867 ;; Clear the undo buffer now, so the user can undo his stuff,
3868 ;; but not the stuff we did. Sneaky!
3869 (setq buffer-undo-list nil)
3870 (set-buffer ob)))
3872 ;; interactive operations
3874 (defun erc-input-message ()
3875 "Read input from the minibuffer."
3876 (interactive)
3877 (let ((minibuffer-allow-text-properties t)
3878 (read-map minibuffer-local-map))
3879 (insert (read-from-minibuffer "Message: "
3880 (string (if (featurep 'xemacs)
3881 last-command-char
3882 last-command-event))
3883 read-map))
3884 (erc-send-current-line)))
3886 (defvar erc-action-history-list ()
3887 "History list for interactive action input.")
3889 (defun erc-input-action ()
3890 "Interactively input a user action and send it to IRC."
3891 (interactive "")
3892 (erc-set-active-buffer (current-buffer))
3893 (let ((action (read-from-minibuffer
3894 "Action: " nil nil nil 'erc-action-history-list)))
3895 (if (not (string-match "^\\s-*$" action))
3896 (erc-send-action (erc-default-target) action))))
3898 (defun erc-join-channel (channel &optional key)
3899 "Join CHANNEL.
3901 If `point' is at the beginning of a channel name, use that as default."
3902 (interactive
3903 (list
3904 (let ((chnl (if (looking-at "\\([&#+!][^ \n]+\\)") (match-string 1) ""))
3905 (table (when (erc-server-buffer-live-p)
3906 (set-buffer (process-buffer erc-server-process))
3907 erc-channel-list)))
3908 (completing-read "Join channel: " table nil nil nil nil chnl))
3909 (when (or current-prefix-arg erc-prompt-for-channel-key)
3910 (read-from-minibuffer "Channel key (RET for none): " nil))))
3911 (erc-cmd-JOIN channel (when (>= (length key) 1) key)))
3913 (defun erc-part-from-channel (reason)
3914 "Part from the current channel and prompt for a REASON."
3915 (interactive
3916 (list
3917 (if (and (boundp 'reason) (stringp reason) (not (string= reason "")))
3918 reason
3919 (read-from-minibuffer (concat "Reason for leaving " (erc-default-target)
3920 ": ")))))
3921 (erc-cmd-PART (concat (erc-default-target)" " reason)))
3923 (defun erc-set-topic (topic)
3924 "Prompt for a TOPIC for the current channel."
3925 (interactive
3926 (list
3927 (read-from-minibuffer
3928 (concat "Set topic of " (erc-default-target) ": ")
3929 (when erc-channel-topic
3930 (let ((ss (split-string erc-channel-topic "\C-o")))
3931 (cons (apply 'concat (if (cdr ss) (butlast ss) ss))
3932 0))))))
3933 (let ((topic-list (split-string topic "\C-o"))) ; strip off the topic setter
3934 (erc-cmd-TOPIC (concat (erc-default-target) " " (car topic-list)))))
3936 (defun erc-set-channel-limit (&optional limit)
3937 "Set a LIMIT for the current channel. Remove limit if nil.
3938 Prompt for one if called interactively."
3939 (interactive (list (read-from-minibuffer
3940 (format "Limit for %s (RET to remove limit): "
3941 (erc-default-target)))))
3942 (let ((tgt (erc-default-target)))
3943 (erc-server-send (if (and limit (>= (length limit) 1))
3944 (format "MODE %s +l %s" tgt limit)
3945 (format "MODE %s -l" tgt)))))
3947 (defun erc-set-channel-key (&optional key)
3948 "Set a KEY for the current channel. Remove key if nil.
3949 Prompt for one if called interactively."
3950 (interactive (list (read-from-minibuffer
3951 (format "Key for %s (RET to remove key): "
3952 (erc-default-target)))))
3953 (let ((tgt (erc-default-target)))
3954 (erc-server-send (if (and key (>= (length key) 1))
3955 (format "MODE %s +k %s" tgt key)
3956 (format "MODE %s -k" tgt)))))
3958 (defun erc-quit-server (reason)
3959 "Disconnect from current server after prompting for REASON.
3960 `erc-quit-reason' works with this just like with `erc-cmd-QUIT'."
3961 (interactive (list (read-from-minibuffer
3962 (format "Reason for quitting %s: "
3963 (or erc-server-announced-name
3964 erc-session-server)))))
3965 (erc-cmd-QUIT reason))
3967 ;; Movement of point
3969 (defun erc-bol ()
3970 "Move `point' to the beginning of the current line.
3972 This places `point' just after the prompt, or at the beginning of the line."
3973 (interactive)
3974 (forward-line 0)
3975 (when (get-text-property (point) 'erc-prompt)
3976 (goto-char erc-input-marker))
3977 (point))
3979 (defun erc-kill-input ()
3980 "Kill current input line using `erc-bol' followed by `kill-line'."
3981 (interactive)
3982 (when (and (erc-bol)
3983 (/= (point) (point-max))) ;; Prevent a (ding) and an error when
3984 ;; there's nothing to kill
3985 (if (boundp 'erc-input-ring-index)
3986 (setq erc-input-ring-index nil))
3987 (kill-line)))
3989 (defun erc-complete-word-at-point ()
3990 (run-hook-with-args-until-success 'erc-complete-functions))
3992 (define-obsolete-function-alias 'erc-complete-word 'completion-at-point "24.1")
3994 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3996 ;; IRC SERVER INPUT HANDLING
3998 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4000 ;;;; New Input parsing
4002 ; Stolen from ZenIRC. I just wanna test this code, so here is
4003 ; experiment area.
4005 (defcustom erc-default-server-hook '(erc-debug-missing-hooks
4006 erc-default-server-handler)
4007 "Default for server messages which aren't covered by `erc-server-hooks'."
4008 :group 'erc-server-hooks
4009 :type 'hook)
4011 (defun erc-default-server-handler (proc parsed)
4012 "Default server handler.
4014 Displays PROC and PARSED appropriately using `erc-display-message'."
4015 (erc-display-message
4016 parsed 'notice proc
4017 (mapconcat
4018 'identity
4019 (let (res)
4020 (mapc #'(lambda (x)
4021 (if (stringp x)
4022 (setq res (append res (list x)))))
4023 parsed)
4024 res)
4025 " ")))
4027 (defvar erc-server-vectors
4028 '(["msgtype" "sender" "to" "arg1" "arg2" "arg3" "..."])
4029 "List of received server messages which ERC does not specifically handle.
4030 See `erc-debug-missing-hooks'.")
4031 ;(make-variable-buffer-local 'erc-server-vectors)
4033 (defun erc-debug-missing-hooks (_proc parsed)
4034 "Add PARSED server message ERC does not yet handle to `erc-server-vectors'.
4035 These vectors can be helpful when adding new server message handlers to ERC.
4036 See `erc-default-server-hook'."
4037 (nconc erc-server-vectors (list parsed))
4038 nil)
4040 (defun erc-query (target server)
4041 "Open a query buffer on TARGET, using SERVER.
4042 To change how this query window is displayed, use `let' to bind
4043 `erc-join-buffer' before calling this."
4044 (unless (and server
4045 (buffer-live-p server)
4046 (set-buffer server))
4047 (error "Couldn't switch to server buffer"))
4048 (let ((buf (erc-open erc-session-server
4049 erc-session-port
4050 (erc-current-nick)
4051 erc-session-user-full-name
4054 (list target)
4055 target
4056 erc-server-process)))
4057 (unless buf
4058 (error "Couldn't open query window"))
4059 (erc-update-mode-line)
4060 buf))
4062 (defcustom erc-auto-query 'window-noselect
4063 "If non-nil, create a query buffer each time you receive a private message.
4064 If the buffer doesn't already exist, it is created.
4066 This can be set to a symbol, to control how the new query window
4067 should appear. The default behavior is to display the buffer in
4068 a new window, but not to select it. See the documentation for
4069 `erc-join-buffer' for a description of the available choices."
4070 :group 'erc-query
4071 :type '(choice (const :tag "Don't create query window" nil)
4072 (const :tag "Split window and select" window)
4073 (const :tag "Split window, don't select" window-noselect)
4074 (const :tag "New frame" frame)
4075 (const :tag "Bury in new buffer" bury)
4076 (const :tag "Use current buffer" buffer)
4077 (const :tag "Use current buffer" t)))
4079 (defcustom erc-query-on-unjoined-chan-privmsg t
4080 "If non-nil create query buffer on receiving any PRIVMSG at all.
4081 This includes PRIVMSGs directed to channels. If you are using an IRC
4082 bouncer, such as dircproxy, to keep a log of channels when you are
4083 disconnected, you should set this option to t."
4084 :group 'erc-query
4085 :type 'boolean)
4087 (defcustom erc-format-query-as-channel-p t
4088 "If non-nil, format text from others in a query buffer like in a channel,
4089 otherwise format like a private message."
4090 :group 'erc-query
4091 :type 'boolean)
4093 (defcustom erc-minibuffer-notice nil
4094 "If non-nil, print ERC notices for the user in the minibuffer.
4095 Only happens when the session buffer isn't visible."
4096 :group 'erc-display
4097 :type 'boolean)
4099 (defcustom erc-minibuffer-ignored nil
4100 "If non-nil, print a message in the minibuffer if we ignored something."
4101 :group 'erc-ignore
4102 :type 'boolean)
4104 (defun erc-wash-quit-reason (reason nick login host)
4105 "Remove duplicate text from quit REASON.
4106 Specifically in relation to NICK (user@host) information. Returns REASON
4107 unmodified if nothing can be removed.
4108 E.g. \"Read error to Nick [user@some.host]: 110\" would be shortened to
4109 \"Read error: 110\". The same applies for \"Ping Timeout\"."
4110 (setq nick (regexp-quote nick)
4111 login (regexp-quote login)
4112 host (regexp-quote host))
4113 (or (when (string-match (concat "^\\(Read error\\) to "
4114 nick "\\[" host "\\]: "
4115 "\\(.+\\)$")
4116 reason)
4117 (concat (match-string 1 reason) ": " (match-string 2 reason)))
4118 (when (string-match (concat "^\\(Ping timeout\\) for "
4119 nick "\\[" host "\\]$")
4120 reason)
4121 (match-string 1 reason))
4122 reason))
4124 (defun erc-nickname-in-use (nick reason)
4125 "If NICK is unavailable, tell the user the REASON.
4127 See also `erc-display-error-notice'."
4128 (if (or (not erc-try-new-nick-p)
4129 ;; how many default-nicks are left + one more try...
4130 (eq erc-nick-change-attempt-count
4131 (if (consp erc-nick)
4132 (+ (length erc-nick) 1)
4133 1)))
4134 (erc-display-error-notice
4136 (format "Nickname %s is %s, try another." nick reason))
4137 (setq erc-nick-change-attempt-count (+ erc-nick-change-attempt-count 1))
4138 (let ((newnick (nth 1 erc-default-nicks))
4139 (nicklen (cdr (assoc "NICKLEN"
4140 (erc-with-server-buffer
4141 erc-server-parameters)))))
4142 (setq erc-bad-nick t)
4143 ;; try to use a different nick
4144 (if erc-default-nicks
4145 (setq erc-default-nicks (cdr erc-default-nicks)))
4146 (if (not newnick)
4147 (setq newnick (concat (truncate-string-to-width
4148 nick
4149 (if (and erc-server-connected nicklen)
4150 (- (string-to-number nicklen)
4151 (length erc-nick-uniquifier))
4152 ;; rfc2812 max nick length = 9
4153 ;; we must assume this is the
4154 ;; server's setting if we haven't
4155 ;; established a connection yet
4156 (- 9 (length erc-nick-uniquifier))))
4157 erc-nick-uniquifier)))
4158 (erc-cmd-NICK newnick)
4159 (erc-display-error-notice
4161 (format "Nickname %s is %s, trying %s"
4162 nick reason newnick)))))
4164 ;;; Server messages
4166 (defgroup erc-server-hooks nil
4167 "Server event callbacks.
4168 Every server event - like numeric replies - has its own hook.
4169 Those hooks are all called using `run-hook-with-args-until-success'.
4170 They receive as first argument the process object from where the event
4171 originated from,
4172 and as second argument the event parsed as a vector."
4173 :group 'erc-hooks)
4175 (defun erc-display-server-message (_proc parsed)
4176 "Display the message sent by the server as a notice."
4177 (erc-display-message
4178 parsed 'notice 'active (erc-response.contents parsed)))
4180 (defun erc-auto-query (proc parsed)
4181 ;; FIXME: This needs more documentation, unless it's not a user function --
4182 ;; Lawrence 2004-01-08
4183 "Put this on `erc-server-PRIVMSG-functions'."
4184 (when erc-auto-query
4185 (let* ((nick (car (erc-parse-user (erc-response.sender parsed))))
4186 (target (car (erc-response.command-args parsed)))
4187 (msg (erc-response.contents parsed))
4188 (query (if (not erc-query-on-unjoined-chan-privmsg)
4189 nick
4190 (if (erc-current-nick-p target)
4191 nick
4192 target))))
4193 (and (not (erc-ignored-user-p (erc-response.sender parsed)))
4194 (or erc-query-on-unjoined-chan-privmsg
4195 (string= target (erc-current-nick)))
4196 (not (erc-get-buffer query proc))
4197 (not (erc-is-message-ctcp-and-not-action-p msg))
4198 (let ((erc-query-display erc-auto-query))
4199 (erc-cmd-QUERY query))
4200 nil))))
4202 (defun erc-is-message-ctcp-p (message)
4203 "Check if MESSAGE is a CTCP message or not."
4204 (string-match "^\C-a\\([^\C-a]*\\)\C-a?$" message))
4206 (defun erc-is-message-ctcp-and-not-action-p (message)
4207 "Check if MESSAGE is a CTCP message or not."
4208 (and (erc-is-message-ctcp-p message)
4209 (not (string-match "^\C-a\\ACTION.*\C-a$" message))))
4211 (defun erc-format-privmessage (nick msg privp msgp)
4212 "Format a PRIVMSG in an insertable fashion."
4213 (let* ((mark-s (if msgp (if privp "*" "<") "-"))
4214 (mark-e (if msgp (if privp "*" ">") "-"))
4215 (str (format "%s%s%s %s" mark-s nick mark-e msg))
4216 (nick-face (if privp 'erc-nick-msg-face 'erc-nick-default-face))
4217 (msg-face (if privp 'erc-direct-msg-face 'erc-default-face)))
4218 ;; add text properties to text before the nick, the nick and after the nick
4219 (erc-put-text-property 0 (length mark-s) 'face msg-face str)
4220 (erc-put-text-property (length mark-s) (+ (length mark-s) (length nick))
4221 'face nick-face str)
4222 (erc-put-text-property (+ (length mark-s) (length nick)) (length str)
4223 'face msg-face str)
4224 str))
4226 (defcustom erc-format-nick-function 'erc-format-nick
4227 "Function to format a nickname for message display."
4228 :group 'erc-display
4229 :type 'function)
4231 (defun erc-format-nick (&optional user _channel-data)
4232 "Return the nickname of USER.
4233 See also `erc-format-nick-function'."
4234 (when user (erc-server-user-nickname user)))
4236 (defun erc-get-user-mode-prefix (user)
4237 (when user
4238 (cond ((erc-channel-user-owner-p user)
4239 (erc-propertize "~" 'help-echo "owner"))
4240 ((erc-channel-user-admin-p user)
4241 (erc-propertize "&" 'help-echo "admin"))
4242 ((erc-channel-user-op-p user)
4243 (erc-propertize "@" 'help-echo "operator"))
4244 ((erc-channel-user-halfop-p user)
4245 (erc-propertize "%" 'help-echo "half-op"))
4246 ((erc-channel-user-voice-p user)
4247 (erc-propertize "+" 'help-echo "voice"))
4248 (t ""))))
4250 (defun erc-format-@nick (&optional user _channel-data)
4251 "Format the nickname of USER showing if USER has a voice, is an
4252 operator, half-op, admin or owner. Owners have \"~\", admins have
4253 \"&\", operators have \"@\" and users with voice have \"+\" as a
4254 prefix. Use CHANNEL-DATA to determine op and voice status. See
4255 also `erc-format-nick-function'."
4256 (when user
4257 (let ((nick (erc-server-user-nickname user)))
4258 (concat (erc-propertize
4259 (erc-get-user-mode-prefix nick)
4260 'face 'erc-nick-prefix-face)
4261 nick))))
4263 (defun erc-format-my-nick ()
4264 "Return the beginning of this user's message, correctly propertized."
4265 (if erc-show-my-nick
4266 (let* ((open "<")
4267 (close "> ")
4268 (nick (erc-current-nick))
4269 (mode (erc-get-user-mode-prefix nick)))
4270 (concat
4271 (erc-propertize open 'face 'erc-default-face)
4272 (erc-propertize mode 'face 'erc-my-nick-prefix-face)
4273 (erc-propertize nick 'face 'erc-my-nick-face)
4274 (erc-propertize close 'face 'erc-default-face)))
4275 (let ((prefix "> "))
4276 (erc-propertize prefix 'face 'erc-default-face))))
4278 (defun erc-echo-notice-in-default-buffer (s parsed buffer _sender)
4279 "Echos a private notice in the default buffer, namely the
4280 target buffer specified by BUFFER, or there is no target buffer,
4281 the server buffer. This function is designed to be added to
4282 either `erc-echo-notice-hook' or `erc-echo-notice-always-hook',
4283 and always returns t."
4284 (erc-display-message parsed nil buffer s)
4287 (defun erc-echo-notice-in-target-buffer (s parsed buffer _sender)
4288 "Echos a private notice in BUFFER, if BUFFER is non-nil. This
4289 function is designed to be added to either `erc-echo-notice-hook'
4290 or `erc-echo-notice-always-hook', and returns non-nil if BUFFER
4291 is non-nil."
4292 (if buffer
4293 (progn (erc-display-message parsed nil buffer s) t)
4294 nil))
4296 (defun erc-echo-notice-in-minibuffer (s _parsed _buffer _sender)
4297 "Echos a private notice in the minibuffer. This function is
4298 designed to be added to either `erc-echo-notice-hook' or
4299 `erc-echo-notice-always-hook', and always returns t."
4300 (message "%s" (concat "NOTICE: " s))
4303 (defun erc-echo-notice-in-server-buffer (s parsed _buffer _sender)
4304 "Echos a private notice in the server buffer. This function is
4305 designed to be added to either `erc-echo-notice-hook' or
4306 `erc-echo-notice-always-hook', and always returns t."
4307 (erc-display-message parsed nil nil s)
4310 (defun erc-echo-notice-in-active-non-server-buffer (s parsed _buffer _sender)
4311 "Echos a private notice in the active buffer if the active
4312 buffer is not the server buffer. This function is designed to be
4313 added to either `erc-echo-notice-hook' or
4314 `erc-echo-notice-always-hook', and returns non-nil if the active
4315 buffer is not the server buffer."
4316 (if (not (eq (erc-server-buffer) (erc-active-buffer)))
4317 (progn (erc-display-message parsed nil 'active s) t)
4318 nil))
4320 (defun erc-echo-notice-in-active-buffer (s parsed _buffer _sender)
4321 "Echos a private notice in the active buffer. This function is
4322 designed to be added to either `erc-echo-notice-hook' or
4323 `erc-echo-notice-always-hook', and always returns t."
4324 (erc-display-message parsed nil 'active s)
4327 (defun erc-echo-notice-in-user-buffers (s parsed _buffer sender)
4328 "Echos a private notice in all of the buffers for which SENDER
4329 is a member. This function is designed to be added to either
4330 `erc-echo-notice-hook' or `erc-echo-notice-always-hook', and
4331 returns non-nil if there is at least one buffer for which the
4332 sender is a member.
4334 See also: `erc-echo-notice-in-first-user-buffer',
4335 `erc-buffer-list-with-nick'."
4336 (let ((buffers (erc-buffer-list-with-nick sender erc-server-process)))
4337 (if buffers
4338 (progn (erc-display-message parsed nil buffers s) t)
4339 nil)))
4341 (defun erc-echo-notice-in-user-and-target-buffers (s parsed buffer sender)
4342 "Echos a private notice in BUFFER and in all of the buffers for
4343 which SENDER is a member. This function is designed to be added
4344 to either `erc-echo-notice-hook' or
4345 `erc-echo-notice-always-hook', and returns non-nil if there is
4346 at least one buffer for which the sender is a member or the
4347 default target.
4349 See also: `erc-echo-notice-in-user-buffers',
4350 `erc-buffer-list-with-nick'."
4351 (let ((buffers (erc-buffer-list-with-nick sender erc-server-process)))
4352 (unless (memq buffer buffers) (push buffer buffers))
4353 (if buffers ;FIXME: How could it be nil?
4354 (progn (erc-display-message parsed nil buffers s) t)
4355 nil)))
4357 (defun erc-echo-notice-in-first-user-buffer (s parsed _buffer sender)
4358 "Echos a private notice in one of the buffers for which SENDER
4359 is a member. This function is designed to be added to either
4360 `erc-echo-notice-hook' or `erc-echo-notice-always-hook', and
4361 returns non-nil if there is at least one buffer for which the
4362 sender is a member.
4364 See also: `erc-echo-notice-in-user-buffers',
4365 `erc-buffer-list-with-nick'."
4366 (let ((buffers (erc-buffer-list-with-nick sender erc-server-process)))
4367 (if buffers
4368 (progn (erc-display-message parsed nil (car buffers) s) t)
4369 nil)))
4371 ;;; Ban manipulation
4373 (defun erc-banlist-store (proc parsed)
4374 "Record ban entries for a channel."
4375 (pcase-let ((`(,channel ,mask ,whoset)
4376 (cdr (erc-response.command-args parsed))))
4377 ;; Determine to which buffer the message corresponds
4378 (let ((buffer (erc-get-buffer channel proc)))
4379 (with-current-buffer buffer
4380 (unless (member (cons whoset mask) erc-channel-banlist)
4381 (setq erc-channel-banlist (cons (cons whoset mask)
4382 erc-channel-banlist))))))
4383 nil)
4385 (defun erc-banlist-finished (proc parsed)
4386 "Record that we have received the banlist."
4387 (let* ((channel (nth 1 (erc-response.command-args parsed)))
4388 (buffer (erc-get-buffer channel proc)))
4389 (with-current-buffer buffer
4390 (put 'erc-channel-banlist 'received-from-server t)))
4391 t) ; suppress the 'end of banlist' message
4393 (defun erc-banlist-update (proc parsed)
4394 "Check MODE commands for bans and update the banlist appropriately."
4395 ;; FIXME: Possibly incorrect. -- Lawrence 2004-05-11
4396 (let* ((tgt (car (erc-response.command-args parsed)))
4397 (mode (erc-response.contents parsed))
4398 (whoset (erc-response.sender parsed))
4399 (buffer (erc-get-buffer tgt proc)))
4400 (when buffer
4401 (with-current-buffer buffer
4402 (cond ((not (get 'erc-channel-banlist 'received-from-server)) nil)
4403 ((string-match "^\\([+-]\\)b" mode)
4404 ;; This is a ban
4405 (cond
4406 ((string-match "^-" mode)
4407 ;; Remove the unbanned masks from the ban list
4408 (setq erc-channel-banlist
4409 (erc-delete-if
4410 #'(lambda (y)
4411 (member (upcase (cdr y))
4412 (mapcar #'upcase
4413 (cdr (split-string mode)))))
4414 erc-channel-banlist)))
4415 ((string-match "^+" mode)
4416 ;; Add the banned mask(s) to the ban list
4417 (mapc
4418 (lambda (mask)
4419 (unless (member (cons whoset mask) erc-channel-banlist)
4420 (setq erc-channel-banlist
4421 (cons (cons whoset mask) erc-channel-banlist))))
4422 (cdr (split-string mode))))))))))
4423 nil)
4425 ;; used for the banlist cmds
4426 (defun erc-group-list (list n)
4427 "Group LIST into sublists of length N."
4428 (cond ((null list) nil)
4429 ((null (nthcdr n list)) (list list))
4430 (t (cons (erc-subseq list 0 n) (erc-group-list (nthcdr n list) n)))))
4433 ;;; MOTD numreplies
4435 (defun erc-handle-login ()
4436 "Handle the logging in process of connection."
4437 (unless erc-logged-in
4438 (setq erc-logged-in t)
4439 (message "Logging in as \'%s\'... done" (erc-current-nick))
4440 ;; execute a startup script
4441 (let ((f (erc-select-startup-file)))
4442 (when f
4443 (erc-load-script f)))))
4445 (defun erc-connection-established (proc parsed)
4446 "Run just after connection.
4448 Set user modes and run `erc-after-connect' hook."
4449 (with-current-buffer (process-buffer proc)
4450 (unless erc-server-connected ; only once per session
4451 (let ((server (or erc-server-announced-name
4452 (erc-response.sender parsed)))
4453 (nick (car (erc-response.command-args parsed)))
4454 (buffer (process-buffer proc)))
4455 (setq erc-server-connected t)
4456 (erc-update-mode-line)
4457 (erc-set-initial-user-mode nick buffer)
4458 (erc-server-setup-periodical-ping buffer)
4459 (run-hook-with-args 'erc-after-connect server nick)))))
4461 (defun erc-set-initial-user-mode (nick buffer)
4462 "If `erc-user-mode' is non-nil for NICK, set the user modes.
4463 The server buffer is given by BUFFER."
4464 (with-current-buffer buffer
4465 (when erc-user-mode
4466 (let ((mode (if (functionp erc-user-mode)
4467 (funcall erc-user-mode)
4468 erc-user-mode)))
4469 (when (stringp mode)
4470 (erc-log (format "changing mode for %s to %s" nick mode))
4471 (erc-server-send (format "MODE %s %s" nick mode)))))))
4473 (defun erc-display-error-notice (parsed string)
4474 "Display STRING as an error notice.
4476 See also `erc-display-message'."
4477 (erc-display-message
4478 parsed '(notice error) 'active string))
4480 (defun erc-process-ctcp-query (proc parsed nick login host)
4481 ;; FIXME: This needs a proper docstring -- Lawrence 2004-01-08
4482 "Process a CTCP query."
4483 (let ((queries (delete "" (split-string (erc-response.contents parsed)
4484 "\C-a"))))
4485 (if (> (length queries) 4)
4486 (erc-display-message
4487 parsed (list 'notice 'error) proc 'ctcp-too-many)
4488 (if (= 0 (length queries))
4489 (erc-display-message
4490 parsed (list 'notice 'error) proc
4491 'ctcp-empty ?n nick)
4492 (while queries
4493 (let* ((type (upcase (car (split-string (car queries)))))
4494 (hook (intern-soft (concat "erc-ctcp-query-" type "-hook"))))
4495 (if (and hook (boundp hook))
4496 (if (string-equal type "ACTION")
4497 (run-hook-with-args-until-success
4498 hook proc parsed nick login host
4499 (car (erc-response.command-args parsed))
4500 (car queries))
4501 (when erc-paranoid
4502 (if (erc-current-nick-p
4503 (car (erc-response.command-args parsed)))
4504 (erc-display-message
4505 parsed 'error 'active 'ctcp-request
4506 ?n nick ?u login ?h host ?r (car queries))
4507 (erc-display-message
4508 parsed 'error 'active 'ctcp-request-to
4509 ?n nick ?u login ?h host ?r (car queries)
4510 ?t (car (erc-response.command-args parsed)))))
4511 (run-hook-with-args-until-success
4512 hook proc nick login host
4513 (car (erc-response.command-args parsed))
4514 (car queries)))
4515 (erc-display-message
4516 parsed (list 'notice 'error) proc
4517 'undefined-ctcp)))
4518 (setq queries (cdr queries)))))))
4520 (defvar erc-ctcp-query-ACTION-hook '(erc-ctcp-query-ACTION))
4522 (defun erc-ctcp-query-ACTION (proc parsed nick login host to msg)
4523 "Respond to a CTCP ACTION query."
4524 (when (string-match "^ACTION\\s-\\(.*\\)\\s-*$" msg)
4525 (let ((s (match-string 1 msg))
4526 (buf (or (erc-get-buffer to proc)
4527 (erc-get-buffer nick proc)
4528 (process-buffer proc))))
4529 (erc-display-message
4530 parsed 'action buf
4531 'ACTION ?n nick ?u login ?h host ?a s))))
4533 (defvar erc-ctcp-query-CLIENTINFO-hook '(erc-ctcp-query-CLIENTINFO))
4535 (defun erc-ctcp-query-CLIENTINFO (_proc nick _login _host _to msg)
4536 "Respond to a CTCP CLIENTINFO query."
4537 (when (string-match "^CLIENTINFO\\(\\s-*\\|\\s-+.*\\)$" msg)
4538 (let ((s (erc-client-info (erc-trim-string (match-string 1 msg)))))
4539 (unless erc-disable-ctcp-replies
4540 (erc-send-ctcp-notice nick (format "CLIENTINFO %s" s)))))
4541 nil)
4543 (defvar erc-ctcp-query-ECHO-hook '(erc-ctcp-query-ECHO))
4544 (defun erc-ctcp-query-ECHO (_proc nick _login _host _to msg)
4545 "Respond to a CTCP ECHO query."
4546 (when (string-match "^ECHO\\s-+\\(.*\\)\\s-*$" msg)
4547 (let ((s (match-string 1 msg)))
4548 (unless erc-disable-ctcp-replies
4549 (erc-send-ctcp-notice nick (format "ECHO %s" s)))))
4550 nil)
4552 (defvar erc-ctcp-query-FINGER-hook '(erc-ctcp-query-FINGER))
4553 (defun erc-ctcp-query-FINGER (_proc nick _login _host _to _msg)
4554 "Respond to a CTCP FINGER query."
4555 (unless erc-disable-ctcp-replies
4556 (let ((s (if erc-anonymous-login
4557 (format "FINGER I'm %s." (erc-current-nick))
4558 (format "FINGER %s (%s@%s)."
4559 (user-full-name)
4560 (user-login-name)
4561 (system-name))))
4562 (ns (erc-time-diff erc-server-last-sent-time (erc-current-time))))
4563 (when (> ns 0)
4564 (setq s (concat s " Idle for " (erc-sec-to-time ns))))
4565 (erc-send-ctcp-notice nick s)))
4566 nil)
4568 (defvar erc-ctcp-query-PING-hook '(erc-ctcp-query-PING))
4569 (defun erc-ctcp-query-PING (_proc nick _login _host _to msg)
4570 "Respond to a CTCP PING query."
4571 (when (string-match "^PING\\s-+\\(.*\\)" msg)
4572 (unless erc-disable-ctcp-replies
4573 (let ((arg (match-string 1 msg)))
4574 (erc-send-ctcp-notice nick (format "PING %s" arg)))))
4575 nil)
4577 (defvar erc-ctcp-query-TIME-hook '(erc-ctcp-query-TIME))
4578 (defun erc-ctcp-query-TIME (_proc nick _login _host _to _msg)
4579 "Respond to a CTCP TIME query."
4580 (unless erc-disable-ctcp-replies
4581 (erc-send-ctcp-notice nick (format "TIME %s" (current-time-string))))
4582 nil)
4584 (defvar erc-ctcp-query-USERINFO-hook '(erc-ctcp-query-USERINFO))
4585 (defun erc-ctcp-query-USERINFO (_proc nick _login _host _to _msg)
4586 "Respond to a CTCP USERINFO query."
4587 (unless erc-disable-ctcp-replies
4588 (erc-send-ctcp-notice nick (format "USERINFO %s" erc-user-information)))
4589 nil)
4591 (defvar erc-ctcp-query-VERSION-hook '(erc-ctcp-query-VERSION))
4592 (defun erc-ctcp-query-VERSION (_proc nick _login _host _to _msg)
4593 "Respond to a CTCP VERSION query."
4594 (unless erc-disable-ctcp-replies
4595 (erc-send-ctcp-notice
4596 nick (format
4597 "VERSION \C-bERC\C-b - an IRC client for Emacs %s (\C-b%s\C-b)"
4598 emacs-version
4599 erc-official-location)))
4600 nil)
4602 (defun erc-process-ctcp-reply (proc parsed nick login host msg)
4603 "Process MSG as a CTCP reply."
4604 (let* ((type (car (split-string msg)))
4605 (hook (intern (concat "erc-ctcp-reply-" type "-hook"))))
4606 (if (boundp hook)
4607 (run-hook-with-args-until-success
4608 hook proc nick login host
4609 (car (erc-response.command-args parsed)) msg)
4610 (erc-display-message
4611 parsed 'notice 'active
4612 'CTCP-UNKNOWN ?n nick ?u login ?h host ?m msg))))
4614 (defvar erc-ctcp-reply-ECHO-hook '(erc-ctcp-reply-ECHO))
4615 (defun erc-ctcp-reply-ECHO (_proc nick _login _host _to msg)
4616 "Handle a CTCP ECHO reply."
4617 (when (string-match "^ECHO\\s-+\\(.*\\)\\s-*$" msg)
4618 (let ((message (match-string 1 msg)))
4619 (erc-display-message
4620 nil '(notice action) 'active
4621 'CTCP-ECHO ?n nick ?m message)))
4622 nil)
4624 (defvar erc-ctcp-reply-CLIENTINFO-hook '(erc-ctcp-reply-CLIENTINFO))
4625 (defun erc-ctcp-reply-CLIENTINFO (_proc nick _login _host _to msg)
4626 "Handle a CTCP CLIENTINFO reply."
4627 (when (string-match "^CLIENTINFO\\s-+\\(.*\\)\\s-*$" msg)
4628 (let ((message (match-string 1 msg)))
4629 (erc-display-message
4630 nil 'notice 'active
4631 'CTCP-CLIENTINFO ?n nick ?m message)))
4632 nil)
4634 (defvar erc-ctcp-reply-FINGER-hook '(erc-ctcp-reply-FINGER))
4635 (defun erc-ctcp-reply-FINGER (_proc nick _login _host _to msg)
4636 "Handle a CTCP FINGER reply."
4637 (when (string-match "^FINGER\\s-+\\(.*\\)\\s-*$" msg)
4638 (let ((message (match-string 1 msg)))
4639 (erc-display-message
4640 nil 'notice 'active
4641 'CTCP-FINGER ?n nick ?m message)))
4642 nil)
4644 (defvar erc-ctcp-reply-PING-hook '(erc-ctcp-reply-PING))
4645 (defun erc-ctcp-reply-PING (_proc nick _login _host _to msg)
4646 "Handle a CTCP PING reply."
4647 (if (not (string-match "^PING\\s-+\\([0-9.]+\\)" msg))
4649 (let ((time (match-string 1 msg)))
4650 (condition-case nil
4651 (let ((delta (erc-time-diff (string-to-number time)
4652 (erc-current-time))))
4653 (erc-display-message
4654 nil 'notice 'active
4655 'CTCP-PING ?n nick
4656 ?t (erc-sec-to-time delta)))
4657 (range-error
4658 (erc-display-message
4659 nil 'error 'active
4660 'bad-ping-response ?n nick ?t time))))))
4662 (defvar erc-ctcp-reply-TIME-hook '(erc-ctcp-reply-TIME))
4663 (defun erc-ctcp-reply-TIME (_proc nick _login _host _to msg)
4664 "Handle a CTCP TIME reply."
4665 (when (string-match "^TIME\\s-+\\(.*\\)\\s-*$" msg)
4666 (let ((message (match-string 1 msg)))
4667 (erc-display-message
4668 nil 'notice 'active
4669 'CTCP-TIME ?n nick ?m message)))
4670 nil)
4672 (defvar erc-ctcp-reply-VERSION-hook '(erc-ctcp-reply-VERSION))
4673 (defun erc-ctcp-reply-VERSION (_proc nick _login _host _to msg)
4674 "Handle a CTCP VERSION reply."
4675 (when (string-match "^VERSION\\s-+\\(.*\\)\\s-*$" msg)
4676 (let ((message (match-string 1 msg)))
4677 (erc-display-message
4678 nil 'notice 'active
4679 'CTCP-VERSION ?n nick ?m message)))
4680 nil)
4682 (defun erc-process-away (proc away-p)
4683 "Toggle the away status of the user depending on the value of AWAY-P.
4685 If nil, set the user as away.
4686 If non-nil, return from being away."
4687 (let ((sessionbuf (process-buffer proc)))
4688 (when sessionbuf
4689 (with-current-buffer sessionbuf
4690 (when erc-away-nickname
4691 (erc-log (format "erc-process-away: away-nick: %s, away-p: %s"
4692 erc-away-nickname away-p))
4693 (erc-cmd-NICK (if away-p
4694 erc-away-nickname
4695 erc-nick)))
4696 (cond
4697 (away-p
4698 (setq erc-away (current-time)))
4700 (let ((away-time erc-away))
4701 ;; away must be set to NIL BEFORE sending anything to prevent
4702 ;; an infinite recursion
4703 (setq erc-away nil)
4704 (with-current-buffer (erc-active-buffer)
4705 (when erc-public-away-p
4706 (erc-send-action
4707 (erc-default-target)
4708 (if away-time
4709 (format "is back (gone for %s)"
4710 (erc-sec-to-time
4711 (erc-time-diff
4712 (erc-emacs-time-to-erc-time away-time)
4713 (erc-current-time))))
4714 "is back")))))))))
4715 (erc-update-mode-line)))
4717 ;;;; List of channel members handling
4719 (defun erc-channel-begin-receiving-names ()
4720 "Internal function.
4722 Used when a channel names list is about to be received. Should
4723 be called with the current buffer set to the channel buffer.
4725 See also `erc-channel-end-receiving-names'."
4726 (setq erc-channel-new-member-names (make-hash-table :test 'equal)))
4728 (defun erc-channel-end-receiving-names ()
4729 "Internal function.
4731 Used to fix `erc-channel-users' after a channel names list has been
4732 received. Should be called with the current buffer set to the
4733 channel buffer.
4735 See also `erc-channel-begin-receiving-names'."
4736 (maphash (lambda (nick _user)
4737 (if (null (gethash nick erc-channel-new-member-names))
4738 (erc-remove-channel-user nick)))
4739 erc-channel-users)
4740 (setq erc-channel-new-member-names nil))
4742 (defun erc-parse-prefix ()
4743 "Return an alist of valid prefix character types and their representations.
4744 Example: (operator) o => @, (voiced) v => +."
4745 (let ((str (or (cdr (assoc "PREFIX" (erc-with-server-buffer
4746 erc-server-parameters)))
4747 ;; provide a sane default
4748 "(qaohv)~&@%+"))
4749 types chars)
4750 (when (string-match "^(\\([^)]+\\))\\(.+\\)$" str)
4751 (setq types (match-string 1 str)
4752 chars (match-string 2 str))
4753 (let ((len (min (length types) (length chars)))
4754 (i 0)
4755 (alist nil))
4756 (while (< i len)
4757 (setq alist (cons (cons (elt types i) (elt chars i))
4758 alist))
4759 (setq i (1+ i)))
4760 alist))))
4762 (defun erc-channel-receive-names (names-string)
4763 "This function is for internal use only.
4765 Update `erc-channel-users' according to NAMES-STRING.
4766 NAMES-STRING is a string listing some of the names on the
4767 channel."
4768 (let* ((prefix (erc-parse-prefix))
4769 (voice-ch (cdr (assq ?v prefix)))
4770 (op-ch (cdr (assq ?o prefix)))
4771 (hop-ch (cdr (assq ?h prefix)))
4772 (adm-ch (cdr (assq ?a prefix)))
4773 (own-ch (cdr (assq ?q prefix)))
4774 (names (delete "" (split-string names-string)))
4775 name op voice halfop admin owner)
4776 (let ((erc-channel-members-changed-hook nil))
4777 (dolist (item names)
4778 (let ((updatep t)
4779 (ch (aref item 0)))
4780 (setq name item op 'off voice 'off halfop 'off admin 'off owner 'off)
4781 (if (rassq ch prefix)
4782 (if (= (length item) 1)
4783 (setq updatep nil)
4784 (setq name (substring item 1))
4785 (setf (pcase ch
4786 ((pred (eq voice-ch)) voice)
4787 ((pred (eq hop-ch)) halfop)
4788 ((pred (eq op-ch)) op)
4789 ((pred (eq adm-ch)) admin)
4790 ((pred (eq own-ch)) owner)
4791 (_ (error "Unknown prefix char `%S'" ch) voice))
4792 'on)))
4793 (when updatep
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."
4804 :group 'erc-hooks
4805 :type 'hook)
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."
4825 (let (changed)
4826 (when user
4827 (when (and new-nick
4828 (not (equal (erc-server-user-nickname user)
4829 new-nick)))
4830 (setq changed t)
4831 (erc-change-user-nickname user new-nick))
4832 (when (and host
4833 (not (equal (erc-server-user-host user) host)))
4834 (setq changed t)
4835 (setf (erc-server-user-host user) host))
4836 (when (and login
4837 (not (equal (erc-server-user-login user) login)))
4838 (setq changed t)
4839 (setf (erc-server-user-login user) login))
4840 (when (and full-name
4841 (not (equal (erc-server-user-full-name user)
4842 full-name)))
4843 (setq changed t)
4844 (setf (erc-server-user-full-name user) full-name))
4845 (when (and info
4846 (not (equal (erc-server-user-info user) info)))
4847 (setq changed t)
4848 (setf (erc-server-user-info user) info))
4849 (if changed
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))))))
4854 changed))
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
4869 lists.
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))))
4880 (if cuser
4881 (progn
4882 (erc-log (format "update-member: user = %S, cuser = %S" user cuser))
4883 (when (and voice
4884 (not (eq (erc-channel-user-voice cuser) voice)))
4885 (setq changed t)
4886 (setf (erc-channel-user-voice cuser)
4887 (cond ((eq voice 'on) t)
4888 ((eq voice 'off) nil)
4889 (t voice))))
4890 (when (and halfop
4891 (not (eq (erc-channel-user-halfop cuser) halfop)))
4892 (setq changed t)
4893 (setf (erc-channel-user-halfop cuser)
4894 (cond ((eq halfop 'on) t)
4895 ((eq halfop 'off) nil)
4896 (t halfop))))
4897 (when (and op
4898 (not (eq (erc-channel-user-op cuser) op)))
4899 (setq changed t)
4900 (setf (erc-channel-user-op cuser)
4901 (cond ((eq op 'on) t)
4902 ((eq op 'off) nil)
4903 (t op))))
4904 (when (and admin
4905 (not (eq (erc-channel-user-admin cuser) admin)))
4906 (setq changed t)
4907 (setf (erc-channel-user-admin cuser)
4908 (cond ((eq admin 'on) t)
4909 ((eq admin 'off) nil)
4910 (t admin))))
4911 (when (and owner
4912 (not (eq (erc-channel-user-owner cuser) owner)))
4913 (setq changed t)
4914 (setf (erc-channel-user-owner cuser)
4915 (cond ((eq owner 'on) t)
4916 ((eq owner 'off) nil)
4917 (t owner))))
4918 (when update-message-time
4919 (setf (erc-channel-user-last-message-time cuser) (current-time)))
4920 (setq user-changed
4921 (erc-update-user user new-nick
4922 host login full-name info)))
4923 (when add
4924 (if (null user)
4925 (progn
4926 (setq user (make-erc-server-user
4927 :nickname nick
4928 :host host
4929 :full-name full-name
4930 :login login
4931 :info info
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)
4940 (t voice))
4941 :halfop (cond ((eq halfop 'on) t)
4942 ((eq halfop 'off) nil)
4943 (t halfop))
4944 :op (cond ((eq op 'on) t)
4945 ((eq op 'off) nil)
4946 (t op))
4947 :admin (cond ((eq admin 'on) t)
4948 ((eq admin 'off) nil)
4949 (t admin))
4950 :owner (cond ((eq owner 'on) t)
4951 ((eq owner 'off) nil)
4952 (t owner))
4953 :last-message-time
4954 (if update-message-time (current-time))))
4955 (puthash (erc-downcase nick) (cons user cuser)
4956 erc-channel-users)
4957 (setq changed t)))
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'."
4969 (erc-with-buffer
4970 (channel)
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)))
4979 (when channel-data
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'."
4987 (erc-with-buffer
4988 (channel)
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))))
5013 (when buf
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)
5018 (while arg-modes
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))
5026 (t nil)))
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.
5037 Side-effect free."
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))
5056 (args nil)
5057 (add-modes nil)
5058 (remove-modes nil)
5059 (arg-modes nil); list of triples: (mode-char 'on/'off argument)
5060 (add-p t))
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
5067 (while chars
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)
5072 (if add-p 'on 'off)
5073 (if args (car args) nil))
5074 arg-modes))
5075 (if args (setq args (cdr args))))
5076 ((string-match "^[LlKk]" (car chars))
5077 (setq arg-modes (cons (list (car chars)
5078 (if add-p 'on 'off)
5079 (if (and add-p args)
5080 (car args) nil))
5081 arg-modes))
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))
5090 nil))
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))))
5106 (when buf
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?
5110 (set-buffer buf)
5111 (if (not (boundp 'erc-channel-modes))
5112 (setq erc-channel-modes nil))
5113 (while remove-modes
5114 (setq erc-channel-modes (delete (car remove-modes)
5115 erc-channel-modes)
5116 remove-modes (cdr remove-modes)))
5117 (while add-modes
5118 (setq erc-channel-modes (cons (car add-modes)
5119 erc-channel-modes)
5120 add-modes (cdr add-modes)))
5121 (setq erc-channel-modes (erc-sort-strings erc-channel-modes))
5122 (while arg-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
5144 (t nil))))
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)))
5151 (erc-with-buffer
5152 (channel)
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."
5158 (erc-with-buffer
5159 (channel)
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:
5174 Event TYPE L
5176 nickname change 'nick (NEW-NICK)"
5177 (erc-log (format "user-change: type: %S nlh: %S l: %S" type nlh l))
5178 (cond
5179 ;; nickname change
5180 ((equal type 'nick)
5183 nil)))
5185 (defun erc-highlight-notice (s)
5186 "Highlight notice message S and return it.
5187 See also variable `erc-notice-highlight-type'."
5188 (cond
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)
5196 (t 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."
5224 (if (listp thing)
5225 thing
5226 (list thing)))
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."
5232 (cond
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."
5258 (unless value-list
5259 (setq value-list (mapcar (lambda (_x) t)
5260 properties)))
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."
5278 (point-max))
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."
5293 :group 'erc
5294 :version "24.4"
5295 :type '(choice number (other :tag "disabled" nil)))
5297 (defun erc-send-current-line ()
5298 "Parse current line and send it to IRC."
5299 (interactive)
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)))
5304 (save-restriction
5305 (widen)
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))
5318 (unwind-protect
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
5323 (save-restriction
5324 (widen)
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
5343 erc-input-marker
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
5354 (cond
5355 ;; Ignore empty input
5356 ((if erc-send-whitespace-lines
5357 (string= input "")
5358 (string-match "\\`[ \t\r\f\n]*\\'" input))
5359 (when erc-warn-about-blank-lines
5360 (message "Blank line - ignoring...")
5361 (beep))
5362 nil)
5364 (defvar str) ;; FIXME: Make it obey the "erc-" prefix convention.
5365 (let ((str input)
5366 (erc-insert-this t))
5367 (setq erc-send-this t)
5368 (run-hook-with-args 'erc-send-pre-hook input)
5369 (when erc-send-this
5370 (if (or (string-match "\n" str)
5371 (not (string-match erc-command-regexp str)))
5372 (mapc
5373 (lambda (line)
5374 (mapc
5375 (lambda (line)
5376 ;; Insert what has to be inserted for this.
5377 (erc-display-msg line)
5378 (erc-process-input-line (concat line "\n")
5379 (null erc-flood-protect) t))
5380 (or (and erc-flood-protect (erc-split-line line))
5381 (list line))))
5382 (split-string str "\n"))
5383 (erc-process-input-line (concat str "\n") t nil))
5384 t)))))
5386 (defun erc-display-command (line)
5387 (when erc-insert-this
5388 (let ((insert-position (point)))
5389 (unless erc-hide-prompt
5390 (erc-display-prompt nil nil (erc-command-indicator)
5391 (and (erc-command-indicator)
5392 'erc-command-indicator-face)))
5393 (let ((beg (point)))
5394 (insert line)
5395 (erc-put-text-property beg (point)
5396 'face 'erc-command-indicator-face)
5397 (insert "\n"))
5398 (when (processp erc-server-process)
5399 (set-marker (process-mark erc-server-process) (point)))
5400 (set-marker erc-insert-marker (point))
5401 (save-excursion
5402 (save-restriction
5403 (narrow-to-region insert-position (point))
5404 (run-hooks 'erc-send-modify-hook)
5405 (run-hooks 'erc-send-post-hook))))))
5407 (defun erc-display-msg (line)
5408 "Display LINE as a message of the user to the current target at the
5409 current position."
5410 (when erc-insert-this
5411 (let ((insert-position (point)))
5412 (insert (erc-format-my-nick))
5413 (let ((beg (point)))
5414 (insert line)
5415 (erc-put-text-property beg (point)
5416 'face 'erc-input-face))
5417 (insert "\n")
5418 (when (processp erc-server-process)
5419 (set-marker (process-mark erc-server-process) (point)))
5420 (set-marker erc-insert-marker (point))
5421 (save-excursion
5422 (save-restriction
5423 (narrow-to-region insert-position (point))
5424 (run-hooks 'erc-send-modify-hook)
5425 (run-hooks 'erc-send-post-hook))))))
5427 (defun erc-command-symbol (command)
5428 "Return the ERC command symbol for COMMAND if it exists and is bound."
5429 (let ((cmd (intern-soft (format "erc-cmd-%s" (upcase command)))))
5430 (when (fboundp cmd) cmd)))
5432 (defun erc-extract-command-from-line (line)
5433 "Extract command and args from the input LINE.
5434 If no command was given, return nil. If command matches, return a
5435 list of the form: (command args) where both elements are strings."
5436 (when (string-match erc-command-regexp line)
5437 (let* ((cmd (erc-command-symbol (match-string 1 line)))
5438 ;; note: return is nil, we apply this simply for side effects
5439 (_canon-defun (while (and cmd (symbolp (symbol-function cmd)))
5440 (setq cmd (symbol-function cmd))))
5441 (cmd-fun (or cmd #'erc-cmd-default))
5442 (arg (if cmd
5443 (if (get cmd-fun 'do-not-parse-args)
5444 (format "%s" (match-string 2 line))
5445 (delete "" (split-string (erc-trim-string
5446 (match-string 2 line)) " ")))
5447 line)))
5448 (list cmd-fun arg))))
5450 (defun erc-split-multiline-safe (string)
5451 "Split STRING, containing multiple lines and return them in a list.
5452 Do it only for STRING as the complete input, do not carry unfinished
5453 strings over to the next call."
5454 (let ((l ())
5455 (i0 0)
5456 (doit t))
5457 (while doit
5458 (let ((i (string-match "\r?\n" string i0))
5459 (s (substring string i0)))
5460 (cond (i (setq l (cons (substring string i0 i) l))
5461 (setq i0 (match-end 0)))
5462 ((> (length s) 0)
5463 (setq l (cons s l))(setq doit nil))
5464 (t (setq doit nil)))))
5465 (nreverse l)))
5467 ;; nick handling
5469 (defun erc-set-current-nick (nick)
5470 "Set the current nickname to NICK."
5471 (with-current-buffer (if (buffer-live-p (erc-server-buffer))
5472 (erc-server-buffer)
5473 (current-buffer))
5474 (setq erc-server-current-nick nick)))
5476 (defun erc-current-nick ()
5477 "Return the current nickname."
5478 (with-current-buffer (if (buffer-live-p (erc-server-buffer))
5479 (erc-server-buffer)
5480 (current-buffer))
5481 erc-server-current-nick))
5483 (defun erc-current-nick-p (nick)
5484 "Return non-nil if NICK is the current nickname."
5485 (erc-nick-equal-p nick (erc-current-nick)))
5487 (defun erc-nick-equal-p (nick1 nick2)
5488 "Return non-nil if NICK1 and NICK2 are the same.
5490 This matches strings according to the IRC protocol's case convention.
5492 See also `erc-downcase'."
5493 (string= (erc-downcase nick1)
5494 (erc-downcase nick2)))
5496 ;; default target handling
5498 (defun erc-default-target ()
5499 "Return the current default target (as a character string) or nil if none."
5500 (let ((tgt (car erc-default-recipients)))
5501 (cond
5502 ((not tgt) nil)
5503 ((listp tgt) (cdr tgt))
5504 (t tgt))))
5506 (defun erc-add-default-channel (channel)
5507 "Add CHANNEL to the default channel list."
5508 (let ((chl (downcase channel)))
5509 (setq erc-default-recipients
5510 (cons chl erc-default-recipients))))
5512 (defun erc-delete-default-channel (channel &optional buffer)
5513 "Delete CHANNEL from the default channel list."
5514 (with-current-buffer (if (and buffer
5515 (bufferp buffer))
5516 buffer
5517 (current-buffer))
5518 (setq erc-default-recipients (delete (downcase channel)
5519 erc-default-recipients))))
5521 (defun erc-add-query (nickname)
5522 "Add QUERY'd NICKNAME to the default channel list.
5524 The previous default target of QUERY type gets removed."
5525 (let ((d1 (car erc-default-recipients))
5526 (d2 (cdr erc-default-recipients))
5527 (qt (cons 'QUERY (downcase nickname))))
5528 (setq erc-default-recipients (cons qt (if (and (listp d1)
5529 (eq (car d1) 'QUERY))
5531 erc-default-recipients)))))
5533 (defun erc-delete-query ()
5534 "Delete the topmost target if it is a QUERY."
5536 (let ((d1 (car erc-default-recipients))
5537 (d2 (cdr erc-default-recipients)))
5538 (if (and (listp d1)
5539 (eq (car d1) 'QUERY))
5540 (setq erc-default-recipients d2)
5541 (error "Current target is not a QUERY"))))
5543 (defun erc-ignored-user-p (spec)
5544 "Return non-nil if SPEC matches something in `erc-ignore-list'.
5546 Takes a full SPEC of a user in the form \"nick!login@host\", and
5547 matches against all the regexp's in `erc-ignore-list'. If any
5548 match, returns that regexp."
5549 (catch 'found
5550 (dolist (ignored (erc-with-server-buffer erc-ignore-list))
5551 (if (string-match ignored spec)
5552 (throw 'found ignored)))))
5554 (defun erc-ignored-reply-p (msg tgt proc)
5555 ;; FIXME: this docstring needs fixing -- Lawrence 2004-01-08
5556 "Return non-nil if MSG matches something in `erc-ignore-reply-list'.
5558 Takes a message MSG to a channel and returns non-nil if the addressed
5559 user matches any regexp in `erc-ignore-reply-list'."
5560 (let ((target-nick (erc-message-target msg)))
5561 (if (not target-nick)
5563 (erc-with-buffer (tgt proc)
5564 (let ((user (erc-get-server-user target-nick)))
5565 (when user
5566 (erc-list-match erc-ignore-reply-list
5567 (erc-user-spec user))))))))
5569 (defun erc-message-target (msg)
5570 "Return the addressed target in MSG.
5572 The addressed target is the string before the first colon in MSG."
5573 (if (string-match "^\\([^: \n]*\\):" msg)
5574 (match-string 1 msg)
5575 nil))
5577 (defun erc-user-spec (user)
5578 "Create a nick!user@host spec from a user struct."
5579 (let ((nick (erc-server-user-nickname user))
5580 (host (erc-server-user-host user))
5581 (login (erc-server-user-login user)))
5582 (concat (or nick "")
5584 (or login "")
5586 (or host ""))))
5588 (defun erc-list-match (lst str)
5589 "Return non-nil if any regexp in LST matches STR."
5590 (memq nil (mapcar (lambda (regexp)
5591 (not (string-match regexp str)))
5592 lst)))
5594 ;; other "toggles"
5596 (defun erc-toggle-ctcp-autoresponse (&optional arg)
5597 "Toggle automatic CTCP replies (like VERSION and PING).
5599 If ARG is positive, turns CTCP replies on.
5601 If ARG is non-nil and not positive, turns CTCP replies off."
5602 (interactive "P")
5603 (cond ((and (numberp arg) (> arg 0))
5604 (setq erc-disable-ctcp-replies t))
5605 (arg (setq erc-disable-ctcp-replies nil))
5606 (t (setq erc-disable-ctcp-replies (not erc-disable-ctcp-replies))))
5607 (message "ERC CTCP replies are %s" (if erc-disable-ctcp-replies "OFF" "ON")))
5609 (defun erc-toggle-flood-control (&optional arg)
5610 "Toggle use of flood control on sent messages.
5612 If ARG is positive, use flood control.
5613 If ARG is non-nil and not positive, do not use flood control.
5615 See `erc-server-flood-margin' for an explanation of the available
5616 flood control parameters."
5617 (interactive "P")
5618 (cond ((and (numberp arg) (> arg 0))
5619 (setq erc-flood-protect t))
5620 (arg (setq erc-flood-protect nil))
5621 (t (setq erc-flood-protect (not erc-flood-protect))))
5622 (message "ERC flood control is %s"
5623 (cond (erc-flood-protect "ON")
5624 (t "OFF"))))
5626 ;; Some useful channel and nick commands for fast key bindings
5628 (defun erc-invite-only-mode (&optional arg)
5629 "Turn on the invite only mode (+i) for the current channel.
5631 If ARG is non-nil, turn this mode off (-i).
5633 This command is sent even if excess flood is detected."
5634 (interactive "P")
5635 (erc-set-active-buffer (current-buffer))
5636 (let ((tgt (erc-default-target)))
5637 (if (or (not tgt) (not (erc-channel-p tgt)))
5638 (erc-display-message nil 'error (current-buffer) 'no-target)
5639 (erc-load-irc-script-lines
5640 (list (concat "/mode " tgt (if arg " -i" " +i")))
5641 t))))
5643 (defun erc-get-channel-mode-from-keypress (key)
5644 "Read a key sequence and call the corresponding channel mode function.
5645 After doing C-c C-o, type in a channel mode letter.
5647 C-g means quit.
5648 RET lets you type more than one mode at a time.
5649 If \"l\" is pressed, `erc-set-channel-limit' gets called.
5650 If \"k\" is pressed, `erc-set-channel-key' gets called.
5651 Anything else will be sent to `erc-toggle-channel-mode'."
5652 (interactive "kChannel mode (RET to set more than one): ")
5653 (when (featurep 'xemacs)
5654 (setq key (char-to-string (event-to-character (aref key 0)))))
5655 (cond ((equal key "\C-g")
5656 (keyboard-quit))
5657 ((equal key "\C-m")
5658 (erc-insert-mode-command))
5659 ((equal key "l")
5660 (call-interactively 'erc-set-channel-limit))
5661 ((equal key "k")
5662 (call-interactively 'erc-set-channel-key))
5663 (t (erc-toggle-channel-mode key))))
5665 (defun erc-toggle-channel-mode (mode &optional channel)
5666 "Toggle channel MODE.
5668 If CHANNEL is non-nil, toggle MODE for that channel, otherwise use
5669 `erc-default-target'."
5670 (interactive "P")
5671 (erc-set-active-buffer (current-buffer))
5672 (let ((tgt (or channel (erc-default-target))))
5673 (if (or (null tgt) (null (erc-channel-p tgt)))
5674 (erc-display-message nil 'error 'active 'no-target)
5675 (let* ((active (member mode erc-channel-modes))
5676 (newstate (if active "OFF" "ON")))
5677 (erc-log (format "%s: Toggle mode %s %s" tgt mode newstate))
5678 (message "Toggle channel mode %s %s" mode newstate)
5679 (erc-server-send (format "MODE %s %s%s"
5680 tgt (if active "-" "+") mode))))))
5682 (defun erc-insert-mode-command ()
5683 "Insert the line \"/mode <current target> \" at `point'."
5684 (interactive)
5685 (let ((tgt (erc-default-target)))
5686 (if tgt (insert (concat "/mode " tgt " "))
5687 (erc-display-message nil 'error (current-buffer) 'no-target))))
5689 (defun erc-channel-names ()
5690 "Run \"/names #channel\" in the current channel."
5691 (interactive)
5692 (erc-set-active-buffer (current-buffer))
5693 (let ((tgt (erc-default-target)))
5694 (if tgt (erc-load-irc-script-lines (list (concat "/names " tgt)))
5695 (erc-display-message nil 'error (current-buffer) 'no-target))))
5697 (defun erc-remove-text-properties-region (start end &optional object)
5698 "Clears the region (START,END) in OBJECT from all colors, etc."
5699 (interactive "r")
5700 (save-excursion
5701 (let ((inhibit-read-only t))
5702 (set-text-properties start end nil object))))
5703 (put 'erc-remove-text-properties-region 'disabled t)
5705 ;; script execution and startup
5707 (defun erc-find-file (file &optional path)
5708 "Search for a FILE in the filesystem.
5709 First the `default-directory' is searched for FILE, then any directories
5710 specified in the list PATH.
5712 If FILE is found, return the path to it."
5713 (let ((filepath file))
5714 (if (file-readable-p filepath) filepath
5715 (while (and path
5716 (progn (setq filepath (expand-file-name file (car path)))
5717 (not (file-readable-p filepath))))
5718 (setq path (cdr path)))
5719 (if path filepath nil))))
5721 (defun erc-select-startup-file ()
5722 "Select an ERC startup file.
5723 See also `erc-startup-file-list'."
5724 (catch 'found
5725 (dolist (f erc-startup-file-list)
5726 (setq f (convert-standard-filename f))
5727 (when (file-readable-p f)
5728 (throw 'found f)))))
5730 (defun erc-find-script-file (file)
5731 "Search for FILE in `default-directory', and any in `erc-script-path'."
5732 (erc-find-file file erc-script-path))
5734 (defun erc-load-script (file)
5735 "Load a script from FILE.
5737 FILE must be the full name, it is not searched in the
5738 `erc-script-path'. If the filename ends with `.el', then load it
5739 as an Emacs Lisp program. Otherwise, treat it as a regular IRC
5740 script."
5741 (erc-log (concat "erc-load-script: " file))
5742 (cond
5743 ((string-match "\\.el\\'" file)
5744 (load file))
5746 (erc-load-irc-script file))))
5748 (defun erc-process-script-line (line &optional args)
5749 "Process an IRC script LINE.
5751 Does script-specific substitutions (script arguments, current nick,
5752 server, etc.) in LINE and returns it.
5754 Substitutions are: %C and %c = current target (channel or nick),
5755 %S %s = current server, %N %n = my current nick, and %x is x verbatim,
5756 where x is any other character;
5757 $* = the entire argument string, $1 = the first argument, $2 = the second,
5758 and so on."
5759 (if (not args) (setq args ""))
5760 (let* ((arg-esc-regexp "\\(\\$\\(\\*\\|[1-9][0-9]*\\)\\)\\([^0-9]\\|$\\)")
5761 (percent-regexp "\\(%.\\)")
5762 (esc-regexp (concat arg-esc-regexp "\\|" percent-regexp))
5763 (tgt (erc-default-target))
5764 (server (and (boundp 'erc-session-server) erc-session-server))
5765 (nick (erc-current-nick))
5766 (res "")
5767 (tmp nil)
5768 (arg-list nil)
5769 (arg-num 0))
5770 (if (not tgt) (setq tgt ""))
5771 (if (not server) (setq server ""))
5772 (if (not nick) (setq nick ""))
5773 ;; First, compute the argument list
5774 (setq tmp args)
5775 (while (string-match "^\\s-*\\(\\S-+\\)\\(\\s-+.*$\\|$\\)" tmp)
5776 (setq arg-list (cons (match-string 1 tmp) arg-list))
5777 (setq tmp (match-string 2 tmp)))
5778 (setq arg-list (nreverse arg-list))
5779 (setq arg-num (length arg-list))
5780 ;; now do the substitution
5781 (setq tmp (string-match esc-regexp line))
5782 (while tmp
5783 ;;(message "beginning of while: tmp=%S" tmp)
5784 (let* ((hd (substring line 0 tmp))
5785 (esc "")
5786 (subst "")
5787 (tail (substring line tmp)))
5788 (cond ((string-match (concat "^" arg-esc-regexp) tail)
5789 (setq esc (match-string 1 tail))
5790 (setq tail (substring tail (match-end 1))))
5791 ((string-match (concat "^" percent-regexp) tail)
5792 (setq esc (match-string 1 tail))
5793 (setq tail (substring tail (match-end 1)))))
5794 ;;(message "hd=%S, esc=%S, tail=%S, arg-num=%S" hd esc tail arg-num)
5795 (setq res (concat res hd))
5796 (setq subst
5797 (cond ((string= esc "") "")
5798 ((string-match "^\\$\\*$" esc) args)
5799 ((string-match "^\\$\\([0-9]+\\)$" esc)
5800 (let ((n (string-to-number (match-string 1 esc))))
5801 (message "n = %S, integerp(n)=%S" n (integerp n))
5802 (if (<= n arg-num) (nth (1- n) arg-list) "")))
5803 ((string-match "^%[Cc]$" esc) tgt)
5804 ((string-match "^%[Ss]$" esc) server)
5805 ((string-match "^%[Nn]$" esc) nick)
5806 ((string-match "^%\\(.\\)$" esc) (match-string 1 esc))
5807 (t (erc-log (format "BUG in erc-process-script-line: bad escape sequence: %S\n" esc))
5808 (message "BUG IN ERC: esc=%S" esc)
5809 "")))
5810 (setq line tail)
5811 (setq tmp (string-match esc-regexp line))
5812 (setq res (concat res subst))
5813 ;;(message "end of while: line=%S, res=%S, tmp=%S" line res tmp)
5815 (setq res (concat res line))
5816 res))
5818 (defun erc-load-irc-script (file &optional force)
5819 "Load an IRC script from FILE."
5820 (erc-log (concat "erc-load-script: " file))
5821 (let ((str (with-temp-buffer
5822 (insert-file-contents file)
5823 (buffer-string))))
5824 (erc-load-irc-script-lines (erc-split-multiline-safe str) force)))
5826 (defun erc-load-irc-script-lines (lines &optional force noexpand)
5827 "Load IRC script LINES (a list of strings).
5829 If optional NOEXPAND is non-nil, do not expand script-specific
5830 sequences, process the lines verbatim. Use this for multiline
5831 user input."
5832 (let* ((cb (current-buffer))
5833 (s "")
5834 (sp (or (erc-command-indicator) (erc-prompt)))
5835 (args (and (boundp 'erc-script-args) erc-script-args)))
5836 (if (and args (string-match "^ " args))
5837 (setq args (substring args 1)))
5838 ;; prepare the prompt string for echo
5839 (erc-put-text-property 0 (length sp)
5840 'face 'erc-command-indicator-face sp)
5841 (while lines
5842 (setq s (car lines))
5843 (erc-log (concat "erc-load-script: CMD: " s))
5844 (unless (string-match "^\\s-*$" s)
5845 (let ((line (if noexpand s (erc-process-script-line s args))))
5846 (if (and (erc-process-input-line line force)
5847 erc-script-echo)
5848 (progn
5849 (erc-put-text-property 0 (length line)
5850 'face 'erc-input-face line)
5851 (erc-display-line (concat sp line) cb)))))
5852 (setq lines (cdr lines)))))
5854 ;; authentication
5856 (defun erc-login ()
5857 "Perform user authentication at the IRC server."
5858 (erc-log (format "login: nick: %s, user: %s %s %s :%s"
5859 (erc-current-nick)
5860 (user-login-name)
5861 (or erc-system-name (system-name))
5862 erc-session-server
5863 erc-session-user-full-name))
5864 (if erc-session-password
5865 (erc-server-send (format "PASS %s" erc-session-password))
5866 (message "Logging in without password"))
5867 (erc-server-send (format "NICK %s" (erc-current-nick)))
5868 (erc-server-send
5869 (format "USER %s %s %s :%s"
5870 ;; hacked - S.B.
5871 (if erc-anonymous-login erc-email-userid (user-login-name))
5872 "0" "*"
5873 erc-session-user-full-name))
5874 (erc-update-mode-line))
5876 ;; connection properties' heuristics
5878 (defun erc-determine-parameters (&optional server port nick name)
5879 "Determine the connection and authentication parameters.
5880 Sets the buffer local variables:
5882 - `erc-session-connector'
5883 - `erc-session-server'
5884 - `erc-session-port'
5885 - `erc-session-full-name'
5886 - `erc-server-current-nick'"
5887 (setq erc-session-connector erc-server-connect-function
5888 erc-session-server (erc-compute-server server)
5889 erc-session-port (or port erc-default-port)
5890 erc-session-user-full-name (erc-compute-full-name name))
5891 (erc-set-current-nick (erc-compute-nick nick)))
5893 (defun erc-compute-server (&optional server)
5894 "Return an IRC server name.
5896 This tries a number of increasingly more default methods until a
5897 non-nil value is found.
5899 - SERVER (the argument passed to this function)
5900 - The `erc-server' option
5901 - The value of the IRCSERVER environment variable
5902 - The `erc-default-server' variable"
5903 (or server
5904 erc-server
5905 (getenv "IRCSERVER")
5906 erc-default-server))
5908 (defun erc-compute-nick (&optional nick)
5909 "Return user's IRC nick.
5911 This tries a number of increasingly more default methods until a
5912 non-nil value is found.
5914 - NICK (the argument passed to this function)
5915 - The `erc-nick' option
5916 - The value of the IRCNICK environment variable
5917 - The result from the `user-login-name' function"
5918 (or nick
5919 (if (consp erc-nick) (car erc-nick) erc-nick)
5920 (getenv "IRCNICK")
5921 (user-login-name)))
5924 (defun erc-compute-full-name (&optional full-name)
5925 "Return user's full name.
5927 This tries a number of increasingly more default methods until a
5928 non-nil value is found.
5930 - FULL-NAME (the argument passed to this function)
5931 - The `erc-user-full-name' option
5932 - The value of the IRCNAME environment variable
5933 - The result from the `user-full-name' function"
5934 (or full-name
5935 erc-user-full-name
5936 (getenv "IRCNAME")
5937 (if erc-anonymous-login "unknown" nil)
5938 (user-full-name)))
5940 (defun erc-compute-port (&optional port)
5941 "Return a port for an IRC server.
5943 This tries a number of increasingly more default methods until a
5944 non-nil value is found.
5946 - PORT (the argument passed to this function)
5947 - The `erc-port' option
5948 - The `erc-default-port' variable"
5949 (or port erc-port erc-default-port))
5951 ;; time routines
5953 (defun erc-string-to-emacs-time (string)
5954 "Convert the long number represented by STRING into an Emacs format.
5955 Returns a list of the form (HIGH LOW), compatible with Emacs time format."
5956 (let* ((n (string-to-number (concat string ".0"))))
5957 (list (truncate (/ n 65536))
5958 (truncate (mod n 65536)))))
5960 (defalias 'erc-emacs-time-to-erc-time
5961 (if (featurep 'xemacs) 'time-to-seconds 'float-time))
5963 (defalias 'erc-current-time 'erc-emacs-time-to-erc-time)
5965 (defun erc-time-diff (t1 t2)
5966 "Return the time difference in seconds between T1 and T2."
5967 (abs (- t2 t1)))
5969 (defun erc-time-gt (t1 t2)
5970 "Check whether T1 > T2."
5971 (> t1 t2))
5973 (defun erc-sec-to-time (ns)
5974 "Convert NS to a time string HH:MM.SS."
5975 (setq ns (truncate ns))
5976 (format "%02d:%02d.%02d"
5977 (/ ns 3600)
5978 (/ (% ns 3600) 60)
5979 (% ns 60)))
5981 (defun erc-seconds-to-string (seconds)
5982 "Convert a number of SECONDS into an English phrase."
5983 (let (days hours minutes format-args output)
5984 (setq days (/ seconds 86400)
5985 seconds (% seconds 86400)
5986 hours (/ seconds 3600)
5987 seconds (% seconds 3600)
5988 minutes (/ seconds 60)
5989 seconds (% seconds 60)
5990 format-args (if (> days 0)
5991 `("%d days, %d hours, %d minutes, %d seconds"
5992 ,days ,hours ,minutes ,seconds)
5993 (if (> hours 0)
5994 `("%d hours, %d minutes, %d seconds"
5995 ,hours ,minutes ,seconds)
5996 (if (> minutes 0)
5997 `("%d minutes, %d seconds" ,minutes ,seconds)
5998 `("%d seconds" ,seconds))))
5999 output (apply 'format format-args))
6000 ;; Change all "1 units" to "1 unit".
6001 (while (string-match "\\([^0-9]\\|^\\)1 \\S-+\\(s\\)" output)
6002 (setq output (erc-replace-match-subexpression-in-string
6003 "" output (match-string 2 output) 2 (match-beginning 2))))
6004 output))
6007 ;; info
6009 (defconst erc-clientinfo-alist
6010 '(("ACTION" . "is used to inform about one's current activity")
6011 ("CLIENTINFO" . "gives help on CTCP commands supported by client")
6012 ("ECHO" . "echoes its arguments back")
6013 ("FINGER" . "shows user's name, location, and idle time")
6014 ("PING" . "measures delay between peers")
6015 ("TIME" . "shows client-side time")
6016 ("USERINFO" . "shows information provided by a user")
6017 ("VERSION" . "shows client type and version"))
6018 "Alist of CTCP CLIENTINFO for ERC commands.")
6020 (defun erc-client-info (s)
6021 "Return CTCP CLIENTINFO on command S.
6022 If S is nil or an empty string then return general CLIENTINFO."
6023 (if (or (not s) (string= s ""))
6024 (concat
6025 (apply #'concat
6026 (mapcar (lambda (e)
6027 (concat (car e) " "))
6028 erc-clientinfo-alist))
6029 ": use CLIENTINFO <COMMAND> to get more specific information")
6030 (let ((h (assoc (upcase s) erc-clientinfo-alist)))
6031 (if h
6032 (concat s " " (cdr h))
6033 (concat s ": unknown command")))))
6035 ;; Hook functions
6037 (defun erc-directory-writable-p (dir)
6038 "Determine whether DIR is a writable directory.
6039 If it doesn't exist, create it."
6040 (unless (file-attributes dir) (make-directory dir))
6041 (or (file-accessible-directory-p dir) (error "Cannot access %s" dir)))
6043 (defun erc-kill-query-buffers (process)
6044 "Kill all buffers of PROCESS."
6045 ;; here, we only want to match the channel buffers, to avoid
6046 ;; "selecting killed buffers" b0rkage.
6047 (erc-with-all-buffers-of-server process
6048 (lambda ()
6049 (not (erc-server-buffer-p)))
6050 (kill-buffer (current-buffer))))
6052 (defun erc-nick-at-point ()
6053 "Give information about the nickname at `point'.
6055 If called interactively, give a human readable message in the
6056 minibuffer. If called programmatically, return the corresponding
6057 entry of `channel-members'."
6058 (interactive)
6059 (require 'thingatpt)
6060 (let* ((word (word-at-point))
6061 (channel-data (erc-get-channel-user word))
6062 (cuser (cdr channel-data))
6063 (user (if channel-data
6064 (car channel-data)
6065 (erc-get-server-user word)))
6066 host login full-name nick voice halfop op admin owner)
6067 (when user
6068 (setq nick (erc-server-user-nickname user)
6069 host (erc-server-user-host user)
6070 login (erc-server-user-login user)
6071 full-name (erc-server-user-full-name user))
6072 (if cuser
6073 (setq voice (erc-channel-user-voice cuser)
6074 halfop (erc-channel-user-halfop cuser)
6075 op (erc-channel-user-op cuser)
6076 admin (erc-channel-user-admin cuser)
6077 owner (erc-channel-user-owner cuser))))
6078 (if (called-interactively-p 'interactive)
6079 (message "%s is %s@%s%s%s"
6080 nick login host
6081 (if full-name (format " (%s)" full-name) "")
6082 (if (or voice halfop op admin owner)
6083 (format " and is +%s%s%s%s%s on %s"
6084 (if voice "v" "")
6085 (if halfop "h" "")
6086 (if op "o" "")
6087 (if admin "a" "")
6088 (if owner "q" "")
6089 (erc-default-target))
6090 ""))
6091 user)))
6093 (defun erc-away-time ()
6094 "Return non-nil if the current ERC process is set away.
6096 In particular, the time that we were set away is returned.
6097 See `current-time' for details on the time format."
6098 (erc-with-server-buffer erc-away))
6100 ;; Mode line handling
6102 (defcustom erc-mode-line-format "%S %a"
6103 "A string to be formatted and shown in the mode-line in `erc-mode'.
6105 The string is formatted using `format-spec' and the result is set as the value
6106 of `mode-line-buffer-identification'.
6108 The following characters are replaced:
6109 %a: String indicating away status or \"\" if you are not away
6110 %l: The estimated lag time to the server
6111 %m: The modes of the channel
6112 %n: The current nick name
6113 %N: The name of the network
6114 %o: The topic of the channel
6115 %p: The session port
6116 %t: The name of the target (channel, nickname, or servername:port)
6117 %s: In the server-buffer, this gets filled with the value of
6118 `erc-server-announced-name', in a channel, the value of
6119 (erc-default-target) also get concatenated.
6120 %S: In the server-buffer, this gets filled with the value of
6121 `erc-network', in a channel, the value of (erc-default-target)
6122 also get concatenated."
6123 :group 'erc-mode-line-and-header
6124 :type 'string)
6126 (defcustom erc-header-line-format "%n on %t (%m,%l) %o"
6127 "A string to be formatted and shown in the header-line in `erc-mode'.
6128 Only used starting in Emacs 21.
6130 Set this to nil if you do not want the header line to be
6131 displayed.
6133 See `erc-mode-line-format' for which characters are can be used."
6134 :group 'erc-mode-line-and-header
6135 :set (lambda (sym val)
6136 (set sym val)
6137 (when (fboundp 'erc-update-mode-line)
6138 (erc-update-mode-line nil)))
6139 :type '(choice (const :tag "Disabled" nil)
6140 string))
6142 (defcustom erc-header-line-uses-tabbar-p nil
6143 "Use tabbar mode instead of the header line to display the header."
6144 :group 'erc-mode-line-and-header
6145 :type 'boolean)
6147 (defcustom erc-header-line-uses-help-echo-p t
6148 "Show the contents of the header line in the echo area or as a tooltip
6149 when you move point into the header line."
6150 :group 'erc-mode-line-and-header
6151 :type 'boolean)
6153 (defcustom erc-header-line-face-method nil
6154 "Determine what method to use when colorizing the header line text.
6156 If nil, don't colorize the header text.
6157 If given a function, call it and use the resulting face name.
6158 Otherwise, use the `erc-header-line' face."
6159 :group 'erc-mode-line-and-header
6160 :type '(choice (const :tag "Don't colorize" nil)
6161 (const :tag "Use the erc-header-line face" t)
6162 (function :tag "Call a function")))
6164 (defcustom erc-show-channel-key-p t
6165 "Show the channel key in the header line."
6166 :group 'erc-paranoia
6167 :type 'boolean)
6169 (defcustom erc-mode-line-away-status-format
6170 "(AWAY since %a %b %d %H:%M) "
6171 "When you're away on a server, this is shown in the mode line.
6172 This should be a string with substitution variables recognized by
6173 `format-time-string'."
6174 :group 'erc-mode-line-and-header
6175 :type 'string)
6177 (defun erc-shorten-server-name (server-name)
6178 "Shorten SERVER-NAME according to `erc-common-server-suffixes'."
6179 (if (stringp server-name)
6180 (with-temp-buffer
6181 (insert server-name)
6182 (let ((alist erc-common-server-suffixes))
6183 (while alist
6184 (goto-char (point-min))
6185 (if (re-search-forward (caar alist) nil t)
6186 (replace-match (cdar alist)))
6187 (setq alist (cdr alist))))
6188 (buffer-string))))
6190 (defun erc-format-target ()
6191 "Return the name of the target (channel or nickname or servername:port)."
6192 (let ((target (erc-default-target)))
6193 (or target
6194 (concat (erc-shorten-server-name
6195 (or erc-server-announced-name
6196 erc-session-server))
6197 ":" (erc-port-to-string erc-session-port)))))
6199 (defun erc-format-target-and/or-server ()
6200 "Return the server name or the current target and server name combined."
6201 (let ((server-name (erc-shorten-server-name
6202 (or erc-server-announced-name
6203 erc-session-server))))
6204 (cond ((erc-default-target)
6205 (concat (erc-string-no-properties (erc-default-target))
6206 "@" server-name))
6207 (server-name server-name)
6208 (t (buffer-name (current-buffer))))))
6210 (defun erc-format-network ()
6211 "Return the name of the network we are currently on."
6212 (let ((network (and (fboundp 'erc-network-name) (erc-network-name))))
6213 (if (and network (symbolp network))
6214 (symbol-name network)
6215 "")))
6217 (defun erc-format-target-and/or-network ()
6218 "Return the network or the current target and network combined.
6219 If the name of the network is not available, then use the
6220 shortened server name instead."
6221 (let ((network-name (or (and (fboundp 'erc-network-name) (erc-network-name))
6222 (erc-shorten-server-name
6223 (or erc-server-announced-name
6224 erc-session-server)))))
6225 (when (and network-name (symbolp network-name))
6226 (setq network-name (symbol-name network-name)))
6227 (cond ((erc-default-target)
6228 (concat (erc-string-no-properties (erc-default-target))
6229 "@" network-name))
6230 ((and network-name
6231 (not (get-buffer network-name)))
6232 (when erc-rename-buffers
6233 (rename-buffer network-name))
6234 network-name)
6235 (t (buffer-name (current-buffer))))))
6237 (defun erc-format-away-status ()
6238 "Return a formatted `erc-mode-line-away-status-format'
6239 if `erc-away' is non-nil."
6240 (let ((a (erc-away-time)))
6241 (if a
6242 (format-time-string erc-mode-line-away-status-format a)
6243 "")))
6245 (defun erc-format-channel-modes ()
6246 "Return the current channel's modes."
6247 (concat (apply 'concat
6248 "+" erc-channel-modes)
6249 (cond ((and erc-channel-user-limit erc-channel-key)
6250 (if erc-show-channel-key-p
6251 (format "lk %.0f %s" erc-channel-user-limit
6252 erc-channel-key)
6253 (format "kl %.0f" erc-channel-user-limit)))
6254 (erc-channel-user-limit
6255 ;; Emacs has no bignums
6256 (format "l %.0f" erc-channel-user-limit))
6257 (erc-channel-key
6258 (if erc-show-channel-key-p
6259 (format "k %s" erc-channel-key)
6260 "k"))
6261 (t nil))))
6263 (defun erc-format-lag-time ()
6264 "Return the estimated lag time to server, `erc-server-lag'."
6265 (let ((lag (erc-with-server-buffer erc-server-lag)))
6266 (cond (lag (format "lag:%.0f" lag))
6267 (t ""))))
6269 ;; erc-goodies is required at end of this file.
6270 (declare-function erc-controls-strip "erc-goodies" (str))
6272 (defvar tabbar--local-hlf)
6274 (defun erc-update-mode-line-buffer (buffer)
6275 "Update the mode line in a single ERC buffer BUFFER."
6276 (with-current-buffer buffer
6277 (let ((spec (format-spec-make
6278 ?a (erc-format-away-status)
6279 ?l (erc-format-lag-time)
6280 ?m (erc-format-channel-modes)
6281 ?n (or (erc-current-nick) "")
6282 ?N (erc-format-network)
6283 ?o (or (erc-controls-strip erc-channel-topic) "")
6284 ?p (erc-port-to-string erc-session-port)
6285 ?s (erc-format-target-and/or-server)
6286 ?S (erc-format-target-and/or-network)
6287 ?t (erc-format-target)))
6288 (process-status (cond ((and (erc-server-process-alive)
6289 (not erc-server-connected))
6290 ":connecting")
6291 ((erc-server-process-alive)
6294 ": CLOSED")))
6295 (face (cond ((eq erc-header-line-face-method nil)
6296 nil)
6297 ((functionp erc-header-line-face-method)
6298 (funcall erc-header-line-face-method))
6300 'erc-header-line))))
6301 (cond ((featurep 'xemacs)
6302 (setq modeline-buffer-identification
6303 (list (format-spec erc-mode-line-format spec)))
6304 (setq modeline-process (list process-status)))
6306 (setq mode-line-buffer-identification
6307 (list (format-spec erc-mode-line-format spec)))
6308 (setq mode-line-process (list process-status))))
6309 (when (boundp 'header-line-format)
6310 (let ((header (if erc-header-line-format
6311 (format-spec erc-header-line-format spec)
6312 nil)))
6313 (cond (erc-header-line-uses-tabbar-p
6314 (set (make-local-variable 'tabbar--local-hlf)
6315 header-line-format)
6316 (kill-local-variable 'header-line-format))
6317 ((null header)
6318 (setq header-line-format nil))
6319 (erc-header-line-uses-help-echo-p
6320 (let ((help-echo (with-temp-buffer
6321 (insert header)
6322 (fill-region (point-min) (point-max))
6323 (buffer-string))))
6324 (setq header-line-format
6325 (erc-replace-regexp-in-string
6327 "%%"
6328 (if face
6329 (erc-propertize header 'help-echo help-echo
6330 'face face)
6331 (erc-propertize header 'help-echo help-echo))))))
6332 (t (setq header-line-format
6333 (if face
6334 (erc-propertize header 'face face)
6335 header)))))))
6336 (if (featurep 'xemacs)
6337 (redraw-modeline)
6338 (force-mode-line-update))))
6340 (defun erc-update-mode-line (&optional buffer)
6341 "Update the mode line in BUFFER.
6343 If BUFFER is nil, update the mode line in all ERC buffers."
6344 (if (and buffer (bufferp buffer))
6345 (erc-update-mode-line-buffer buffer)
6346 (dolist (buf (erc-buffer-list))
6347 (when (buffer-live-p buf)
6348 (erc-update-mode-line-buffer buf)))))
6350 ;; Miscellaneous
6352 (defun erc-port-to-string (p)
6353 "Convert port P to a string.
6354 P may be an integer or a service name."
6355 (if (integerp p)
6356 (int-to-string p)
6359 (defun erc-string-to-port (s)
6360 "Convert string S to either an integer port number or a service name."
6361 (if (numberp s)
6363 (let ((n (string-to-number s)))
6364 (if (= n 0)
6366 n))))
6368 (defun erc-version (&optional here)
6369 "Show the version number of ERC in the minibuffer.
6370 If optional argument HERE is non-nil, insert version number at point."
6371 (interactive "P")
6372 (let ((version-string
6373 (format "ERC (IRC client for Emacs %s)" emacs-version)))
6374 (if here
6375 (insert version-string)
6376 (if (called-interactively-p 'interactive)
6377 (message "%s" version-string)
6378 version-string))))
6380 (defun erc-modes (&optional here)
6381 "Show the active ERC modes in the minibuffer.
6382 If optional argument HERE is non-nil, insert version number at point."
6383 (interactive "P")
6384 (let ((string
6385 (mapconcat 'identity
6386 (let (modes (case-fold-search nil))
6387 (dolist (var (apropos-internal "^erc-.*mode$"))
6388 (when (and (boundp var)
6389 (symbol-value var))
6390 (setq modes (cons (symbol-name var)
6391 modes))))
6392 modes)
6393 ", ")))
6394 (if here
6395 (insert string)
6396 (if (called-interactively-p 'interactive)
6397 (message "%s" string)
6398 string))))
6400 (defun erc-trim-string (s)
6401 "Trim leading and trailing spaces off S."
6402 (cond
6403 ((not (stringp s)) nil)
6404 ((string-match "^\\s-*$" s)
6406 ((string-match "^\\s-*\\(.*\\S-\\)\\s-*$" s)
6407 (match-string 1 s))
6409 s)))
6411 (defun erc-arrange-session-in-multiple-windows ()
6412 "Open a window for every non-server buffer related to `erc-session-server'.
6414 All windows are opened in the current frame."
6415 (interactive)
6416 (unless erc-server-process
6417 (error "No erc-server-process found in current buffer"))
6418 (let ((bufs (erc-buffer-list nil erc-server-process)))
6419 (when bufs
6420 (delete-other-windows)
6421 (switch-to-buffer (car bufs))
6422 (setq bufs (cdr bufs))
6423 (while bufs
6424 (split-window)
6425 (other-window 1)
6426 (switch-to-buffer (car bufs))
6427 (setq bufs (cdr bufs))
6428 (balance-windows)))))
6430 (defun erc-popup-input-buffer ()
6431 "Provide an input buffer."
6432 (interactive)
6433 (let ((buffer-name (generate-new-buffer-name "*ERC input*"))
6434 (mode (intern
6435 (completing-read
6436 "Mode: "
6437 (mapcar (lambda (e)
6438 (list (symbol-name e)))
6439 (apropos-internal "-mode$" 'commandp))
6440 nil t))))
6441 (pop-to-buffer (make-indirect-buffer (current-buffer) buffer-name))
6442 (funcall mode)
6443 (narrow-to-region (point) (point))
6444 (shrink-window-if-larger-than-buffer)))
6446 ;;; Message catalog
6448 (defun erc-make-message-variable-name (catalog entry)
6449 "Create a variable name corresponding to CATALOG's ENTRY."
6450 (intern (concat "erc-message-"
6451 (symbol-name catalog) "-" (symbol-name entry))))
6453 (defun erc-define-catalog-entry (catalog entry format-spec)
6454 "Set CATALOG's ENTRY to FORMAT-SPEC."
6455 (set (erc-make-message-variable-name catalog entry)
6456 format-spec))
6458 (defun erc-define-catalog (catalog entries)
6459 "Define a CATALOG according to ENTRIES."
6460 (dolist (entry entries)
6461 (erc-define-catalog-entry catalog (car entry) (cdr entry))))
6463 (erc-define-catalog
6464 'english
6465 '((bad-ping-response . "Unexpected PING response from %n (time %t)")
6466 (bad-syntax . "Error occurred - incorrect usage?\n%c %u\n%d")
6467 (incorrect-args . "Incorrect arguments. Usage:\n%c %u\n%d")
6468 (cannot-find-file . "Cannot find file %f")
6469 (cannot-read-file . "Cannot read file %f")
6470 (connect . "Connecting to %S:%p... ")
6471 (country . "%c")
6472 (country-unknown . "%d: No such domain")
6473 (ctcp-empty . "Illegal empty CTCP query received from %n. Ignoring.")
6474 (ctcp-request . "==> CTCP request from %n (%u@%h): %r")
6475 (ctcp-request-to . "==> CTCP request from %n (%u@%h) to %t: %r")
6476 (ctcp-too-many . "Too many CTCP queries in single message. Ignoring")
6477 (flood-ctcp-off . "FLOOD PROTECTION: Automatic CTCP responses turned off.")
6478 (flood-strict-mode
6479 . "FLOOD PROTECTION: Switched to Strict Flood Control mode.")
6480 (disconnected . "\n\nConnection failed! Re-establishing connection...\n")
6481 (disconnected-noreconnect
6482 . "\n\nConnection failed! Not re-establishing connection.\n")
6483 (finished . "\n\n*** ERC finished ***\n")
6484 (terminated . "\n\n*** ERC terminated: %e\n")
6485 (login . "Logging in as \'%n\'...")
6486 (nick-in-use . "%n is in use. Choose new nickname: ")
6487 (nick-too-long
6488 . "WARNING: Nick length (%i) exceeds max NICKLEN(%l) defined by server")
6489 (no-default-channel . "No default channel")
6490 (no-invitation . "You've got no invitation")
6491 (no-target . "No target")
6492 (ops . "%i operator%s: %o")
6493 (ops-none . "No operators in this channel.")
6494 (undefined-ctcp . "Undefined CTCP query received. Silently ignored")
6495 (variable-not-bound . "Variable not bound!")
6496 (ACTION . "* %n %a")
6497 (CTCP-CLIENTINFO . "Client info for %n: %m")
6498 (CTCP-ECHO . "Echo %n: %m")
6499 (CTCP-FINGER . "Finger info for %n: %m")
6500 (CTCP-PING . "Ping time to %n is %t")
6501 (CTCP-TIME . "Time by %n is %m")
6502 (CTCP-UNKNOWN . "Unknown CTCP message from %n (%u@%h): %m")
6503 (CTCP-VERSION . "Version for %n is %m")
6504 (ERROR . "==> ERROR from %s: %c\n")
6505 (INVITE . "%n (%u@%h) invites you to channel %c")
6506 (JOIN . "%n (%u@%h) has joined channel %c")
6507 (JOIN-you . "You have joined channel %c")
6508 (KICK . "%n (%u@%h) has kicked %k off channel %c: %r")
6509 (KICK-you . "You have been kicked off channel %c by %n (%u@%h): %r")
6510 (KICK-by-you . "You have kicked %k off channel %c: %r")
6511 (MODE . "%n (%u@%h) has changed mode for %t to %m")
6512 (MODE-nick . "%n has changed mode for %t to %m")
6513 (NICK . "%n (%u@%h) is now known as %N")
6514 (NICK-you . "Your new nickname is %N")
6515 (PART . erc-message-english-PART)
6516 (PING . "PING from server (last: %s sec. ago)")
6517 (PONG . "PONG from %h (%i second%s)")
6518 (QUIT . "%n (%u@%h) has quit: %r")
6519 (TOPIC . "%n (%u@%h) has set the topic for %c: \"%T\"")
6520 (WALLOPS . "Wallops from %n: %m")
6521 (s004 . "%s %v %U %C")
6522 (s221 . "User modes for %n: %m")
6523 (s252 . "%i operator(s) online")
6524 (s253 . "%i unknown connection(s)")
6525 (s254 . "%i channels formed")
6526 (s275 . "%n %m")
6527 (s301 . "%n is AWAY: %r")
6528 (s303 . "Is online: %n")
6529 (s305 . "%m")
6530 (s306 . "%m")
6531 (s307 . "%n %m")
6532 (s311 . "%n is %f (%u@%h)")
6533 (s312 . "%n is/was on server %s (%c)")
6534 (s313 . "%n is an IRC operator")
6535 (s314 . "%n was %f (%u@%h)")
6536 (s317 . "%n has been idle for %i")
6537 (s317-on-since . "%n has been idle for %i, on since %t")
6538 (s319 . "%n is on channel(s): %c")
6539 (s320 . "%n is an identified user")
6540 (s321 . "Channel Users Topic")
6541 (s322 . "%c [%u] %t")
6542 (s324 . "%c modes: %m")
6543 (s328 . "%c URL: %u")
6544 (s329 . "%c was created on %t")
6545 (s330 . "%n %a %i")
6546 (s331 . "No topic is set for %c")
6547 (s332 . "Topic for %c: %T")
6548 (s333 . "%c: topic set by %n, %t")
6549 (s341 . "Inviting %n to channel %c")
6550 (s352 . "%-11c %-10n %-4a %u@%h (%f)")
6551 (s353 . "Users on %c: %u")
6552 (s367 . "Ban for %b on %c")
6553 (s367-set-by . "Ban for %b on %c set by %s on %t")
6554 (s368 . "Banlist of %c ends.")
6555 (s379 . "%c: Forwarded to %f")
6556 (s391 . "The time at %s is %t")
6557 (s401 . "%n: No such nick/channel")
6558 (s403 . "%c: No such channel")
6559 (s404 . "%c: Cannot send to channel")
6560 (s405 . "%c: You have joined too many channels")
6561 (s406 . "%n: There was no such nickname")
6562 (s412 . "No text to send")
6563 (s421 . "%c: Unknown command")
6564 (s431 . "No nickname given")
6565 (s432 . "%n is an erroneous nickname")
6566 (s442 . "%c: You're not on that channel")
6567 (s445 . "SUMMON has been disabled")
6568 (s446 . "USERS has been disabled")
6569 (s451 . "You have not registered")
6570 (s461 . "%c: not enough parameters")
6571 (s462 . "Unauthorized command (already registered)")
6572 (s463 . "Your host isn't among the privileged")
6573 (s464 . "Password incorrect")
6574 (s465 . "You are banned from this server")
6575 (s474 . "You can't join %c because you're banned (+b)")
6576 (s475 . "You must specify the correct channel key (+k) to join %c")
6577 (s481 . "Permission Denied - You're not an IRC operator")
6578 (s482 . "You need to be a channel operator of %c to do that")
6579 (s483 . "You can't kill a server!")
6580 (s484 . "Your connection is restricted!")
6581 (s485 . "You're not the original channel operator")
6582 (s491 . "No O-lines for your host")
6583 (s501 . "Unknown MODE flag")
6584 (s502 . "You can't change modes for other users")
6585 (s671 . "%n %a")))
6587 (defun erc-message-english-PART (&rest args)
6588 "Format a proper PART message.
6590 This function is an example on what could be done with formatting
6591 functions."
6592 (let ((nick (cadr (memq ?n args)))
6593 (user (cadr (memq ?u args)))
6594 (host (cadr (memq ?h args)))
6595 (channel (cadr (memq ?c args)))
6596 (reason (cadr (memq ?r args))))
6597 (if (string= nick (erc-current-nick))
6598 (format "You have left channel %s" channel)
6599 (format "%s (%s@%s) has left channel %s%s"
6600 nick user host channel
6601 (if (not (string= reason ""))
6602 (format ": %s"
6603 (erc-replace-regexp-in-string "%" "%%" reason))
6604 "")))))
6607 (defvar erc-current-message-catalog 'english)
6608 (make-variable-buffer-local 'erc-current-message-catalog)
6610 (defun erc-retrieve-catalog-entry (entry &optional catalog)
6611 "Retrieve ENTRY from CATALOG.
6613 If CATALOG is nil, `erc-current-message-catalog' is used.
6615 If ENTRY is nil in CATALOG, it is retrieved from the fallback,
6616 english, catalog."
6617 (unless catalog (setq catalog erc-current-message-catalog))
6618 (let ((var (erc-make-message-variable-name catalog entry)))
6619 (if (boundp var)
6620 (symbol-value var)
6621 (when (boundp (erc-make-message-variable-name 'english entry))
6622 (symbol-value (erc-make-message-variable-name 'english entry))))))
6624 (defun erc-format-message (msg &rest args)
6625 "Format MSG according to ARGS.
6627 See also `format-spec'."
6628 (when (eq (logand (length args) 1) 1) ; oddp
6629 (error "Obscure usage of this function appeared"))
6630 (let ((entry (erc-retrieve-catalog-entry msg)))
6631 (when (not entry)
6632 (error "No format spec for message %s" msg))
6633 (when (functionp entry)
6634 (setq entry (apply entry args)))
6635 (format-spec entry (apply 'format-spec-make args))))
6637 ;;; Various hook functions
6639 (add-hook 'kill-buffer-hook 'erc-kill-buffer-function)
6641 (defcustom erc-kill-server-hook '(erc-kill-server)
6642 "Invoked whenever a server buffer is killed via `kill-buffer'."
6643 :group 'erc-hooks
6644 :type 'hook)
6646 (defcustom erc-kill-channel-hook '(erc-kill-channel)
6647 "Invoked whenever a channel-buffer is killed via `kill-buffer'."
6648 :group 'erc-hooks
6649 :type 'hook)
6651 (defcustom erc-kill-buffer-hook nil
6652 "Hook run whenever a non-server or channel buffer is killed.
6654 See also `kill-buffer'."
6655 :group 'erc-hooks
6656 :type 'hook)
6658 (defun erc-kill-buffer-function ()
6659 "Function to call when an ERC buffer is killed.
6660 This function should be on `kill-buffer-hook'.
6661 When the current buffer is in `erc-mode', this function will run
6662 one of the following hooks:
6663 `erc-kill-server-hook' if the server buffer was killed,
6664 `erc-kill-channel-hook' if a channel buffer was killed,
6665 or `erc-kill-buffer-hook' if any other buffer."
6666 (when (eq major-mode 'erc-mode)
6667 (erc-remove-channel-users)
6668 (cond
6669 ((eq (erc-server-buffer) (current-buffer))
6670 (run-hooks 'erc-kill-server-hook))
6671 ((erc-channel-p (erc-default-target))
6672 (run-hooks 'erc-kill-channel-hook))
6674 (run-hooks 'erc-kill-buffer-hook)))))
6676 (defun erc-kill-server ()
6677 "Sends a QUIT command to the server when the server buffer is killed.
6678 This function should be on `erc-kill-server-hook'."
6679 (when (erc-server-process-alive)
6680 (setq erc-server-quitting t)
6681 (erc-server-send (format "QUIT :%s" (funcall erc-quit-reason nil)))))
6683 (defun erc-kill-channel ()
6684 "Sends a PART command to the server when the channel buffer is killed.
6685 This function should be on `erc-kill-channel-hook'."
6686 (when (erc-server-process-alive)
6687 (let ((tgt (erc-default-target)))
6688 (erc-server-send (format "PART %s :%s" tgt
6689 (funcall erc-part-reason nil))
6690 nil tgt))))
6692 ;;; Dealing with `erc-parsed'
6694 (defun erc-find-parsed-property ()
6695 "Find the next occurrence of the `erc-parsed' text property."
6696 (text-property-not-all (point-min) (point-max) 'erc-parsed nil))
6698 (defun erc-restore-text-properties ()
6699 "Restore the property 'erc-parsed for the region."
6700 (let ((parsed-posn (erc-find-parsed-property)))
6701 (put-text-property
6702 (point-min) (point-max)
6703 'erc-parsed (when parsed-posn (erc-get-parsed-vector parsed-posn)))))
6705 (defun erc-get-parsed-vector (point)
6706 "Return the whole parsed vector on POINT."
6707 (get-text-property point 'erc-parsed))
6709 (defun erc-get-parsed-vector-nick (vect)
6710 "Return nickname in the parsed vector VECT."
6711 (let* ((untreated-nick (and vect (erc-response.sender vect)))
6712 (maybe-nick (when untreated-nick
6713 (car (split-string untreated-nick "!")))))
6714 (when (and (not (null maybe-nick))
6715 (erc-is-valid-nick-p maybe-nick))
6716 untreated-nick)))
6718 (defun erc-get-parsed-vector-type (vect)
6719 "Return message type in the parsed vector VECT."
6720 (and vect
6721 (erc-response.command vect)))
6723 ;; Teach url.el how to open irc:// URLs with ERC.
6724 ;; To activate, customize `url-irc-function' to `url-irc-erc'.
6726 ;;;###autoload
6727 (defun erc-handle-irc-url (host port channel user password)
6728 "Use ERC to IRC on HOST:PORT in CHANNEL as USER with PASSWORD.
6729 If ERC is already connected to HOST:PORT, simply /join CHANNEL.
6730 Otherwise, connect to HOST:PORT as USER and /join CHANNEL."
6731 (let ((server-buffer
6732 (car (erc-buffer-filter
6733 (lambda ()
6734 (and (string-equal erc-session-server host)
6735 (= erc-session-port port)
6736 (erc-open-server-buffer-p)))))))
6737 (with-current-buffer (or server-buffer (current-buffer))
6738 (if (and server-buffer channel)
6739 (erc-cmd-JOIN channel)
6740 (erc-open host port (or user (erc-compute-nick)) (erc-compute-full-name)
6741 (not server-buffer) password nil channel
6742 (when server-buffer
6743 (get-buffer-process server-buffer)))))))
6745 (provide 'erc)
6747 ;; Deprecated. We might eventually stop requiring the goodies automatically.
6748 ;; IMPORTANT: This require must appear _after_ the above (provide 'erc) to
6749 ;; avoid a recursive require error when byte-compiling the entire package.
6750 (require 'erc-goodies)
6752 ;;; erc.el ends here
6754 ;; Local Variables:
6755 ;; outline-regexp: ";;+"
6756 ;; indent-tabs-mode: t
6757 ;; tab-width: 8
6758 ;; End: