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