* lisp/emacs-lisp/byte-opt.el (byte-optimize-form-code-walker): Don't try to
[emacs.git] / lisp / erc / erc.el
bloba84f9f07523e0dd01344f0ff0ed8eaa989d754e1
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
15 ;; Version: 5.3
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 "Non-nil means rename buffers with network name, if available."
201 :version "24.5"
202 :group 'erc
203 :type 'boolean)
205 (defvar erc-password nil
206 "Password to use when authenticating to an IRC server.
207 It is not strictly necessary to provide this, since ERC will
208 prompt you for it.")
210 (defcustom erc-user-mode nil
211 "Initial user modes to be set after a connection is established."
212 :group 'erc
213 :type '(choice (const nil) string function))
216 (defcustom erc-prompt-for-password t
217 "Asks before using the default password, or whether to enter a new one."
218 :group 'erc
219 :type 'boolean)
221 (defcustom erc-warn-about-blank-lines t
222 "Warn the user if they attempt to send a blank line."
223 :group 'erc
224 :type 'boolean)
226 (defcustom erc-send-whitespace-lines nil
227 "If set to non-nil, send lines consisting of only whitespace."
228 :group 'erc
229 :type 'boolean)
231 (defcustom erc-hide-prompt nil
232 "If non-nil, do not display the prompt for commands.
234 \(A command is any input starting with a '/').
236 See also the variables `erc-prompt' and `erc-command-indicator'."
237 :group 'erc-display
238 :type 'boolean)
240 ;; tunable GUI stuff
242 (defcustom erc-show-my-nick t
243 "If non-nil, display one's own nickname when sending a message.
245 If non-nil, \"<nickname>\" will be shown.
246 If nil, only \"> \" will be shown."
247 :group 'erc-display
248 :type 'boolean)
250 (define-widget 'erc-message-type 'set
251 "A set of standard IRC Message types."
252 :args '((const "JOIN")
253 (const "KICK")
254 (const "NICK")
255 (const "PART")
256 (const "QUIT")
257 (const "MODE")
258 (repeat :inline t :tag "Others" (string :tag "IRC Message Type"))))
260 (defcustom erc-hide-list nil
261 "List of IRC type messages to hide.
262 A typical value would be '(\"JOIN\" \"PART\" \"QUIT\")."
263 :group 'erc-ignore
264 :type 'erc-message-type)
266 (defvar erc-session-password nil
267 "The password used for the current session.")
268 (make-variable-buffer-local 'erc-session-password)
270 (defcustom erc-disconnected-hook nil
271 "Run this hook with arguments (NICK IP REASON) when disconnected.
272 This happens before automatic reconnection. Note, that
273 `erc-server-QUIT-functions' might not be run when we disconnect,
274 simply because we do not necessarily receive the QUIT event."
275 :group 'erc-hooks
276 :type 'hook)
278 (defcustom erc-complete-functions nil
279 "These functions get called when the user hits TAB in ERC.
280 Each function in turn is called until one returns non-nil to
281 indicate it has handled the input."
282 :group 'erc-hooks
283 :type 'hook)
285 (defcustom erc-join-hook nil
286 "Hook run when we join a channel. Hook functions are called
287 without arguments, with the current buffer set to the buffer of
288 the new channel.
290 See also `erc-server-JOIN-functions', `erc-part-hook'."
291 :group 'erc-hooks
292 :type 'hook)
294 (defcustom erc-quit-hook nil
295 "Hook run when processing a quit command directed at our nick.
297 The hook receives one argument, the current PROCESS.
298 See also `erc-server-QUIT-functions' and `erc-disconnected-hook'."
299 :group 'erc-hooks
300 :type 'hook)
302 (defcustom erc-part-hook nil
303 "Hook run when processing a PART message directed at our nick.
305 The hook receives one argument, the current BUFFER.
306 See also `erc-server-QUIT-functions', `erc-quit-hook' and
307 `erc-disconnected-hook'."
308 :group 'erc-hooks
309 :type 'hook)
311 (defcustom erc-kick-hook nil
312 "Hook run when processing a KICK message directed at our nick.
314 The hook receives one argument, the current BUFFER.
315 See also `erc-server-PART-functions' and `erc-part-hook'."
316 :group 'erc-hooks
317 :type 'hook)
319 (defcustom erc-nick-changed-functions nil
320 "List of functions run when your nick was successfully changed.
322 Each function should accept two arguments, NEW-NICK and OLD-NICK."
323 :group 'erc-hooks
324 :type 'hook)
326 (defcustom erc-connect-pre-hook '(erc-initialize-log-marker)
327 "Hook called just before `erc' calls `erc-connect'.
328 Functions are passed a buffer as the first argument."
329 :group 'erc-hooks
330 :type 'hook)
333 (defvar erc-channel-users nil
334 "A hash table of members in the current channel, which
335 associates nicknames with cons cells of the form:
336 \(USER . MEMBER-DATA) where USER is a pointer to an
337 erc-server-user struct, and MEMBER-DATA is a pointer to an
338 erc-channel-user struct.")
339 (make-variable-buffer-local 'erc-channel-users)
341 (defvar erc-server-users nil
342 "A hash table of users on the current server, which associates
343 nicknames with erc-server-user struct instances.")
344 (make-variable-buffer-local 'erc-server-users)
346 (defun erc-downcase (string)
347 "Convert STRING to IRC standard conforming downcase."
348 (let ((s (downcase string))
349 (c '((?\[ . ?\{)
350 (?\] . ?\})
351 (?\\ . ?\|)
352 (?~ . ?^))))
353 (save-match-data
354 (while (string-match "[]\\[~]" s)
355 (aset s (match-beginning 0)
356 (cdr (assq (aref s (match-beginning 0)) c)))))
359 (defmacro erc-with-server-buffer (&rest body)
360 "Execute BODY in the current ERC server buffer.
361 If no server buffer exists, return nil."
362 (declare (indent 0) (debug (body)))
363 (let ((buffer (make-symbol "buffer")))
364 `(let ((,buffer (erc-server-buffer)))
365 (when (buffer-live-p ,buffer)
366 (with-current-buffer ,buffer
367 ,@body)))))
369 (cl-defstruct (erc-server-user (:type vector) :named)
370 ;; User data
371 nickname host login full-name info
372 ;; Buffers
374 ;; This is an alist of the form (BUFFER . CHANNEL-DATA), where
375 ;; CHANNEL-DATA is either nil or an erc-channel-user struct.
376 (buffers nil)
379 (cl-defstruct (erc-channel-user (:type vector) :named)
380 voice halfop op admin owner
381 ;; Last message time (in the form of the return value of
382 ;; (current-time)
384 ;; This is useful for ordered name completion.
385 (last-message-time nil))
387 (defsubst erc-get-channel-user (nick)
388 "Find the (USER . CHANNEL-DATA) element corresponding to NICK
389 in the current buffer's `erc-channel-users' hash table."
390 (gethash (erc-downcase nick) erc-channel-users))
392 (defsubst erc-get-server-user (nick)
393 "Find the USER corresponding to NICK in the current server's
394 `erc-server-users' hash table."
395 (erc-with-server-buffer
396 (gethash (erc-downcase nick) erc-server-users)))
398 (defsubst erc-add-server-user (nick user)
399 "This function is for internal use only.
401 Adds USER with nickname NICK to the `erc-server-users' hash table."
402 (erc-with-server-buffer
403 (puthash (erc-downcase nick) user erc-server-users)))
405 (defsubst erc-remove-server-user (nick)
406 "This function is for internal use only.
408 Removes the user with nickname NICK from the `erc-server-users'
409 hash table. This user is not removed from the
410 `erc-channel-users' lists of other buffers.
412 See also: `erc-remove-user'."
413 (erc-with-server-buffer
414 (remhash (erc-downcase nick) erc-server-users)))
416 (defun erc-change-user-nickname (user new-nick)
417 "This function is for internal use only.
419 Changes the nickname of USER to NEW-NICK in the
420 `erc-server-users' hash table. The `erc-channel-users' lists of
421 other buffers are also changed."
422 (let ((nick (erc-server-user-nickname user)))
423 (setf (erc-server-user-nickname user) new-nick)
424 (erc-with-server-buffer
425 (remhash (erc-downcase nick) erc-server-users)
426 (puthash (erc-downcase new-nick) user erc-server-users))
427 (dolist (buf (erc-server-user-buffers user))
428 (if (buffer-live-p buf)
429 (with-current-buffer buf
430 (let ((cdata (erc-get-channel-user nick)))
431 (remhash (erc-downcase nick) erc-channel-users)
432 (puthash (erc-downcase new-nick) cdata
433 erc-channel-users)))))))
435 (defun erc-remove-channel-user (nick)
436 "This function is for internal use only.
438 Removes the user with nickname NICK from the `erc-channel-users'
439 list for this channel. If this user is not in the
440 `erc-channel-users' list of any other buffers, the user is also
441 removed from the server's `erc-server-users' list.
443 See also: `erc-remove-server-user' and `erc-remove-user'."
444 (let ((channel-data (erc-get-channel-user nick)))
445 (when channel-data
446 (let ((user (car channel-data)))
447 (setf (erc-server-user-buffers user)
448 (delq (current-buffer)
449 (erc-server-user-buffers user)))
450 (remhash (erc-downcase nick) erc-channel-users)
451 (if (null (erc-server-user-buffers user))
452 (erc-remove-server-user nick))))))
454 (defun erc-remove-user (nick)
455 "This function is for internal use only.
457 Removes the user with nickname NICK from the `erc-server-users'
458 list as well as from all `erc-channel-users' lists.
460 See also: `erc-remove-server-user' and
461 `erc-remove-channel-user'."
462 (let ((user (erc-get-server-user nick)))
463 (when user
464 (let ((buffers (erc-server-user-buffers user)))
465 (dolist (buf buffers)
466 (if (buffer-live-p buf)
467 (with-current-buffer buf
468 (remhash (erc-downcase nick) erc-channel-users)
469 (run-hooks 'erc-channel-members-changed-hook)))))
470 (erc-remove-server-user nick))))
472 (defun erc-remove-channel-users ()
473 "This function is for internal use only.
475 Removes all users in the current channel. This is called by
476 `erc-server-PART' and `erc-server-QUIT'."
477 (when (and erc-server-connected
478 (erc-server-process-alive)
479 (hash-table-p erc-channel-users))
480 (maphash (lambda (nick _cdata)
481 (erc-remove-channel-user nick))
482 erc-channel-users)
483 (clrhash erc-channel-users)))
485 (defsubst erc-channel-user-owner-p (nick)
486 "Return non-nil if NICK is an owner of the current channel."
487 (and nick
488 (hash-table-p erc-channel-users)
489 (let ((cdata (erc-get-channel-user nick)))
490 (and cdata (cdr cdata)
491 (erc-channel-user-owner (cdr cdata))))))
493 (defsubst erc-channel-user-admin-p (nick)
494 "Return non-nil if NICK is an admin in the current channel."
495 (and nick
496 (hash-table-p erc-channel-users)
497 (let ((cdata (erc-get-channel-user nick)))
498 (and cdata (cdr cdata)
499 (erc-channel-user-admin (cdr cdata))))))
501 (defsubst erc-channel-user-op-p (nick)
502 "Return non-nil if NICK is an operator in the current channel."
503 (and nick
504 (hash-table-p erc-channel-users)
505 (let ((cdata (erc-get-channel-user nick)))
506 (and cdata (cdr cdata)
507 (erc-channel-user-op (cdr cdata))))))
509 (defsubst erc-channel-user-halfop-p (nick)
510 "Return non-nil if NICK is a half-operator in the current channel."
511 (and nick
512 (hash-table-p erc-channel-users)
513 (let ((cdata (erc-get-channel-user nick)))
514 (and cdata (cdr cdata)
515 (erc-channel-user-halfop (cdr cdata))))))
517 (defsubst erc-channel-user-voice-p (nick)
518 "Return non-nil if NICK has voice in the current channel."
519 (and nick
520 (hash-table-p erc-channel-users)
521 (let ((cdata (erc-get-channel-user nick)))
522 (and cdata (cdr cdata)
523 (erc-channel-user-voice (cdr cdata))))))
525 (defun erc-get-channel-user-list ()
526 "Return a list of users in the current channel. Each element
527 of the list is of the form (USER . CHANNEL-DATA), where USER is
528 an erc-server-user struct, and CHANNEL-DATA is either nil or an
529 erc-channel-user struct.
531 See also: `erc-sort-channel-users-by-activity'"
532 (let (users)
533 (if (hash-table-p erc-channel-users)
534 (maphash (lambda (_nick cdata)
535 (setq users (cons cdata users)))
536 erc-channel-users))
537 users))
539 (defun erc-get-server-nickname-list ()
540 "Return a list of known nicknames on the current server."
541 (erc-with-server-buffer
542 (let (nicks)
543 (when (hash-table-p erc-server-users)
544 (maphash (lambda (_n user)
545 (setq nicks
546 (cons (erc-server-user-nickname user)
547 nicks)))
548 erc-server-users)
549 nicks))))
551 (defun erc-get-channel-nickname-list ()
552 "Return a list of known nicknames on the current channel."
553 (let (nicks)
554 (when (hash-table-p erc-channel-users)
555 (maphash (lambda (_n cdata)
556 (setq nicks
557 (cons (erc-server-user-nickname (car cdata))
558 nicks)))
559 erc-channel-users)
560 nicks)))
562 (defun erc-get-server-nickname-alist ()
563 "Return an alist of known nicknames on the current server."
564 (erc-with-server-buffer
565 (let (nicks)
566 (when (hash-table-p erc-server-users)
567 (maphash (lambda (_n user)
568 (setq nicks
569 (cons (cons (erc-server-user-nickname user) nil)
570 nicks)))
571 erc-server-users)
572 nicks))))
574 (defun erc-get-channel-nickname-alist ()
575 "Return an alist of known nicknames on the current channel."
576 (let (nicks)
577 (when (hash-table-p erc-channel-users)
578 (maphash (lambda (_n cdata)
579 (setq nicks
580 (cons (cons (erc-server-user-nickname (car cdata)) nil)
581 nicks)))
582 erc-channel-users)
583 nicks)))
585 (defun erc-sort-channel-users-by-activity (list)
586 "Sort LIST such that users which have spoken most recently are listed first.
587 LIST must be of the form (USER . CHANNEL-DATA).
589 See also: `erc-get-channel-user-list'."
590 (sort list
591 (lambda (x y)
592 (when (and (cdr x) (cdr y))
593 (let ((tx (erc-channel-user-last-message-time (cdr x)))
594 (ty (erc-channel-user-last-message-time (cdr y))))
595 (and tx
596 (or (not ty)
597 (time-less-p ty tx))))))))
599 (defun erc-sort-channel-users-alphabetically (list)
600 "Sort LIST so that users' nicknames are in alphabetical order.
601 LIST must be of the form (USER . CHANNEL-DATA).
603 See also: `erc-get-channel-user-list'."
604 (sort list
605 (lambda (x y)
606 (when (and (cdr x) (cdr y))
607 (let ((nickx (downcase (erc-server-user-nickname (car x))))
608 (nicky (downcase (erc-server-user-nickname (car y)))))
609 (and nickx
610 (or (not nicky)
611 (string-lessp nickx nicky))))))))
613 (defvar erc-channel-topic nil
614 "A topic string for the channel. Should only be used in channel-buffers.")
615 (make-variable-buffer-local 'erc-channel-topic)
617 (defvar erc-channel-modes nil
618 "List of strings representing channel modes.
619 E.g. '(\"i\" \"m\" \"s\" \"b Quake!*@*\")
620 \(not sure the ban list will be here, but why not)")
621 (make-variable-buffer-local 'erc-channel-modes)
623 (defvar erc-insert-marker nil
624 "The place where insertion of new text in erc buffers should happen.")
625 (make-variable-buffer-local 'erc-insert-marker)
627 (defvar erc-input-marker nil
628 "The marker where input should be inserted.")
629 (make-variable-buffer-local 'erc-input-marker)
631 (defun erc-string-no-properties (string)
632 "Return a copy of STRING will all text-properties removed."
633 (let ((newstring (copy-sequence string)))
634 (set-text-properties 0 (length newstring) nil newstring)
635 newstring))
637 (defcustom erc-prompt "ERC>"
638 "Prompt used by ERC. Trailing whitespace is not required."
639 :group 'erc-display
640 :type '(choice string function))
642 (defun erc-prompt ()
643 "Return the input prompt as a string.
645 See also the variable `erc-prompt'."
646 (let ((prompt (if (functionp erc-prompt)
647 (funcall erc-prompt)
648 erc-prompt)))
649 (if (> (length prompt) 0)
650 (concat prompt " ")
651 prompt)))
653 (defcustom erc-command-indicator nil
654 "Indicator used by ERC for showing commands.
656 If non-nil, this will be used in the ERC buffer to indicate
657 commands (i.e., input starting with a '/').
659 If nil, the prompt will be constructed from the variable `erc-prompt'."
660 :group 'erc-display
661 :type '(choice (const nil) string function))
663 (defun erc-command-indicator ()
664 "Return the command indicator prompt as a string.
666 This only has any meaning if the variable `erc-command-indicator' is non-nil."
667 (and erc-command-indicator
668 (let ((prompt (if (functionp erc-command-indicator)
669 (funcall erc-command-indicator)
670 erc-command-indicator)))
671 (if (> (length prompt) 0)
672 (concat prompt " ")
673 prompt))))
675 (defcustom erc-notice-prefix "*** "
676 "Prefix for all notices."
677 :group 'erc-display
678 :type 'string)
680 (defcustom erc-notice-highlight-type 'all
681 "Determines how to highlight notices.
682 See `erc-notice-prefix'.
684 The following values are allowed:
686 'prefix - highlight notice prefix only
687 'all - highlight the entire notice
689 Any other value disables notice's highlighting altogether."
690 :group 'erc-display
691 :type '(choice (const :tag "highlight notice prefix only" prefix)
692 (const :tag "highlight the entire notice" all)
693 (const :tag "don't highlight notices at all" nil)))
695 (defcustom erc-echo-notice-hook nil
696 "List of functions to call to echo a private notice.
697 Each function is called with four arguments, the string
698 to display, the parsed server message, the target buffer (or
699 nil), and the sender. The functions are called in order, until a
700 function evaluates to non-nil. These hooks are called after
701 those specified in `erc-echo-notice-always-hook'.
703 See also: `erc-echo-notice-always-hook',
704 `erc-echo-notice-in-default-buffer',
705 `erc-echo-notice-in-target-buffer',
706 `erc-echo-notice-in-minibuffer',
707 `erc-echo-notice-in-server-buffer',
708 `erc-echo-notice-in-active-non-server-buffer',
709 `erc-echo-notice-in-active-buffer',
710 `erc-echo-notice-in-user-buffers',
711 `erc-echo-notice-in-user-and-target-buffers',
712 `erc-echo-notice-in-first-user-buffer'"
713 :group 'erc-hooks
714 :type 'hook
715 :options '(erc-echo-notice-in-default-buffer
716 erc-echo-notice-in-target-buffer
717 erc-echo-notice-in-minibuffer
718 erc-echo-notice-in-server-buffer
719 erc-echo-notice-in-active-non-server-buffer
720 erc-echo-notice-in-active-buffer
721 erc-echo-notice-in-user-buffers
722 erc-echo-notice-in-user-and-target-buffers
723 erc-echo-notice-in-first-user-buffer))
725 (defcustom erc-echo-notice-always-hook
726 '(erc-echo-notice-in-default-buffer)
727 "List of functions to call to echo a private notice.
728 Each function is called with four arguments, the string
729 to display, the parsed server message, the target buffer (or
730 nil), and the sender. The functions are called in order, and all
731 functions are called. These hooks are called before those
732 specified in `erc-echo-notice-hook'.
734 See also: `erc-echo-notice-hook',
735 `erc-echo-notice-in-default-buffer',
736 `erc-echo-notice-in-target-buffer',
737 `erc-echo-notice-in-minibuffer',
738 `erc-echo-notice-in-server-buffer',
739 `erc-echo-notice-in-active-non-server-buffer',
740 `erc-echo-notice-in-active-buffer',
741 `erc-echo-notice-in-user-buffers',
742 `erc-echo-notice-in-user-and-target-buffers',
743 `erc-echo-notice-in-first-user-buffer'"
744 :group 'erc-hooks
745 :type 'hook
746 :options '(erc-echo-notice-in-default-buffer
747 erc-echo-notice-in-target-buffer
748 erc-echo-notice-in-minibuffer
749 erc-echo-notice-in-server-buffer
750 erc-echo-notice-in-active-non-server-buffer
751 erc-echo-notice-in-active-buffer
752 erc-echo-notice-in-user-buffers
753 erc-echo-notice-in-user-and-target-buffers
754 erc-echo-notice-in-first-user-buffer))
756 ;; other tunable parameters
758 (defcustom erc-whowas-on-nosuchnick nil
759 "If non-nil, do a whowas on a nick if no such nick."
760 :group 'erc
761 :type 'boolean)
763 (defcustom erc-verbose-server-ping nil
764 "If non-nil, show every time you get a PING or PONG from the server."
765 :group 'erc-paranoia
766 :type 'boolean)
768 (defcustom erc-public-away-p nil
769 "Let others know you are back when you are no longer marked away.
770 This happens in this form:
771 * <nick> is back (gone for <time>)
773 Many consider it impolite to do so automatically."
774 :group 'erc
775 :type 'boolean)
777 (defcustom erc-away-nickname nil
778 "The nickname to take when you are marked as being away."
779 :group 'erc
780 :type '(choice (const nil)
781 string))
783 (defcustom erc-paranoid nil
784 "If non-nil, then all incoming CTCP requests will be shown."
785 :group 'erc-paranoia
786 :type 'boolean)
788 (defcustom erc-disable-ctcp-replies nil
789 "Disable replies to CTCP requests that require a reply.
790 If non-nil, then all incoming CTCP requests that normally require
791 an automatic reply (like VERSION or PING) will be ignored. Good to
792 set if some hacker is trying to flood you away."
793 :group 'erc-paranoia
794 :type 'boolean)
796 (defcustom erc-anonymous-login t
797 "Be paranoid, don't give away your machine name."
798 :group 'erc-paranoia
799 :type 'boolean)
801 (defcustom erc-prompt-for-channel-key nil
802 "Prompt for channel key when using `erc-join-channel' interactively."
803 :group 'erc
804 :type 'boolean)
806 (defcustom erc-email-userid "user"
807 "Use this as your email user ID."
808 :group 'erc
809 :type 'string)
811 (defcustom erc-system-name nil
812 "Use this as the name of your system.
813 If nil, ERC will call `system-name' to get this information."
814 :group 'erc
815 :type '(choice (const :tag "Default system name" nil)
816 string))
818 (defcustom erc-ignore-list nil
819 "List of regexps matching user identifiers to ignore.
821 A user identifier has the form \"nick!login@host\". If an
822 identifier matches, the message from the person will not be
823 processed."
824 :group 'erc-ignore
825 :type '(repeat regexp))
826 (make-variable-buffer-local 'erc-ignore-list)
828 (defcustom erc-ignore-reply-list nil
829 "List of regexps matching user identifiers to ignore completely.
831 This differs from `erc-ignore-list' in that it also ignores any
832 messages directed at the user.
834 A user identifier has the form \"nick!login@host\".
836 If an identifier matches, or a message is addressed to a nick
837 whose identifier matches, the message will not be processed.
839 CAVEAT: ERC doesn't know about the user and host of anyone who
840 was already in the channel when you joined, but never said
841 anything, so it won't be able to match the user and host of those
842 people. You can update the ERC internal info using /WHO *."
843 :group 'erc-ignore
844 :type '(repeat regexp))
846 (defvar erc-flood-protect t
847 "If non-nil, flood protection is enabled.
848 Flooding is sending too much information to the server in too
849 short of an interval, which may cause the server to terminate the
850 connection.
852 See `erc-server-flood-margin' for other flood-related parameters.")
854 ;; Script parameters
856 (defcustom erc-startup-file-list
857 (list (concat erc-user-emacs-directory ".ercrc.el")
858 (concat erc-user-emacs-directory ".ercrc")
859 "~/.ercrc.el" "~/.ercrc" ".ercrc.el" ".ercrc")
860 "List of files to try for a startup script.
861 The first existent and readable one will get executed.
863 If the filename ends with `.el' it is presumed to be an Emacs Lisp
864 script and it gets (load)ed. Otherwise it is treated as a bunch of
865 regular IRC commands."
866 :group 'erc-scripts
867 :type '(repeat file))
869 (defcustom erc-script-path nil
870 "List of directories to look for a script in /load command.
871 The script is first searched in the current directory, then in each
872 directory in the list."
873 :group 'erc-scripts
874 :type '(repeat directory))
876 (defcustom erc-script-echo t
877 "If non-nil, echo the IRC script commands locally."
878 :group 'erc-scripts
879 :type 'boolean)
881 (defvar erc-last-saved-position nil
882 "A marker containing the position the current buffer was last saved at.")
883 (make-variable-buffer-local 'erc-last-saved-position)
885 (defcustom erc-kill-buffer-on-part nil
886 "Kill the channel buffer on PART.
887 This variable should probably stay nil, as ERC can reuse buffers if
888 you rejoin them later."
889 :group 'erc-quit-and-part
890 :type 'boolean)
892 (defcustom erc-kill-queries-on-quit nil
893 "Kill all query (also channel) buffers of this server on QUIT.
894 See the variable `erc-kill-buffer-on-part' for details."
895 :group 'erc-quit-and-part
896 :type 'boolean)
898 (defcustom erc-kill-server-buffer-on-quit nil
899 "Kill the server buffer of the process on QUIT."
900 :group 'erc-quit-and-part
901 :type 'boolean)
903 (defcustom erc-quit-reason-various-alist nil
904 "Alist of possible arguments to the /quit command.
906 Each element has the form:
907 (REGEXP RESULT)
909 If REGEXP matches the argument to /quit, then its relevant RESULT
910 will be used. RESULT may be either a string, or a function. If
911 a function, it should return the quit message as a string.
913 If no elements match, then the empty string is used.
915 As an example:
916 (setq erc-quit-reason-various-alist
917 '((\"xmms\" dme:now-playing)
918 (\"version\" erc-quit-reason-normal)
919 (\"home\" \"Gone home !\")
920 (\"^$\" \"Default Reason\")))
921 If the user types \"/quit home\", then \"Gone home !\" will be used
922 as the quit message."
923 :group 'erc-quit-and-part
924 :type '(repeat (list regexp (choice (string) (function)))))
926 (defcustom erc-part-reason-various-alist nil
927 "Alist of possible arguments to the /part command.
929 Each element has the form:
930 (REGEXP RESULT)
932 If REGEXP matches the argument to /part, then its relevant RESULT
933 will be used. RESULT may be either a string, or a function. If
934 a function, it should return the part message as a string.
936 If no elements match, then the empty string is used.
938 As an example:
939 (setq erc-part-reason-various-alist
940 '((\"xmms\" dme:now-playing)
941 (\"version\" erc-part-reason-normal)
942 (\"home\" \"Gone home !\")
943 (\"^$\" \"Default Reason\")))
944 If the user types \"/part home\", then \"Gone home !\" will be used
945 as the part message."
946 :group 'erc-quit-and-part
947 :type '(repeat (list regexp (choice (string) (function)))))
949 (defcustom erc-quit-reason 'erc-quit-reason-normal
950 "A function which returns the reason for quitting.
952 The function is passed a single argument, the string typed by the
953 user after \"/quit\"."
954 :group 'erc-quit-and-part
955 :type '(choice (const erc-quit-reason-normal)
956 (const erc-quit-reason-various)
957 (symbol)))
959 (defcustom erc-part-reason 'erc-part-reason-normal
960 "A function which returns the reason for parting a channel.
962 The function is passed a single argument, the string typed by the
963 user after \"/PART\"."
964 :group 'erc-quit-and-part
965 :type '(choice (const erc-part-reason-normal)
966 (const erc-part-reason-various)
967 (symbol)))
969 (defvar erc-grab-buffer-name "*erc-grab*"
970 "The name of the buffer created by `erc-grab-region'.")
972 ;; variables available for IRC scripts
974 (defvar erc-user-information "ERC User"
975 "USER_INFORMATION IRC variable.")
977 ;; Hooks
979 (defgroup erc-hooks nil
980 "Hook variables for fancy customizations of ERC."
981 :group 'erc)
983 (defcustom erc-mode-hook nil
984 "Hook run after `erc-mode' setup is finished."
985 :group 'erc-hooks
986 :type 'hook
987 :options '(erc-add-scroll-to-bottom))
989 (defcustom erc-timer-hook nil
990 "Put functions which should get called more or less periodically here.
991 The idea is that servers always play ping pong with the client, and so there
992 is no need for any idle-timer games with Emacs."
993 :group 'erc-hooks
994 :type 'hook)
996 (defcustom erc-insert-pre-hook nil
997 "Hook called first when some text is inserted through `erc-display-line'.
998 It gets called with one argument, STRING.
999 To be able to modify the inserted text, use `erc-insert-modify-hook' instead.
1000 Filtering functions can set `erc-insert-this' to nil to avoid
1001 display of that particular string at all."
1002 :group 'erc-hooks
1003 :type 'hook)
1005 (defcustom erc-send-pre-hook nil
1006 "Hook called first when some text is sent through `erc-send-current-line'.
1007 It gets called with one argument, STRING.
1009 To change the text that will be sent, set the variable `str' which is
1010 used in `erc-send-current-line'.
1012 To change the text inserted into the buffer without changing the text
1013 that will be sent, use `erc-send-modify-hook' instead.
1015 Filtering functions can set `erc-send-this' to nil to avoid sending of
1016 that particular string at all and `erc-insert-this' to prevent
1017 inserting that particular string into the buffer.
1019 Note that it's useless to set `erc-send-this' to nil and
1020 `erc-insert-this' to t. ERC is sane enough to not insert the text
1021 anyway."
1022 :group 'erc-hooks
1023 :type 'hook)
1025 (defvar erc-insert-this t
1026 "Insert the text into the target buffer or not.
1027 Functions on `erc-insert-pre-hook' can set this variable to nil
1028 if they wish to avoid insertion of a particular string.")
1030 (defvar erc-send-this t
1031 "Send the text to the target or not.
1032 Functions on `erc-send-pre-hook' can set this variable to nil
1033 if they wish to avoid sending of a particular string.")
1035 (defcustom erc-insert-modify-hook ()
1036 "Insertion hook for functions that will change the text's appearance.
1037 This hook is called just after `erc-insert-pre-hook' when the value
1038 of `erc-insert-this' is t.
1039 While this hook is run, narrowing is in effect and `current-buffer' is
1040 the buffer where the text got inserted. One possible value to add here
1041 is `erc-fill'."
1042 :group 'erc-hooks
1043 :type 'hook)
1045 (defcustom erc-insert-post-hook nil
1046 "This hook is called just after `erc-insert-modify-hook'.
1047 At this point, all modifications from prior hook functions are done."
1048 :group 'erc-hooks
1049 :type 'hook
1050 :options '(erc-truncate-buffer
1051 erc-make-read-only
1052 erc-save-buffer-in-logs))
1054 (defcustom erc-send-modify-hook nil
1055 "Sending hook for functions that will change the text's appearance.
1056 This hook is called just after `erc-send-pre-hook' when the values
1057 of `erc-send-this' and `erc-insert-this' are both t.
1058 While this hook is run, narrowing is in effect and `current-buffer' is
1059 the buffer where the text got inserted.
1061 Note that no function in this hook can change the appearance of the
1062 text that is sent. Only changing the sent text's appearance on the
1063 sending user's screen is possible. One possible value to add here
1064 is `erc-fill'."
1065 :group 'erc-hooks
1066 :type 'hook)
1068 (defcustom erc-send-post-hook nil
1069 "This hook is called just after `erc-send-modify-hook'.
1070 At this point, all modifications from prior hook functions are done.
1071 NOTE: The functions on this hook are called _before_ sending a command
1072 to the server.
1074 This function is called with narrowing, ala `erc-send-modify-hook'."
1075 :group 'erc-hooks
1076 :type 'hook
1077 :options '(erc-make-read-only))
1079 (defcustom erc-send-completed-hook
1080 (when (fboundp 'emacspeak-auditory-icon)
1081 (list (byte-compile
1082 (lambda (_str)
1083 (emacspeak-auditory-icon 'select-object)))))
1084 "Hook called after a message has been parsed by ERC.
1086 The single argument to the functions is the unmodified string
1087 which the local user typed."
1088 :group 'erc-hooks
1089 :type 'hook)
1090 ;; mode-specific tables
1092 (defvar erc-mode-syntax-table
1093 (let ((syntax-table (make-syntax-table)))
1094 (modify-syntax-entry ?\" ". " syntax-table)
1095 (modify-syntax-entry ?\\ ". " syntax-table)
1096 (modify-syntax-entry ?' "w " syntax-table)
1097 ;; Make dabbrev-expand useful for nick names
1098 (modify-syntax-entry ?< "." syntax-table)
1099 (modify-syntax-entry ?> "." syntax-table)
1100 syntax-table)
1101 "Syntax table used while in ERC mode.")
1103 (defvar erc-mode-abbrev-table nil
1104 "Abbrev table used while in ERC mode.")
1105 (define-abbrev-table 'erc-mode-abbrev-table ())
1107 (defvar erc-mode-map
1108 (let ((map (make-sparse-keymap)))
1109 (define-key map "\C-m" 'erc-send-current-line)
1110 (define-key map "\C-a" 'erc-bol)
1111 (define-key map [home] 'erc-bol)
1112 (define-key map "\C-c\C-a" 'erc-bol)
1113 (define-key map "\C-c\C-b" 'erc-iswitchb)
1114 (define-key map "\C-c\C-c" 'erc-toggle-interpret-controls)
1115 (define-key map "\C-c\C-d" 'erc-input-action)
1116 (define-key map "\C-c\C-e" 'erc-toggle-ctcp-autoresponse)
1117 (define-key map "\C-c\C-f" 'erc-toggle-flood-control)
1118 (define-key map "\C-c\C-i" 'erc-invite-only-mode)
1119 (define-key map "\C-c\C-j" 'erc-join-channel)
1120 (define-key map "\C-c\C-n" 'erc-channel-names)
1121 (define-key map "\C-c\C-o" 'erc-get-channel-mode-from-keypress)
1122 (define-key map "\C-c\C-p" 'erc-part-from-channel)
1123 (define-key map "\C-c\C-q" 'erc-quit-server)
1124 (define-key map "\C-c\C-r" 'erc-remove-text-properties-region)
1125 (define-key map "\C-c\C-t" 'erc-set-topic)
1126 (define-key map "\C-c\C-u" 'erc-kill-input)
1127 (define-key map "\C-c\C-x" 'erc-quit-server)
1128 (define-key map "\M-\t" 'ispell-complete-word)
1129 (define-key map "\t" 'completion-at-point)
1131 ;; Suppress `font-lock-fontify-block' key binding since it
1132 ;; destroys face properties.
1133 (define-key map [remap font-lock-fontify-block] 'undefined)
1135 map)
1136 "ERC keymap.")
1138 ;; Faces
1140 ; Honestly, I have a horrible sense of color and the "defaults" below
1141 ; are supposed to be really bad. But colors ARE required in IRC to
1142 ; convey different parts of conversation. If you think you know better
1143 ; defaults - send them to me.
1145 ;; Now colors are a bit nicer, at least to my eyes.
1146 ;; You may still want to change them to better fit your background.-- S.B.
1148 (defgroup erc-faces nil
1149 "Faces for ERC."
1150 :group 'erc)
1152 ;; FIXME faces should not end in "-face".
1153 (defface erc-default-face '((t))
1154 "ERC default face."
1155 :group 'erc-faces)
1157 (defface erc-nick-prefix-face '((t :inherit erc-nick-default-face :weight bold))
1158 "ERC face used for user mode prefix."
1159 :group 'erc-faces)
1161 (defface erc-my-nick-prefix-face '((t :inherit erc-nick-default-face :weight bold))
1162 "ERC face used for my user mode prefix."
1163 :group 'erc-faces)
1165 (defface erc-direct-msg-face '((t :foreground "IndianRed"))
1166 "ERC face used for messages you receive in the main erc buffer."
1167 :group 'erc-faces)
1169 (defface erc-header-line
1170 '((t :foreground "grey20" :background "grey90"))
1171 "ERC face used for the header line.
1173 This will only be used if `erc-header-line-face-method' is non-nil."
1174 :group 'erc-faces)
1176 (defface erc-input-face '((t :foreground "brown"))
1177 "ERC face used for your input."
1178 :group 'erc-faces)
1180 (defface erc-prompt-face
1181 '((t :weight bold :foreground "Black" :background "lightBlue2"))
1182 "ERC face for the prompt."
1183 :group 'erc-faces)
1185 (defface erc-command-indicator-face
1186 '((t :weight bold))
1187 "ERC face for the command indicator.
1188 See the variable `erc-command-indicator'."
1189 :group 'erc-faces)
1191 (defface erc-notice-face
1192 '((default :weight bold)
1193 (((class color) (min-colors 88)) :foreground "SlateBlue")
1194 (t :foreground "blue"))
1195 "ERC face for notices."
1196 :group 'erc-faces)
1198 (defface erc-action-face '((t :weight bold))
1199 "ERC face for actions generated by /ME."
1200 :group 'erc-faces)
1202 (defface erc-error-face '((t :foreground "red"))
1203 "ERC face for errors."
1204 :group 'erc-faces)
1206 ;; same default color as `erc-input-face'
1207 (defface erc-my-nick-face '((t :weight bold :foreground "brown"))
1208 "ERC face for your current nickname in messages sent by you.
1209 See also `erc-show-my-nick'."
1210 :group 'erc-faces)
1212 (defface erc-nick-default-face '((t :weight bold))
1213 "ERC nickname default face."
1214 :group 'erc-faces)
1216 (defface erc-nick-msg-face '((t :weight bold :foreground "IndianRed"))
1217 "ERC nickname face for private messages."
1218 :group 'erc-faces)
1220 ;; Debugging support
1222 (defvar erc-log-p nil
1223 "When set to t, generate debug messages in a separate debug buffer.")
1225 (defvar erc-debug-log-file (expand-file-name "ERC.debug")
1226 "Debug log file name.")
1228 (defvar erc-dbuf nil)
1229 (make-variable-buffer-local 'erc-dbuf)
1231 (defmacro define-erc-module (name alias doc enable-body disable-body
1232 &optional local-p)
1233 "Define a new minor mode using ERC conventions.
1234 Symbol NAME is the name of the module.
1235 Symbol ALIAS is the alias to use, or nil.
1236 DOC is the documentation string to use for the minor mode.
1237 ENABLE-BODY is a list of expressions used to enable the mode.
1238 DISABLE-BODY is a list of expressions used to disable the mode.
1239 If LOCAL-P is non-nil, the mode will be created as a buffer-local
1240 mode, rather than a global one.
1242 This will define a minor mode called erc-NAME-mode, possibly
1243 an alias erc-ALIAS-mode, as well as the helper functions
1244 erc-NAME-enable, and erc-NAME-disable.
1246 Example:
1248 ;;;###autoload (autoload 'erc-replace-mode \"erc-replace\")
1249 (define-erc-module replace nil
1250 \"This mode replaces incoming text according to `erc-replace-alist'.\"
1251 ((add-hook 'erc-insert-modify-hook
1252 'erc-replace-insert))
1253 ((remove-hook 'erc-insert-modify-hook
1254 'erc-replace-insert)))"
1255 (declare (doc-string 3))
1256 (let* ((sn (symbol-name name))
1257 (mode (intern (format "erc-%s-mode" (downcase sn))))
1258 (group (intern (format "erc-%s" (downcase sn))))
1259 (enable (intern (format "erc-%s-enable" (downcase sn))))
1260 (disable (intern (format "erc-%s-disable" (downcase sn)))))
1261 `(progn
1262 (erc-define-minor-mode
1263 ,mode
1264 ,(format "Toggle ERC %S mode.
1265 With a prefix argument ARG, enable %s if ARG is positive,
1266 and disable it otherwise. If called from Lisp, enable the mode
1267 if ARG is omitted or nil.
1268 %s" name name doc)
1269 nil nil nil
1270 :global ,(not local-p) :group (quote ,group)
1271 (if ,mode
1272 (,enable)
1273 (,disable)))
1274 (defun ,enable ()
1275 ,(format "Enable ERC %S mode."
1276 name)
1277 (interactive)
1278 (add-to-list 'erc-modules (quote ,name))
1279 (setq ,mode t)
1280 ,@enable-body)
1281 (defun ,disable ()
1282 ,(format "Disable ERC %S mode."
1283 name)
1284 (interactive)
1285 (setq erc-modules (delq (quote ,name) erc-modules))
1286 (setq ,mode nil)
1287 ,@disable-body)
1288 ,(when (and alias (not (eq name alias)))
1289 `(defalias
1290 (quote
1291 ,(intern
1292 (format "erc-%s-mode"
1293 (downcase (symbol-name alias)))))
1294 (quote
1295 ,mode)))
1296 ;; For find-function and find-variable.
1297 (put ',mode 'definition-name ',name)
1298 (put ',enable 'definition-name ',name)
1299 (put ',disable 'definition-name ',name))))
1301 (defun erc-once-with-server-event (event f)
1302 "Run function F the next time EVENT occurs in the `current-buffer'.
1304 You should make sure that `current-buffer' is a server buffer.
1306 This function temporarily adds a function to EVENT's hook to call F with
1307 two arguments (`proc' and `parsed'). After F is called, the function is
1308 removed from EVENT's hook. F should return either nil
1309 or t, where nil indicates that the other functions on EVENT's hook
1310 should be run too, and t indicates that other functions should
1311 not be run.
1313 Please be sure to use this function in server-buffers. In
1314 channel-buffers it may not work at all, as it uses the LOCAL
1315 argument of `add-hook' and `remove-hook' to ensure multiserver
1316 capabilities."
1317 (unless (erc-server-buffer-p)
1318 (error
1319 "You should only run `erc-once-with-server-event' in a server buffer"))
1320 (let ((fun (make-symbol "fun"))
1321 (hook (erc-get-hook event)))
1322 (put fun 'erc-original-buffer (current-buffer))
1323 (fset fun (lambda (proc parsed)
1324 (with-current-buffer (get fun 'erc-original-buffer)
1325 (remove-hook hook fun t))
1326 (fmakunbound fun)
1327 (funcall f proc parsed)))
1328 (add-hook hook fun nil t)
1329 fun))
1331 (defsubst erc-log (string)
1332 "Logs STRING if logging is on (see `erc-log-p')."
1333 (when erc-log-p
1334 (erc-log-aux string)))
1336 (defun erc-server-buffer ()
1337 "Return the server buffer for the current buffer's process.
1338 The buffer-local variable `erc-server-process' is used to find
1339 the process buffer."
1340 (and (erc-server-buffer-live-p)
1341 (process-buffer erc-server-process)))
1343 (defun erc-server-buffer-live-p ()
1344 "Return t if the server buffer has not been killed."
1345 (and (processp erc-server-process)
1346 (buffer-live-p (process-buffer erc-server-process))))
1348 (defun erc-server-buffer-p (&optional buffer)
1349 "Return non-nil if argument BUFFER is an ERC server buffer.
1351 If BUFFER is nil, the current buffer is used."
1352 (with-current-buffer (or buffer (current-buffer))
1353 (and (eq major-mode 'erc-mode)
1354 (null (erc-default-target)))))
1356 (defun erc-open-server-buffer-p (&optional buffer)
1357 "Return non-nil if argument BUFFER is an ERC server buffer that
1358 has an open IRC process.
1360 If BUFFER is nil, the current buffer is used."
1361 (and (erc-server-buffer-p buffer)
1362 (erc-server-process-alive buffer)))
1364 (defun erc-query-buffer-p (&optional buffer)
1365 "Return non-nil if BUFFER is an ERC query buffer.
1366 If BUFFER is nil, the current buffer is used."
1367 (with-current-buffer (or buffer (current-buffer))
1368 (let ((target (erc-default-target)))
1369 (and (eq major-mode 'erc-mode)
1370 target
1371 (not (memq (aref target 0) '(?# ?& ?+ ?!)))))))
1373 (defun erc-ison-p (nick)
1374 "Return non-nil if NICK is online."
1375 (interactive "sNick: ")
1376 (erc-with-server-buffer
1377 (let ((erc-online-p 'unknown))
1378 (erc-once-with-server-event
1380 (lambda (_proc parsed)
1381 (let ((ison (split-string (aref parsed 3))))
1382 (setq erc-online-p (car (erc-member-ignore-case nick ison)))
1383 t)))
1384 (erc-server-send (format "ISON %s" nick))
1385 (while (eq erc-online-p 'unknown) (accept-process-output))
1386 (if (called-interactively-p 'interactive)
1387 (message "%s is %sonline"
1388 (or erc-online-p nick)
1389 (if erc-online-p "" "not "))
1390 erc-online-p))))
1392 (defun erc-log-aux (string)
1393 "Do the debug logging of STRING."
1394 (let ((cb (current-buffer))
1395 (point 1)
1396 (was-eob nil)
1397 (session-buffer (erc-server-buffer)))
1398 (if session-buffer
1399 (progn
1400 (set-buffer session-buffer)
1401 (if (not (and erc-dbuf (bufferp erc-dbuf) (buffer-live-p erc-dbuf)))
1402 (progn
1403 (setq erc-dbuf (get-buffer-create
1404 (concat "*ERC-DEBUG: "
1405 erc-session-server "*")))))
1406 (set-buffer erc-dbuf)
1407 (setq point (point))
1408 (setq was-eob (eobp))
1409 (goto-char (point-max))
1410 (insert (concat "** " string "\n"))
1411 (if was-eob (goto-char (point-max))
1412 (goto-char point))
1413 (set-buffer cb))
1414 (message "ERC: ** %s" string))))
1416 ;; Last active buffer, to print server messages in the right place
1418 (defvar erc-active-buffer nil
1419 "The current active buffer, the one where the user typed the last command.
1420 Defaults to the server buffer, and should only be set in the
1421 server buffer.")
1422 (make-variable-buffer-local 'erc-active-buffer)
1424 (defun erc-active-buffer ()
1425 "Return the value of `erc-active-buffer' for the current server.
1426 Defaults to the server buffer."
1427 (erc-with-server-buffer
1428 (if (buffer-live-p erc-active-buffer)
1429 erc-active-buffer
1430 (setq erc-active-buffer (current-buffer)))))
1432 (defun erc-set-active-buffer (buffer)
1433 "Set the value of `erc-active-buffer' to BUFFER."
1434 (cond ((erc-server-buffer)
1435 (with-current-buffer (erc-server-buffer)
1436 (setq erc-active-buffer buffer)))
1437 (t (setq erc-active-buffer buffer))))
1439 ;; Mode activation routines
1441 (define-derived-mode erc-mode fundamental-mode "ERC"
1442 "Major mode for Emacs IRC."
1443 (setq local-abbrev-table erc-mode-abbrev-table)
1444 (when (boundp 'next-line-add-newlines)
1445 (set (make-local-variable 'next-line-add-newlines) nil))
1446 (setq line-move-ignore-invisible t)
1447 (set (make-local-variable 'paragraph-separate)
1448 (concat "\C-l\\|\\(^" (regexp-quote (erc-prompt)) "\\)"))
1449 (set (make-local-variable 'paragraph-start)
1450 (concat "\\(" (regexp-quote (erc-prompt)) "\\)"))
1451 (add-hook 'completion-at-point-functions 'erc-complete-word-at-point nil t))
1453 ;; activation
1455 (defconst erc-default-server "irc.freenode.net"
1456 "IRC server to use if it cannot be detected otherwise.")
1458 (defconst erc-default-port 6667
1459 "IRC port to use if it cannot be detected otherwise.")
1461 (defcustom erc-join-buffer 'buffer
1462 "Determines how to display a newly created IRC buffer.
1464 The available choices are:
1466 'window - in another window,
1467 'window-noselect - in another window, but don't select that one,
1468 'frame - in another frame,
1469 'bury - bury it in a new buffer,
1470 'buffer - in place of the current buffer,
1471 any other value - in place of the current buffer."
1472 :group 'erc-buffers
1473 :type '(choice (const :tag "Split window and select" window)
1474 (const :tag "Split window, don't select" window-noselect)
1475 (const :tag "New frame" frame)
1476 (const :tag "Bury in new buffer" bury)
1477 (const :tag "Use current buffer" buffer)
1478 (const :tag "Use current buffer" t)))
1480 (defcustom erc-frame-alist nil
1481 "Alist of frame parameters for creating erc frames.
1482 A value of nil means to use `default-frame-alist'."
1483 :group 'erc-buffers
1484 :type '(repeat (cons :format "%v"
1485 (symbol :tag "Parameter")
1486 (sexp :tag "Value"))))
1488 (defcustom erc-frame-dedicated-flag nil
1489 "Non-nil means the erc frames are dedicated to that buffer.
1490 This only has effect when `erc-join-buffer' is set to `frame'."
1491 :group 'erc-buffers
1492 :type 'boolean)
1494 (defcustom erc-reuse-frames t
1495 "Determines whether new frames are always created.
1496 Non-nil means that a new frame is not created to display an ERC
1497 buffer if there is already a window displaying it. This only has
1498 effect when `erc-join-buffer' is set to `frame'."
1499 :group 'erc-buffers
1500 :type 'boolean)
1502 (defun erc-channel-p (channel)
1503 "Return non-nil if CHANNEL seems to be an IRC channel name."
1504 (cond ((stringp channel)
1505 (memq (aref channel 0) '(?# ?& ?+ ?!)))
1506 ((and (bufferp channel) (buffer-live-p channel))
1507 (with-current-buffer channel
1508 (erc-channel-p (erc-default-target))))
1509 (t nil)))
1511 (defcustom erc-reuse-buffers t
1512 "If nil, create new buffers on joining a channel/query.
1513 If non-nil, a new buffer will only be created when you join
1514 channels with same names on different servers, or have query buffers
1515 open with nicks of the same name on different servers. Otherwise,
1516 the existing buffers will be reused."
1517 :group 'erc-buffers
1518 :type 'boolean)
1520 (defun erc-normalize-port (port)
1521 "Normalize the port specification PORT to integer form.
1522 PORT may be an integer, a string or a symbol. If it is a string or a
1523 symbol, it may have these values:
1524 * irc -> 194
1525 * ircs -> 994
1526 * ircd -> 6667
1527 * ircd-dalnet -> 7000"
1528 (cond
1529 ((symbolp port)
1530 (erc-normalize-port (symbol-name port)))
1531 ((stringp port)
1532 (let ((port-nr (string-to-number port)))
1533 (cond
1534 ((> port-nr 0)
1535 port-nr)
1536 ((string-equal port "irc")
1537 194)
1538 ((string-equal port "ircs")
1539 994)
1540 ((string-equal port "ircd")
1541 6667)
1542 ((string-equal port "ircd-dalnet")
1543 7000)
1545 nil))))
1546 ((numberp port)
1547 port)
1549 nil)))
1551 (defun erc-port-equal (a b)
1552 "Check whether ports A and B are equal."
1553 (= (erc-normalize-port a) (erc-normalize-port b)))
1555 (defun erc-generate-new-buffer-name (server port target)
1556 "Create a new buffer name based on the arguments."
1557 (when (numberp port) (setq port (number-to-string port)))
1558 (let ((buf-name (or target
1559 (or (let ((name (concat server ":" port)))
1560 (when (> (length name) 1)
1561 name))
1562 ;; This fallback should in fact never happen
1563 "*erc-server-buffer*")))
1564 buffer-name)
1565 ;; Reuse existing buffers, but not if the buffer is a connected server
1566 ;; buffer and not if its associated with a different server than the
1567 ;; current ERC buffer.
1568 ;; if buf-name is taken by a different connection (or by something !erc)
1569 ;; then see if "buf-name/server" meets the same criteria
1570 (dolist (candidate (list buf-name (concat buf-name "/" server)))
1571 (if (and (not buffer-name)
1572 erc-reuse-buffers
1573 (get-buffer candidate)
1574 (or target
1575 (with-current-buffer (get-buffer candidate)
1576 (and (erc-server-buffer-p)
1577 (not (erc-server-process-alive)))))
1578 (with-current-buffer (get-buffer candidate)
1579 (and (string= erc-session-server server)
1580 (erc-port-equal erc-session-port port))))
1581 (setq buffer-name candidate)))
1582 ;; if buffer-name is unset, neither candidate worked out for us,
1583 ;; fallback to the old <N> uniquification method:
1584 (or buffer-name (generate-new-buffer-name buf-name)) ))
1586 (defun erc-get-buffer-create (server port target)
1587 "Create a new buffer based on the arguments."
1588 (get-buffer-create (erc-generate-new-buffer-name server port target)))
1591 (defun erc-member-ignore-case (string list)
1592 "Return non-nil if STRING is a member of LIST.
1594 All strings are compared according to IRC protocol case rules, see
1595 `erc-downcase'."
1596 (setq string (erc-downcase string))
1597 (catch 'result
1598 (while list
1599 (if (string= string (erc-downcase (car list)))
1600 (throw 'result list)
1601 (setq list (cdr list))))))
1603 (defmacro erc-with-buffer (spec &rest body)
1604 "Execute BODY in the buffer associated with SPEC.
1606 SPEC should have the form
1608 (TARGET [PROCESS])
1610 If TARGET is a buffer, use it. Otherwise, use the buffer
1611 matching TARGET in the process specified by PROCESS.
1613 If PROCESS is nil, use the current `erc-server-process'.
1614 See `erc-get-buffer' for details.
1616 See also `with-current-buffer'.
1618 \(fn (TARGET [PROCESS]) BODY...)"
1619 (declare (indent 1) (debug ((form &optional form) body)))
1620 (let ((buf (make-symbol "buf"))
1621 (proc (make-symbol "proc"))
1622 (target (make-symbol "target"))
1623 (process (make-symbol "process")))
1624 `(let* ((,target ,(car spec))
1625 (,process ,(cadr spec))
1626 (,buf (if (bufferp ,target)
1627 ,target
1628 (let ((,proc (or ,process
1629 (and (processp erc-server-process)
1630 erc-server-process))))
1631 (if (and ,target ,proc)
1632 (erc-get-buffer ,target ,proc))))))
1633 (when (buffer-live-p ,buf)
1634 (with-current-buffer ,buf
1635 ,@body)))))
1637 (defun erc-get-buffer (target &optional proc)
1638 "Return the buffer matching TARGET in the process PROC.
1639 If PROC is not supplied, all processes are searched."
1640 (let ((downcased-target (erc-downcase target)))
1641 (catch 'buffer
1642 (erc-buffer-filter
1643 (lambda ()
1644 (let ((current (erc-default-target)))
1645 (and (stringp current)
1646 (string-equal downcased-target (erc-downcase current))
1647 (throw 'buffer (current-buffer)))))
1648 proc))))
1650 (defun erc-buffer-filter (predicate &optional proc)
1651 "Return a list of `erc-mode' buffers matching certain criteria.
1652 PREDICATE is a function executed with each buffer, if it returns t, that buffer
1653 is considered a valid match.
1655 PROC is either an `erc-server-process', identifying a certain
1656 server connection, or nil which means all open connections."
1657 (save-excursion
1658 (delq
1660 (mapcar (lambda (buf)
1661 (when (buffer-live-p buf)
1662 (with-current-buffer buf
1663 (and (eq major-mode 'erc-mode)
1664 (or (not proc)
1665 (eq proc erc-server-process))
1666 (funcall predicate)
1667 buf))))
1668 (buffer-list)))))
1670 (defun erc-buffer-list (&optional predicate proc)
1671 "Return a list of ERC buffers.
1672 PREDICATE is a function which executes with every buffer satisfying
1673 the predicate. If PREDICATE is passed as nil, return a list of all ERC
1674 buffers. If PROC is given, the buffers local variable `erc-server-process'
1675 needs to match PROC."
1676 (unless predicate
1677 (setq predicate (lambda () t)))
1678 (erc-buffer-filter predicate proc))
1680 (defmacro erc-with-all-buffers-of-server (process pred &rest forms)
1681 "Execute FORMS in all buffers which have same process as this server.
1682 FORMS will be evaluated in all buffers having the process PROCESS and
1683 where PRED matches or in all buffers of the server process if PRED is
1684 nil."
1685 (declare (indent 1) (debug (form form body)))
1686 ;; Make the evaluation have the correct order
1687 (let ((pre (make-symbol "pre"))
1688 (pro (make-symbol "pro")))
1689 `(let* ((,pro ,process)
1690 (,pre ,pred)
1691 (res (mapcar (lambda (buffer)
1692 (with-current-buffer buffer
1693 ,@forms))
1694 (erc-buffer-list ,pre
1695 ,pro))))
1696 ;; Silence the byte-compiler by binding the result of mapcar to
1697 ;; a variable.
1698 res)))
1700 ;; (iswitchb-mode) will autoload iswitchb.el
1701 (defvar iswitchb-temp-buflist)
1702 (declare-function iswitchb-read-buffer "iswitchb"
1703 (prompt &optional default require-match start matches-set))
1704 (defvar iswitchb-make-buflist-hook)
1706 (defun erc-iswitchb (&optional arg)
1707 "Use `iswitchb-read-buffer' to prompt for a ERC buffer to switch to.
1708 When invoked with prefix argument, use all erc buffers. Without prefix
1709 ARG, allow only buffers related to same session server.
1710 If `erc-track-mode' is in enabled, put the last element of
1711 `erc-modified-channels-alist' in front of the buffer list.
1713 Due to some yet unresolved reason, global function `iswitchb-mode'
1714 needs to be active for this function to work."
1715 (interactive "P")
1716 (let ((enabled (bound-and-true-p iswitchb-mode)))
1717 (or enabled (iswitchb-mode 1))
1718 (unwind-protect
1719 (let ((iswitchb-make-buflist-hook
1720 (lambda ()
1721 (setq iswitchb-temp-buflist
1722 (mapcar 'buffer-name
1723 (erc-buffer-list
1725 (when arg erc-server-process)))))))
1726 (switch-to-buffer
1727 (iswitchb-read-buffer
1728 "Switch-to: "
1729 (if (boundp 'erc-modified-channels-alist)
1730 (buffer-name (caar (last erc-modified-channels-alist)))
1731 nil)
1732 t)))
1733 (or enabled (iswitchb-mode -1)))))
1735 (defun erc-channel-list (proc)
1736 "Return a list of channel buffers.
1737 PROC is the process for the server connection. If PROC is nil, return
1738 all channel buffers on all servers."
1739 (erc-buffer-filter
1740 (lambda ()
1741 (and (erc-default-target)
1742 (erc-channel-p (erc-default-target))))
1743 proc))
1745 (defun erc-buffer-list-with-nick (nick proc)
1746 "Return buffers containing NICK in the `erc-channel-users' list."
1747 (with-current-buffer (process-buffer proc)
1748 (let ((user (gethash (erc-downcase nick) erc-server-users)))
1749 (if user
1750 (erc-server-user-buffers user)
1751 nil))))
1753 ;; Some local variables
1755 (defvar erc-default-recipients nil
1756 "List of default recipients of the current buffer.")
1757 (make-variable-buffer-local 'erc-default-recipients)
1759 (defvar erc-session-user-full-name nil
1760 "Full name of the user on the current server.")
1761 (make-variable-buffer-local 'erc-session-user-full-name)
1763 (defvar erc-channel-user-limit nil
1764 "Limit of users per channel.")
1765 (make-variable-buffer-local 'erc-channel-user-limit)
1767 (defvar erc-channel-key nil
1768 "Key needed to join channel.")
1769 (make-variable-buffer-local 'erc-channel-key)
1771 (defvar erc-invitation nil
1772 "Last invitation channel.")
1773 (make-variable-buffer-local 'erc-invitation)
1775 (defvar erc-away nil
1776 "Non-nil indicates that we are away.
1778 Use `erc-away-time' to access this if you might be in a channel
1779 buffer rather than a server buffer.")
1780 (make-variable-buffer-local 'erc-away)
1782 (defvar erc-channel-list nil
1783 "Server channel list.")
1784 (make-variable-buffer-local 'erc-channel-list)
1786 (defvar erc-bad-nick nil
1787 "Non-nil indicates that we got a `nick in use' error while connecting.")
1788 (make-variable-buffer-local 'erc-bad-nick)
1790 (defvar erc-logged-in nil
1791 "Non-nil indicates that we are logged in.")
1792 (make-variable-buffer-local 'erc-logged-in)
1794 (defvar erc-default-nicks nil
1795 "The local copy of `erc-nick' - the list of nicks to choose from.")
1796 (make-variable-buffer-local 'erc-default-nicks)
1798 (defvar erc-nick-change-attempt-count 0
1799 "Used to keep track of how many times an attempt at changing nick is made.")
1800 (make-variable-buffer-local 'erc-nick-change-attempt-count)
1802 (defun erc-migrate-modules (mods)
1803 "Migrate old names of ERC modules to new ones."
1804 ;; modify `transforms' to specify what needs to be changed
1805 ;; each item is in the format '(old . new)
1806 (let ((transforms '((pcomplete . completion))))
1807 (erc-delete-dups
1808 (mapcar (lambda (m) (or (cdr (assoc m transforms)) m))
1809 mods))))
1811 (defcustom erc-modules '(netsplit fill button match track completion readonly
1812 networks ring autojoin noncommands irccontrols
1813 move-to-prompt stamp menu list)
1814 "A list of modules which ERC should enable.
1815 If you set the value of this without using `customize' remember to call
1816 \(erc-update-modules) after you change it. When using `customize', modules
1817 removed from the list will be disabled."
1818 :get (lambda (sym)
1819 ;; replace outdated names with their newer equivalents
1820 (erc-migrate-modules (symbol-value sym)))
1821 :set (lambda (sym val)
1822 ;; disable modules which have just been removed
1823 (when (and (boundp 'erc-modules) erc-modules val)
1824 (dolist (module erc-modules)
1825 (unless (member module val)
1826 (let ((f (intern-soft (format "erc-%s-mode" module))))
1827 (when (and (fboundp f) (boundp f) (symbol-value f))
1828 (message "Disabling `erc-%s'" module)
1829 (funcall f 0))))))
1830 (set sym val)
1831 ;; this test is for the case where erc hasn't been loaded yet
1832 (when (fboundp 'erc-update-modules)
1833 (erc-update-modules)))
1834 :type
1835 '(set
1836 :greedy t
1837 (const :tag "autoaway: Set away status automatically" autoaway)
1838 (const :tag "autojoin: Join channels automatically" autojoin)
1839 (const :tag "button: Buttonize URLs, nicknames, and other text" button)
1840 (const :tag "capab: Mark unidentified users on servers supporting CAPAB"
1841 capab-identify)
1842 (const :tag "completion: Complete nicknames and commands (programmable)"
1843 completion)
1844 (const :tag "hecomplete: Complete nicknames and commands (obsolete, use \"completion\")" hecomplete)
1845 (const :tag "dcc: Provide Direct Client-to-Client support" dcc)
1846 (const :tag "fill: Wrap long lines" fill)
1847 (const :tag "identd: Launch an identd server on port 8113" identd)
1848 (const :tag "irccontrols: Highlight or remove IRC control characters"
1849 irccontrols)
1850 (const :tag "keep-place: Leave point above un-viewed text" keep-place)
1851 (const :tag "list: List channels in a separate buffer" list)
1852 (const :tag "log: Save buffers in logs" log)
1853 (const :tag "match: Highlight pals, fools, and other keywords" match)
1854 (const :tag "menu: Display a menu in ERC buffers" menu)
1855 (const :tag "move-to-prompt: Move to the prompt when typing text"
1856 move-to-prompt)
1857 (const :tag "netsplit: Detect netsplits" netsplit)
1858 (const :tag "networks: Provide data about IRC networks" networks)
1859 (const :tag "noncommands: Don't display non-IRC commands after evaluation"
1860 noncommands)
1861 (const :tag
1862 "notify: Notify when the online status of certain users changes"
1863 notify)
1864 (const :tag "notifications: Send notifications on PRIVMSG or nickname mentions"
1865 notifications)
1866 (const :tag "page: Process CTCP PAGE requests from IRC" page)
1867 (const :tag "readonly: Make displayed lines read-only" readonly)
1868 (const :tag "replace: Replace text in messages" replace)
1869 (const :tag "ring: Enable an input history" ring)
1870 (const :tag "scrolltobottom: Scroll to the bottom of the buffer"
1871 scrolltobottom)
1872 (const :tag "services: Identify to Nickserv (IRC Services) automatically"
1873 services)
1874 (const :tag "smiley: Convert smileys to pretty icons" smiley)
1875 (const :tag "sound: Play sounds when you receive CTCP SOUND requests"
1876 sound)
1877 (const :tag "stamp: Add timestamps to messages" stamp)
1878 (const :tag "spelling: Check spelling" spelling)
1879 (const :tag "track: Track channel activity in the mode-line" track)
1880 (const :tag "truncate: Truncate buffers to a certain size" truncate)
1881 (const :tag "unmorse: Translate morse code in messages" unmorse)
1882 (const :tag "xdcc: Act as an XDCC file-server" xdcc)
1883 (repeat :tag "Others" :inline t symbol))
1884 :group 'erc)
1886 (defun erc-update-modules ()
1887 "Run this to enable erc-foo-mode for all modules in `erc-modules'."
1888 (let (req)
1889 (dolist (mod erc-modules)
1890 (setq req (concat "erc-" (symbol-name mod)))
1891 (cond
1892 ;; yuck. perhaps we should bring the filenames into sync?
1893 ((string= req "erc-capab-identify")
1894 (setq req "erc-capab"))
1895 ((string= req "erc-completion")
1896 (setq req "erc-pcomplete"))
1897 ((string= req "erc-pcomplete")
1898 (setq mod 'completion))
1899 ((string= req "erc-autojoin")
1900 (setq req "erc-join")))
1901 (condition-case nil
1902 (require (intern req))
1903 (error nil))
1904 (let ((sym (intern-soft (concat "erc-" (symbol-name mod) "-mode"))))
1905 (if (fboundp sym)
1906 (funcall sym 1)
1907 (error "`%s' is not a known ERC module" mod))))))
1909 (defun erc-setup-buffer (buffer)
1910 "Consults `erc-join-buffer' to find out how to display `BUFFER'."
1911 (pcase erc-join-buffer
1912 (`window
1913 (if (active-minibuffer-window)
1914 (display-buffer buffer)
1915 (switch-to-buffer-other-window buffer)))
1916 (`window-noselect
1917 (display-buffer buffer))
1918 (`bury
1919 nil)
1920 (`frame
1921 (when (or (not erc-reuse-frames)
1922 (not (get-buffer-window buffer t)))
1923 (let ((frame (make-frame (or erc-frame-alist
1924 default-frame-alist))))
1925 (raise-frame frame)
1926 (select-frame frame))
1927 (switch-to-buffer buffer)
1928 (when erc-frame-dedicated-flag
1929 (set-window-dedicated-p (selected-window) t))))
1931 (if (active-minibuffer-window)
1932 (display-buffer buffer)
1933 (switch-to-buffer buffer)))))
1935 (defun erc-open (&optional server port nick full-name
1936 connect passwd tgt-list channel process)
1937 "Connect to SERVER on PORT as NICK with FULL-NAME.
1939 If CONNECT is non-nil, connect to the server. Otherwise assume
1940 already connected and just create a separate buffer for the new
1941 target CHANNEL.
1943 Use PASSWD as user password on the server. If TGT-LIST is
1944 non-nil, use it to initialize `erc-default-recipients'.
1946 Returns the buffer for the given server or channel."
1947 (let ((server-announced-name (when (and (boundp 'erc-session-server)
1948 (string= server erc-session-server))
1949 erc-server-announced-name))
1950 (connected-p (unless connect erc-server-connected))
1951 (buffer (erc-get-buffer-create server port channel))
1952 (old-buffer (current-buffer))
1953 old-point
1954 continued-session)
1955 (when connect (run-hook-with-args 'erc-before-connect server port nick))
1956 (erc-update-modules)
1957 (set-buffer buffer)
1958 (setq old-point (point))
1959 (erc-mode)
1960 (setq erc-server-announced-name server-announced-name)
1961 (setq erc-server-connected connected-p)
1962 ;; connection parameters
1963 (setq erc-server-process process)
1964 (setq erc-insert-marker (make-marker))
1965 (setq erc-input-marker (make-marker))
1966 ;; go to the end of the buffer and open a new line
1967 ;; (the buffer may have existed)
1968 (goto-char (point-max))
1969 (forward-line 0)
1970 (when (get-text-property (point) 'erc-prompt)
1971 (setq continued-session t)
1972 (set-marker erc-input-marker
1973 (or (next-single-property-change (point) 'erc-prompt)
1974 (point-max))))
1975 (unless continued-session
1976 (goto-char (point-max))
1977 (insert "\n"))
1978 (set-marker erc-insert-marker (point))
1979 ;; stack of default recipients
1980 (setq erc-default-recipients tgt-list)
1981 (setq erc-server-current-nick nil)
1982 ;; Initialize erc-server-users and erc-channel-users
1983 (if connect
1984 (progn ;; server buffer
1985 (setq erc-server-users
1986 (make-hash-table :test 'equal))
1987 (setq erc-channel-users nil))
1988 (progn ;; target buffer
1989 (setq erc-server-users nil)
1990 (setq erc-channel-users
1991 (make-hash-table :test 'equal))))
1992 ;; clear last incomplete line read
1993 (setq erc-server-filter-data nil)
1994 (setq erc-channel-topic "")
1995 ;; limit on the number of users on the channel (mode +l)
1996 (setq erc-channel-user-limit nil)
1997 (setq erc-channel-key nil)
1998 ;; last active buffer, defaults to this one
1999 (erc-set-active-buffer buffer)
2000 ;; last invitation channel
2001 (setq erc-invitation nil)
2002 ;; Server channel list
2003 (setq erc-channel-list ())
2004 ;; login-time 'nick in use' error
2005 (setq erc-bad-nick nil)
2006 ;; whether we have logged in
2007 (setq erc-logged-in nil)
2008 ;; The local copy of `erc-nick' - the list of nicks to choose
2009 (setq erc-default-nicks (if (consp erc-nick) erc-nick (list erc-nick)))
2010 ;; password stuff
2011 (setq erc-session-password
2012 (or passwd
2013 (let ((secret
2014 (plist-get
2015 (nth 0
2016 (auth-source-search :host server
2017 :max 1
2018 :user nick
2019 :port port
2020 :require '(:secret)))
2021 :secret)))
2022 (if (functionp secret)
2023 (funcall secret)
2024 secret))))
2025 ;; debug output buffer
2026 (setq erc-dbuf
2027 (when erc-log-p
2028 (get-buffer-create (concat "*ERC-DEBUG: " server "*"))))
2029 ;; set up prompt
2030 (unless continued-session
2031 (goto-char (point-max))
2032 (insert "\n"))
2033 (if continued-session
2034 (goto-char old-point)
2035 (set-marker erc-insert-marker (point))
2036 (erc-display-prompt)
2037 (goto-char (point-max)))
2039 (erc-determine-parameters server port nick full-name)
2041 ;; Saving log file on exit
2042 (run-hook-with-args 'erc-connect-pre-hook buffer)
2044 (when connect
2045 (erc-server-connect erc-session-server erc-session-port buffer))
2046 (erc-update-mode-line)
2048 ;; Now display the buffer in a window as per user wishes.
2049 (unless (eq buffer old-buffer)
2050 (when erc-log-p
2051 ;; we can't log to debug buffer, it may not exist yet
2052 (message "erc: old buffer %s, switching to %s"
2053 old-buffer buffer))
2054 (erc-setup-buffer buffer))
2056 buffer))
2058 (defun erc-initialize-log-marker (buffer)
2059 "Initialize the `erc-last-saved-position' marker to a sensible position.
2060 BUFFER is the current buffer."
2061 (with-current-buffer buffer
2062 (unless (markerp erc-last-saved-position)
2063 (setq erc-last-saved-position (make-marker))
2064 (move-marker erc-last-saved-position
2065 (1- (marker-position erc-insert-marker))))))
2067 ;; interactive startup
2069 (defvar erc-server-history-list nil
2070 "IRC server interactive selection history list.")
2072 (defvar erc-nick-history-list nil
2073 "Nickname interactive selection history list.")
2075 (defun erc-already-logged-in (server port nick)
2076 "Return the buffers corresponding to a NICK on PORT of a session SERVER.
2077 This is determined by looking for the appropriate buffer and checking
2078 whether the connection is still alive.
2079 If no buffer matches, return nil."
2080 (erc-buffer-list
2081 (lambda ()
2082 (and (erc-server-process-alive)
2083 (string= erc-session-server server)
2084 (erc-port-equal erc-session-port port)
2085 (erc-current-nick-p nick)))))
2087 (defcustom erc-before-connect nil
2088 "Hook called before connecting to a server.
2089 This hook gets executed before `erc' actually invokes `erc-mode'
2090 with your input data. The functions in here get called with three
2091 parameters, SERVER, PORT and NICK."
2092 :group 'erc-hooks
2093 :type 'hook)
2095 (defcustom erc-after-connect nil
2096 "Hook called after connecting to a server.
2097 This hook gets executed when an end of MOTD has been received. All
2098 functions in here get called with the parameters SERVER and NICK."
2099 :group 'erc-hooks
2100 :type 'hook)
2102 ;;;###autoload
2103 (defun erc-select-read-args ()
2104 "Prompt the user for values of nick, server, port, and password."
2105 (let (user-input server port nick passwd)
2106 (setq user-input (read-from-minibuffer
2107 "IRC server: "
2108 (erc-compute-server) nil nil 'erc-server-history-list))
2110 (if (string-match "\\(.*\\):\\(.*\\)\\'" user-input)
2111 (setq port (erc-string-to-port (match-string 2 user-input))
2112 user-input (match-string 1 user-input))
2113 (setq port
2114 (erc-string-to-port (read-from-minibuffer
2115 "IRC port: " (erc-port-to-string
2116 (erc-compute-port))))))
2118 (if (string-match "\\`\\(.*\\)@\\(.*\\)" user-input)
2119 (setq nick (match-string 1 user-input)
2120 user-input (match-string 2 user-input))
2121 (setq nick
2122 (if (erc-already-logged-in server port nick)
2123 (read-from-minibuffer
2124 (erc-format-message 'nick-in-use ?n nick)
2125 nick
2126 nil nil 'erc-nick-history-list)
2127 (read-from-minibuffer
2128 "Nickname: " (erc-compute-nick nick)
2129 nil nil 'erc-nick-history-list))))
2131 (setq server user-input)
2133 (setq passwd (if erc-prompt-for-password
2134 (if (and erc-password
2135 (y-or-n-p "Use the default password? "))
2136 erc-password
2137 (read-passwd "Password: "))
2138 erc-password))
2139 (when (and passwd (string= "" passwd))
2140 (setq passwd nil))
2142 (while (erc-already-logged-in server port nick)
2143 ;; hmm, this is a problem when using multiple connections to a bnc
2144 ;; with the same nick. Currently this code prevents using more than one
2145 ;; bnc with the same nick. actually it would be nice to have
2146 ;; bncs transparent, so that erc-compute-buffer-name displays
2147 ;; the server one is connected to.
2148 (setq nick (read-from-minibuffer
2149 (erc-format-message 'nick-in-use ?n nick)
2150 nick
2151 nil nil 'erc-nick-history-list)))
2152 (list :server server :port port :nick nick :password passwd)))
2154 ;;;###autoload
2155 (cl-defun erc (&key (server (erc-compute-server))
2156 (port (erc-compute-port))
2157 (nick (erc-compute-nick))
2158 password
2159 (full-name (erc-compute-full-name)))
2160 "ERC is a powerful, modular, and extensible IRC client.
2161 This function is the main entry point for ERC.
2163 It permits you to select connection parameters, and then starts ERC.
2165 Non-interactively, it takes the keyword arguments
2166 (server (erc-compute-server))
2167 (port (erc-compute-port))
2168 (nick (erc-compute-nick))
2169 password
2170 (full-name (erc-compute-full-name)))
2172 That is, if called with
2174 (erc :server \"irc.freenode.net\" :full-name \"Harry S Truman\")
2176 then the server and full-name will be set to those values, whereas
2177 `erc-compute-port', `erc-compute-nick' and `erc-compute-full-name' will
2178 be invoked for the values of the other parameters."
2179 (interactive (erc-select-read-args))
2180 (erc-open server port nick full-name t password))
2182 ;;;###autoload
2183 (defalias 'erc-select 'erc)
2184 (defalias 'erc-ssl 'erc-tls)
2186 ;;;###autoload
2187 (defun erc-tls (&rest r)
2188 "Interactively select TLS connection parameters and run ERC.
2189 Arguments are the same as for `erc'."
2190 (interactive (erc-select-read-args))
2191 (let ((erc-server-connect-function 'erc-open-tls-stream))
2192 (apply 'erc r)))
2194 (defun erc-open-tls-stream (name buffer host port)
2195 "Open an TLS stream to an IRC server.
2196 The process will be given the name NAME, its target buffer will be
2197 BUFFER. HOST and PORT specify the connection target."
2198 (open-network-stream name buffer host port
2199 :type 'tls))
2201 ;;; Displaying error messages
2203 (defun erc-error (&rest args)
2204 "Pass ARGS to `format', and display the result as an error message.
2205 If `debug-on-error' is set to non-nil, then throw a real error with this
2206 message instead, to make debugging easier."
2207 (if debug-on-error
2208 (apply #'error args)
2209 (apply #'message args)
2210 (beep)))
2212 ;;; Debugging the protocol
2214 (defvar erc-debug-irc-protocol nil
2215 "If non-nil, log all IRC protocol traffic to the buffer \"*erc-protocol*\".
2217 The buffer is created if it doesn't exist.
2219 NOTE: If this variable is non-nil, and you kill the only
2220 visible \"*erc-protocol*\" buffer, it will be recreated shortly,
2221 but you won't see it.
2223 WARNING: Do not set this variable directly! Instead, use the
2224 function `erc-toggle-debug-irc-protocol' to toggle its value.")
2226 (declare-function erc-network-name "erc-networks" ())
2228 (defun erc-log-irc-protocol (string &optional outbound)
2229 "Append STRING to the buffer *erc-protocol*.
2231 This only has any effect if `erc-debug-irc-protocol' is non-nil.
2233 The buffer is created if it doesn't exist.
2235 If OUTBOUND is non-nil, STRING is being sent to the IRC server
2236 and appears in face `erc-input-face' in the buffer."
2237 (when erc-debug-irc-protocol
2238 (let ((network-name (or (ignore-errors (erc-network-name))
2239 "???")))
2240 (with-current-buffer (get-buffer-create "*erc-protocol*")
2241 (save-excursion
2242 (goto-char (point-max))
2243 (let ((inhibit-read-only t))
2244 (insert (if (not outbound)
2245 ;; Cope with the fact that string might
2246 ;; contain multiple lines of text.
2247 (let ((lines (delete "" (split-string string
2248 "\n\\|\r\n")))
2249 (result ""))
2250 (dolist (line lines)
2251 (setq result (concat result network-name
2252 " << " line "\n")))
2253 result)
2254 (erc-propertize
2255 (concat network-name " >> " string
2256 (if (/= ?\n
2257 (aref string
2258 (1- (length string))))
2259 "\n"))
2260 'face 'erc-input-face)))))
2261 (let ((orig-win (selected-window))
2262 (debug-buffer-window (get-buffer-window (current-buffer) t)))
2263 (when debug-buffer-window
2264 (select-window debug-buffer-window)
2265 (when (= 1 (count-lines (point) (point-max)))
2266 (goto-char (point-max))
2267 (recenter -1))
2268 (select-window orig-win)))))))
2270 (defun erc-toggle-debug-irc-protocol (&optional arg)
2271 "Toggle the value of `erc-debug-irc-protocol'.
2273 If ARG is non-nil, show the *erc-protocol* buffer."
2274 (interactive "P")
2275 (let* ((buf (get-buffer-create "*erc-protocol*")))
2276 (with-current-buffer buf
2277 (erc-view-mode-enter)
2278 (when (null (current-local-map))
2279 (let ((inhibit-read-only t))
2280 (insert (erc-make-notice "This buffer displays all IRC protocol traffic exchanged with each server.\n"))
2281 (insert (erc-make-notice "Kill this buffer to terminate protocol logging.\n\n")))
2282 (use-local-map (make-sparse-keymap))
2283 (local-set-key (kbd "t") 'erc-toggle-debug-irc-protocol))
2284 (add-hook 'kill-buffer-hook
2285 #'(lambda () (setq erc-debug-irc-protocol nil))
2286 nil 'local)
2287 (goto-char (point-max))
2288 (let ((inhibit-read-only t))
2289 (insert (erc-make-notice
2290 (format "IRC protocol logging %s at %s -- Press `t' to toggle logging.\n"
2291 (if erc-debug-irc-protocol "disabled" "enabled")
2292 (current-time-string))))))
2293 (setq erc-debug-irc-protocol (not erc-debug-irc-protocol))
2294 (if (and arg
2295 (not (get-buffer-window "*erc-protocol*" t)))
2296 (display-buffer buf t))
2297 (message "IRC protocol traffic logging %s (see buffer *erc-protocol*)."
2298 (if erc-debug-irc-protocol "enabled" "disabled"))))
2300 ;;; I/O interface
2302 ;; send interface
2304 (defun erc-send-action (tgt str &optional force)
2305 "Send CTCP ACTION information described by STR to TGT."
2306 (erc-send-ctcp-message tgt (format "ACTION %s" str) force)
2307 (erc-display-message
2308 nil 'input (current-buffer)
2309 'ACTION ?n (erc-current-nick) ?a str ?u "" ?h ""))
2311 ;; Display interface
2313 (defun erc-string-invisible-p (string)
2314 "Check whether STRING is invisible or not.
2315 I.e. any char in it has the `invisible' property set."
2316 (text-property-any 0 (length string) 'invisible t string))
2318 (defcustom erc-remove-parsed-property t
2319 "Whether to remove the erc-parsed text property after displaying a message.
2321 The default is to remove it, since it causes ERC to take up extra
2322 memory. If you have code that relies on this property, then set
2323 this option to nil."
2324 :type 'boolean
2325 :group 'erc)
2327 (defun erc-display-line-1 (string buffer)
2328 "Display STRING in `erc-mode' BUFFER.
2329 Auxiliary function used in `erc-display-line'. The line gets filtered to
2330 interpret the control characters. Then, `erc-insert-pre-hook' gets called.
2331 If `erc-insert-this' is still t, STRING gets inserted into the buffer.
2332 Afterwards, `erc-insert-modify' and `erc-insert-post-hook' get called.
2333 If STRING is nil, the function does nothing."
2334 (when string
2335 (with-current-buffer (or buffer (process-buffer erc-server-process))
2336 (let ((insert-position (or (marker-position erc-insert-marker)
2337 (point-max))))
2338 (let ((string string) ;; FIXME! Can this be removed?
2339 (buffer-undo-list t)
2340 (inhibit-read-only t))
2341 (unless (string-match "\n$" string)
2342 (setq string (concat string "\n"))
2343 (when (erc-string-invisible-p string)
2344 (erc-put-text-properties 0 (length string)
2345 '(invisible intangible) string)))
2346 (erc-log (concat "erc-display-line: " string
2347 (format "(%S)" string) " in buffer "
2348 (format "%s" buffer)))
2349 (setq erc-insert-this t)
2350 (run-hook-with-args 'erc-insert-pre-hook string)
2351 (if (null erc-insert-this)
2352 ;; Leave erc-insert-this set to t as much as possible. Fran
2353 ;; Litterio <franl> has seen erc-insert-this set to nil while
2354 ;; erc-send-pre-hook is running, which should never happen. This
2355 ;; may cure it.
2356 (setq erc-insert-this t)
2357 (save-excursion ;; to restore point in the new buffer
2358 (save-restriction
2359 (widen)
2360 (goto-char insert-position)
2361 (insert-before-markers string)
2362 ;; run insertion hook, with point at restored location
2363 (save-restriction
2364 (narrow-to-region insert-position (point))
2365 (run-hooks 'erc-insert-modify-hook)
2366 (run-hooks 'erc-insert-post-hook)
2367 (when erc-remove-parsed-property
2368 (remove-text-properties (point-min) (point-max)
2369 '(erc-parsed nil))))))))
2370 (erc-update-undo-list (- (or (marker-position erc-insert-marker)
2371 (point-max))
2372 insert-position))))))
2374 (defun erc-update-undo-list (shift)
2375 ;; Translate buffer positions in buffer-undo-list by SHIFT.
2376 (unless (or (zerop shift) (atom buffer-undo-list))
2377 (let ((list buffer-undo-list) elt)
2378 (while list
2379 (setq elt (car list))
2380 (cond ((integerp elt) ; POSITION
2381 (cl-incf (car list) shift))
2382 ((or (atom elt) ; nil, EXTENT
2383 ;; (eq t (car elt)) ; (t . TIME)
2384 (markerp (car elt))) ; (MARKER . DISTANCE)
2385 nil)
2386 ((integerp (car elt)) ; (BEGIN . END)
2387 (cl-incf (car elt) shift)
2388 (cl-incf (cdr elt) shift))
2389 ((stringp (car elt)) ; (TEXT . POSITION)
2390 (cl-incf (cdr elt) (* (if (natnump (cdr elt)) 1 -1) shift)))
2391 ((null (car elt)) ; (nil PROPERTY VALUE BEG . END)
2392 (let ((cons (nthcdr 3 elt)))
2393 (cl-incf (car cons) shift)
2394 (cl-incf (cdr cons) shift)))
2395 ((and (featurep 'xemacs)
2396 (extentp (car elt))) ; (EXTENT START END)
2397 (cl-incf (nth 1 elt) shift)
2398 (cl-incf (nth 2 elt) shift)))
2399 (setq list (cdr list))))))
2401 (defvar erc-valid-nick-regexp "[]a-zA-Z^[;\\`_{}|][]^[;\\`_{}|a-zA-Z0-9-]*"
2402 "Regexp which matches all valid characters in a IRC nickname.")
2404 (defun erc-is-valid-nick-p (nick)
2405 "Check if NICK is a valid IRC nickname."
2406 (string-match (concat "^" erc-valid-nick-regexp "$") nick))
2408 (defun erc-display-line (string &optional buffer)
2409 "Display STRING in the ERC BUFFER.
2410 All screen output must be done through this function. If BUFFER is nil
2411 or omitted, the default ERC buffer for the `erc-session-server' is used.
2412 The BUFFER can be an actual buffer, a list of buffers, 'all or 'active.
2413 If BUFFER = 'all, the string is displayed in all the ERC buffers for the
2414 current session. 'active means the current active buffer
2415 \(`erc-active-buffer'). If the buffer can't be resolved, the current
2416 buffer is used. `erc-display-line-1' is used to display STRING.
2418 If STRING is nil, the function does nothing."
2419 (let ((inhibit-point-motion-hooks t)
2420 new-bufs)
2421 (dolist (buf (cond
2422 ((bufferp buffer) (list buffer))
2423 ((listp buffer) buffer)
2424 ((processp buffer) (list (process-buffer buffer)))
2425 ((eq 'all buffer)
2426 ;; Hmm, or all of the same session server?
2427 (erc-buffer-list nil erc-server-process))
2428 ((and (eq 'active buffer) (erc-active-buffer))
2429 (list (erc-active-buffer)))
2430 ((erc-server-buffer-live-p)
2431 (list (process-buffer erc-server-process)))
2432 (t (list (current-buffer)))))
2433 (when (buffer-live-p buf)
2434 (erc-display-line-1 string buf)
2435 (push buf new-bufs)))
2436 (when (null new-bufs)
2437 (erc-display-line-1 string (if (erc-server-buffer-live-p)
2438 (process-buffer erc-server-process)
2439 (current-buffer))))))
2441 (defun erc-display-message-highlight (type string)
2442 "Highlight STRING according to TYPE, where erc-TYPE-face is an ERC face.
2444 See also `erc-make-notice'."
2445 (cond ((eq type 'notice)
2446 (erc-make-notice string))
2448 (erc-put-text-property
2449 0 (length string)
2450 'face (or (intern-soft
2451 (concat "erc-" (symbol-name type) "-face"))
2452 "erc-default-face")
2453 string)
2454 string)))
2456 (defvar erc-lurker-state nil
2457 "Track the time of the last PRIVMSG for each (server,nick) pair.
2459 This is implemented as a hash of hashes, where the outer key is
2460 the canonicalized server name (as returned by
2461 `erc-canonicalize-server-name') and the outer value is a hash
2462 table mapping nicks (as returned by `erc-lurker-maybe-trim') to
2463 the times of their most recently received PRIVMSG on any channel
2464 on the given server.")
2466 (defcustom erc-lurker-trim-nicks t
2467 "If t, trim trailing `erc-lurker-ignore-chars' from nicks.
2469 This causes e.g. nick and nick` to be considered as the same
2470 individual for activity tracking and lurkiness detection
2471 purposes."
2472 :group 'erc-lurker
2473 :type 'boolean)
2475 (defcustom erc-lurker-ignore-chars "`_"
2476 "Characters at the end of a nick to strip for activity tracking purposes.
2478 See also `erc-lurker-trim-nicks'."
2479 :group 'erc-lurker
2480 :type 'string)
2482 (defun erc-lurker-maybe-trim (nick)
2483 "Maybe trim trailing `erc-lurker-ignore-chars' from NICK.
2485 Returns NICK unmodified unless `erc-lurker-trim-nicks' is
2486 non-nil."
2487 (if erc-lurker-trim-nicks
2488 (replace-regexp-in-string
2489 (format "[%s]"
2490 (mapconcat (lambda (char)
2491 (regexp-quote (char-to-string char)))
2492 erc-lurker-ignore-chars ""))
2493 "" nick)
2494 nick))
2496 (defcustom erc-lurker-hide-list nil
2497 "List of IRC type messages to hide when sent by lurkers.
2499 A typical value would be '(\"JOIN\" \"PART\" \"QUIT\").
2500 See also `erc-lurker-p' and `erc-hide-list'."
2501 :group 'erc-lurker
2502 :type 'erc-message-type)
2504 (defcustom erc-lurker-threshold-time (* 60 60 24) ; 24h by default
2505 "Nicks from which no PRIVMSGs have been received within this
2506 interval (in units of seconds) are considered lurkers by
2507 `erc-lurker-p' and as a result their messages of types in
2508 `erc-lurker-hide-list' will be hidden."
2509 :group 'erc-lurker
2510 :type 'integer)
2512 (defun erc-lurker-initialize ()
2513 "Initialize ERC lurker tracking functionality.
2515 This function adds `erc-lurker-update-status' to
2516 `erc-insert-pre-hook' in order to record the time of each nick's
2517 most recent PRIVMSG as well as initializing the state variable
2518 storing this information."
2519 (setq erc-lurker-state (make-hash-table :test 'equal))
2520 (add-hook 'erc-insert-pre-hook 'erc-lurker-update-status))
2522 (defun erc-lurker-cleanup ()
2523 "Remove all last PRIVMSG state older than `erc-lurker-threshold-time'.
2525 This should be called regularly to avoid excessive resource
2526 consumption for long-lived IRC or Emacs sessions."
2527 (maphash
2528 (lambda (server hash)
2529 (maphash
2530 (lambda (nick last-PRIVMSG-time)
2531 (when
2532 (> (float-time (time-subtract
2533 (current-time)
2534 last-PRIVMSG-time))
2535 erc-lurker-threshold-time)
2536 (remhash nick hash)))
2537 hash)
2538 (if (zerop (hash-table-count hash))
2539 (remhash server erc-lurker-state)))
2540 erc-lurker-state))
2542 (defvar erc-lurker-cleanup-count 0
2543 "Internal counter variable for use with `erc-lurker-cleanup-interval'.")
2545 (defvar erc-lurker-cleanup-interval 100
2546 "Frequency of cleaning up stale erc-lurker state.
2548 `erc-lurker-update-status' calls `erc-lurker-cleanup' once for
2549 every `erc-lurker-cleanup-interval' updates to
2550 `erc-lurker-state'. This is designed to limit the memory
2551 consumption of lurker state during long Emacs sessions and/or ERC
2552 sessions with large numbers of incoming PRIVMSGs.")
2554 (defun erc-lurker-update-status (_message)
2555 "Update `erc-lurker-state' if necessary.
2557 This function is called from `erc-insert-pre-hook'. If the
2558 current message is a PRIVMSG, update `erc-lurker-state' to
2559 reflect the fact that its sender has issued a PRIVMSG at the
2560 current time. Otherwise, take no action.
2562 This function depends on the fact that `erc-display-message'
2563 dynamically binds `parsed', which is used to check if the current
2564 message is a PRIVMSG and to determine its sender. See also
2565 `erc-lurker-trim-nicks' and `erc-lurker-ignore-chars'.
2567 In order to limit memory consumption, this function also calls
2568 `erc-lurker-cleanup' once every `erc-lurker-cleanup-interval'
2569 updates of `erc-lurker-state'."
2570 (when (and (boundp 'parsed) (erc-response-p parsed))
2571 (let* ((command (erc-response.command parsed))
2572 (sender
2573 (erc-lurker-maybe-trim
2574 (car (erc-parse-user (erc-response.sender parsed)))))
2575 (server
2576 (erc-canonicalize-server-name erc-server-announced-name)))
2577 (when (equal command "PRIVMSG")
2578 (when (>= (cl-incf erc-lurker-cleanup-count)
2579 erc-lurker-cleanup-interval)
2580 (setq erc-lurker-cleanup-count 0)
2581 (erc-lurker-cleanup))
2582 (unless (gethash server erc-lurker-state)
2583 (puthash server (make-hash-table :test 'equal) erc-lurker-state))
2584 (puthash sender (current-time)
2585 (gethash server erc-lurker-state))))))
2587 (defun erc-lurker-p (nick)
2588 "Predicate indicating NICK's lurking status on the current server.
2590 Lurking is the condition where NICK has issued no PRIVMSG on this
2591 server within `erc-lurker-threshold-time'. See also
2592 `erc-lurker-trim-nicks' and `erc-lurker-ignore-chars'."
2593 (unless erc-lurker-state (erc-lurker-initialize))
2594 (let* ((server
2595 (erc-canonicalize-server-name erc-server-announced-name))
2596 (last-PRIVMSG-time
2597 (gethash (erc-lurker-maybe-trim nick)
2598 (gethash server erc-lurker-state (make-hash-table)))))
2599 (or (null last-PRIVMSG-time)
2600 (> (float-time
2601 (time-subtract (current-time) last-PRIVMSG-time))
2602 erc-lurker-threshold-time))))
2604 (defcustom erc-common-server-suffixes
2605 '(("openprojects.net$" . "OPN")
2606 ("freenode.net$" . "freenode")
2607 ("oftc.net$" . "OFTC"))
2608 "Alist of common server name suffixes.
2609 This variable is used in mode-line display to save screen
2610 real estate. Set it to nil if you want to avoid changing
2611 displayed hostnames."
2612 :group 'erc-mode-line-and-header
2613 :type 'alist)
2615 (defun erc-canonicalize-server-name (server)
2616 "Return the canonical network name for SERVER if any,
2617 otherwise `erc-server-announced-name'. SERVER is matched against
2618 `erc-common-server-suffixes'."
2619 (when server
2620 (or (cdar (erc-remove-if-not
2621 (lambda (net) (string-match (car net) server))
2622 erc-common-server-suffixes))
2623 erc-server-announced-name)))
2625 (defun erc-hide-current-message-p (parsed)
2626 "Predicate indicating whether the parsed ERC response PARSED should be hidden.
2628 Messages are always hidden if the message type of PARSED appears in
2629 `erc-hide-list'. In addition, messages whose type is a member of
2630 `erc-lurker-hide-list' are hidden if `erc-lurker-p' returns true."
2631 (let* ((command (erc-response.command parsed))
2632 (sender (car (erc-parse-user (erc-response.sender parsed)))))
2633 (or (member command erc-hide-list)
2634 (and (member command erc-lurker-hide-list) (erc-lurker-p sender)))))
2636 (defun erc-display-message (parsed type buffer msg &rest args)
2637 "Display MSG in BUFFER.
2639 ARGS, PARSED, and TYPE are used to format MSG sensibly.
2641 See also `erc-format-message' and `erc-display-line'."
2642 (let ((string (if (symbolp msg)
2643 (apply 'erc-format-message msg args)
2644 msg)))
2645 (setq string
2646 (cond
2647 ((null type)
2648 string)
2649 ((listp type)
2650 (mapc (lambda (type)
2651 (setq string
2652 (erc-display-message-highlight type string)))
2653 type)
2654 string)
2655 ((symbolp type)
2656 (erc-display-message-highlight type string))))
2658 (if (not (erc-response-p parsed))
2659 (erc-display-line string buffer)
2660 (unless (erc-hide-current-message-p parsed)
2661 (erc-put-text-property 0 (length string) 'erc-parsed parsed string)
2662 (erc-put-text-property 0 (length string) 'rear-sticky t string)
2663 (erc-display-line string buffer)))))
2665 (defun erc-message-type-member (position list)
2666 "Return non-nil if the erc-parsed text-property at POSITION is in LIST.
2668 This function relies on the erc-parsed text-property being
2669 present."
2670 (let ((prop-val (erc-get-parsed-vector position)))
2671 (and prop-val (member (erc-response.command prop-val) list))))
2673 (defvar erc-send-input-line-function 'erc-send-input-line)
2674 (make-variable-buffer-local 'erc-send-input-line-function)
2676 (defun erc-send-input-line (target line &optional force)
2677 "Send LINE to TARGET.
2679 See also `erc-server-send'."
2680 (setq line (format "PRIVMSG %s :%s"
2681 target
2682 ;; If the line is empty, we still want to
2683 ;; send it - i.e. an empty pasted line.
2684 (if (string= line "\n")
2685 " \n"
2686 line)))
2687 (erc-server-send line force target))
2689 (defun erc-get-arglist (fun)
2690 "Return the argument list of a function without the parens."
2691 (let ((arglist (format "%S" (erc-function-arglist fun))))
2692 (if (string-match "^(\\(.*\\))$" arglist)
2693 (match-string 1 arglist)
2694 arglist)))
2696 (defun erc-command-no-process-p (str)
2697 "Return non-nil if STR is an ERC command that can be run when the process
2698 is not alive, nil otherwise."
2699 (let ((fun (erc-extract-command-from-line str)))
2700 (and fun
2701 (symbolp (car fun))
2702 (get (car fun) 'process-not-needed))))
2704 (defun erc-command-name (cmd)
2705 "For CMD being the function name of a ERC command, something like
2706 erc-cmd-FOO, this returns a string /FOO."
2707 (let ((command-name (symbol-name cmd)))
2708 (if (string-match "^erc-cmd-\\(.*\\)$" command-name)
2709 (concat "/" (match-string 1 command-name))
2710 command-name)))
2712 (defun erc-process-input-line (line &optional force no-command)
2713 "Translate LINE to an RFC1459 command and send it based.
2714 Returns non-nil if the command is actually sent to the server, and nil
2715 otherwise.
2717 If the command in the LINE is not bound as a function `erc-cmd-<COMMAND>',
2718 it is passed to `erc-cmd-default'. If LINE is not a command (i.e. doesn't
2719 start with /<COMMAND>) then it is sent as a message.
2721 An optional FORCE argument forces sending the line when flood
2722 protection is in effect. The optional NO-COMMAND argument prohibits
2723 this function from interpreting the line as a command."
2724 (let ((command-list (erc-extract-command-from-line line)))
2725 (if (and command-list
2726 (not no-command))
2727 (let* ((cmd (nth 0 command-list))
2728 (args (nth 1 command-list)))
2729 (condition-case nil
2730 (if (listp args)
2731 (apply cmd args)
2732 (funcall cmd args))
2733 (wrong-number-of-arguments
2734 (erc-display-message nil 'error (current-buffer) 'incorrect-args
2735 ?c (erc-command-name cmd)
2736 ?u (or (erc-get-arglist cmd)
2738 ?d (format "%s\n"
2739 (or (documentation cmd) "")))
2740 nil)))
2741 (let ((r (erc-default-target)))
2742 (if r
2743 (funcall erc-send-input-line-function r line force)
2744 (erc-display-message nil 'error (current-buffer) 'no-target)
2745 nil)))))
2747 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2748 ;; Input commands handlers
2749 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2751 (defun erc-cmd-AMSG (line)
2752 "Send LINE to all channels of the current server that you are on."
2753 (interactive "sSend to all channels you're on: ")
2754 (setq line (erc-trim-string line))
2755 (erc-with-all-buffers-of-server nil
2756 (lambda ()
2757 (erc-channel-p (erc-default-target)))
2758 (erc-send-message line)))
2759 (put 'erc-cmd-AMSG 'do-not-parse-args t)
2761 (defun erc-cmd-SAY (line)
2762 "Send LINE to the current query or channel as a message, not a command.
2764 Use this when you want to send a message with a leading '/'. Note
2765 that since multi-line messages are never a command, you don't
2766 need this when pasting multiple lines of text."
2767 (if (string-match "^\\s-*$" line)
2769 (string-match "^ ?\\(.*\\)" line)
2770 (erc-process-input-line (match-string 1 line) nil t)))
2771 (put 'erc-cmd-SAY 'do-not-parse-args t)
2773 (defun erc-cmd-SET (line)
2774 "Set the variable named by the first word in LINE to some VALUE.
2775 VALUE is computed by evaluating the rest of LINE in Lisp."
2776 (cond
2777 ((string-match "^\\s-*\\(\\S-+\\)\\s-+\\(.*\\)$" line)
2778 (let ((var (read (concat "erc-" (match-string 1 line))))
2779 (val (read (match-string 2 line))))
2780 (if (boundp var)
2781 (progn
2782 (set var (eval val))
2783 (erc-display-message
2784 nil nil 'active (format "Set %S to %S" var val))
2786 (setq var (read (match-string 1 line)))
2787 (if (boundp var)
2788 (progn
2789 (set var (eval val))
2790 (erc-display-message
2791 nil nil 'active (format "Set %S to %S" var val))
2793 (erc-display-message nil 'error 'active 'variable-not-bound)
2794 nil))))
2795 ((string-match "^\\s-*$" line)
2796 (erc-display-line
2797 (concat "Available user variables:\n"
2798 (apply
2799 'concat
2800 (mapcar
2801 (lambda (var)
2802 (let ((val (symbol-value var)))
2803 (concat (format "%S:" var)
2804 (if (consp val)
2805 (concat "\n" (pp-to-string val))
2806 (format " %S\n" val)))))
2807 (apropos-internal "^erc-" 'custom-variable-p))))
2808 (current-buffer))
2810 (t nil)))
2811 (defalias 'erc-cmd-VAR 'erc-cmd-SET)
2812 (defalias 'erc-cmd-VARIABLE 'erc-cmd-SET)
2813 (put 'erc-cmd-SET 'do-not-parse-args t)
2814 (put 'erc-cmd-SET 'process-not-needed t)
2816 (defun erc-cmd-default (line)
2817 "Fallback command.
2819 Commands for which no erc-cmd-xxx exists, are tunneled through
2820 this function. LINE is sent to the server verbatim, and
2821 therefore has to contain the command itself as well."
2822 (erc-log (format "cmd: DEFAULT: %s" line))
2823 (erc-server-send (substring line 1))
2826 (defun erc-cmd-IGNORE (&optional user)
2827 "Ignore USER. This should be a regexp matching nick!user@host.
2828 If no USER argument is specified, list the contents of `erc-ignore-list'."
2829 (if user
2830 (let ((quoted (regexp-quote user)))
2831 (when (and (not (string= user quoted))
2832 (y-or-n-p (format "Use regexp-quoted form (%s) instead? "
2833 quoted)))
2834 (setq user quoted))
2835 (erc-display-line
2836 (erc-make-notice (format "Now ignoring %s" user))
2837 'active)
2838 (erc-with-server-buffer (add-to-list 'erc-ignore-list user)))
2839 (if (null (erc-with-server-buffer erc-ignore-list))
2840 (erc-display-line (erc-make-notice "Ignore list is empty") 'active)
2841 (erc-display-line (erc-make-notice "Ignore list:") 'active)
2842 (mapc #'(lambda (item)
2843 (erc-display-line (erc-make-notice item)
2844 'active))
2845 (erc-with-server-buffer erc-ignore-list))))
2848 (defun erc-cmd-UNIGNORE (user)
2849 "Remove the user specified in USER from the ignore list."
2850 (let ((ignored-nick (car (erc-with-server-buffer
2851 (erc-member-ignore-case (regexp-quote user)
2852 erc-ignore-list)))))
2853 (unless ignored-nick
2854 (if (setq ignored-nick (erc-ignored-user-p user))
2855 (unless (y-or-n-p (format "Remove this regexp (%s)? "
2856 ignored-nick))
2857 (setq ignored-nick nil))
2858 (erc-display-line
2859 (erc-make-notice (format "%s is not currently ignored!" user))
2860 'active)))
2861 (when ignored-nick
2862 (erc-display-line
2863 (erc-make-notice (format "No longer ignoring %s" user))
2864 'active)
2865 (erc-with-server-buffer
2866 (setq erc-ignore-list (delete ignored-nick erc-ignore-list)))))
2869 (defun erc-cmd-CLEAR ()
2870 "Clear the window content."
2871 (recenter 0)
2873 (put 'erc-cmd-CLEAR 'process-not-needed t)
2875 (defun erc-cmd-OPS ()
2876 "Show the ops in the current channel."
2877 (interactive)
2878 (let ((ops nil))
2879 (if erc-channel-users
2880 (maphash (lambda (_nick user-data)
2881 (let ((cuser (cdr user-data)))
2882 (if (and cuser
2883 (erc-channel-user-op cuser))
2884 (setq ops (cons (erc-server-user-nickname
2885 (car user-data))
2886 ops)))))
2887 erc-channel-users))
2888 (setq ops (sort ops 'string-lessp))
2889 (if ops
2890 (erc-display-message
2891 nil 'notice (current-buffer) 'ops
2892 ?i (length ops) ?s (if (> (length ops) 1) "s" "")
2893 ?o (mapconcat 'identity ops " "))
2894 (erc-display-message nil 'notice (current-buffer) 'ops-none)))
2897 (defun erc-cmd-COUNTRY (tld)
2898 "Display the country associated with the top level domain TLD."
2899 (require 'mail-extr)
2900 (let ((co (ignore-errors (what-domain tld))))
2901 (if co
2902 (erc-display-message
2903 nil 'notice 'active 'country ?c co ?d tld)
2904 (erc-display-message
2905 nil 'notice 'active 'country-unknown ?d tld))
2907 (put 'erc-cmd-COUNTRY 'process-not-needed t)
2909 (defun erc-cmd-AWAY (line)
2910 "Mark the user as being away, the reason being indicated by LINE.
2911 If no reason is given, unset away status."
2912 (when (string-match "^\\s-*\\(.*\\)$" line)
2913 (let ((reason (match-string 1 line)))
2914 (erc-log (format "cmd: AWAY: %s" reason))
2915 (erc-server-send
2916 (if (string= reason "")
2917 "AWAY"
2918 (concat "AWAY :" reason))))
2920 (put 'erc-cmd-AWAY 'do-not-parse-args t)
2922 (defun erc-cmd-GAWAY (line)
2923 "Mark the user as being away everywhere, the reason being indicated by LINE."
2924 ;; on all server buffers.
2925 (erc-with-all-buffers-of-server nil
2926 #'erc-open-server-buffer-p
2927 (erc-cmd-AWAY line)))
2928 (put 'erc-cmd-GAWAY 'do-not-parse-args t)
2930 (defun erc-cmd-CTCP (nick cmd &rest args)
2931 "Send a Client To Client Protocol message to NICK.
2933 CMD is the CTCP command, possible values being ECHO, FINGER, CLIENTINFO, TIME,
2934 VERSION and so on. It is called with ARGS."
2935 (let ((str (concat cmd
2936 (when args
2937 (concat " " (mapconcat #'identity args " "))))))
2938 (erc-log (format "cmd: CTCP [%s]: [%s]" nick str))
2939 (erc-send-ctcp-message nick str)
2942 (defun erc-cmd-HELP (&optional func)
2943 "Popup help information.
2945 If FUNC contains a valid function or variable, help about that
2946 will be displayed. If FUNC is empty, display an apropos about
2947 ERC commands. Otherwise, do `apropos' in the ERC namespace
2948 \(\"erc-.*LINE\"\).
2950 Examples:
2951 To find out about erc and bbdb, do
2952 /help bbdb.*
2954 For help about the WHOIS command, do:
2955 /help whois
2957 For a list of user commands (/join /part, ...):
2958 /help."
2959 (if func
2960 (let* ((sym (or (let ((sym (intern-soft
2961 (concat "erc-cmd-" (upcase func)))))
2962 (if (and sym (or (boundp sym) (fboundp sym)))
2964 nil))
2965 (let ((sym (intern-soft func)))
2966 (if (and sym (or (boundp sym) (fboundp sym)))
2968 nil))
2969 (let ((sym (intern-soft (concat "erc-" func))))
2970 (if (and sym (or (boundp sym) (fboundp sym)))
2972 nil)))))
2973 (if sym
2974 (cond
2975 ((boundp sym) (describe-variable sym))
2976 ((fboundp sym) (describe-function sym))
2977 (t nil))
2978 (apropos-command (concat "erc-.*" func) nil
2979 (lambda (x)
2980 (or (commandp x)
2981 (get x 'custom-type))))
2983 (apropos "erc-cmd-")
2984 (message "Type C-h m to get additional information about keybindings.")
2987 (defalias 'erc-cmd-H 'erc-cmd-HELP)
2988 (put 'erc-cmd-HELP 'process-not-needed t)
2990 (defun erc-cmd-JOIN (channel &optional key)
2991 "Join the channel given in CHANNEL, optionally with KEY.
2992 If CHANNEL is specified as \"-invite\", join the channel to which you
2993 were most recently invited. See also `invitation'."
2994 (let (chnl)
2995 (if (string= (upcase channel) "-INVITE")
2996 (if erc-invitation
2997 (setq chnl erc-invitation)
2998 (erc-display-message nil 'error (current-buffer) 'no-invitation))
2999 (setq chnl (erc-ensure-channel-name channel)))
3000 (when chnl
3001 ;; Prevent double joining of same channel on same server.
3002 (let ((joined-channels
3003 (mapcar #'(lambda (chanbuf)
3004 (with-current-buffer chanbuf (erc-default-target)))
3005 (erc-channel-list erc-server-process))))
3006 (if (erc-member-ignore-case chnl joined-channels)
3007 (switch-to-buffer (car (erc-member-ignore-case chnl
3008 joined-channels)))
3009 (erc-log (format "cmd: JOIN: %s" chnl))
3010 (erc-server-send (if (and chnl key)
3011 (format "JOIN %s %s" chnl key)
3012 (format "JOIN %s" chnl)))))))
3015 (defalias 'erc-cmd-CHANNEL 'erc-cmd-JOIN)
3016 (defalias 'erc-cmd-J 'erc-cmd-JOIN)
3018 (defvar erc-channel-new-member-names nil
3019 "If non-nil, a names list is currently being received.
3021 If non-nil, this variable is a hash-table that associates
3022 received nicks with t.")
3023 (make-variable-buffer-local 'erc-channel-new-member-names)
3025 (defun erc-cmd-NAMES (&optional channel)
3026 "Display the users in CHANNEL.
3027 If CHANNEL is not specified, display the users in the current channel.
3028 This function clears the channel name list first, then sends the
3029 command."
3030 (let ((tgt (or (and (erc-channel-p channel) channel)
3031 (erc-default-target))))
3032 (if (and tgt (erc-channel-p tgt))
3033 (progn
3034 (erc-log (format "cmd: DEFAULT: NAMES %s" tgt))
3035 (erc-with-buffer
3036 (tgt)
3037 (erc-channel-begin-receiving-names))
3038 (erc-server-send (concat "NAMES " tgt)))
3039 (erc-display-message nil 'error (current-buffer) 'no-default-channel)))
3041 (defalias 'erc-cmd-N 'erc-cmd-NAMES)
3043 (defun erc-cmd-KICK (target &optional reason-or-nick &rest reasonwords)
3044 "Kick the user indicated in LINE from the current channel.
3045 LINE has the format: \"#CHANNEL NICK REASON\" or \"NICK REASON\"."
3046 (let ((reasonstring (mapconcat 'identity reasonwords " ")))
3047 (if (string= "" reasonstring)
3048 (setq reasonstring (format "Kicked by %s" (erc-current-nick))))
3049 (if (erc-channel-p target)
3050 (let ((nick reason-or-nick))
3051 (erc-log (format "cmd: KICK: %s/%s: %s" nick target reasonstring))
3052 (erc-server-send (format "KICK %s %s :%s" target nick reasonstring)
3053 nil target)
3055 (when target
3056 (let ((ch (erc-default-target)))
3057 (setq reasonstring (concat
3058 (if reason-or-nick (concat reason-or-nick " "))
3059 reasonstring))
3060 (if ch
3061 (progn
3062 (erc-log
3063 (format "cmd: KICK: %s/%s: %s" target ch reasonstring))
3064 (erc-server-send
3065 (format "KICK %s %s :%s" ch target reasonstring) nil ch))
3066 (erc-display-message nil 'error (current-buffer)
3067 'no-default-channel))
3068 t)))))
3070 (defvar erc-script-args nil)
3072 (defun erc-cmd-LOAD (line)
3073 "Load the script provided in the LINE.
3074 If LINE continues beyond the file name, the rest of
3075 it is put in a (local) variable `erc-script-args',
3076 which can be used in Emacs Lisp scripts.
3078 The optional FORCE argument is ignored here - you can't force loading
3079 a script after exceeding the flood threshold."
3080 (cond
3081 ((string-match "^\\s-*\\(\\S-+\\)\\(.*\\)$" line)
3082 (let* ((file-to-find (match-string 1 line))
3083 (erc-script-args (match-string 2 line))
3084 (file (erc-find-file file-to-find erc-script-path)))
3085 (erc-log (format "cmd: LOAD: %s" file-to-find))
3086 (cond
3087 ((not file)
3088 (erc-display-message nil 'error (current-buffer)
3089 'cannot-find-file ?f file-to-find))
3090 ((not (file-readable-p file))
3091 (erc-display-message nil 'error (current-buffer)
3092 'cannot-read-file ?f file))
3094 (message "Loading \'%s\'..." file)
3095 (erc-load-script file)
3096 (message "Loading \'%s\'...done" file))))
3098 (t nil)))
3100 (defun erc-cmd-WHOIS (user &optional server)
3101 "Display whois information for USER.
3103 If SERVER is non-nil, use that, rather than the current server."
3104 ;; FIXME: is the above docstring correct? -- Lawrence 2004-01-08
3105 (let ((send (if server
3106 (format "WHOIS %s %s" user server)
3107 (format "WHOIS %s" user))))
3108 (erc-log (format "cmd: %s" send))
3109 (erc-server-send send)
3111 (defalias 'erc-cmd-WI 'erc-cmd-WHOIS)
3113 (defun erc-cmd-WHOAMI ()
3114 "Display whois information about yourself."
3115 (erc-cmd-WHOIS (erc-current-nick))
3118 (defun erc-cmd-IDLE (nick)
3119 "Show the length of time NICK has been idle."
3120 (let ((origbuf (current-buffer))
3121 symlist)
3122 (erc-with-server-buffer
3123 (push (cons (erc-once-with-server-event
3124 311 (lambda (_proc parsed)
3125 (string= nick
3126 (nth 1 (erc-response.command-args
3127 parsed)))))
3128 'erc-server-311-functions)
3129 symlist)
3130 (push (cons (erc-once-with-server-event
3131 312 (lambda (_proc parsed)
3132 (string= nick
3133 (nth 1 (erc-response.command-args
3134 parsed)))))
3135 'erc-server-312-functions)
3136 symlist)
3137 (push (cons (erc-once-with-server-event
3138 318 (lambda (_proc parsed)
3139 (string= nick
3140 (nth 1 (erc-response.command-args
3141 parsed)))))
3142 'erc-server-318-functions)
3143 symlist)
3144 (push (cons (erc-once-with-server-event
3145 319 (lambda (_proc parsed)
3146 (string= nick
3147 (nth 1 (erc-response.command-args
3148 parsed)))))
3149 'erc-server-319-functions)
3150 symlist)
3151 (push (cons (erc-once-with-server-event
3152 320 (lambda (_proc parsed)
3153 (string= nick
3154 (nth 1 (erc-response.command-args
3155 parsed)))))
3156 'erc-server-320-functions)
3157 symlist)
3158 (push (cons (erc-once-with-server-event
3159 330 (lambda (_proc parsed)
3160 (string= nick
3161 (nth 1 (erc-response.command-args
3162 parsed)))))
3163 'erc-server-330-functions)
3164 symlist)
3165 (push (cons (erc-once-with-server-event
3167 (lambda (_proc parsed)
3168 (let ((idleseconds
3169 (string-to-number
3170 (cl-third
3171 (erc-response.command-args parsed)))))
3172 (erc-display-line
3173 (erc-make-notice
3174 (format "%s has been idle for %s."
3175 (erc-string-no-properties nick)
3176 (erc-seconds-to-string idleseconds)))
3177 origbuf)
3178 t)))
3179 'erc-server-317-functions)
3180 symlist)
3182 ;; Send the WHOIS command.
3183 (erc-cmd-WHOIS nick)
3185 ;; Remove the uninterned symbols from the server hooks that did not run.
3186 (run-at-time 20 nil (lambda (buf symlist)
3187 (with-current-buffer buf
3188 (dolist (sym symlist)
3189 (let ((hooksym (cdr sym))
3190 (funcsym (car sym)))
3191 (remove-hook hooksym funcsym t)))))
3192 (current-buffer) symlist)))
3195 (defun erc-cmd-DESCRIBE (line)
3196 "Pose some action to a certain user.
3197 LINE has the format \"USER ACTION\"."
3198 (cond
3199 ((string-match
3200 "^\\s-*\\(\\S-+\\)\\s-\\(.*\\)$" line)
3201 (let ((dst (match-string 1 line))
3202 (s (match-string 2 line)))
3203 (erc-log (format "cmd: DESCRIBE: [%s] %s" dst s))
3204 (erc-send-action dst s))
3206 (t nil)))
3207 (put 'erc-cmd-DESCRIBE 'do-not-parse-args t)
3209 (defun erc-cmd-ME (line)
3210 "Send LINE as an action."
3211 (cond
3212 ((string-match "^\\s-\\(.*\\)$" line)
3213 (let ((s (match-string 1 line)))
3214 (erc-log (format "cmd: ME: %s" s))
3215 (erc-send-action (erc-default-target) s))
3217 (t nil)))
3218 (put 'erc-cmd-ME 'do-not-parse-args t)
3220 (defun erc-cmd-ME\'S (line)
3221 "Do a /ME command, but add the string \" 's\" to the beginning."
3222 (erc-cmd-ME (concat " 's" line)))
3223 (put 'erc-cmd-ME\'S 'do-not-parse-args t)
3225 (defun erc-cmd-LASTLOG (line)
3226 "Show all lines in the current buffer matching the regexp LINE.
3228 If a match spreads across multiple lines, all those lines are shown.
3230 The lines are shown in a buffer named `*Occur*'.
3231 It serves as a menu to find any of the occurrences in this buffer.
3232 \\[describe-mode] in that buffer will explain how.
3234 If LINE contains upper case characters (excluding those preceded by `\'),
3235 the matching is case-sensitive."
3236 (occur line)
3238 (put 'erc-cmd-LASTLOG 'do-not-parse-args t)
3239 (put 'erc-cmd-LASTLOG 'process-not-needed t)
3241 (defun erc-send-message (line &optional force)
3242 "Send LINE to the current channel or user and display it.
3244 See also `erc-message' and `erc-display-line'."
3245 (erc-message "PRIVMSG" (concat (erc-default-target) " " line) force)
3246 (erc-display-line
3247 (concat (erc-format-my-nick) line)
3248 (current-buffer))
3249 ;; FIXME - treat multiline, run hooks, or remove me?
3252 (defun erc-cmd-MODE (line)
3253 "Change or display the mode value of a channel or user.
3254 The first word specifies the target. The rest is the mode string
3255 to send.
3257 If only one word is given, display the mode of that target.
3259 A list of valid mode strings for Freenode may be found at
3260 URL `http://freenode.net/using_the_network.shtml'."
3261 (cond
3262 ((string-match "^\\s-\\(.*\\)$" line)
3263 (let ((s (match-string 1 line)))
3264 (erc-log (format "cmd: MODE: %s" s))
3265 (erc-server-send (concat "MODE " line)))
3267 (t nil)))
3268 (put 'erc-cmd-MODE 'do-not-parse-args t)
3270 (defun erc-cmd-NOTICE (channel-or-user &rest message)
3271 "Send a notice to the channel or user given as the first word.
3272 The rest is the message to send."
3273 (erc-message "NOTICE" (concat channel-or-user " "
3274 (mapconcat #'identity message " "))))
3276 (defun erc-cmd-MSG (line)
3277 "Send a message to the channel or user given as the first word in LINE.
3279 The rest of LINE is the message to send."
3280 (erc-message "PRIVMSG" line))
3282 (defalias 'erc-cmd-M 'erc-cmd-MSG)
3283 (put 'erc-cmd-MSG 'do-not-parse-args t)
3285 (defun erc-cmd-SQUERY (line)
3286 "Send a Service Query to the service given as the first word in LINE.
3288 The rest of LINE is the message to send."
3289 (erc-message "SQUERY" line))
3291 (defun erc-cmd-NICK (nick)
3292 "Change current nickname to NICK."
3293 (erc-log (format "cmd: NICK: %s (erc-bad-nick: %S)" nick erc-bad-nick))
3294 (let ((nicklen (cdr (assoc "NICKLEN" (erc-with-server-buffer
3295 erc-server-parameters)))))
3296 (and nicklen (> (length nick) (string-to-number nicklen))
3297 (erc-display-message
3298 nil 'notice 'active 'nick-too-long
3299 ?i (length nick) ?l nicklen)))
3300 (erc-server-send (format "NICK %s" nick))
3301 (cond (erc-bad-nick
3302 (erc-set-current-nick nick)
3303 (erc-update-mode-line)
3304 (setq erc-bad-nick nil)))
3307 (defun erc-cmd-PART (line)
3308 "When LINE is an empty string, leave the current channel.
3309 Otherwise leave the channel indicated by LINE."
3310 (cond
3311 ((string-match "^\\s-*\\([&#+!]\\S-+\\)\\s-?\\(.*\\)$" line)
3312 (let* ((ch (match-string 1 line))
3313 (msg (match-string 2 line))
3314 (reason (funcall erc-part-reason (if (equal msg "") nil msg))))
3315 (erc-log (format "cmd: PART: %s: %s" ch reason))
3316 (erc-server-send (if (string= reason "")
3317 (format "PART %s" ch)
3318 (format "PART %s :%s" ch reason))
3319 nil ch))
3321 ((string-match "^\\s-*\\(.*\\)$" line)
3322 (let* ((ch (erc-default-target))
3323 (msg (match-string 1 line))
3324 (reason (funcall erc-part-reason (if (equal msg "") nil msg))))
3325 (if (and ch (erc-channel-p ch))
3326 (progn
3327 (erc-log (format "cmd: PART: %s: %s" ch reason))
3328 (erc-server-send (if (string= reason "")
3329 (format "PART %s" ch)
3330 (format "PART %s :%s" ch reason))
3331 nil ch))
3332 (erc-display-message nil 'error (current-buffer) 'no-target)))
3334 (t nil)))
3335 (put 'erc-cmd-PART 'do-not-parse-args t)
3337 (defalias 'erc-cmd-LEAVE 'erc-cmd-PART)
3339 (defun erc-cmd-PING (recipient)
3340 "Ping RECIPIENT."
3341 (let ((time (format "%f" (erc-current-time))))
3342 (erc-log (format "cmd: PING: %s" time))
3343 (erc-cmd-CTCP recipient "PING" time)))
3345 (defun erc-cmd-QUOTE (line)
3346 "Send LINE directly to the server.
3347 All the text given as argument is sent to the sever as unmodified,
3348 just as you provided it. Use this command with care!"
3349 (cond
3350 ((string-match "^ ?\\(.+\\)$" line)
3351 (erc-server-send (match-string 1 line)))
3352 (t nil)))
3353 (put 'erc-cmd-QUOTE 'do-not-parse-args t)
3355 (defcustom erc-query-display 'window
3356 "Indicates how to display query buffers when using the /QUERY
3357 command to talk to someone.
3359 The default behavior is to display the message in a new window
3360 and bring it to the front. See the documentation for
3361 `erc-join-buffer' for a description of the available choices.
3363 See also `erc-auto-query' to decide how private messages from
3364 other people should be displayed."
3365 :group 'erc-query
3366 :type '(choice (const :tag "Split window and select" window)
3367 (const :tag "Split window, don't select" window-noselect)
3368 (const :tag "New frame" frame)
3369 (const :tag "Bury in new buffer" bury)
3370 (const :tag "Use current buffer" buffer)
3371 (const :tag "Use current buffer" t)))
3373 (defun erc-cmd-QUERY (&optional user)
3374 "Open a query with USER.
3375 The type of query window/frame/etc will depend on the value of
3376 `erc-query-display'.
3378 If USER is omitted, close the current query buffer if one exists
3379 - except this is broken now ;-)"
3380 (interactive
3381 (list (read-from-minibuffer "Start a query with: " nil)))
3382 (let ((session-buffer (erc-server-buffer))
3383 (erc-join-buffer erc-query-display))
3384 (if user
3385 (erc-query user session-buffer)
3386 ;; currently broken, evil hack to display help anyway
3387 ;(erc-delete-query))))
3388 (signal 'wrong-number-of-arguments ""))))
3389 (defalias 'erc-cmd-Q 'erc-cmd-QUERY)
3391 (defun erc-quit/part-reason-default ()
3392 "Default quit/part message."
3393 (format "\C-bERC\C-b (IRC client for Emacs %s)" emacs-version))
3396 (defun erc-quit-reason-normal (&optional s)
3397 "Normal quit message.
3399 If S is non-nil, it will be used as the quit reason."
3400 (or s (erc-quit/part-reason-default)))
3402 (defun erc-quit-reason-zippy (&optional s)
3403 "Zippy quit message.
3405 If S is non-nil, it will be used as the quit reason."
3406 (or s
3407 (if (fboundp 'yow)
3408 (erc-replace-regexp-in-string "\n" "" (yow))
3409 (erc-quit/part-reason-default))))
3411 (make-obsolete 'erc-quit-reason-zippy "it will be removed." "24.4")
3413 (defun erc-quit-reason-various (s)
3414 "Choose a quit reason based on S (a string)."
3415 (when (featurep 'xemacs) (require 'poe))
3416 (let ((res (car (assoc-default (or s "")
3417 erc-quit-reason-various-alist 'string-match))))
3418 (cond
3419 ((functionp res) (funcall res))
3420 ((stringp res) res)
3421 (s s)
3422 (t (erc-quit/part-reason-default)))))
3424 (defun erc-part-reason-normal (&optional s)
3425 "Normal part message.
3427 If S is non-nil, it will be used as the part reason."
3428 (or s (erc-quit/part-reason-default)))
3430 (defun erc-part-reason-zippy (&optional s)
3431 "Zippy part message.
3433 If S is non-nil, it will be used as the quit reason."
3434 (or s
3435 (if (fboundp 'yow)
3436 (erc-replace-regexp-in-string "\n" "" (yow))
3437 (erc-quit/part-reason-default))))
3439 (make-obsolete 'erc-part-reason-zippy "it will be removed." "24.4")
3441 (defun erc-part-reason-various (s)
3442 "Choose a part reason based on S (a string)."
3443 (when (featurep 'xemacs) (require 'poe))
3444 (let ((res (car (assoc-default (or s "")
3445 erc-part-reason-various-alist 'string-match))))
3446 (cond
3447 ((functionp res) (funcall res))
3448 ((stringp res) res)
3449 (s s)
3450 (t (erc-quit/part-reason-default)))))
3452 (defun erc-cmd-QUIT (reason)
3453 "Disconnect from the current server.
3454 If REASON is omitted, display a default quit message, otherwise display
3455 the message given by REASON."
3456 (unless reason
3457 (setq reason ""))
3458 (cond
3459 ((string-match "^\\s-*\\(.*\\)$" reason)
3460 (let* ((s (match-string 1 reason))
3461 (buffer (erc-server-buffer))
3462 (reason (funcall erc-quit-reason (if (equal s "") nil s)))
3463 server-proc)
3464 (with-current-buffer (if (and buffer
3465 (bufferp buffer))
3466 buffer
3467 (current-buffer))
3468 (erc-log (format "cmd: QUIT: %s" reason))
3469 (setq erc-server-quitting t)
3470 (erc-set-active-buffer (erc-server-buffer))
3471 (setq server-proc erc-server-process)
3472 (erc-server-send (format "QUIT :%s" reason)))
3473 (run-hook-with-args 'erc-quit-hook server-proc)
3474 (when erc-kill-queries-on-quit
3475 (erc-kill-query-buffers server-proc))
3476 ;; if the process has not been killed within 4 seconds, kill it
3477 (run-at-time 4 nil
3478 (lambda (proc)
3479 (when (and (processp proc)
3480 (memq (process-status proc) '(run open)))
3481 (delete-process proc)))
3482 server-proc))
3484 (t nil)))
3486 (defalias 'erc-cmd-BYE 'erc-cmd-QUIT)
3487 (defalias 'erc-cmd-EXIT 'erc-cmd-QUIT)
3488 (defalias 'erc-cmd-SIGNOFF 'erc-cmd-QUIT)
3489 (put 'erc-cmd-QUIT 'do-not-parse-args t)
3490 (put 'erc-cmd-QUIT 'process-not-needed t)
3492 (defun erc-cmd-GQUIT (reason)
3493 "Disconnect from all servers at once with the same quit REASON."
3494 (erc-with-all-buffers-of-server nil #'erc-open-server-buffer-p
3495 (erc-cmd-QUIT reason))
3496 (when erc-kill-queries-on-quit
3497 ;; if the query buffers have not been killed within 4 seconds,
3498 ;; kill them
3499 (run-at-time
3500 4 nil
3501 (lambda ()
3502 (dolist (buffer (erc-buffer-list (lambda (buf)
3503 (not (erc-server-buffer-p buf)))))
3504 (kill-buffer buffer)))))
3507 (defalias 'erc-cmd-GQ 'erc-cmd-GQUIT)
3508 (put 'erc-cmd-GQUIT 'do-not-parse-args t)
3509 (put 'erc-cmd-GQUIT 'process-not-needed t)
3511 (defun erc-cmd-RECONNECT ()
3512 "Try to reconnect to the current IRC server."
3513 (let ((buffer (erc-server-buffer))
3514 (process nil))
3515 (unless (buffer-live-p buffer)
3516 (setq buffer (current-buffer)))
3517 (with-current-buffer buffer
3518 (setq erc-server-quitting nil)
3519 (setq erc-server-reconnecting t)
3520 (setq erc-server-reconnect-count 0)
3521 (setq process (get-buffer-process (erc-server-buffer)))
3522 (if process
3523 (delete-process process)
3524 (erc-server-reconnect))
3525 (setq erc-server-reconnecting nil)))
3527 (put 'erc-cmd-RECONNECT 'process-not-needed t)
3529 (defun erc-cmd-SERVER (server)
3530 "Connect to SERVER, leaving existing connection intact."
3531 (erc-log (format "cmd: SERVER: %s" server))
3532 (condition-case nil
3533 (erc :server server :nick (erc-current-nick))
3534 (error
3535 (erc-error "Cannot find host %s." server)))
3537 (put 'erc-cmd-SERVER 'process-not-needed t)
3539 (defvar motif-version-string)
3540 (defvar gtk-version-string)
3542 (defun erc-cmd-SV ()
3543 "Say the current ERC and Emacs version into channel."
3544 (erc-send-message (format "I'm using ERC with %s %s (%s%s) of %s."
3545 (if (featurep 'xemacs) "XEmacs" "GNU Emacs")
3546 emacs-version
3547 system-configuration
3548 (concat
3549 (cond ((featurep 'motif)
3550 (concat ", " (substring
3551 motif-version-string 4)))
3552 ((featurep 'gtk)
3553 (concat ", GTK+ Version "
3554 gtk-version-string))
3555 ((featurep 'x-toolkit) ", X toolkit")
3556 (t ""))
3557 (if (and (boundp 'x-toolkit-scroll-bars)
3558 (memq x-toolkit-scroll-bars
3559 '(xaw xaw3d)))
3560 (format ", %s scroll bars"
3561 (capitalize (symbol-name
3562 x-toolkit-scroll-bars)))
3564 (if (featurep 'multi-tty) ", multi-tty" ""))
3565 erc-emacs-build-time))
3568 (defun erc-cmd-SM ()
3569 "Say the current ERC modes into channel."
3570 (erc-send-message (format "I'm using the following modules: %s!"
3571 (erc-modes)))
3574 (defun erc-cmd-DEOP (&rest people)
3575 "Remove the operator setting from user(s) given in PEOPLE."
3576 (when (> (length people) 0)
3577 (erc-server-send (concat "MODE " (erc-default-target)
3578 " -"
3579 (make-string (length people) ?o)
3581 (mapconcat 'identity people " ")))
3584 (defun erc-cmd-OP (&rest people)
3585 "Add the operator setting to users(s) given in PEOPLE."
3586 (when (> (length people) 0)
3587 (erc-server-send (concat "MODE " (erc-default-target)
3588 " +"
3589 (make-string (length people) ?o)
3591 (mapconcat 'identity people " ")))
3594 (defun erc-cmd-TIME (&optional line)
3595 "Request the current time and date from the current server."
3596 (cond
3597 ((and line (string-match "^\\s-*\\(.*\\)$" line))
3598 (let ((args (match-string 1 line)))
3599 (erc-log (format "cmd: TIME: %s" args))
3600 (erc-server-send (concat "TIME " args)))
3602 (t (erc-server-send "TIME"))))
3603 (defalias 'erc-cmd-DATE 'erc-cmd-TIME)
3605 (defun erc-cmd-TOPIC (topic)
3606 "Set or request the topic for a channel.
3607 LINE has the format: \"#CHANNEL TOPIC\", \"#CHANNEL\", \"TOPIC\"
3608 or the empty string.
3610 If no #CHANNEL is given, the default channel is used. If TOPIC is
3611 given, the channel topic is modified, otherwise the current topic will
3612 be displayed."
3613 (cond
3614 ;; /topic #channel TOPIC
3615 ((string-match "^\\s-*\\([&#+!]\\S-+\\)\\s-\\(.*\\)$" topic)
3616 (let ((ch (match-string 1 topic))
3617 (topic (match-string 2 topic)))
3618 (erc-log (format "cmd: TOPIC [%s]: %s" ch topic))
3619 (erc-server-send (format "TOPIC %s :%s" ch topic) nil ch))
3621 ;; /topic #channel
3622 ((string-match "^\\s-*\\([&#+!]\\S-+\\)" topic)
3623 (let ((ch (match-string 1 topic)))
3624 (erc-server-send (format "TOPIC %s" ch) nil ch)
3626 ;; /topic
3627 ((string-match "^\\s-*$" topic)
3628 (let ((ch (erc-default-target)))
3629 (erc-server-send (format "TOPIC %s" ch) nil ch)
3631 ;; /topic TOPIC
3632 ((string-match "^\\s-*\\(.*\\)$" topic)
3633 (let ((ch (erc-default-target))
3634 (topic (match-string 1 topic)))
3635 (if (and ch (erc-channel-p ch))
3636 (progn
3637 (erc-log (format "cmd: TOPIC [%s]: %s" ch topic))
3638 (erc-server-send (format "TOPIC %s :%s" ch topic) nil ch))
3639 (erc-display-message nil 'error (current-buffer) 'no-target)))
3641 (t nil)))
3642 (defalias 'erc-cmd-T 'erc-cmd-TOPIC)
3643 (put 'erc-cmd-TOPIC 'do-not-parse-args t)
3645 (defun erc-cmd-APPENDTOPIC (topic)
3646 "Append TOPIC to the current channel topic, separated by a space."
3647 (let ((oldtopic erc-channel-topic))
3648 ;; display help when given no arguments
3649 (when (string-match "^\\s-*$" topic)
3650 (signal 'wrong-number-of-arguments nil))
3651 ;; strip trailing ^O
3652 (when (string-match "\\(.*\\)\C-o" oldtopic)
3653 (erc-cmd-TOPIC (concat (match-string 1 oldtopic) topic)))))
3654 (defalias 'erc-cmd-AT 'erc-cmd-APPENDTOPIC)
3655 (put 'erc-cmd-APPENDTOPIC 'do-not-parse-args t)
3657 (defun erc-cmd-CLEARTOPIC (&optional channel)
3658 "Clear the topic for a CHANNEL.
3659 If CHANNEL is not specified, clear the topic for the default channel."
3660 (interactive "sClear topic of channel (RET is current channel): ")
3661 (let ((chnl (or (and (erc-channel-p channel) channel) (erc-default-target))))
3662 (when chnl
3663 (erc-server-send (format "TOPIC %s :" chnl))
3664 t)))
3666 ;;; Banlists
3668 (defvar erc-channel-banlist nil
3669 "A list of bans seen for the current channel.
3671 Each ban is an alist of the form:
3672 (WHOSET . MASK)
3674 The property `received-from-server' indicates whether
3675 or not the ban list has been requested from the server.")
3676 (make-variable-buffer-local 'erc-channel-banlist)
3677 (put 'erc-channel-banlist 'received-from-server nil)
3679 (defun erc-cmd-BANLIST ()
3680 "Pretty-print the contents of `erc-channel-banlist'.
3682 The ban list is fetched from the server if necessary."
3683 (let ((chnl (erc-default-target))
3684 (chnl-name (buffer-name)))
3686 (cond
3687 ((not (erc-channel-p chnl))
3688 (erc-display-line (erc-make-notice "You're not on a channel\n")
3689 'active))
3691 ((not (get 'erc-channel-banlist 'received-from-server))
3692 (let ((old-367-hook erc-server-367-functions))
3693 (setq erc-server-367-functions 'erc-banlist-store
3694 erc-channel-banlist nil)
3695 ;; fetch the ban list then callback
3696 (erc-with-server-buffer
3697 (erc-once-with-server-event
3699 (lambda (_proc _parsed)
3700 (with-current-buffer chnl-name
3701 (put 'erc-channel-banlist 'received-from-server t)
3702 (setq erc-server-367-functions old-367-hook)
3703 (erc-cmd-BANLIST)
3704 t)))
3705 (erc-server-send (format "MODE %s b" chnl)))))
3707 ((null erc-channel-banlist)
3708 (erc-display-line (erc-make-notice
3709 (format "No bans for channel: %s\n" chnl))
3710 'active)
3711 (put 'erc-channel-banlist 'received-from-server nil))
3714 (let* ((erc-fill-column (or (and (boundp 'erc-fill-column)
3715 erc-fill-column)
3716 (and (boundp 'fill-column)
3717 fill-column)
3718 (1- (window-width))))
3719 (separator (make-string erc-fill-column ?=))
3720 (fmt (concat
3721 "%-" (number-to-string (/ erc-fill-column 2)) "s"
3722 "%" (number-to-string (/ erc-fill-column 2)) "s")))
3724 (erc-display-line
3725 (erc-make-notice (format "Ban list for channel: %s\n"
3726 (erc-default-target)))
3727 'active)
3729 (erc-display-line separator 'active)
3730 (erc-display-line (format fmt "Ban Mask" "Banned By") 'active)
3731 (erc-display-line separator 'active)
3733 (mapc
3734 (lambda (x)
3735 (erc-display-line
3736 (format fmt
3737 (truncate-string-to-width (cdr x) (/ erc-fill-column 2))
3738 (if (car x)
3739 (truncate-string-to-width (car x) (/ erc-fill-column 2))
3740 ""))
3741 'active))
3742 erc-channel-banlist)
3744 (erc-display-line (erc-make-notice "End of Ban list")
3745 'active)
3746 (put 'erc-channel-banlist 'received-from-server nil)))))
3749 (defalias 'erc-cmd-BL 'erc-cmd-BANLIST)
3751 (defun erc-cmd-MASSUNBAN ()
3752 "Mass Unban.
3754 Unban all currently banned users in the current channel."
3755 (let ((chnl (erc-default-target)))
3756 (cond
3758 ((not (erc-channel-p chnl))
3759 (erc-display-line
3760 (erc-make-notice "You're not on a channel\n")
3761 'active))
3763 ((not (get 'erc-channel-banlist 'received-from-server))
3764 (let ((old-367-hook erc-server-367-functions))
3765 (setq erc-server-367-functions 'erc-banlist-store)
3766 ;; fetch the ban list then callback
3767 (erc-with-server-buffer
3768 (erc-once-with-server-event
3770 (lambda (_proc _parsed)
3771 (with-current-buffer chnl
3772 (put 'erc-channel-banlist 'received-from-server t)
3773 (setq erc-server-367-functions old-367-hook)
3774 (erc-cmd-MASSUNBAN)
3775 t)))
3776 (erc-server-send (format "MODE %s b" chnl)))))
3778 (t (let ((bans (mapcar 'cdr erc-channel-banlist)))
3779 (when bans
3780 ;; Glob the bans into groups of three, and carry out the unban.
3781 ;; eg. /mode #foo -bbb a*!*@* b*!*@* c*!*@*
3782 (mapc
3783 (lambda (x)
3784 (erc-server-send
3785 (format "MODE %s -%s %s" (erc-default-target)
3786 (make-string (length x) ?b)
3787 (mapconcat 'identity x " "))))
3788 (erc-group-list bans 3))))
3789 t))))
3791 (defalias 'erc-cmd-MUB 'erc-cmd-MASSUNBAN)
3793 ;;;; End of IRC commands
3795 (defun erc-ensure-channel-name (channel)
3796 "Return CHANNEL if it is a valid channel name.
3797 Eventually add a # in front of it, if that turns it into a valid channel name."
3798 (if (erc-channel-p channel)
3799 channel
3800 (concat "#" channel)))
3802 (defun erc-grab-region (start end)
3803 "Copy the region between START and END in a recreatable format.
3805 Converts all the IRC text properties in each line of the region
3806 into control codes and writes them to a separate buffer. The
3807 resulting text may be used directly as a script to generate this
3808 text again."
3809 (interactive "r")
3810 (erc-set-active-buffer (current-buffer))
3811 (save-excursion
3812 (let* ((cb (current-buffer))
3813 (buf (generate-new-buffer erc-grab-buffer-name))
3814 (region (buffer-substring start end))
3815 (lines (erc-split-multiline-safe region)))
3816 (set-buffer buf)
3817 (dolist (line lines)
3818 (insert (concat line "\n")))
3819 (set-buffer cb)
3820 (switch-to-buffer-other-window buf)))
3821 (message "erc-grab-region doesn't grab colors etc. anymore. If you use this, please tell the maintainers.")
3822 (ding))
3824 (defun erc-display-prompt (&optional buffer pos prompt face)
3825 "Display PROMPT in BUFFER at position POS.
3826 Display an ERC prompt in BUFFER.
3828 If PROMPT is nil, one is constructed with the function `erc-prompt'.
3829 If BUFFER is nil, the `current-buffer' is used.
3830 If POS is nil, PROMPT will be displayed at `point'.
3831 If FACE is non-nil, it will be used to propertize the prompt. If it is nil,
3832 `erc-prompt-face' will be used."
3833 (let* ((prompt (or prompt (erc-prompt)))
3834 (l (length prompt))
3835 (ob (current-buffer)))
3836 ;; We cannot use save-excursion because we move point, therefore
3837 ;; we resort to the ol' ob trick to restore this.
3838 (when (and buffer (bufferp buffer))
3839 (set-buffer buffer))
3841 ;; now save excursion again to store where point and mark are
3842 ;; in the current buffer
3843 (save-excursion
3844 (setq pos (or pos (point)))
3845 (goto-char pos)
3846 (when (> l 0)
3847 ;; Do not extend the text properties when typing at the end
3848 ;; of the prompt, but stuff typed in front of the prompt
3849 ;; shall remain part of the prompt.
3850 (setq prompt (erc-propertize prompt
3851 'start-open t ; XEmacs
3852 'rear-nonsticky t ; Emacs
3853 'erc-prompt t
3854 'field t
3855 'front-sticky t
3856 'read-only t))
3857 (erc-put-text-property 0 (1- (length prompt))
3858 'face (or face 'erc-prompt-face)
3859 prompt)
3860 (insert prompt))
3861 ;; Set the input marker
3862 (set-marker erc-input-marker (point)))
3864 ;; Now we are back at the old position. If the prompt was
3865 ;; inserted here or before us, advance point by the length of
3866 ;; the prompt.
3867 (when (or (not pos) (<= (point) pos))
3868 (forward-char l))
3869 ;; Clear the undo buffer now, so the user can undo his stuff,
3870 ;; but not the stuff we did. Sneaky!
3871 (setq buffer-undo-list nil)
3872 (set-buffer ob)))
3874 ;; interactive operations
3876 (defun erc-input-message ()
3877 "Read input from the minibuffer."
3878 (interactive)
3879 (let ((minibuffer-allow-text-properties t)
3880 (read-map minibuffer-local-map))
3881 (insert (read-from-minibuffer "Message: "
3882 (string (if (featurep 'xemacs)
3883 last-command-char
3884 last-command-event))
3885 read-map))
3886 (erc-send-current-line)))
3888 (defvar erc-action-history-list ()
3889 "History list for interactive action input.")
3891 (defun erc-input-action ()
3892 "Interactively input a user action and send it to IRC."
3893 (interactive "")
3894 (erc-set-active-buffer (current-buffer))
3895 (let ((action (read-from-minibuffer
3896 "Action: " nil nil nil 'erc-action-history-list)))
3897 (if (not (string-match "^\\s-*$" action))
3898 (erc-send-action (erc-default-target) action))))
3900 (defun erc-join-channel (channel &optional key)
3901 "Join CHANNEL.
3903 If `point' is at the beginning of a channel name, use that as default."
3904 (interactive
3905 (list
3906 (let ((chnl (if (looking-at "\\([&#+!][^ \n]+\\)") (match-string 1) ""))
3907 (table (when (erc-server-buffer-live-p)
3908 (set-buffer (process-buffer erc-server-process))
3909 erc-channel-list)))
3910 (completing-read "Join channel: " table nil nil nil nil chnl))
3911 (when (or current-prefix-arg erc-prompt-for-channel-key)
3912 (read-from-minibuffer "Channel key (RET for none): " nil))))
3913 (erc-cmd-JOIN channel (when (>= (length key) 1) key)))
3915 (defun erc-part-from-channel (reason)
3916 "Part from the current channel and prompt for a REASON."
3917 (interactive
3918 (list
3919 (if (and (boundp 'reason) (stringp reason) (not (string= reason "")))
3920 reason
3921 (read-from-minibuffer (concat "Reason for leaving " (erc-default-target)
3922 ": ")))))
3923 (erc-cmd-PART (concat (erc-default-target)" " reason)))
3925 (defun erc-set-topic (topic)
3926 "Prompt for a TOPIC for the current channel."
3927 (interactive
3928 (list
3929 (read-from-minibuffer
3930 (concat "Set topic of " (erc-default-target) ": ")
3931 (when erc-channel-topic
3932 (let ((ss (split-string erc-channel-topic "\C-o")))
3933 (cons (apply 'concat (if (cdr ss) (butlast ss) ss))
3934 0))))))
3935 (let ((topic-list (split-string topic "\C-o"))) ; strip off the topic setter
3936 (erc-cmd-TOPIC (concat (erc-default-target) " " (car topic-list)))))
3938 (defun erc-set-channel-limit (&optional limit)
3939 "Set a LIMIT for the current channel. Remove limit if nil.
3940 Prompt for one if called interactively."
3941 (interactive (list (read-from-minibuffer
3942 (format "Limit for %s (RET to remove limit): "
3943 (erc-default-target)))))
3944 (let ((tgt (erc-default-target)))
3945 (erc-server-send (if (and limit (>= (length limit) 1))
3946 (format "MODE %s +l %s" tgt limit)
3947 (format "MODE %s -l" tgt)))))
3949 (defun erc-set-channel-key (&optional key)
3950 "Set a KEY for the current channel. Remove key if nil.
3951 Prompt for one if called interactively."
3952 (interactive (list (read-from-minibuffer
3953 (format "Key for %s (RET to remove key): "
3954 (erc-default-target)))))
3955 (let ((tgt (erc-default-target)))
3956 (erc-server-send (if (and key (>= (length key) 1))
3957 (format "MODE %s +k %s" tgt key)
3958 (format "MODE %s -k" tgt)))))
3960 (defun erc-quit-server (reason)
3961 "Disconnect from current server after prompting for REASON.
3962 `erc-quit-reason' works with this just like with `erc-cmd-QUIT'."
3963 (interactive (list (read-from-minibuffer
3964 (format "Reason for quitting %s: "
3965 (or erc-server-announced-name
3966 erc-session-server)))))
3967 (erc-cmd-QUIT reason))
3969 ;; Movement of point
3971 (defun erc-bol ()
3972 "Move `point' to the beginning of the current line.
3974 This places `point' just after the prompt, or at the beginning of the line."
3975 (interactive)
3976 (forward-line 0)
3977 (when (get-text-property (point) 'erc-prompt)
3978 (goto-char erc-input-marker))
3979 (point))
3981 (defun erc-kill-input ()
3982 "Kill current input line using `erc-bol' followed by `kill-line'."
3983 (interactive)
3984 (when (and (erc-bol)
3985 (/= (point) (point-max))) ;; Prevent a (ding) and an error when
3986 ;; there's nothing to kill
3987 (if (boundp 'erc-input-ring-index)
3988 (setq erc-input-ring-index nil))
3989 (kill-line)))
3991 (defun erc-complete-word-at-point ()
3992 (run-hook-with-args-until-success 'erc-complete-functions))
3994 (define-obsolete-function-alias 'erc-complete-word 'completion-at-point "24.1")
3996 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3998 ;; IRC SERVER INPUT HANDLING
4000 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4002 ;;;; New Input parsing
4004 ; Stolen from ZenIRC. I just wanna test this code, so here is
4005 ; experiment area.
4007 (defcustom erc-default-server-hook '(erc-debug-missing-hooks
4008 erc-default-server-handler)
4009 "Default for server messages which aren't covered by `erc-server-hooks'."
4010 :group 'erc-server-hooks
4011 :type 'hook)
4013 (defun erc-default-server-handler (proc parsed)
4014 "Default server handler.
4016 Displays PROC and PARSED appropriately using `erc-display-message'."
4017 (erc-display-message
4018 parsed 'notice proc
4019 (mapconcat
4020 'identity
4021 (let (res)
4022 (mapc #'(lambda (x)
4023 (if (stringp x)
4024 (setq res (append res (list x)))))
4025 parsed)
4026 res)
4027 " ")))
4029 (defvar erc-server-vectors
4030 '(["msgtype" "sender" "to" "arg1" "arg2" "arg3" "..."])
4031 "List of received server messages which ERC does not specifically handle.
4032 See `erc-debug-missing-hooks'.")
4033 ;(make-variable-buffer-local 'erc-server-vectors)
4035 (defun erc-debug-missing-hooks (_proc parsed)
4036 "Add PARSED server message ERC does not yet handle to `erc-server-vectors'.
4037 These vectors can be helpful when adding new server message handlers to ERC.
4038 See `erc-default-server-hook'."
4039 (nconc erc-server-vectors (list parsed))
4040 nil)
4042 (defun erc-query (target server)
4043 "Open a query buffer on TARGET, using SERVER.
4044 To change how this query window is displayed, use `let' to bind
4045 `erc-join-buffer' before calling this."
4046 (unless (and server
4047 (buffer-live-p server)
4048 (set-buffer server))
4049 (error "Couldn't switch to server buffer"))
4050 (let ((buf (erc-open erc-session-server
4051 erc-session-port
4052 (erc-current-nick)
4053 erc-session-user-full-name
4056 (list target)
4057 target
4058 erc-server-process)))
4059 (unless buf
4060 (error "Couldn't open query window"))
4061 (erc-update-mode-line)
4062 buf))
4064 (defcustom erc-auto-query 'window-noselect
4065 "If non-nil, create a query buffer each time you receive a private message.
4066 If the buffer doesn't already exist, it is created.
4068 This can be set to a symbol, to control how the new query window
4069 should appear. The default behavior is to display the buffer in
4070 a new window, but not to select it. See the documentation for
4071 `erc-join-buffer' for a description of the available choices."
4072 :group 'erc-query
4073 :type '(choice (const :tag "Don't create query window" nil)
4074 (const :tag "Split window and select" window)
4075 (const :tag "Split window, don't select" window-noselect)
4076 (const :tag "New frame" frame)
4077 (const :tag "Bury in new buffer" bury)
4078 (const :tag "Use current buffer" buffer)
4079 (const :tag "Use current buffer" t)))
4081 (defcustom erc-query-on-unjoined-chan-privmsg t
4082 "If non-nil create query buffer on receiving any PRIVMSG at all.
4083 This includes PRIVMSGs directed to channels. If you are using an IRC
4084 bouncer, such as dircproxy, to keep a log of channels when you are
4085 disconnected, you should set this option to t."
4086 :group 'erc-query
4087 :type 'boolean)
4089 (defcustom erc-format-query-as-channel-p t
4090 "If non-nil, format text from others in a query buffer like in a channel,
4091 otherwise format like a private message."
4092 :group 'erc-query
4093 :type 'boolean)
4095 (defcustom erc-minibuffer-notice nil
4096 "If non-nil, print ERC notices for the user in the minibuffer.
4097 Only happens when the session buffer isn't visible."
4098 :group 'erc-display
4099 :type 'boolean)
4101 (defcustom erc-minibuffer-ignored nil
4102 "If non-nil, print a message in the minibuffer if we ignored something."
4103 :group 'erc-ignore
4104 :type 'boolean)
4106 (defun erc-wash-quit-reason (reason nick login host)
4107 "Remove duplicate text from quit REASON.
4108 Specifically in relation to NICK (user@host) information. Returns REASON
4109 unmodified if nothing can be removed.
4110 E.g. \"Read error to Nick [user@some.host]: 110\" would be shortened to
4111 \"Read error: 110\". The same applies for \"Ping Timeout\"."
4112 (setq nick (regexp-quote nick)
4113 login (regexp-quote login)
4114 host (regexp-quote host))
4115 (or (when (string-match (concat "^\\(Read error\\) to "
4116 nick "\\[" host "\\]: "
4117 "\\(.+\\)$")
4118 reason)
4119 (concat (match-string 1 reason) ": " (match-string 2 reason)))
4120 (when (string-match (concat "^\\(Ping timeout\\) for "
4121 nick "\\[" host "\\]$")
4122 reason)
4123 (match-string 1 reason))
4124 reason))
4126 (defun erc-nickname-in-use (nick reason)
4127 "If NICK is unavailable, tell the user the REASON.
4129 See also `erc-display-error-notice'."
4130 (if (or (not erc-try-new-nick-p)
4131 ;; how many default-nicks are left + one more try...
4132 (eq erc-nick-change-attempt-count
4133 (if (consp erc-nick)
4134 (+ (length erc-nick) 1)
4135 1)))
4136 (erc-display-error-notice
4138 (format "Nickname %s is %s, try another." nick reason))
4139 (setq erc-nick-change-attempt-count (+ erc-nick-change-attempt-count 1))
4140 (let ((newnick (nth 1 erc-default-nicks))
4141 (nicklen (cdr (assoc "NICKLEN"
4142 (erc-with-server-buffer
4143 erc-server-parameters)))))
4144 (setq erc-bad-nick t)
4145 ;; try to use a different nick
4146 (if erc-default-nicks
4147 (setq erc-default-nicks (cdr erc-default-nicks)))
4148 (if (not newnick)
4149 (setq newnick (concat (truncate-string-to-width
4150 nick
4151 (if (and erc-server-connected nicklen)
4152 (- (string-to-number nicklen)
4153 (length erc-nick-uniquifier))
4154 ;; rfc2812 max nick length = 9
4155 ;; we must assume this is the
4156 ;; server's setting if we haven't
4157 ;; established a connection yet
4158 (- 9 (length erc-nick-uniquifier))))
4159 erc-nick-uniquifier)))
4160 (erc-cmd-NICK newnick)
4161 (erc-display-error-notice
4163 (format "Nickname %s is %s, trying %s"
4164 nick reason newnick)))))
4166 ;;; Server messages
4168 (defgroup erc-server-hooks nil
4169 "Server event callbacks.
4170 Every server event - like numeric replies - has its own hook.
4171 Those hooks are all called using `run-hook-with-args-until-success'.
4172 They receive as first argument the process object from where the event
4173 originated from,
4174 and as second argument the event parsed as a vector."
4175 :group 'erc-hooks)
4177 (defun erc-display-server-message (_proc parsed)
4178 "Display the message sent by the server as a notice."
4179 (erc-display-message
4180 parsed 'notice 'active (erc-response.contents parsed)))
4182 (defun erc-auto-query (proc parsed)
4183 ;; FIXME: This needs more documentation, unless it's not a user function --
4184 ;; Lawrence 2004-01-08
4185 "Put this on `erc-server-PRIVMSG-functions'."
4186 (when erc-auto-query
4187 (let* ((nick (car (erc-parse-user (erc-response.sender parsed))))
4188 (target (car (erc-response.command-args parsed)))
4189 (msg (erc-response.contents parsed))
4190 (query (if (not erc-query-on-unjoined-chan-privmsg)
4191 nick
4192 (if (erc-current-nick-p target)
4193 nick
4194 target))))
4195 (and (not (erc-ignored-user-p (erc-response.sender parsed)))
4196 (or erc-query-on-unjoined-chan-privmsg
4197 (string= target (erc-current-nick)))
4198 (not (erc-get-buffer query proc))
4199 (not (erc-is-message-ctcp-and-not-action-p msg))
4200 (let ((erc-query-display erc-auto-query))
4201 (erc-cmd-QUERY query))
4202 nil))))
4204 (defun erc-is-message-ctcp-p (message)
4205 "Check if MESSAGE is a CTCP message or not."
4206 (string-match "^\C-a\\([^\C-a]*\\)\C-a?$" message))
4208 (defun erc-is-message-ctcp-and-not-action-p (message)
4209 "Check if MESSAGE is a CTCP message or not."
4210 (and (erc-is-message-ctcp-p message)
4211 (not (string-match "^\C-a\\ACTION.*\C-a$" message))))
4213 (defun erc-format-privmessage (nick msg privp msgp)
4214 "Format a PRIVMSG in an insertable fashion."
4215 (let* ((mark-s (if msgp (if privp "*" "<") "-"))
4216 (mark-e (if msgp (if privp "*" ">") "-"))
4217 (str (format "%s%s%s %s" mark-s nick mark-e msg))
4218 (nick-face (if privp 'erc-nick-msg-face 'erc-nick-default-face))
4219 (msg-face (if privp 'erc-direct-msg-face 'erc-default-face)))
4220 ;; add text properties to text before the nick, the nick and after the nick
4221 (erc-put-text-property 0 (length mark-s) 'face msg-face str)
4222 (erc-put-text-property (length mark-s) (+ (length mark-s) (length nick))
4223 'face nick-face str)
4224 (erc-put-text-property (+ (length mark-s) (length nick)) (length str)
4225 'face msg-face str)
4226 str))
4228 (defcustom erc-format-nick-function 'erc-format-nick
4229 "Function to format a nickname for message display."
4230 :group 'erc-display
4231 :type 'function)
4233 (defun erc-format-nick (&optional user _channel-data)
4234 "Return the nickname of USER.
4235 See also `erc-format-nick-function'."
4236 (when user (erc-server-user-nickname user)))
4238 (defun erc-get-user-mode-prefix (user)
4239 (when user
4240 (cond ((erc-channel-user-owner-p user)
4241 (erc-propertize "~" 'help-echo "owner"))
4242 ((erc-channel-user-admin-p user)
4243 (erc-propertize "&" 'help-echo "admin"))
4244 ((erc-channel-user-op-p user)
4245 (erc-propertize "@" 'help-echo "operator"))
4246 ((erc-channel-user-halfop-p user)
4247 (erc-propertize "%" 'help-echo "half-op"))
4248 ((erc-channel-user-voice-p user)
4249 (erc-propertize "+" 'help-echo "voice"))
4250 (t ""))))
4252 (defun erc-format-@nick (&optional user _channel-data)
4253 "Format the nickname of USER showing if USER has a voice, is an
4254 operator, half-op, admin or owner. Owners have \"~\", admins have
4255 \"&\", operators have \"@\" and users with voice have \"+\" as a
4256 prefix. Use CHANNEL-DATA to determine op and voice status. See
4257 also `erc-format-nick-function'."
4258 (when user
4259 (let ((nick (erc-server-user-nickname user)))
4260 (concat (erc-propertize
4261 (erc-get-user-mode-prefix nick)
4262 'face 'erc-nick-prefix-face)
4263 nick))))
4265 (defun erc-format-my-nick ()
4266 "Return the beginning of this user's message, correctly propertized."
4267 (if erc-show-my-nick
4268 (let* ((open "<")
4269 (close "> ")
4270 (nick (erc-current-nick))
4271 (mode (erc-get-user-mode-prefix nick)))
4272 (concat
4273 (erc-propertize open 'face 'erc-default-face)
4274 (erc-propertize mode 'face 'erc-my-nick-prefix-face)
4275 (erc-propertize nick 'face 'erc-my-nick-face)
4276 (erc-propertize close 'face 'erc-default-face)))
4277 (let ((prefix "> "))
4278 (erc-propertize prefix 'face 'erc-default-face))))
4280 (defun erc-echo-notice-in-default-buffer (s parsed buffer _sender)
4281 "Echos a private notice in the default buffer, namely the
4282 target buffer specified by BUFFER, or there is no target buffer,
4283 the server buffer. This function is designed to be added to
4284 either `erc-echo-notice-hook' or `erc-echo-notice-always-hook',
4285 and always returns t."
4286 (erc-display-message parsed nil buffer s)
4289 (defun erc-echo-notice-in-target-buffer (s parsed buffer _sender)
4290 "Echos a private notice in BUFFER, if BUFFER is non-nil. This
4291 function is designed to be added to either `erc-echo-notice-hook'
4292 or `erc-echo-notice-always-hook', and returns non-nil if BUFFER
4293 is non-nil."
4294 (if buffer
4295 (progn (erc-display-message parsed nil buffer s) t)
4296 nil))
4298 (defun erc-echo-notice-in-minibuffer (s _parsed _buffer _sender)
4299 "Echos a private notice in the minibuffer. This function is
4300 designed to be added to either `erc-echo-notice-hook' or
4301 `erc-echo-notice-always-hook', and always returns t."
4302 (message "%s" (concat "NOTICE: " s))
4305 (defun erc-echo-notice-in-server-buffer (s parsed _buffer _sender)
4306 "Echos a private notice in the server buffer. This function is
4307 designed to be added to either `erc-echo-notice-hook' or
4308 `erc-echo-notice-always-hook', and always returns t."
4309 (erc-display-message parsed nil nil s)
4312 (defun erc-echo-notice-in-active-non-server-buffer (s parsed _buffer _sender)
4313 "Echos a private notice in the active buffer if the active
4314 buffer is not the server buffer. This function is designed to be
4315 added to either `erc-echo-notice-hook' or
4316 `erc-echo-notice-always-hook', and returns non-nil if the active
4317 buffer is not the server buffer."
4318 (if (not (eq (erc-server-buffer) (erc-active-buffer)))
4319 (progn (erc-display-message parsed nil 'active s) t)
4320 nil))
4322 (defun erc-echo-notice-in-active-buffer (s parsed _buffer _sender)
4323 "Echos a private notice in the active buffer. This function is
4324 designed to be added to either `erc-echo-notice-hook' or
4325 `erc-echo-notice-always-hook', and always returns t."
4326 (erc-display-message parsed nil 'active s)
4329 (defun erc-echo-notice-in-user-buffers (s parsed _buffer sender)
4330 "Echos a private notice in all of the buffers for which SENDER
4331 is a member. This function is designed to be added to either
4332 `erc-echo-notice-hook' or `erc-echo-notice-always-hook', and
4333 returns non-nil if there is at least one buffer for which the
4334 sender is a member.
4336 See also: `erc-echo-notice-in-first-user-buffer',
4337 `erc-buffer-list-with-nick'."
4338 (let ((buffers (erc-buffer-list-with-nick sender erc-server-process)))
4339 (if buffers
4340 (progn (erc-display-message parsed nil buffers s) t)
4341 nil)))
4343 (defun erc-echo-notice-in-user-and-target-buffers (s parsed buffer sender)
4344 "Echos a private notice in BUFFER and in all of the buffers for
4345 which SENDER is a member. This function is designed to be added
4346 to either `erc-echo-notice-hook' or
4347 `erc-echo-notice-always-hook', and returns non-nil if there is
4348 at least one buffer for which the sender is a member or the
4349 default target.
4351 See also: `erc-echo-notice-in-user-buffers',
4352 `erc-buffer-list-with-nick'."
4353 (let ((buffers (erc-buffer-list-with-nick sender erc-server-process)))
4354 (unless (memq buffer buffers) (push buffer buffers))
4355 (if buffers ;FIXME: How could it be nil?
4356 (progn (erc-display-message parsed nil buffers s) t)
4357 nil)))
4359 (defun erc-echo-notice-in-first-user-buffer (s parsed _buffer sender)
4360 "Echos a private notice in one of the buffers for which SENDER
4361 is a member. This function is designed to be added to either
4362 `erc-echo-notice-hook' or `erc-echo-notice-always-hook', and
4363 returns non-nil if there is at least one buffer for which the
4364 sender is a member.
4366 See also: `erc-echo-notice-in-user-buffers',
4367 `erc-buffer-list-with-nick'."
4368 (let ((buffers (erc-buffer-list-with-nick sender erc-server-process)))
4369 (if buffers
4370 (progn (erc-display-message parsed nil (car buffers) s) t)
4371 nil)))
4373 ;;; Ban manipulation
4375 (defun erc-banlist-store (proc parsed)
4376 "Record ban entries for a channel."
4377 (pcase-let ((`(,channel ,mask ,whoset)
4378 (cdr (erc-response.command-args parsed))))
4379 ;; Determine to which buffer the message corresponds
4380 (let ((buffer (erc-get-buffer channel proc)))
4381 (with-current-buffer buffer
4382 (unless (member (cons whoset mask) erc-channel-banlist)
4383 (setq erc-channel-banlist (cons (cons whoset mask)
4384 erc-channel-banlist))))))
4385 nil)
4387 (defun erc-banlist-finished (proc parsed)
4388 "Record that we have received the banlist."
4389 (let* ((channel (nth 1 (erc-response.command-args parsed)))
4390 (buffer (erc-get-buffer channel proc)))
4391 (with-current-buffer buffer
4392 (put 'erc-channel-banlist 'received-from-server t)))
4393 t) ; suppress the 'end of banlist' message
4395 (defun erc-banlist-update (proc parsed)
4396 "Check MODE commands for bans and update the banlist appropriately."
4397 ;; FIXME: Possibly incorrect. -- Lawrence 2004-05-11
4398 (let* ((tgt (car (erc-response.command-args parsed)))
4399 (mode (erc-response.contents parsed))
4400 (whoset (erc-response.sender parsed))
4401 (buffer (erc-get-buffer tgt proc)))
4402 (when buffer
4403 (with-current-buffer buffer
4404 (cond ((not (get 'erc-channel-banlist 'received-from-server)) nil)
4405 ((string-match "^\\([+-]\\)b" mode)
4406 ;; This is a ban
4407 (cond
4408 ((string-match "^-" mode)
4409 ;; Remove the unbanned masks from the ban list
4410 (setq erc-channel-banlist
4411 (erc-delete-if
4412 #'(lambda (y)
4413 (member (upcase (cdr y))
4414 (mapcar #'upcase
4415 (cdr (split-string mode)))))
4416 erc-channel-banlist)))
4417 ((string-match "^+" mode)
4418 ;; Add the banned mask(s) to the ban list
4419 (mapc
4420 (lambda (mask)
4421 (unless (member (cons whoset mask) erc-channel-banlist)
4422 (setq erc-channel-banlist
4423 (cons (cons whoset mask) erc-channel-banlist))))
4424 (cdr (split-string mode))))))))))
4425 nil)
4427 ;; used for the banlist cmds
4428 (defun erc-group-list (list n)
4429 "Group LIST into sublists of length N."
4430 (cond ((null list) nil)
4431 ((null (nthcdr n list)) (list list))
4432 (t (cons (erc-subseq list 0 n) (erc-group-list (nthcdr n list) n)))))
4435 ;;; MOTD numreplies
4437 (defun erc-handle-login ()
4438 "Handle the logging in process of connection."
4439 (unless erc-logged-in
4440 (setq erc-logged-in t)
4441 (message "Logging in as \'%s\'... done" (erc-current-nick))
4442 ;; execute a startup script
4443 (let ((f (erc-select-startup-file)))
4444 (when f
4445 (erc-load-script f)))))
4447 (defun erc-connection-established (proc parsed)
4448 "Run just after connection.
4450 Set user modes and run `erc-after-connect' hook."
4451 (with-current-buffer (process-buffer proc)
4452 (unless erc-server-connected ; only once per session
4453 (let ((server (or erc-server-announced-name
4454 (erc-response.sender parsed)))
4455 (nick (car (erc-response.command-args parsed)))
4456 (buffer (process-buffer proc)))
4457 (setq erc-server-connected t)
4458 (erc-update-mode-line)
4459 (erc-set-initial-user-mode nick buffer)
4460 (erc-server-setup-periodical-ping buffer)
4461 (run-hook-with-args 'erc-after-connect server nick)))))
4463 (defun erc-set-initial-user-mode (nick buffer)
4464 "If `erc-user-mode' is non-nil for NICK, set the user modes.
4465 The server buffer is given by BUFFER."
4466 (with-current-buffer buffer
4467 (when erc-user-mode
4468 (let ((mode (if (functionp erc-user-mode)
4469 (funcall erc-user-mode)
4470 erc-user-mode)))
4471 (when (stringp mode)
4472 (erc-log (format "changing mode for %s to %s" nick mode))
4473 (erc-server-send (format "MODE %s %s" nick mode)))))))
4475 (defun erc-display-error-notice (parsed string)
4476 "Display STRING as an error notice.
4478 See also `erc-display-message'."
4479 (erc-display-message
4480 parsed '(notice error) 'active string))
4482 (defun erc-process-ctcp-query (proc parsed nick login host)
4483 ;; FIXME: This needs a proper docstring -- Lawrence 2004-01-08
4484 "Process a CTCP query."
4485 (let ((queries (delete "" (split-string (erc-response.contents parsed)
4486 "\C-a"))))
4487 (if (> (length queries) 4)
4488 (erc-display-message
4489 parsed (list 'notice 'error) proc 'ctcp-too-many)
4490 (if (= 0 (length queries))
4491 (erc-display-message
4492 parsed (list 'notice 'error) proc
4493 'ctcp-empty ?n nick)
4494 (while queries
4495 (let* ((type (upcase (car (split-string (car queries)))))
4496 (hook (intern-soft (concat "erc-ctcp-query-" type "-hook"))))
4497 (if (and hook (boundp hook))
4498 (if (string-equal type "ACTION")
4499 (run-hook-with-args-until-success
4500 hook proc parsed nick login host
4501 (car (erc-response.command-args parsed))
4502 (car queries))
4503 (when erc-paranoid
4504 (if (erc-current-nick-p
4505 (car (erc-response.command-args parsed)))
4506 (erc-display-message
4507 parsed 'error 'active 'ctcp-request
4508 ?n nick ?u login ?h host ?r (car queries))
4509 (erc-display-message
4510 parsed 'error 'active 'ctcp-request-to
4511 ?n nick ?u login ?h host ?r (car queries)
4512 ?t (car (erc-response.command-args parsed)))))
4513 (run-hook-with-args-until-success
4514 hook proc nick login host
4515 (car (erc-response.command-args parsed))
4516 (car queries)))
4517 (erc-display-message
4518 parsed (list 'notice 'error) proc
4519 'undefined-ctcp)))
4520 (setq queries (cdr queries)))))))
4522 (defvar erc-ctcp-query-ACTION-hook '(erc-ctcp-query-ACTION))
4524 (defun erc-ctcp-query-ACTION (proc parsed nick login host to msg)
4525 "Respond to a CTCP ACTION query."
4526 (when (string-match "^ACTION\\s-\\(.*\\)\\s-*$" msg)
4527 (let ((s (match-string 1 msg))
4528 (buf (or (erc-get-buffer to proc)
4529 (erc-get-buffer nick proc)
4530 (process-buffer proc))))
4531 (erc-display-message
4532 parsed 'action buf
4533 'ACTION ?n nick ?u login ?h host ?a s))))
4535 (defvar erc-ctcp-query-CLIENTINFO-hook '(erc-ctcp-query-CLIENTINFO))
4537 (defun erc-ctcp-query-CLIENTINFO (_proc nick _login _host _to msg)
4538 "Respond to a CTCP CLIENTINFO query."
4539 (when (string-match "^CLIENTINFO\\(\\s-*\\|\\s-+.*\\)$" msg)
4540 (let ((s (erc-client-info (erc-trim-string (match-string 1 msg)))))
4541 (unless erc-disable-ctcp-replies
4542 (erc-send-ctcp-notice nick (format "CLIENTINFO %s" s)))))
4543 nil)
4545 (defvar erc-ctcp-query-ECHO-hook '(erc-ctcp-query-ECHO))
4546 (defun erc-ctcp-query-ECHO (_proc nick _login _host _to msg)
4547 "Respond to a CTCP ECHO query."
4548 (when (string-match "^ECHO\\s-+\\(.*\\)\\s-*$" msg)
4549 (let ((s (match-string 1 msg)))
4550 (unless erc-disable-ctcp-replies
4551 (erc-send-ctcp-notice nick (format "ECHO %s" s)))))
4552 nil)
4554 (defvar erc-ctcp-query-FINGER-hook '(erc-ctcp-query-FINGER))
4555 (defun erc-ctcp-query-FINGER (_proc nick _login _host _to _msg)
4556 "Respond to a CTCP FINGER query."
4557 (unless erc-disable-ctcp-replies
4558 (let ((s (if erc-anonymous-login
4559 (format "FINGER I'm %s." (erc-current-nick))
4560 (format "FINGER %s (%s@%s)."
4561 (user-full-name)
4562 (user-login-name)
4563 (system-name))))
4564 (ns (erc-time-diff erc-server-last-sent-time (erc-current-time))))
4565 (when (> ns 0)
4566 (setq s (concat s " Idle for " (erc-sec-to-time ns))))
4567 (erc-send-ctcp-notice nick s)))
4568 nil)
4570 (defvar erc-ctcp-query-PING-hook '(erc-ctcp-query-PING))
4571 (defun erc-ctcp-query-PING (_proc nick _login _host _to msg)
4572 "Respond to a CTCP PING query."
4573 (when (string-match "^PING\\s-+\\(.*\\)" msg)
4574 (unless erc-disable-ctcp-replies
4575 (let ((arg (match-string 1 msg)))
4576 (erc-send-ctcp-notice nick (format "PING %s" arg)))))
4577 nil)
4579 (defvar erc-ctcp-query-TIME-hook '(erc-ctcp-query-TIME))
4580 (defun erc-ctcp-query-TIME (_proc nick _login _host _to _msg)
4581 "Respond to a CTCP TIME query."
4582 (unless erc-disable-ctcp-replies
4583 (erc-send-ctcp-notice nick (format "TIME %s" (current-time-string))))
4584 nil)
4586 (defvar erc-ctcp-query-USERINFO-hook '(erc-ctcp-query-USERINFO))
4587 (defun erc-ctcp-query-USERINFO (_proc nick _login _host _to _msg)
4588 "Respond to a CTCP USERINFO query."
4589 (unless erc-disable-ctcp-replies
4590 (erc-send-ctcp-notice nick (format "USERINFO %s" erc-user-information)))
4591 nil)
4593 (defvar erc-ctcp-query-VERSION-hook '(erc-ctcp-query-VERSION))
4594 (defun erc-ctcp-query-VERSION (_proc nick _login _host _to _msg)
4595 "Respond to a CTCP VERSION query."
4596 (unless erc-disable-ctcp-replies
4597 (erc-send-ctcp-notice
4598 nick (format
4599 "VERSION \C-bERC\C-b - an IRC client for Emacs %s (\C-b%s\C-b)"
4600 emacs-version
4601 erc-official-location)))
4602 nil)
4604 (defun erc-process-ctcp-reply (proc parsed nick login host msg)
4605 "Process MSG as a CTCP reply."
4606 (let* ((type (car (split-string msg)))
4607 (hook (intern (concat "erc-ctcp-reply-" type "-hook"))))
4608 (if (boundp hook)
4609 (run-hook-with-args-until-success
4610 hook proc nick login host
4611 (car (erc-response.command-args parsed)) msg)
4612 (erc-display-message
4613 parsed 'notice 'active
4614 'CTCP-UNKNOWN ?n nick ?u login ?h host ?m msg))))
4616 (defvar erc-ctcp-reply-ECHO-hook '(erc-ctcp-reply-ECHO))
4617 (defun erc-ctcp-reply-ECHO (_proc nick _login _host _to msg)
4618 "Handle a CTCP ECHO reply."
4619 (when (string-match "^ECHO\\s-+\\(.*\\)\\s-*$" msg)
4620 (let ((message (match-string 1 msg)))
4621 (erc-display-message
4622 nil '(notice action) 'active
4623 'CTCP-ECHO ?n nick ?m message)))
4624 nil)
4626 (defvar erc-ctcp-reply-CLIENTINFO-hook '(erc-ctcp-reply-CLIENTINFO))
4627 (defun erc-ctcp-reply-CLIENTINFO (_proc nick _login _host _to msg)
4628 "Handle a CTCP CLIENTINFO reply."
4629 (when (string-match "^CLIENTINFO\\s-+\\(.*\\)\\s-*$" msg)
4630 (let ((message (match-string 1 msg)))
4631 (erc-display-message
4632 nil 'notice 'active
4633 'CTCP-CLIENTINFO ?n nick ?m message)))
4634 nil)
4636 (defvar erc-ctcp-reply-FINGER-hook '(erc-ctcp-reply-FINGER))
4637 (defun erc-ctcp-reply-FINGER (_proc nick _login _host _to msg)
4638 "Handle a CTCP FINGER reply."
4639 (when (string-match "^FINGER\\s-+\\(.*\\)\\s-*$" msg)
4640 (let ((message (match-string 1 msg)))
4641 (erc-display-message
4642 nil 'notice 'active
4643 'CTCP-FINGER ?n nick ?m message)))
4644 nil)
4646 (defvar erc-ctcp-reply-PING-hook '(erc-ctcp-reply-PING))
4647 (defun erc-ctcp-reply-PING (_proc nick _login _host _to msg)
4648 "Handle a CTCP PING reply."
4649 (if (not (string-match "^PING\\s-+\\([0-9.]+\\)" msg))
4651 (let ((time (match-string 1 msg)))
4652 (condition-case nil
4653 (let ((delta (erc-time-diff (string-to-number time)
4654 (erc-current-time))))
4655 (erc-display-message
4656 nil 'notice 'active
4657 'CTCP-PING ?n nick
4658 ?t (erc-sec-to-time delta)))
4659 (range-error
4660 (erc-display-message
4661 nil 'error 'active
4662 'bad-ping-response ?n nick ?t time))))))
4664 (defvar erc-ctcp-reply-TIME-hook '(erc-ctcp-reply-TIME))
4665 (defun erc-ctcp-reply-TIME (_proc nick _login _host _to msg)
4666 "Handle a CTCP TIME reply."
4667 (when (string-match "^TIME\\s-+\\(.*\\)\\s-*$" msg)
4668 (let ((message (match-string 1 msg)))
4669 (erc-display-message
4670 nil 'notice 'active
4671 'CTCP-TIME ?n nick ?m message)))
4672 nil)
4674 (defvar erc-ctcp-reply-VERSION-hook '(erc-ctcp-reply-VERSION))
4675 (defun erc-ctcp-reply-VERSION (_proc nick _login _host _to msg)
4676 "Handle a CTCP VERSION reply."
4677 (when (string-match "^VERSION\\s-+\\(.*\\)\\s-*$" msg)
4678 (let ((message (match-string 1 msg)))
4679 (erc-display-message
4680 nil 'notice 'active
4681 'CTCP-VERSION ?n nick ?m message)))
4682 nil)
4684 (defun erc-process-away (proc away-p)
4685 "Toggle the away status of the user depending on the value of AWAY-P.
4687 If nil, set the user as away.
4688 If non-nil, return from being away."
4689 (let ((sessionbuf (process-buffer proc)))
4690 (when sessionbuf
4691 (with-current-buffer sessionbuf
4692 (when erc-away-nickname
4693 (erc-log (format "erc-process-away: away-nick: %s, away-p: %s"
4694 erc-away-nickname away-p))
4695 (erc-cmd-NICK (if away-p
4696 erc-away-nickname
4697 erc-nick)))
4698 (cond
4699 (away-p
4700 (setq erc-away (current-time)))
4702 (let ((away-time erc-away))
4703 ;; away must be set to NIL BEFORE sending anything to prevent
4704 ;; an infinite recursion
4705 (setq erc-away nil)
4706 (with-current-buffer (erc-active-buffer)
4707 (when erc-public-away-p
4708 (erc-send-action
4709 (erc-default-target)
4710 (if away-time
4711 (format "is back (gone for %s)"
4712 (erc-sec-to-time
4713 (erc-time-diff
4714 (erc-emacs-time-to-erc-time away-time)
4715 (erc-current-time))))
4716 "is back")))))))))
4717 (erc-update-mode-line)))
4719 ;;;; List of channel members handling
4721 (defun erc-channel-begin-receiving-names ()
4722 "Internal function.
4724 Used when a channel names list is about to be received. Should
4725 be called with the current buffer set to the channel buffer.
4727 See also `erc-channel-end-receiving-names'."
4728 (setq erc-channel-new-member-names (make-hash-table :test 'equal)))
4730 (defun erc-channel-end-receiving-names ()
4731 "Internal function.
4733 Used to fix `erc-channel-users' after a channel names list has been
4734 received. Should be called with the current buffer set to the
4735 channel buffer.
4737 See also `erc-channel-begin-receiving-names'."
4738 (maphash (lambda (nick _user)
4739 (if (null (gethash nick erc-channel-new-member-names))
4740 (erc-remove-channel-user nick)))
4741 erc-channel-users)
4742 (setq erc-channel-new-member-names nil))
4744 (defun erc-parse-prefix ()
4745 "Return an alist of valid prefix character types and their representations.
4746 Example: (operator) o => @, (voiced) v => +."
4747 (let ((str (or (cdr (assoc "PREFIX" (erc-with-server-buffer
4748 erc-server-parameters)))
4749 ;; provide a sane default
4750 "(qaohv)~&@%+"))
4751 types chars)
4752 (when (string-match "^(\\([^)]+\\))\\(.+\\)$" str)
4753 (setq types (match-string 1 str)
4754 chars (match-string 2 str))
4755 (let ((len (min (length types) (length chars)))
4756 (i 0)
4757 (alist nil))
4758 (while (< i len)
4759 (setq alist (cons (cons (elt types i) (elt chars i))
4760 alist))
4761 (setq i (1+ i)))
4762 alist))))
4764 (defun erc-channel-receive-names (names-string)
4765 "This function is for internal use only.
4767 Update `erc-channel-users' according to NAMES-STRING.
4768 NAMES-STRING is a string listing some of the names on the
4769 channel."
4770 (let* ((prefix (erc-parse-prefix))
4771 (voice-ch (cdr (assq ?v prefix)))
4772 (op-ch (cdr (assq ?o prefix)))
4773 (hop-ch (cdr (assq ?h prefix)))
4774 (adm-ch (cdr (assq ?a prefix)))
4775 (own-ch (cdr (assq ?q prefix)))
4776 (names (delete "" (split-string names-string)))
4777 name op voice halfop admin owner)
4778 (let ((erc-channel-members-changed-hook nil))
4779 (dolist (item names)
4780 (let ((updatep t)
4781 (ch (aref item 0)))
4782 (setq name item op 'off voice 'off halfop 'off admin 'off owner 'off)
4783 (if (rassq ch prefix)
4784 (if (= (length item) 1)
4785 (setq updatep nil)
4786 (setq name (substring item 1))
4787 (setf (pcase ch
4788 ((pred (eq voice-ch)) voice)
4789 ((pred (eq hop-ch)) halfop)
4790 ((pred (eq op-ch)) op)
4791 ((pred (eq adm-ch)) admin)
4792 ((pred (eq own-ch)) owner)
4793 (_ (error "Unknown prefix char `%S'" ch) voice))
4794 'on)))
4795 (when updatep
4796 (puthash (erc-downcase name) t
4797 erc-channel-new-member-names)
4798 (erc-update-current-channel-member
4799 name name t voice halfop op admin owner)))))
4800 (run-hooks 'erc-channel-members-changed-hook)))
4803 (defcustom erc-channel-members-changed-hook nil
4804 "This hook is called every time the variable `channel-members' changes.
4805 The buffer where the change happened is current while this hook is called."
4806 :group 'erc-hooks
4807 :type 'hook)
4809 (defun erc-update-user-nick (nick &optional new-nick
4810 host login full-name info)
4811 "Update the stored user information for the user with nickname NICK.
4813 See also: `erc-update-user'."
4814 (erc-update-user (erc-get-server-user nick) new-nick
4815 host login full-name info))
4817 (defun erc-update-user (user &optional new-nick
4818 host login full-name info)
4819 "Update user info for USER. USER must be an erc-server-user
4820 struct. Any of NEW-NICK, HOST, LOGIN, FULL-NAME, INFO which are
4821 non-nil and not equal to the existing values for USER are used to
4822 replace the stored values in USER.
4824 If, and only if, a change is made,
4825 `erc-channel-members-changed-hook' is run for each channel for
4826 which USER is a member, and t is returned."
4827 (let (changed)
4828 (when user
4829 (when (and new-nick
4830 (not (equal (erc-server-user-nickname user)
4831 new-nick)))
4832 (setq changed t)
4833 (erc-change-user-nickname user new-nick))
4834 (when (and host
4835 (not (equal (erc-server-user-host user) host)))
4836 (setq changed t)
4837 (setf (erc-server-user-host user) host))
4838 (when (and login
4839 (not (equal (erc-server-user-login user) login)))
4840 (setq changed t)
4841 (setf (erc-server-user-login user) login))
4842 (when (and full-name
4843 (not (equal (erc-server-user-full-name user)
4844 full-name)))
4845 (setq changed t)
4846 (setf (erc-server-user-full-name user) full-name))
4847 (when (and info
4848 (not (equal (erc-server-user-info user) info)))
4849 (setq changed t)
4850 (setf (erc-server-user-info user) info))
4851 (if changed
4852 (dolist (buf (erc-server-user-buffers user))
4853 (if (buffer-live-p buf)
4854 (with-current-buffer buf
4855 (run-hooks 'erc-channel-members-changed-hook))))))
4856 changed))
4858 (defun erc-update-current-channel-member
4859 (nick new-nick &optional add voice halfop op admin owner host login full-name info
4860 update-message-time)
4861 "Update the stored user information for the user with nickname NICK.
4862 `erc-update-user' is called to handle changes to nickname,
4863 HOST, LOGIN, FULL-NAME, and INFO. If VOICE HALFOP OP ADMIN or OWNER
4864 are non-nil, they must be equal to either `on' or `off', in which
4865 case the status of the user in the current channel is changed accordingly.
4866 If UPDATE-MESSAGE-TIME is non-nil, the last-message-time of the user
4867 in the current channel is set to (current-time).
4869 If ADD is non-nil, the user will be added with the specified
4870 information if it is not already present in the user or channel
4871 lists.
4873 If, and only if, changes are made, or the user is added,
4874 `erc-channel-members-updated-hook' is run, and t is returned.
4876 See also: `erc-update-user' and `erc-update-channel-member'."
4877 (let* (changed user-changed
4878 (channel-data (erc-get-channel-user nick))
4879 (cuser (cdr channel-data))
4880 (user (if channel-data (car channel-data)
4881 (erc-get-server-user nick))))
4882 (if cuser
4883 (progn
4884 (erc-log (format "update-member: user = %S, cuser = %S" user cuser))
4885 (when (and voice
4886 (not (eq (erc-channel-user-voice cuser) voice)))
4887 (setq changed t)
4888 (setf (erc-channel-user-voice cuser)
4889 (cond ((eq voice 'on) t)
4890 ((eq voice 'off) nil)
4891 (t voice))))
4892 (when (and halfop
4893 (not (eq (erc-channel-user-halfop cuser) halfop)))
4894 (setq changed t)
4895 (setf (erc-channel-user-halfop cuser)
4896 (cond ((eq halfop 'on) t)
4897 ((eq halfop 'off) nil)
4898 (t halfop))))
4899 (when (and op
4900 (not (eq (erc-channel-user-op cuser) op)))
4901 (setq changed t)
4902 (setf (erc-channel-user-op cuser)
4903 (cond ((eq op 'on) t)
4904 ((eq op 'off) nil)
4905 (t op))))
4906 (when (and admin
4907 (not (eq (erc-channel-user-admin cuser) admin)))
4908 (setq changed t)
4909 (setf (erc-channel-user-admin cuser)
4910 (cond ((eq admin 'on) t)
4911 ((eq admin 'off) nil)
4912 (t admin))))
4913 (when (and owner
4914 (not (eq (erc-channel-user-owner cuser) owner)))
4915 (setq changed t)
4916 (setf (erc-channel-user-owner cuser)
4917 (cond ((eq owner 'on) t)
4918 ((eq owner 'off) nil)
4919 (t owner))))
4920 (when update-message-time
4921 (setf (erc-channel-user-last-message-time cuser) (current-time)))
4922 (setq user-changed
4923 (erc-update-user user new-nick
4924 host login full-name info)))
4925 (when add
4926 (if (null user)
4927 (progn
4928 (setq user (make-erc-server-user
4929 :nickname nick
4930 :host host
4931 :full-name full-name
4932 :login login
4933 :info info
4934 :buffers (list (current-buffer))))
4935 (erc-add-server-user nick user))
4936 (setf (erc-server-user-buffers user)
4937 (cons (current-buffer)
4938 (erc-server-user-buffers user))))
4939 (setq cuser (make-erc-channel-user
4940 :voice (cond ((eq voice 'on) t)
4941 ((eq voice 'off) nil)
4942 (t voice))
4943 :halfop (cond ((eq halfop 'on) t)
4944 ((eq halfop 'off) nil)
4945 (t halfop))
4946 :op (cond ((eq op 'on) t)
4947 ((eq op 'off) nil)
4948 (t op))
4949 :admin (cond ((eq admin 'on) t)
4950 ((eq admin 'off) nil)
4951 (t admin))
4952 :owner (cond ((eq owner 'on) t)
4953 ((eq owner 'off) nil)
4954 (t owner))
4955 :last-message-time
4956 (if update-message-time (current-time))))
4957 (puthash (erc-downcase nick) (cons user cuser)
4958 erc-channel-users)
4959 (setq changed t)))
4960 (when (and changed (null user-changed))
4961 (run-hooks 'erc-channel-members-changed-hook))
4962 (or changed user-changed add)))
4964 (defun erc-update-channel-member (channel nick new-nick
4965 &optional add voice halfop op admin owner host login
4966 full-name info update-message-time)
4967 "Update user and channel information for the user with
4968 nickname NICK in channel CHANNEL.
4970 See also: `erc-update-current-channel-member'."
4971 (erc-with-buffer
4972 (channel)
4973 (erc-update-current-channel-member nick new-nick add voice halfop op admin owner host
4974 login full-name info
4975 update-message-time)))
4977 (defun erc-remove-current-channel-member (nick)
4978 "Remove NICK from current channel membership list.
4979 Runs `erc-channel-members-changed-hook'."
4980 (let ((channel-data (erc-get-channel-user nick)))
4981 (when channel-data
4982 (erc-remove-channel-user nick)
4983 (run-hooks 'erc-channel-members-changed-hook))))
4985 (defun erc-remove-channel-member (channel nick)
4986 "Remove NICK from CHANNEL's membership list.
4988 See also `erc-remove-current-channel-member'."
4989 (erc-with-buffer
4990 (channel)
4991 (erc-remove-current-channel-member nick)))
4993 (defun erc-update-channel-topic (channel topic &optional modify)
4994 "Find a buffer for CHANNEL and set the TOPIC for it.
4996 If optional MODIFY is 'append or 'prepend, then append or prepend the
4997 TOPIC string to the current topic."
4998 (erc-with-buffer (channel)
4999 (cond ((eq modify 'append)
5000 (setq erc-channel-topic (concat erc-channel-topic topic)))
5001 ((eq modify 'prepend)
5002 (setq erc-channel-topic (concat topic erc-channel-topic)))
5003 (t (setq erc-channel-topic topic)))
5004 (erc-update-mode-line-buffer (current-buffer))))
5006 (defun erc-set-modes (tgt mode-string)
5007 "Set the modes for the TGT provided as MODE-STRING."
5008 (let* ((modes (erc-parse-modes mode-string))
5009 (add-modes (nth 0 modes))
5010 ;; list of triples: (mode-char 'on/'off argument)
5011 (arg-modes (nth 2 modes)))
5012 (cond ((erc-channel-p tgt); channel modes
5013 (let ((buf (and erc-server-process
5014 (erc-get-buffer tgt erc-server-process))))
5015 (when buf
5016 (with-current-buffer buf
5017 (setq erc-channel-modes add-modes)
5018 (setq erc-channel-user-limit nil)
5019 (setq erc-channel-key nil)
5020 (while arg-modes
5021 (let ((mode (nth 0 (car arg-modes)))
5022 (onoff (nth 1 (car arg-modes)))
5023 (arg (nth 2 (car arg-modes))))
5024 (cond ((string-match "^[Ll]" mode)
5025 (erc-update-channel-limit tgt onoff arg))
5026 ((string-match "^[Kk]" mode)
5027 (erc-update-channel-key tgt onoff arg))
5028 (t nil)))
5029 (setq arg-modes (cdr arg-modes)))
5030 (erc-update-mode-line-buffer buf)))))
5031 ;; we do not keep our nick's modes yet
5032 ;;(t (setq erc-user-modes add-modes))
5036 (defun erc-sort-strings (list-of-strings)
5037 "Sort LIST-OF-STRINGS in lexicographic order.
5039 Side-effect free."
5040 (sort (copy-sequence list-of-strings) 'string<))
5042 (defun erc-parse-modes (mode-string)
5043 "Parse MODE-STRING into a list.
5045 Returns a list of three elements:
5047 (ADD-MODES REMOVE-MODES ARG-MODES).
5049 The add-modes and remove-modes are lists of single-character strings
5050 for modes without parameters to add and remove respectively. The
5051 arg-modes is a list of triples of the form:
5053 (MODE-CHAR ON/OFF ARGUMENT)."
5054 (if (string-match "^\\s-*\\(\\S-+\\)\\(\\s-.*$\\|$\\)" mode-string)
5055 (let ((chars (mapcar 'char-to-string (match-string 1 mode-string)))
5056 ;; arguments in channel modes
5057 (args-str (match-string 2 mode-string))
5058 (args nil)
5059 (add-modes nil)
5060 (remove-modes nil)
5061 (arg-modes nil); list of triples: (mode-char 'on/'off argument)
5062 (add-p t))
5063 ;; make the argument list
5064 (while (string-match "^\\s-*\\(\\S-+\\)\\(\\s-+.*$\\|$\\)" args-str)
5065 (setq args (cons (match-string 1 args-str) args))
5066 (setq args-str (match-string 2 args-str)))
5067 (setq args (nreverse args))
5068 ;; collect what modes changed, and match them with arguments
5069 (while chars
5070 (cond ((string= (car chars) "+") (setq add-p t))
5071 ((string= (car chars) "-") (setq add-p nil))
5072 ((string-match "^[qaovhbQAOVHB]" (car chars))
5073 (setq arg-modes (cons (list (car chars)
5074 (if add-p 'on 'off)
5075 (if args (car args) nil))
5076 arg-modes))
5077 (if args (setq args (cdr args))))
5078 ((string-match "^[LlKk]" (car chars))
5079 (setq arg-modes (cons (list (car chars)
5080 (if add-p 'on 'off)
5081 (if (and add-p args)
5082 (car args) nil))
5083 arg-modes))
5084 (if (and add-p args) (setq args (cdr args))))
5085 (add-p (setq add-modes (cons (car chars) add-modes)))
5086 (t (setq remove-modes (cons (car chars) remove-modes))))
5087 (setq chars (cdr chars)))
5088 (setq add-modes (nreverse add-modes))
5089 (setq remove-modes (nreverse remove-modes))
5090 (setq arg-modes (nreverse arg-modes))
5091 (list add-modes remove-modes arg-modes))
5092 nil))
5094 (defun erc-update-modes (tgt mode-string &optional _nick _host _login)
5095 "Update the mode information for TGT, provided as MODE-STRING.
5096 Optional arguments: NICK, HOST and LOGIN - the attributes of the
5097 person who changed the modes."
5098 ;; FIXME: neither of nick, host, and login are used!
5099 (let* ((modes (erc-parse-modes mode-string))
5100 (add-modes (nth 0 modes))
5101 (remove-modes (nth 1 modes))
5102 ;; list of triples: (mode-char 'on/'off argument)
5103 (arg-modes (nth 2 modes)))
5104 ;; now parse the modes changes and do the updates
5105 (cond ((erc-channel-p tgt); channel modes
5106 (let ((buf (and erc-server-process
5107 (erc-get-buffer tgt erc-server-process))))
5108 (when buf
5109 ;; FIXME! This used to have an original buffer
5110 ;; variable, but it never switched back to the original
5111 ;; buffer. Is this wanted behavior?
5112 (set-buffer buf)
5113 (if (not (boundp 'erc-channel-modes))
5114 (setq erc-channel-modes nil))
5115 (while remove-modes
5116 (setq erc-channel-modes (delete (car remove-modes)
5117 erc-channel-modes)
5118 remove-modes (cdr remove-modes)))
5119 (while add-modes
5120 (setq erc-channel-modes (cons (car add-modes)
5121 erc-channel-modes)
5122 add-modes (cdr add-modes)))
5123 (setq erc-channel-modes (erc-sort-strings erc-channel-modes))
5124 (while arg-modes
5125 (let ((mode (nth 0 (car arg-modes)))
5126 (onoff (nth 1 (car arg-modes)))
5127 (arg (nth 2 (car arg-modes))))
5128 (cond ((string-match "^[Vv]" mode)
5129 (erc-update-channel-member tgt arg arg nil onoff))
5130 ((string-match "^[hH]" mode)
5131 (erc-update-channel-member tgt arg arg nil nil onoff))
5132 ((string-match "^[oO]" mode)
5133 (erc-update-channel-member tgt arg arg nil nil nil onoff))
5134 ((string-match "^[aA]" mode)
5135 (erc-update-channel-member tgt arg arg nil nil nil nil onoff))
5136 ((string-match "^[qQ]" mode)
5137 (erc-update-channel-member tgt arg arg nil nil nil nil nil onoff))
5138 ((string-match "^[Ll]" mode)
5139 (erc-update-channel-limit tgt onoff arg))
5140 ((string-match "^[Kk]" mode)
5141 (erc-update-channel-key tgt onoff arg))
5142 (t nil)); only ops are tracked now
5143 (setq arg-modes (cdr arg-modes))))
5144 (erc-update-mode-line buf))))
5145 ;; nick modes - ignored at this point
5146 (t nil))))
5148 (defun erc-update-channel-limit (channel onoff n)
5149 ;; FIXME: what does ONOFF actually do? -- Lawrence 2004-01-08
5150 "Update CHANNEL's user limit to N."
5151 (if (or (not (eq onoff 'on))
5152 (and (stringp n) (string-match "^[0-9]+$" n)))
5153 (erc-with-buffer
5154 (channel)
5155 (cond ((eq onoff 'on) (setq erc-channel-user-limit (string-to-number n)))
5156 (t (setq erc-channel-user-limit nil))))))
5158 (defun erc-update-channel-key (channel onoff key)
5159 "Update CHANNEL's key to KEY if ONOFF is 'on or to nil if it's 'off."
5160 (erc-with-buffer
5161 (channel)
5162 (cond ((eq onoff 'on) (setq erc-channel-key key))
5163 (t (setq erc-channel-key nil)))))
5165 (defun erc-handle-user-status-change (type nlh &optional l)
5166 "Handle changes in any user's status.
5168 So far, only nick change is handled.
5170 Generally, the TYPE argument is a symbol describing the change type, NLH is
5171 a list containing the original nickname, login name and hostname for the user,
5172 and L is a list containing additional TYPE-specific arguments.
5174 So far the following TYPE/L pairs are supported:
5176 Event TYPE L
5178 nickname change 'nick (NEW-NICK)"
5179 (erc-log (format "user-change: type: %S nlh: %S l: %S" type nlh l))
5180 (cond
5181 ;; nickname change
5182 ((equal type 'nick)
5185 nil)))
5187 (defun erc-highlight-notice (s)
5188 "Highlight notice message S and return it.
5189 See also variable `erc-notice-highlight-type'."
5190 (cond
5191 ((eq erc-notice-highlight-type 'prefix)
5192 (erc-put-text-property 0 (length erc-notice-prefix)
5193 'face 'erc-notice-face s)
5195 ((eq erc-notice-highlight-type 'all)
5196 (erc-put-text-property 0 (length s) 'face 'erc-notice-face s)
5198 (t s)))
5200 (defun erc-make-notice (message)
5201 "Notify the user of MESSAGE."
5202 (when erc-minibuffer-notice
5203 (message "%s" message))
5204 (erc-highlight-notice (concat erc-notice-prefix message)))
5206 (defun erc-highlight-error (s)
5207 "Highlight error message S and return it."
5208 (erc-put-text-property 0 (length s) 'face 'erc-error-face s)
5211 (defun erc-put-text-property (start end property value &optional object)
5212 "Set text-property for an object (usually a string).
5213 START and END define the characters covered.
5214 PROPERTY is the text-property set, usually the symbol `face'.
5215 VALUE is the value for the text-property, usually a face symbol such as
5216 the face `bold' or `erc-pal-face'.
5217 OBJECT is a string which will be modified and returned.
5218 OBJECT is modified without being copied first.
5220 You can redefine or `defadvice' this function in order to add
5221 EmacsSpeak support."
5222 (put-text-property start end property value object))
5224 (defun erc-list (thing)
5225 "Return THING if THING is a list, or a list with THING as its element."
5226 (if (listp thing)
5227 thing
5228 (list thing)))
5230 (defun erc-parse-user (string)
5231 "Parse STRING as a user specification (nick!login@host).
5233 Return a list of the three separate tokens."
5234 (cond
5235 ((string-match "^\\([^!\n]*\\)!\\([^@\n]*\\)@\\(.*\\)$" string)
5236 (list (match-string 1 string)
5237 (match-string 2 string)
5238 (match-string 3 string)))
5239 ;; Some bogus bouncers send Nick!(null), try to live with that.
5240 ((string-match "^\\([^!\n]*\\)!\\(.*\\)$" string)
5241 (list (match-string 1 string)
5243 (match-string 2 string)))
5245 (list string "" ""))))
5247 (defun erc-extract-nick (string)
5248 "Return the nick corresponding to a user specification STRING.
5250 See also `erc-parse-user'."
5251 (car (erc-parse-user string)))
5253 (defun erc-put-text-properties (start end properties
5254 &optional object value-list)
5255 "Set text-properties for OBJECT.
5257 START and END describe positions in OBJECT.
5258 If VALUE-LIST is nil, set each property in PROPERTIES to t, else set
5259 each property to the corresponding value in VALUE-LIST."
5260 (unless value-list
5261 (setq value-list (mapcar (lambda (_x) t)
5262 properties)))
5263 (while (and properties value-list)
5264 (erc-put-text-property
5265 start end (pop properties) (pop value-list) object)))
5267 ;;; Input area handling:
5269 (defun erc-beg-of-input-line ()
5270 "Return the value of `point' at the beginning of the input line.
5272 Specifically, return the position of `erc-insert-marker'."
5273 (or (and (boundp 'erc-insert-marker)
5274 (markerp erc-insert-marker))
5275 (error "erc-insert-marker has no value, please report a bug"))
5276 (marker-position erc-insert-marker))
5278 (defun erc-end-of-input-line ()
5279 "Return the value of `point' at the end of the input line."
5280 (point-max))
5282 (defvar erc-last-input-time 0
5283 "Time of last call to `erc-send-current-line'.
5284 If that function has never been called, the value is 0.")
5286 (defcustom erc-accidental-paste-threshold-seconds nil
5287 "Minimum time, in seconds, before sending new lines via IRC.
5288 If the value is a number, `erc-send-current-line' signals an error
5289 if its previous invocation was fewer than this many seconds ago.
5290 This is useful so that if you accidentally enter large amounts of text
5291 into the ERC buffer, that text is not sent to the IRC server.
5293 If the value is nil, `erc-send-current-line' always considers any
5294 submitted line to be intentional."
5295 :group 'erc
5296 :version "24.4"
5297 :type '(choice number (other :tag "disabled" nil)))
5299 (defun erc-send-current-line ()
5300 "Parse current line and send it to IRC."
5301 (interactive)
5302 (let ((now (float-time)))
5303 (if (or (not erc-accidental-paste-threshold-seconds)
5304 (< erc-accidental-paste-threshold-seconds
5305 (- now erc-last-input-time)))
5306 (save-restriction
5307 (widen)
5308 (if (< (point) (erc-beg-of-input-line))
5309 (erc-error "Point is not in the input area")
5310 (let ((inhibit-read-only t)
5311 (str (erc-user-input))
5312 (old-buf (current-buffer)))
5313 (if (and (not (erc-server-buffer-live-p))
5314 (not (erc-command-no-process-p str)))
5315 (erc-error "ERC: No process running")
5316 (erc-set-active-buffer (current-buffer))
5317 ;; Kill the input and the prompt
5318 (delete-region (erc-beg-of-input-line)
5319 (erc-end-of-input-line))
5320 (unwind-protect
5321 (erc-send-input str)
5322 ;; Fix the buffer if the command didn't kill it
5323 (when (buffer-live-p old-buf)
5324 (with-current-buffer old-buf
5325 (save-restriction
5326 (widen)
5327 (goto-char (point-max))
5328 (when (processp erc-server-process)
5329 (set-marker (process-mark erc-server-process) (point)))
5330 (set-marker erc-insert-marker (point))
5331 (let ((buffer-modified (buffer-modified-p)))
5332 (erc-display-prompt)
5333 (set-buffer-modified-p buffer-modified))))))
5335 ;; Only when last hook has been run...
5336 (run-hook-with-args 'erc-send-completed-hook str))))
5337 (setq erc-last-input-time now))
5338 (switch-to-buffer "*ERC Accidental Paste Overflow*")
5339 (lwarn 'erc :warning
5340 "You seem to have accidentally pasted some text!"))))
5342 (defun erc-user-input ()
5343 "Return the input of the user in the current buffer."
5344 (buffer-substring-no-properties
5345 erc-input-marker
5346 (erc-end-of-input-line)))
5348 (defvar erc-command-regexp "^/\\([A-Za-z']+\\)\\(\\s-+.*\\|\\s-*\\)$"
5349 "Regular expression used for matching commands in ERC.")
5351 (defun erc-send-input (input)
5352 "Treat INPUT as typed in by the user. It is assumed that the input
5353 and the prompt is already deleted.
5354 This returns non-nil only if we actually send anything."
5355 ;; Handle different kinds of inputs
5356 (cond
5357 ;; Ignore empty input
5358 ((if erc-send-whitespace-lines
5359 (string= input "")
5360 (string-match "\\`[ \t\r\f\n]*\\'" input))
5361 (when erc-warn-about-blank-lines
5362 (message "Blank line - ignoring...")
5363 (beep))
5364 nil)
5366 (defvar str) ;; FIXME: Make it obey the "erc-" prefix convention.
5367 (let ((str input)
5368 (erc-insert-this t))
5369 (setq erc-send-this t)
5370 (run-hook-with-args 'erc-send-pre-hook input)
5371 (when erc-send-this
5372 (if (or (string-match "\n" str)
5373 (not (string-match erc-command-regexp str)))
5374 (mapc
5375 (lambda (line)
5376 (mapc
5377 (lambda (line)
5378 ;; Insert what has to be inserted for this.
5379 (erc-display-msg line)
5380 (erc-process-input-line (concat line "\n")
5381 (null erc-flood-protect) t))
5382 (or (and erc-flood-protect (erc-split-line line))
5383 (list line))))
5384 (split-string str "\n"))
5385 (erc-process-input-line (concat str "\n") t nil))
5386 t)))))
5388 (defun erc-display-command (line)
5389 (when erc-insert-this
5390 (let ((insert-position (point)))
5391 (unless erc-hide-prompt
5392 (erc-display-prompt nil nil (erc-command-indicator)
5393 (and (erc-command-indicator)
5394 'erc-command-indicator-face)))
5395 (let ((beg (point)))
5396 (insert line)
5397 (erc-put-text-property beg (point)
5398 'face 'erc-command-indicator-face)
5399 (insert "\n"))
5400 (when (processp erc-server-process)
5401 (set-marker (process-mark erc-server-process) (point)))
5402 (set-marker erc-insert-marker (point))
5403 (save-excursion
5404 (save-restriction
5405 (narrow-to-region insert-position (point))
5406 (run-hooks 'erc-send-modify-hook)
5407 (run-hooks 'erc-send-post-hook))))))
5409 (defun erc-display-msg (line)
5410 "Display LINE as a message of the user to the current target at the
5411 current position."
5412 (when erc-insert-this
5413 (let ((insert-position (point)))
5414 (insert (erc-format-my-nick))
5415 (let ((beg (point)))
5416 (insert line)
5417 (erc-put-text-property beg (point)
5418 'face 'erc-input-face))
5419 (insert "\n")
5420 (when (processp erc-server-process)
5421 (set-marker (process-mark erc-server-process) (point)))
5422 (set-marker erc-insert-marker (point))
5423 (save-excursion
5424 (save-restriction
5425 (narrow-to-region insert-position (point))
5426 (run-hooks 'erc-send-modify-hook)
5427 (run-hooks 'erc-send-post-hook))))))
5429 (defun erc-command-symbol (command)
5430 "Return the ERC command symbol for COMMAND if it exists and is bound."
5431 (let ((cmd (intern-soft (format "erc-cmd-%s" (upcase command)))))
5432 (when (fboundp cmd) cmd)))
5434 (defun erc-extract-command-from-line (line)
5435 "Extract command and args from the input LINE.
5436 If no command was given, return nil. If command matches, return a
5437 list of the form: (command args) where both elements are strings."
5438 (when (string-match erc-command-regexp line)
5439 (let* ((cmd (erc-command-symbol (match-string 1 line)))
5440 ;; note: return is nil, we apply this simply for side effects
5441 (_canon-defun (while (and cmd (symbolp (symbol-function cmd)))
5442 (setq cmd (symbol-function cmd))))
5443 (cmd-fun (or cmd #'erc-cmd-default))
5444 (arg (if cmd
5445 (if (get cmd-fun 'do-not-parse-args)
5446 (format "%s" (match-string 2 line))
5447 (delete "" (split-string (erc-trim-string
5448 (match-string 2 line)) " ")))
5449 line)))
5450 (list cmd-fun arg))))
5452 (defun erc-split-multiline-safe (string)
5453 "Split STRING, containing multiple lines and return them in a list.
5454 Do it only for STRING as the complete input, do not carry unfinished
5455 strings over to the next call."
5456 (let ((l ())
5457 (i0 0)
5458 (doit t))
5459 (while doit
5460 (let ((i (string-match "\r?\n" string i0))
5461 (s (substring string i0)))
5462 (cond (i (setq l (cons (substring string i0 i) l))
5463 (setq i0 (match-end 0)))
5464 ((> (length s) 0)
5465 (setq l (cons s l))(setq doit nil))
5466 (t (setq doit nil)))))
5467 (nreverse l)))
5469 ;; nick handling
5471 (defun erc-set-current-nick (nick)
5472 "Set the current nickname to NICK."
5473 (with-current-buffer (if (buffer-live-p (erc-server-buffer))
5474 (erc-server-buffer)
5475 (current-buffer))
5476 (setq erc-server-current-nick nick)))
5478 (defun erc-current-nick ()
5479 "Return the current nickname."
5480 (with-current-buffer (if (buffer-live-p (erc-server-buffer))
5481 (erc-server-buffer)
5482 (current-buffer))
5483 erc-server-current-nick))
5485 (defun erc-current-nick-p (nick)
5486 "Return non-nil if NICK is the current nickname."
5487 (erc-nick-equal-p nick (erc-current-nick)))
5489 (defun erc-nick-equal-p (nick1 nick2)
5490 "Return non-nil if NICK1 and NICK2 are the same.
5492 This matches strings according to the IRC protocol's case convention.
5494 See also `erc-downcase'."
5495 (string= (erc-downcase nick1)
5496 (erc-downcase nick2)))
5498 ;; default target handling
5500 (defun erc-default-target ()
5501 "Return the current default target (as a character string) or nil if none."
5502 (let ((tgt (car erc-default-recipients)))
5503 (cond
5504 ((not tgt) nil)
5505 ((listp tgt) (cdr tgt))
5506 (t tgt))))
5508 (defun erc-add-default-channel (channel)
5509 "Add CHANNEL to the default channel list."
5510 (let ((chl (downcase channel)))
5511 (setq erc-default-recipients
5512 (cons chl erc-default-recipients))))
5514 (defun erc-delete-default-channel (channel &optional buffer)
5515 "Delete CHANNEL from the default channel list."
5516 (with-current-buffer (if (and buffer
5517 (bufferp buffer))
5518 buffer
5519 (current-buffer))
5520 (setq erc-default-recipients (delete (downcase channel)
5521 erc-default-recipients))))
5523 (defun erc-add-query (nickname)
5524 "Add QUERY'd NICKNAME to the default channel list.
5526 The previous default target of QUERY type gets removed."
5527 (let ((d1 (car erc-default-recipients))
5528 (d2 (cdr erc-default-recipients))
5529 (qt (cons 'QUERY (downcase nickname))))
5530 (setq erc-default-recipients (cons qt (if (and (listp d1)
5531 (eq (car d1) 'QUERY))
5533 erc-default-recipients)))))
5535 (defun erc-delete-query ()
5536 "Delete the topmost target if it is a QUERY."
5538 (let ((d1 (car erc-default-recipients))
5539 (d2 (cdr erc-default-recipients)))
5540 (if (and (listp d1)
5541 (eq (car d1) 'QUERY))
5542 (setq erc-default-recipients d2)
5543 (error "Current target is not a QUERY"))))
5545 (defun erc-ignored-user-p (spec)
5546 "Return non-nil if SPEC matches something in `erc-ignore-list'.
5548 Takes a full SPEC of a user in the form \"nick!login@host\", and
5549 matches against all the regexp's in `erc-ignore-list'. If any
5550 match, returns that regexp."
5551 (catch 'found
5552 (dolist (ignored (erc-with-server-buffer erc-ignore-list))
5553 (if (string-match ignored spec)
5554 (throw 'found ignored)))))
5556 (defun erc-ignored-reply-p (msg tgt proc)
5557 ;; FIXME: this docstring needs fixing -- Lawrence 2004-01-08
5558 "Return non-nil if MSG matches something in `erc-ignore-reply-list'.
5560 Takes a message MSG to a channel and returns non-nil if the addressed
5561 user matches any regexp in `erc-ignore-reply-list'."
5562 (let ((target-nick (erc-message-target msg)))
5563 (if (not target-nick)
5565 (erc-with-buffer (tgt proc)
5566 (let ((user (erc-get-server-user target-nick)))
5567 (when user
5568 (erc-list-match erc-ignore-reply-list
5569 (erc-user-spec user))))))))
5571 (defun erc-message-target (msg)
5572 "Return the addressed target in MSG.
5574 The addressed target is the string before the first colon in MSG."
5575 (if (string-match "^\\([^: \n]*\\):" msg)
5576 (match-string 1 msg)
5577 nil))
5579 (defun erc-user-spec (user)
5580 "Create a nick!user@host spec from a user struct."
5581 (let ((nick (erc-server-user-nickname user))
5582 (host (erc-server-user-host user))
5583 (login (erc-server-user-login user)))
5584 (concat (or nick "")
5586 (or login "")
5588 (or host ""))))
5590 (defun erc-list-match (lst str)
5591 "Return non-nil if any regexp in LST matches STR."
5592 (memq nil (mapcar (lambda (regexp)
5593 (not (string-match regexp str)))
5594 lst)))
5596 ;; other "toggles"
5598 (defun erc-toggle-ctcp-autoresponse (&optional arg)
5599 "Toggle automatic CTCP replies (like VERSION and PING).
5601 If ARG is positive, turns CTCP replies on.
5603 If ARG is non-nil and not positive, turns CTCP replies off."
5604 (interactive "P")
5605 (cond ((and (numberp arg) (> arg 0))
5606 (setq erc-disable-ctcp-replies t))
5607 (arg (setq erc-disable-ctcp-replies nil))
5608 (t (setq erc-disable-ctcp-replies (not erc-disable-ctcp-replies))))
5609 (message "ERC CTCP replies are %s" (if erc-disable-ctcp-replies "OFF" "ON")))
5611 (defun erc-toggle-flood-control (&optional arg)
5612 "Toggle use of flood control on sent messages.
5614 If ARG is positive, use flood control.
5615 If ARG is non-nil and not positive, do not use flood control.
5617 See `erc-server-flood-margin' for an explanation of the available
5618 flood control parameters."
5619 (interactive "P")
5620 (cond ((and (numberp arg) (> arg 0))
5621 (setq erc-flood-protect t))
5622 (arg (setq erc-flood-protect nil))
5623 (t (setq erc-flood-protect (not erc-flood-protect))))
5624 (message "ERC flood control is %s"
5625 (cond (erc-flood-protect "ON")
5626 (t "OFF"))))
5628 ;; Some useful channel and nick commands for fast key bindings
5630 (defun erc-invite-only-mode (&optional arg)
5631 "Turn on the invite only mode (+i) for the current channel.
5633 If ARG is non-nil, turn this mode off (-i).
5635 This command is sent even if excess flood is detected."
5636 (interactive "P")
5637 (erc-set-active-buffer (current-buffer))
5638 (let ((tgt (erc-default-target)))
5639 (if (or (not tgt) (not (erc-channel-p tgt)))
5640 (erc-display-message nil 'error (current-buffer) 'no-target)
5641 (erc-load-irc-script-lines
5642 (list (concat "/mode " tgt (if arg " -i" " +i")))
5643 t))))
5645 (defun erc-get-channel-mode-from-keypress (key)
5646 "Read a key sequence and call the corresponding channel mode function.
5647 After doing C-c C-o, type in a channel mode letter.
5649 C-g means quit.
5650 RET lets you type more than one mode at a time.
5651 If \"l\" is pressed, `erc-set-channel-limit' gets called.
5652 If \"k\" is pressed, `erc-set-channel-key' gets called.
5653 Anything else will be sent to `erc-toggle-channel-mode'."
5654 (interactive "kChannel mode (RET to set more than one): ")
5655 (when (featurep 'xemacs)
5656 (setq key (char-to-string (event-to-character (aref key 0)))))
5657 (cond ((equal key "\C-g")
5658 (keyboard-quit))
5659 ((equal key "\C-m")
5660 (erc-insert-mode-command))
5661 ((equal key "l")
5662 (call-interactively 'erc-set-channel-limit))
5663 ((equal key "k")
5664 (call-interactively 'erc-set-channel-key))
5665 (t (erc-toggle-channel-mode key))))
5667 (defun erc-toggle-channel-mode (mode &optional channel)
5668 "Toggle channel MODE.
5670 If CHANNEL is non-nil, toggle MODE for that channel, otherwise use
5671 `erc-default-target'."
5672 (interactive "P")
5673 (erc-set-active-buffer (current-buffer))
5674 (let ((tgt (or channel (erc-default-target))))
5675 (if (or (null tgt) (null (erc-channel-p tgt)))
5676 (erc-display-message nil 'error 'active 'no-target)
5677 (let* ((active (member mode erc-channel-modes))
5678 (newstate (if active "OFF" "ON")))
5679 (erc-log (format "%s: Toggle mode %s %s" tgt mode newstate))
5680 (message "Toggle channel mode %s %s" mode newstate)
5681 (erc-server-send (format "MODE %s %s%s"
5682 tgt (if active "-" "+") mode))))))
5684 (defun erc-insert-mode-command ()
5685 "Insert the line \"/mode <current target> \" at `point'."
5686 (interactive)
5687 (let ((tgt (erc-default-target)))
5688 (if tgt (insert (concat "/mode " tgt " "))
5689 (erc-display-message nil 'error (current-buffer) 'no-target))))
5691 (defun erc-channel-names ()
5692 "Run \"/names #channel\" in the current channel."
5693 (interactive)
5694 (erc-set-active-buffer (current-buffer))
5695 (let ((tgt (erc-default-target)))
5696 (if tgt (erc-load-irc-script-lines (list (concat "/names " tgt)))
5697 (erc-display-message nil 'error (current-buffer) 'no-target))))
5699 (defun erc-remove-text-properties-region (start end &optional object)
5700 "Clears the region (START,END) in OBJECT from all colors, etc."
5701 (interactive "r")
5702 (save-excursion
5703 (let ((inhibit-read-only t))
5704 (set-text-properties start end nil object))))
5705 (put 'erc-remove-text-properties-region 'disabled t)
5707 ;; script execution and startup
5709 (defun erc-find-file (file &optional path)
5710 "Search for a FILE in the filesystem.
5711 First the `default-directory' is searched for FILE, then any directories
5712 specified in the list PATH.
5714 If FILE is found, return the path to it."
5715 (let ((filepath file))
5716 (if (file-readable-p filepath) filepath
5717 (while (and path
5718 (progn (setq filepath (expand-file-name file (car path)))
5719 (not (file-readable-p filepath))))
5720 (setq path (cdr path)))
5721 (if path filepath nil))))
5723 (defun erc-select-startup-file ()
5724 "Select an ERC startup file.
5725 See also `erc-startup-file-list'."
5726 (catch 'found
5727 (dolist (f erc-startup-file-list)
5728 (setq f (convert-standard-filename f))
5729 (when (file-readable-p f)
5730 (throw 'found f)))))
5732 (defun erc-find-script-file (file)
5733 "Search for FILE in `default-directory', and any in `erc-script-path'."
5734 (erc-find-file file erc-script-path))
5736 (defun erc-load-script (file)
5737 "Load a script from FILE.
5739 FILE must be the full name, it is not searched in the
5740 `erc-script-path'. If the filename ends with `.el', then load it
5741 as an Emacs Lisp program. Otherwise, treat it as a regular IRC
5742 script."
5743 (erc-log (concat "erc-load-script: " file))
5744 (cond
5745 ((string-match "\\.el\\'" file)
5746 (load file))
5748 (erc-load-irc-script file))))
5750 (defun erc-process-script-line (line &optional args)
5751 "Process an IRC script LINE.
5753 Does script-specific substitutions (script arguments, current nick,
5754 server, etc.) in LINE and returns it.
5756 Substitutions are: %C and %c = current target (channel or nick),
5757 %S %s = current server, %N %n = my current nick, and %x is x verbatim,
5758 where x is any other character;
5759 $* = the entire argument string, $1 = the first argument, $2 = the second,
5760 and so on."
5761 (if (not args) (setq args ""))
5762 (let* ((arg-esc-regexp "\\(\\$\\(\\*\\|[1-9][0-9]*\\)\\)\\([^0-9]\\|$\\)")
5763 (percent-regexp "\\(%.\\)")
5764 (esc-regexp (concat arg-esc-regexp "\\|" percent-regexp))
5765 (tgt (erc-default-target))
5766 (server (and (boundp 'erc-session-server) erc-session-server))
5767 (nick (erc-current-nick))
5768 (res "")
5769 (tmp nil)
5770 (arg-list nil)
5771 (arg-num 0))
5772 (if (not tgt) (setq tgt ""))
5773 (if (not server) (setq server ""))
5774 (if (not nick) (setq nick ""))
5775 ;; First, compute the argument list
5776 (setq tmp args)
5777 (while (string-match "^\\s-*\\(\\S-+\\)\\(\\s-+.*$\\|$\\)" tmp)
5778 (setq arg-list (cons (match-string 1 tmp) arg-list))
5779 (setq tmp (match-string 2 tmp)))
5780 (setq arg-list (nreverse arg-list))
5781 (setq arg-num (length arg-list))
5782 ;; now do the substitution
5783 (setq tmp (string-match esc-regexp line))
5784 (while tmp
5785 ;;(message "beginning of while: tmp=%S" tmp)
5786 (let* ((hd (substring line 0 tmp))
5787 (esc "")
5788 (subst "")
5789 (tail (substring line tmp)))
5790 (cond ((string-match (concat "^" arg-esc-regexp) tail)
5791 (setq esc (match-string 1 tail))
5792 (setq tail (substring tail (match-end 1))))
5793 ((string-match (concat "^" percent-regexp) tail)
5794 (setq esc (match-string 1 tail))
5795 (setq tail (substring tail (match-end 1)))))
5796 ;;(message "hd=%S, esc=%S, tail=%S, arg-num=%S" hd esc tail arg-num)
5797 (setq res (concat res hd))
5798 (setq subst
5799 (cond ((string= esc "") "")
5800 ((string-match "^\\$\\*$" esc) args)
5801 ((string-match "^\\$\\([0-9]+\\)$" esc)
5802 (let ((n (string-to-number (match-string 1 esc))))
5803 (message "n = %S, integerp(n)=%S" n (integerp n))
5804 (if (<= n arg-num) (nth (1- n) arg-list) "")))
5805 ((string-match "^%[Cc]$" esc) tgt)
5806 ((string-match "^%[Ss]$" esc) server)
5807 ((string-match "^%[Nn]$" esc) nick)
5808 ((string-match "^%\\(.\\)$" esc) (match-string 1 esc))
5809 (t (erc-log (format "BUG in erc-process-script-line: bad escape sequence: %S\n" esc))
5810 (message "BUG IN ERC: esc=%S" esc)
5811 "")))
5812 (setq line tail)
5813 (setq tmp (string-match esc-regexp line))
5814 (setq res (concat res subst))
5815 ;;(message "end of while: line=%S, res=%S, tmp=%S" line res tmp)
5817 (setq res (concat res line))
5818 res))
5820 (defun erc-load-irc-script (file &optional force)
5821 "Load an IRC script from FILE."
5822 (erc-log (concat "erc-load-script: " file))
5823 (let ((str (with-temp-buffer
5824 (insert-file-contents file)
5825 (buffer-string))))
5826 (erc-load-irc-script-lines (erc-split-multiline-safe str) force)))
5828 (defun erc-load-irc-script-lines (lines &optional force noexpand)
5829 "Load IRC script LINES (a list of strings).
5831 If optional NOEXPAND is non-nil, do not expand script-specific
5832 sequences, process the lines verbatim. Use this for multiline
5833 user input."
5834 (let* ((cb (current-buffer))
5835 (s "")
5836 (sp (or (erc-command-indicator) (erc-prompt)))
5837 (args (and (boundp 'erc-script-args) erc-script-args)))
5838 (if (and args (string-match "^ " args))
5839 (setq args (substring args 1)))
5840 ;; prepare the prompt string for echo
5841 (erc-put-text-property 0 (length sp)
5842 'face 'erc-command-indicator-face sp)
5843 (while lines
5844 (setq s (car lines))
5845 (erc-log (concat "erc-load-script: CMD: " s))
5846 (unless (string-match "^\\s-*$" s)
5847 (let ((line (if noexpand s (erc-process-script-line s args))))
5848 (if (and (erc-process-input-line line force)
5849 erc-script-echo)
5850 (progn
5851 (erc-put-text-property 0 (length line)
5852 'face 'erc-input-face line)
5853 (erc-display-line (concat sp line) cb)))))
5854 (setq lines (cdr lines)))))
5856 ;; authentication
5858 (defun erc-login ()
5859 "Perform user authentication at the IRC server."
5860 (erc-log (format "login: nick: %s, user: %s %s %s :%s"
5861 (erc-current-nick)
5862 (user-login-name)
5863 (or erc-system-name (system-name))
5864 erc-session-server
5865 erc-session-user-full-name))
5866 (if erc-session-password
5867 (erc-server-send (format "PASS %s" erc-session-password))
5868 (message "Logging in without password"))
5869 (erc-server-send (format "NICK %s" (erc-current-nick)))
5870 (erc-server-send
5871 (format "USER %s %s %s :%s"
5872 ;; hacked - S.B.
5873 (if erc-anonymous-login erc-email-userid (user-login-name))
5874 "0" "*"
5875 erc-session-user-full-name))
5876 (erc-update-mode-line))
5878 ;; connection properties' heuristics
5880 (defun erc-determine-parameters (&optional server port nick name)
5881 "Determine the connection and authentication parameters.
5882 Sets the buffer local variables:
5884 - `erc-session-connector'
5885 - `erc-session-server'
5886 - `erc-session-port'
5887 - `erc-session-full-name'
5888 - `erc-server-current-nick'"
5889 (setq erc-session-connector erc-server-connect-function
5890 erc-session-server (erc-compute-server server)
5891 erc-session-port (or port erc-default-port)
5892 erc-session-user-full-name (erc-compute-full-name name))
5893 (erc-set-current-nick (erc-compute-nick nick)))
5895 (defun erc-compute-server (&optional server)
5896 "Return an IRC server name.
5898 This tries a number of increasingly more default methods until a
5899 non-nil value is found.
5901 - SERVER (the argument passed to this function)
5902 - The `erc-server' option
5903 - The value of the IRCSERVER environment variable
5904 - The `erc-default-server' variable"
5905 (or server
5906 erc-server
5907 (getenv "IRCSERVER")
5908 erc-default-server))
5910 (defun erc-compute-nick (&optional nick)
5911 "Return user's IRC nick.
5913 This tries a number of increasingly more default methods until a
5914 non-nil value is found.
5916 - NICK (the argument passed to this function)
5917 - The `erc-nick' option
5918 - The value of the IRCNICK environment variable
5919 - The result from the `user-login-name' function"
5920 (or nick
5921 (if (consp erc-nick) (car erc-nick) erc-nick)
5922 (getenv "IRCNICK")
5923 (user-login-name)))
5926 (defun erc-compute-full-name (&optional full-name)
5927 "Return user's full name.
5929 This tries a number of increasingly more default methods until a
5930 non-nil value is found.
5932 - FULL-NAME (the argument passed to this function)
5933 - The `erc-user-full-name' option
5934 - The value of the IRCNAME environment variable
5935 - The result from the `user-full-name' function"
5936 (or full-name
5937 erc-user-full-name
5938 (getenv "IRCNAME")
5939 (if erc-anonymous-login "unknown" nil)
5940 (user-full-name)))
5942 (defun erc-compute-port (&optional port)
5943 "Return a port for an IRC server.
5945 This tries a number of increasingly more default methods until a
5946 non-nil value is found.
5948 - PORT (the argument passed to this function)
5949 - The `erc-port' option
5950 - The `erc-default-port' variable"
5951 (or port erc-port erc-default-port))
5953 ;; time routines
5955 (defun erc-string-to-emacs-time (string)
5956 "Convert the long number represented by STRING into an Emacs format.
5957 Returns a list of the form (HIGH LOW), compatible with Emacs time format."
5958 (let* ((n (string-to-number (concat string ".0"))))
5959 (list (truncate (/ n 65536))
5960 (truncate (mod n 65536)))))
5962 (defalias 'erc-emacs-time-to-erc-time
5963 (if (featurep 'xemacs) 'time-to-seconds 'float-time))
5965 (defalias 'erc-current-time 'erc-emacs-time-to-erc-time)
5967 (defun erc-time-diff (t1 t2)
5968 "Return the time difference in seconds between T1 and T2."
5969 (abs (- t2 t1)))
5971 (defun erc-time-gt (t1 t2)
5972 "Check whether T1 > T2."
5973 (> t1 t2))
5975 (defun erc-sec-to-time (ns)
5976 "Convert NS to a time string HH:MM.SS."
5977 (setq ns (truncate ns))
5978 (format "%02d:%02d.%02d"
5979 (/ ns 3600)
5980 (/ (% ns 3600) 60)
5981 (% ns 60)))
5983 (defun erc-seconds-to-string (seconds)
5984 "Convert a number of SECONDS into an English phrase."
5985 (let (days hours minutes format-args output)
5986 (setq days (/ seconds 86400)
5987 seconds (% seconds 86400)
5988 hours (/ seconds 3600)
5989 seconds (% seconds 3600)
5990 minutes (/ seconds 60)
5991 seconds (% seconds 60)
5992 format-args (if (> days 0)
5993 `("%d days, %d hours, %d minutes, %d seconds"
5994 ,days ,hours ,minutes ,seconds)
5995 (if (> hours 0)
5996 `("%d hours, %d minutes, %d seconds"
5997 ,hours ,minutes ,seconds)
5998 (if (> minutes 0)
5999 `("%d minutes, %d seconds" ,minutes ,seconds)
6000 `("%d seconds" ,seconds))))
6001 output (apply 'format format-args))
6002 ;; Change all "1 units" to "1 unit".
6003 (while (string-match "\\([^0-9]\\|^\\)1 \\S-+\\(s\\)" output)
6004 (setq output (erc-replace-match-subexpression-in-string
6005 "" output (match-string 2 output) 2 (match-beginning 2))))
6006 output))
6009 ;; info
6011 (defconst erc-clientinfo-alist
6012 '(("ACTION" . "is used to inform about one's current activity")
6013 ("CLIENTINFO" . "gives help on CTCP commands supported by client")
6014 ("ECHO" . "echoes its arguments back")
6015 ("FINGER" . "shows user's name, location, and idle time")
6016 ("PING" . "measures delay between peers")
6017 ("TIME" . "shows client-side time")
6018 ("USERINFO" . "shows information provided by a user")
6019 ("VERSION" . "shows client type and version"))
6020 "Alist of CTCP CLIENTINFO for ERC commands.")
6022 (defun erc-client-info (s)
6023 "Return CTCP CLIENTINFO on command S.
6024 If S is nil or an empty string then return general CLIENTINFO."
6025 (if (or (not s) (string= s ""))
6026 (concat
6027 (apply #'concat
6028 (mapcar (lambda (e)
6029 (concat (car e) " "))
6030 erc-clientinfo-alist))
6031 ": use CLIENTINFO <COMMAND> to get more specific information")
6032 (let ((h (assoc (upcase s) erc-clientinfo-alist)))
6033 (if h
6034 (concat s " " (cdr h))
6035 (concat s ": unknown command")))))
6037 ;; Hook functions
6039 (defun erc-directory-writable-p (dir)
6040 "Determine whether DIR is a writable directory.
6041 If it doesn't exist, create it."
6042 (unless (file-attributes dir) (make-directory dir))
6043 (or (file-accessible-directory-p dir) (error "Cannot access %s" dir)))
6045 (defun erc-kill-query-buffers (process)
6046 "Kill all buffers of PROCESS."
6047 ;; here, we only want to match the channel buffers, to avoid
6048 ;; "selecting killed buffers" b0rkage.
6049 (erc-with-all-buffers-of-server process
6050 (lambda ()
6051 (not (erc-server-buffer-p)))
6052 (kill-buffer (current-buffer))))
6054 (defun erc-nick-at-point ()
6055 "Give information about the nickname at `point'.
6057 If called interactively, give a human readable message in the
6058 minibuffer. If called programmatically, return the corresponding
6059 entry of `channel-members'."
6060 (interactive)
6061 (require 'thingatpt)
6062 (let* ((word (word-at-point))
6063 (channel-data (erc-get-channel-user word))
6064 (cuser (cdr channel-data))
6065 (user (if channel-data
6066 (car channel-data)
6067 (erc-get-server-user word)))
6068 host login full-name nick voice halfop op admin owner)
6069 (when user
6070 (setq nick (erc-server-user-nickname user)
6071 host (erc-server-user-host user)
6072 login (erc-server-user-login user)
6073 full-name (erc-server-user-full-name user))
6074 (if cuser
6075 (setq voice (erc-channel-user-voice cuser)
6076 halfop (erc-channel-user-halfop cuser)
6077 op (erc-channel-user-op cuser)
6078 admin (erc-channel-user-admin cuser)
6079 owner (erc-channel-user-owner cuser))))
6080 (if (called-interactively-p 'interactive)
6081 (message "%s is %s@%s%s%s"
6082 nick login host
6083 (if full-name (format " (%s)" full-name) "")
6084 (if (or voice halfop op admin owner)
6085 (format " and is +%s%s%s%s%s on %s"
6086 (if voice "v" "")
6087 (if halfop "h" "")
6088 (if op "o" "")
6089 (if admin "a" "")
6090 (if owner "q" "")
6091 (erc-default-target))
6092 ""))
6093 user)))
6095 (defun erc-away-time ()
6096 "Return non-nil if the current ERC process is set away.
6098 In particular, the time that we were set away is returned.
6099 See `current-time' for details on the time format."
6100 (erc-with-server-buffer erc-away))
6102 ;; Mode line handling
6104 (defcustom erc-mode-line-format "%S %a"
6105 "A string to be formatted and shown in the mode-line in `erc-mode'.
6107 The string is formatted using `format-spec' and the result is set as the value
6108 of `mode-line-buffer-identification'.
6110 The following characters are replaced:
6111 %a: String indicating away status or \"\" if you are not away
6112 %l: The estimated lag time to the server
6113 %m: The modes of the channel
6114 %n: The current nick name
6115 %N: The name of the network
6116 %o: The topic of the channel
6117 %p: The session port
6118 %t: The name of the target (channel, nickname, or servername:port)
6119 %s: In the server-buffer, this gets filled with the value of
6120 `erc-server-announced-name', in a channel, the value of
6121 (erc-default-target) also get concatenated.
6122 %S: In the server-buffer, this gets filled with the value of
6123 `erc-network', in a channel, the value of (erc-default-target)
6124 also get concatenated."
6125 :group 'erc-mode-line-and-header
6126 :type 'string)
6128 (defcustom erc-header-line-format "%n on %t (%m,%l) %o"
6129 "A string to be formatted and shown in the header-line in `erc-mode'.
6130 Only used starting in Emacs 21.
6132 Set this to nil if you do not want the header line to be
6133 displayed.
6135 See `erc-mode-line-format' for which characters are can be used."
6136 :group 'erc-mode-line-and-header
6137 :set (lambda (sym val)
6138 (set sym val)
6139 (when (fboundp 'erc-update-mode-line)
6140 (erc-update-mode-line nil)))
6141 :type '(choice (const :tag "Disabled" nil)
6142 string))
6144 (defcustom erc-header-line-uses-tabbar-p nil
6145 "Use tabbar mode instead of the header line to display the header."
6146 :group 'erc-mode-line-and-header
6147 :type 'boolean)
6149 (defcustom erc-header-line-uses-help-echo-p t
6150 "Show the contents of the header line in the echo area or as a tooltip
6151 when you move point into the header line."
6152 :group 'erc-mode-line-and-header
6153 :type 'boolean)
6155 (defcustom erc-header-line-face-method nil
6156 "Determine what method to use when colorizing the header line text.
6158 If nil, don't colorize the header text.
6159 If given a function, call it and use the resulting face name.
6160 Otherwise, use the `erc-header-line' face."
6161 :group 'erc-mode-line-and-header
6162 :type '(choice (const :tag "Don't colorize" nil)
6163 (const :tag "Use the erc-header-line face" t)
6164 (function :tag "Call a function")))
6166 (defcustom erc-show-channel-key-p t
6167 "Show the channel key in the header line."
6168 :group 'erc-paranoia
6169 :type 'boolean)
6171 (defcustom erc-mode-line-away-status-format
6172 "(AWAY since %a %b %d %H:%M) "
6173 "When you're away on a server, this is shown in the mode line.
6174 This should be a string with substitution variables recognized by
6175 `format-time-string'."
6176 :group 'erc-mode-line-and-header
6177 :type 'string)
6179 (defun erc-shorten-server-name (server-name)
6180 "Shorten SERVER-NAME according to `erc-common-server-suffixes'."
6181 (if (stringp server-name)
6182 (with-temp-buffer
6183 (insert server-name)
6184 (let ((alist erc-common-server-suffixes))
6185 (while alist
6186 (goto-char (point-min))
6187 (if (re-search-forward (caar alist) nil t)
6188 (replace-match (cdar alist)))
6189 (setq alist (cdr alist))))
6190 (buffer-string))))
6192 (defun erc-format-target ()
6193 "Return the name of the target (channel or nickname or servername:port)."
6194 (let ((target (erc-default-target)))
6195 (or target
6196 (concat (erc-shorten-server-name
6197 (or erc-server-announced-name
6198 erc-session-server))
6199 ":" (erc-port-to-string erc-session-port)))))
6201 (defun erc-format-target-and/or-server ()
6202 "Return the server name or the current target and server name combined."
6203 (let ((server-name (erc-shorten-server-name
6204 (or erc-server-announced-name
6205 erc-session-server))))
6206 (cond ((erc-default-target)
6207 (concat (erc-string-no-properties (erc-default-target))
6208 "@" server-name))
6209 (server-name server-name)
6210 (t (buffer-name (current-buffer))))))
6212 (defun erc-format-network ()
6213 "Return the name of the network we are currently on."
6214 (let ((network (and (fboundp 'erc-network-name) (erc-network-name))))
6215 (if (and network (symbolp network))
6216 (symbol-name network)
6217 "")))
6219 (defun erc-format-target-and/or-network ()
6220 "Return the network or the current target and network combined.
6221 If the name of the network is not available, then use the
6222 shortened server name instead."
6223 (let ((network-name (or (and (fboundp 'erc-network-name) (erc-network-name))
6224 (erc-shorten-server-name
6225 (or erc-server-announced-name
6226 erc-session-server)))))
6227 (when (and network-name (symbolp network-name))
6228 (setq network-name (symbol-name network-name)))
6229 (cond ((erc-default-target)
6230 (concat (erc-string-no-properties (erc-default-target))
6231 "@" network-name))
6232 ((and network-name
6233 (not (get-buffer network-name)))
6234 (when erc-rename-buffers
6235 (rename-buffer network-name))
6236 network-name)
6237 (t (buffer-name (current-buffer))))))
6239 (defun erc-format-away-status ()
6240 "Return a formatted `erc-mode-line-away-status-format'
6241 if `erc-away' is non-nil."
6242 (let ((a (erc-away-time)))
6243 (if a
6244 (format-time-string erc-mode-line-away-status-format a)
6245 "")))
6247 (defun erc-format-channel-modes ()
6248 "Return the current channel's modes."
6249 (concat (apply 'concat
6250 "+" erc-channel-modes)
6251 (cond ((and erc-channel-user-limit erc-channel-key)
6252 (if erc-show-channel-key-p
6253 (format "lk %.0f %s" erc-channel-user-limit
6254 erc-channel-key)
6255 (format "kl %.0f" erc-channel-user-limit)))
6256 (erc-channel-user-limit
6257 ;; Emacs has no bignums
6258 (format "l %.0f" erc-channel-user-limit))
6259 (erc-channel-key
6260 (if erc-show-channel-key-p
6261 (format "k %s" erc-channel-key)
6262 "k"))
6263 (t nil))))
6265 (defun erc-format-lag-time ()
6266 "Return the estimated lag time to server, `erc-server-lag'."
6267 (let ((lag (erc-with-server-buffer erc-server-lag)))
6268 (cond (lag (format "lag:%.0f" lag))
6269 (t ""))))
6271 ;; erc-goodies is required at end of this file.
6272 (declare-function erc-controls-strip "erc-goodies" (str))
6274 (defvar tabbar--local-hlf)
6276 (defun erc-update-mode-line-buffer (buffer)
6277 "Update the mode line in a single ERC buffer BUFFER."
6278 (with-current-buffer buffer
6279 (let ((spec (format-spec-make
6280 ?a (erc-format-away-status)
6281 ?l (erc-format-lag-time)
6282 ?m (erc-format-channel-modes)
6283 ?n (or (erc-current-nick) "")
6284 ?N (erc-format-network)
6285 ?o (or (erc-controls-strip erc-channel-topic) "")
6286 ?p (erc-port-to-string erc-session-port)
6287 ?s (erc-format-target-and/or-server)
6288 ?S (erc-format-target-and/or-network)
6289 ?t (erc-format-target)))
6290 (process-status (cond ((and (erc-server-process-alive)
6291 (not erc-server-connected))
6292 ":connecting")
6293 ((erc-server-process-alive)
6296 ": CLOSED")))
6297 (face (cond ((eq erc-header-line-face-method nil)
6298 nil)
6299 ((functionp erc-header-line-face-method)
6300 (funcall erc-header-line-face-method))
6302 'erc-header-line))))
6303 (cond ((featurep 'xemacs)
6304 (setq modeline-buffer-identification
6305 (list (format-spec erc-mode-line-format spec)))
6306 (setq modeline-process (list process-status)))
6308 (setq mode-line-buffer-identification
6309 (list (format-spec erc-mode-line-format spec)))
6310 (setq mode-line-process (list process-status))))
6311 (when (boundp 'header-line-format)
6312 (let ((header (if erc-header-line-format
6313 (format-spec erc-header-line-format spec)
6314 nil)))
6315 (cond (erc-header-line-uses-tabbar-p
6316 (set (make-local-variable 'tabbar--local-hlf)
6317 header-line-format)
6318 (kill-local-variable 'header-line-format))
6319 ((null header)
6320 (setq header-line-format nil))
6321 (erc-header-line-uses-help-echo-p
6322 (let ((help-echo (with-temp-buffer
6323 (insert header)
6324 (fill-region (point-min) (point-max))
6325 (buffer-string))))
6326 (setq header-line-format
6327 (erc-replace-regexp-in-string
6329 "%%"
6330 (if face
6331 (erc-propertize header 'help-echo help-echo
6332 'face face)
6333 (erc-propertize header 'help-echo help-echo))))))
6334 (t (setq header-line-format
6335 (if face
6336 (erc-propertize header 'face face)
6337 header)))))))
6338 (if (featurep 'xemacs)
6339 (redraw-modeline)
6340 (force-mode-line-update))))
6342 (defun erc-update-mode-line (&optional buffer)
6343 "Update the mode line in BUFFER.
6345 If BUFFER is nil, update the mode line in all ERC buffers."
6346 (if (and buffer (bufferp buffer))
6347 (erc-update-mode-line-buffer buffer)
6348 (dolist (buf (erc-buffer-list))
6349 (when (buffer-live-p buf)
6350 (erc-update-mode-line-buffer buf)))))
6352 ;; Miscellaneous
6354 (defun erc-port-to-string (p)
6355 "Convert port P to a string.
6356 P may be an integer or a service name."
6357 (if (integerp p)
6358 (int-to-string p)
6361 (defun erc-string-to-port (s)
6362 "Convert string S to either an integer port number or a service name."
6363 (if (numberp s)
6365 (let ((n (string-to-number s)))
6366 (if (= n 0)
6368 n))))
6370 (defun erc-version (&optional here)
6371 "Show the version number of ERC in the minibuffer.
6372 If optional argument HERE is non-nil, insert version number at point."
6373 (interactive "P")
6374 (let ((version-string
6375 (format "ERC (IRC client for Emacs %s)" emacs-version)))
6376 (if here
6377 (insert version-string)
6378 (if (called-interactively-p 'interactive)
6379 (message "%s" version-string)
6380 version-string))))
6382 (defun erc-modes (&optional here)
6383 "Show the active ERC modes in the minibuffer.
6384 If optional argument HERE is non-nil, insert version number at point."
6385 (interactive "P")
6386 (let ((string
6387 (mapconcat 'identity
6388 (let (modes (case-fold-search nil))
6389 (dolist (var (apropos-internal "^erc-.*mode$"))
6390 (when (and (boundp var)
6391 (symbol-value var))
6392 (setq modes (cons (symbol-name var)
6393 modes))))
6394 modes)
6395 ", ")))
6396 (if here
6397 (insert string)
6398 (if (called-interactively-p 'interactive)
6399 (message "%s" string)
6400 string))))
6402 (defun erc-trim-string (s)
6403 "Trim leading and trailing spaces off S."
6404 (cond
6405 ((not (stringp s)) nil)
6406 ((string-match "^\\s-*$" s)
6408 ((string-match "^\\s-*\\(.*\\S-\\)\\s-*$" s)
6409 (match-string 1 s))
6411 s)))
6413 (defun erc-arrange-session-in-multiple-windows ()
6414 "Open a window for every non-server buffer related to `erc-session-server'.
6416 All windows are opened in the current frame."
6417 (interactive)
6418 (unless erc-server-process
6419 (error "No erc-server-process found in current buffer"))
6420 (let ((bufs (erc-buffer-list nil erc-server-process)))
6421 (when bufs
6422 (delete-other-windows)
6423 (switch-to-buffer (car bufs))
6424 (setq bufs (cdr bufs))
6425 (while bufs
6426 (split-window)
6427 (other-window 1)
6428 (switch-to-buffer (car bufs))
6429 (setq bufs (cdr bufs))
6430 (balance-windows)))))
6432 (defun erc-popup-input-buffer ()
6433 "Provide an input buffer."
6434 (interactive)
6435 (let ((buffer-name (generate-new-buffer-name "*ERC input*"))
6436 (mode (intern
6437 (completing-read
6438 "Mode: "
6439 (mapcar (lambda (e)
6440 (list (symbol-name e)))
6441 (apropos-internal "-mode$" 'commandp))
6442 nil t))))
6443 (pop-to-buffer (make-indirect-buffer (current-buffer) buffer-name))
6444 (funcall mode)
6445 (narrow-to-region (point) (point))
6446 (shrink-window-if-larger-than-buffer)))
6448 ;;; Message catalog
6450 (defun erc-make-message-variable-name (catalog entry)
6451 "Create a variable name corresponding to CATALOG's ENTRY."
6452 (intern (concat "erc-message-"
6453 (symbol-name catalog) "-" (symbol-name entry))))
6455 (defun erc-define-catalog-entry (catalog entry format-spec)
6456 "Set CATALOG's ENTRY to FORMAT-SPEC."
6457 (set (erc-make-message-variable-name catalog entry)
6458 format-spec))
6460 (defun erc-define-catalog (catalog entries)
6461 "Define a CATALOG according to ENTRIES."
6462 (dolist (entry entries)
6463 (erc-define-catalog-entry catalog (car entry) (cdr entry))))
6465 (erc-define-catalog
6466 'english
6467 '((bad-ping-response . "Unexpected PING response from %n (time %t)")
6468 (bad-syntax . "Error occurred - incorrect usage?\n%c %u\n%d")
6469 (incorrect-args . "Incorrect arguments. Usage:\n%c %u\n%d")
6470 (cannot-find-file . "Cannot find file %f")
6471 (cannot-read-file . "Cannot read file %f")
6472 (connect . "Connecting to %S:%p... ")
6473 (country . "%c")
6474 (country-unknown . "%d: No such domain")
6475 (ctcp-empty . "Illegal empty CTCP query received from %n. Ignoring.")
6476 (ctcp-request . "==> CTCP request from %n (%u@%h): %r")
6477 (ctcp-request-to . "==> CTCP request from %n (%u@%h) to %t: %r")
6478 (ctcp-too-many . "Too many CTCP queries in single message. Ignoring")
6479 (flood-ctcp-off . "FLOOD PROTECTION: Automatic CTCP responses turned off.")
6480 (flood-strict-mode
6481 . "FLOOD PROTECTION: Switched to Strict Flood Control mode.")
6482 (disconnected . "\n\nConnection failed! Re-establishing connection...\n")
6483 (disconnected-noreconnect
6484 . "\n\nConnection failed! Not re-establishing connection.\n")
6485 (finished . "\n\n*** ERC finished ***\n")
6486 (terminated . "\n\n*** ERC terminated: %e\n")
6487 (login . "Logging in as \'%n\'...")
6488 (nick-in-use . "%n is in use. Choose new nickname: ")
6489 (nick-too-long
6490 . "WARNING: Nick length (%i) exceeds max NICKLEN(%l) defined by server")
6491 (no-default-channel . "No default channel")
6492 (no-invitation . "You've got no invitation")
6493 (no-target . "No target")
6494 (ops . "%i operator%s: %o")
6495 (ops-none . "No operators in this channel.")
6496 (undefined-ctcp . "Undefined CTCP query received. Silently ignored")
6497 (variable-not-bound . "Variable not bound!")
6498 (ACTION . "* %n %a")
6499 (CTCP-CLIENTINFO . "Client info for %n: %m")
6500 (CTCP-ECHO . "Echo %n: %m")
6501 (CTCP-FINGER . "Finger info for %n: %m")
6502 (CTCP-PING . "Ping time to %n is %t")
6503 (CTCP-TIME . "Time by %n is %m")
6504 (CTCP-UNKNOWN . "Unknown CTCP message from %n (%u@%h): %m")
6505 (CTCP-VERSION . "Version for %n is %m")
6506 (ERROR . "==> ERROR from %s: %c\n")
6507 (INVITE . "%n (%u@%h) invites you to channel %c")
6508 (JOIN . "%n (%u@%h) has joined channel %c")
6509 (JOIN-you . "You have joined channel %c")
6510 (KICK . "%n (%u@%h) has kicked %k off channel %c: %r")
6511 (KICK-you . "You have been kicked off channel %c by %n (%u@%h): %r")
6512 (KICK-by-you . "You have kicked %k off channel %c: %r")
6513 (MODE . "%n (%u@%h) has changed mode for %t to %m")
6514 (MODE-nick . "%n has changed mode for %t to %m")
6515 (NICK . "%n (%u@%h) is now known as %N")
6516 (NICK-you . "Your new nickname is %N")
6517 (PART . erc-message-english-PART)
6518 (PING . "PING from server (last: %s sec. ago)")
6519 (PONG . "PONG from %h (%i second%s)")
6520 (QUIT . "%n (%u@%h) has quit: %r")
6521 (TOPIC . "%n (%u@%h) has set the topic for %c: \"%T\"")
6522 (WALLOPS . "Wallops from %n: %m")
6523 (s004 . "%s %v %U %C")
6524 (s221 . "User modes for %n: %m")
6525 (s252 . "%i operator(s) online")
6526 (s253 . "%i unknown connection(s)")
6527 (s254 . "%i channels formed")
6528 (s275 . "%n %m")
6529 (s301 . "%n is AWAY: %r")
6530 (s303 . "Is online: %n")
6531 (s305 . "%m")
6532 (s306 . "%m")
6533 (s307 . "%n %m")
6534 (s311 . "%n is %f (%u@%h)")
6535 (s312 . "%n is/was on server %s (%c)")
6536 (s313 . "%n is an IRC operator")
6537 (s314 . "%n was %f (%u@%h)")
6538 (s317 . "%n has been idle for %i")
6539 (s317-on-since . "%n has been idle for %i, on since %t")
6540 (s319 . "%n is on channel(s): %c")
6541 (s320 . "%n is an identified user")
6542 (s321 . "Channel Users Topic")
6543 (s322 . "%c [%u] %t")
6544 (s324 . "%c modes: %m")
6545 (s328 . "%c URL: %u")
6546 (s329 . "%c was created on %t")
6547 (s330 . "%n %a %i")
6548 (s331 . "No topic is set for %c")
6549 (s332 . "Topic for %c: %T")
6550 (s333 . "%c: topic set by %n, %t")
6551 (s341 . "Inviting %n to channel %c")
6552 (s352 . "%-11c %-10n %-4a %u@%h (%f)")
6553 (s353 . "Users on %c: %u")
6554 (s367 . "Ban for %b on %c")
6555 (s367-set-by . "Ban for %b on %c set by %s on %t")
6556 (s368 . "Banlist of %c ends.")
6557 (s379 . "%c: Forwarded to %f")
6558 (s391 . "The time at %s is %t")
6559 (s401 . "%n: No such nick/channel")
6560 (s403 . "%c: No such channel")
6561 (s404 . "%c: Cannot send to channel")
6562 (s405 . "%c: You have joined too many channels")
6563 (s406 . "%n: There was no such nickname")
6564 (s412 . "No text to send")
6565 (s421 . "%c: Unknown command")
6566 (s431 . "No nickname given")
6567 (s432 . "%n is an erroneous nickname")
6568 (s442 . "%c: You're not on that channel")
6569 (s445 . "SUMMON has been disabled")
6570 (s446 . "USERS has been disabled")
6571 (s451 . "You have not registered")
6572 (s461 . "%c: not enough parameters")
6573 (s462 . "Unauthorized command (already registered)")
6574 (s463 . "Your host isn't among the privileged")
6575 (s464 . "Password incorrect")
6576 (s465 . "You are banned from this server")
6577 (s474 . "You can't join %c because you're banned (+b)")
6578 (s475 . "You must specify the correct channel key (+k) to join %c")
6579 (s481 . "Permission Denied - You're not an IRC operator")
6580 (s482 . "You need to be a channel operator of %c to do that")
6581 (s483 . "You can't kill a server!")
6582 (s484 . "Your connection is restricted!")
6583 (s485 . "You're not the original channel operator")
6584 (s491 . "No O-lines for your host")
6585 (s501 . "Unknown MODE flag")
6586 (s502 . "You can't change modes for other users")
6587 (s671 . "%n %a")))
6589 (defun erc-message-english-PART (&rest args)
6590 "Format a proper PART message.
6592 This function is an example on what could be done with formatting
6593 functions."
6594 (let ((nick (cadr (memq ?n args)))
6595 (user (cadr (memq ?u args)))
6596 (host (cadr (memq ?h args)))
6597 (channel (cadr (memq ?c args)))
6598 (reason (cadr (memq ?r args))))
6599 (if (string= nick (erc-current-nick))
6600 (format "You have left channel %s" channel)
6601 (format "%s (%s@%s) has left channel %s%s"
6602 nick user host channel
6603 (if (not (string= reason ""))
6604 (format ": %s"
6605 (erc-replace-regexp-in-string "%" "%%" reason))
6606 "")))))
6609 (defvar erc-current-message-catalog 'english)
6610 (make-variable-buffer-local 'erc-current-message-catalog)
6612 (defun erc-retrieve-catalog-entry (entry &optional catalog)
6613 "Retrieve ENTRY from CATALOG.
6615 If CATALOG is nil, `erc-current-message-catalog' is used.
6617 If ENTRY is nil in CATALOG, it is retrieved from the fallback,
6618 english, catalog."
6619 (unless catalog (setq catalog erc-current-message-catalog))
6620 (let ((var (erc-make-message-variable-name catalog entry)))
6621 (if (boundp var)
6622 (symbol-value var)
6623 (when (boundp (erc-make-message-variable-name 'english entry))
6624 (symbol-value (erc-make-message-variable-name 'english entry))))))
6626 (defun erc-format-message (msg &rest args)
6627 "Format MSG according to ARGS.
6629 See also `format-spec'."
6630 (when (eq (logand (length args) 1) 1) ; oddp
6631 (error "Obscure usage of this function appeared"))
6632 (let ((entry (erc-retrieve-catalog-entry msg)))
6633 (when (not entry)
6634 (error "No format spec for message %s" msg))
6635 (when (functionp entry)
6636 (setq entry (apply entry args)))
6637 (format-spec entry (apply 'format-spec-make args))))
6639 ;;; Various hook functions
6641 (add-hook 'kill-buffer-hook 'erc-kill-buffer-function)
6643 (defcustom erc-kill-server-hook '(erc-kill-server)
6644 "Invoked whenever a server buffer is killed via `kill-buffer'."
6645 :group 'erc-hooks
6646 :type 'hook)
6648 (defcustom erc-kill-channel-hook '(erc-kill-channel)
6649 "Invoked whenever a channel-buffer is killed via `kill-buffer'."
6650 :group 'erc-hooks
6651 :type 'hook)
6653 (defcustom erc-kill-buffer-hook nil
6654 "Hook run whenever a non-server or channel buffer is killed.
6656 See also `kill-buffer'."
6657 :group 'erc-hooks
6658 :type 'hook)
6660 (defun erc-kill-buffer-function ()
6661 "Function to call when an ERC buffer is killed.
6662 This function should be on `kill-buffer-hook'.
6663 When the current buffer is in `erc-mode', this function will run
6664 one of the following hooks:
6665 `erc-kill-server-hook' if the server buffer was killed,
6666 `erc-kill-channel-hook' if a channel buffer was killed,
6667 or `erc-kill-buffer-hook' if any other buffer."
6668 (when (eq major-mode 'erc-mode)
6669 (erc-remove-channel-users)
6670 (cond
6671 ((eq (erc-server-buffer) (current-buffer))
6672 (run-hooks 'erc-kill-server-hook))
6673 ((erc-channel-p (erc-default-target))
6674 (run-hooks 'erc-kill-channel-hook))
6676 (run-hooks 'erc-kill-buffer-hook)))))
6678 (defun erc-kill-server ()
6679 "Sends a QUIT command to the server when the server buffer is killed.
6680 This function should be on `erc-kill-server-hook'."
6681 (when (erc-server-process-alive)
6682 (setq erc-server-quitting t)
6683 (erc-server-send (format "QUIT :%s" (funcall erc-quit-reason nil)))))
6685 (defun erc-kill-channel ()
6686 "Sends a PART command to the server when the channel buffer is killed.
6687 This function should be on `erc-kill-channel-hook'."
6688 (when (erc-server-process-alive)
6689 (let ((tgt (erc-default-target)))
6690 (erc-server-send (format "PART %s :%s" tgt
6691 (funcall erc-part-reason nil))
6692 nil tgt))))
6694 ;;; Dealing with `erc-parsed'
6696 (defun erc-find-parsed-property ()
6697 "Find the next occurrence of the `erc-parsed' text property."
6698 (text-property-not-all (point-min) (point-max) 'erc-parsed nil))
6700 (defun erc-restore-text-properties ()
6701 "Restore the property 'erc-parsed for the region."
6702 (let ((parsed-posn (erc-find-parsed-property)))
6703 (put-text-property
6704 (point-min) (point-max)
6705 'erc-parsed (when parsed-posn (erc-get-parsed-vector parsed-posn)))))
6707 (defun erc-get-parsed-vector (point)
6708 "Return the whole parsed vector on POINT."
6709 (get-text-property point 'erc-parsed))
6711 (defun erc-get-parsed-vector-nick (vect)
6712 "Return nickname in the parsed vector VECT."
6713 (let* ((untreated-nick (and vect (erc-response.sender vect)))
6714 (maybe-nick (when untreated-nick
6715 (car (split-string untreated-nick "!")))))
6716 (when (and (not (null maybe-nick))
6717 (erc-is-valid-nick-p maybe-nick))
6718 untreated-nick)))
6720 (defun erc-get-parsed-vector-type (vect)
6721 "Return message type in the parsed vector VECT."
6722 (and vect
6723 (erc-response.command vect)))
6725 ;; Teach url.el how to open irc:// URLs with ERC.
6726 ;; To activate, customize `url-irc-function' to `url-irc-erc'.
6728 ;;;###autoload
6729 (defun erc-handle-irc-url (host port channel user password)
6730 "Use ERC to IRC on HOST:PORT in CHANNEL as USER with PASSWORD.
6731 If ERC is already connected to HOST:PORT, simply /join CHANNEL.
6732 Otherwise, connect to HOST:PORT as USER and /join CHANNEL."
6733 (let ((server-buffer
6734 (car (erc-buffer-filter
6735 (lambda ()
6736 (and (string-equal erc-session-server host)
6737 (= erc-session-port port)
6738 (erc-open-server-buffer-p)))))))
6739 (with-current-buffer (or server-buffer (current-buffer))
6740 (if (and server-buffer channel)
6741 (erc-cmd-JOIN channel)
6742 (erc-open host port (or user (erc-compute-nick)) (erc-compute-full-name)
6743 (not server-buffer) password nil channel
6744 (when server-buffer
6745 (get-buffer-process server-buffer)))))))
6747 (provide 'erc)
6749 ;; Deprecated. We might eventually stop requiring the goodies automatically.
6750 ;; IMPORTANT: This require must appear _after_ the above (provide 'erc) to
6751 ;; avoid a recursive require error when byte-compiling the entire package.
6752 (require 'erc-goodies)
6754 ;;; erc.el ends here
6756 ;; Local Variables:
6757 ;; outline-regexp: ";;+"
6758 ;; indent-tabs-mode: t
6759 ;; tab-width: 8
6760 ;; End: