Prefer directed to neutral quotes
[emacs.git] / lisp / net / rcirc.el
blobcd5bbbdabdf81cd466dc17061b2d200f4ad97534
1 ;;; rcirc.el --- default, simple IRC client -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2005-2015 Free Software Foundation, Inc.
5 ;; Author: Ryan Yeske <rcyeske@gmail.com>
6 ;; Maintainers: Ryan Yeske <rcyeske@gmail.com>,
7 ;; Leo Liu <sdl.web@gmail.com>
8 ;; Keywords: comm
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;; Commentary:
27 ;; Internet Relay Chat (IRC) is a form of instant communication over
28 ;; the Internet. It is mainly designed for group (many-to-many)
29 ;; communication in discussion forums called channels, but also allows
30 ;; one-to-one communication.
32 ;; Rcirc has simple defaults and clear and consistent behavior.
33 ;; Message arrival timestamps, activity notification on the mode line,
34 ;; message filling, nick completion, and keepalive pings are all
35 ;; enabled by default, but can easily be adjusted or turned off. Each
36 ;; discussion takes place in its own buffer and there is a single
37 ;; server buffer per connection.
39 ;; Open a new irc connection with:
40 ;; M-x irc RET
42 ;;; Todo:
44 ;;; Code:
46 (require 'cl-lib)
47 (require 'ring)
48 (require 'time-date)
50 (defgroup rcirc nil
51 "Simple IRC client."
52 :version "22.1"
53 :prefix "rcirc-"
54 :link '(custom-manual "(rcirc)")
55 :group 'applications)
57 (defcustom rcirc-server-alist
58 '(("irc.freenode.net" :channels ("#rcirc")
59 ;; Don't use the TLS port by default, in case gnutls is not available.
60 ;; :port 7000 :encryption tls
62 "An alist of IRC connections to establish when running `rcirc'.
63 Each element looks like (SERVER-NAME PARAMETERS).
65 SERVER-NAME is a string describing the server to connect
66 to.
68 The optional PARAMETERS come in pairs PARAMETER VALUE.
70 The following parameters are recognized:
72 `:nick'
74 VALUE must be a string. If absent, `rcirc-default-nick' is used
75 for this connection.
77 `:port'
79 VALUE must be a number or string. If absent,
80 `rcirc-default-port' is used.
82 `:user-name'
84 VALUE must be a string. If absent, `rcirc-default-user-name' is
85 used.
87 `:password'
89 VALUE must be a string. If absent, no PASS command will be sent
90 to the server.
92 `:full-name'
94 VALUE must be a string. If absent, `rcirc-default-full-name' is
95 used.
97 `:channels'
99 VALUE must be a list of strings describing which channels to join
100 when connecting to this server. If absent, no channels will be
101 connected to automatically.
103 `:encryption'
105 VALUE must be `plain' (the default) for unencrypted connections, or `tls'
106 for connections using SSL/TLS."
107 :type '(alist :key-type string
108 :value-type (plist :options
109 ((:nick string)
110 (:port integer)
111 (:user-name string)
112 (:password string)
113 (:full-name string)
114 (:channels (repeat string))
115 (:encryption (choice (const tls)
116 (const plain))))))
117 :group 'rcirc)
119 (defcustom rcirc-default-port 6667
120 "The default port to connect to."
121 :type 'integer
122 :group 'rcirc)
124 (defcustom rcirc-default-nick (user-login-name)
125 "Your nick."
126 :type 'string
127 :group 'rcirc)
129 (defcustom rcirc-default-user-name "user"
130 "Your user name sent to the server when connecting."
131 :version "24.1" ; changed default
132 :type 'string
133 :group 'rcirc)
135 (defcustom rcirc-default-full-name "unknown"
136 "The full name sent to the server when connecting."
137 :version "24.1" ; changed default
138 :type 'string
139 :group 'rcirc)
141 (defcustom rcirc-fill-flag t
142 "Non-nil means line-wrap messages printed in channel buffers."
143 :type 'boolean
144 :group 'rcirc)
146 (defcustom rcirc-fill-column nil
147 "Column beyond which automatic line-wrapping should happen.
148 If nil, use value of `fill-column'.
149 If a function (e.g., `frame-text-width' or `window-text-width'),
150 call it to compute the number of columns."
151 :risky t ; can get funcalled
152 :type '(choice (const :tag "Value of `fill-column'" nil)
153 (integer :tag "Number of columns")
154 (function :tag "Function returning the number of columns"))
155 :group 'rcirc)
157 (defcustom rcirc-fill-prefix nil
158 "Text to insert before filled lines.
159 If nil, calculate the prefix dynamically to line up text
160 underneath each nick."
161 :type '(choice (const :tag "Dynamic" nil)
162 (string :tag "Prefix text"))
163 :group 'rcirc)
165 (defvar rcirc-ignore-buffer-activity-flag nil
166 "If non-nil, ignore activity in this buffer.")
167 (make-variable-buffer-local 'rcirc-ignore-buffer-activity-flag)
169 (defvar rcirc-low-priority-flag nil
170 "If non-nil, activity in this buffer is considered low priority.")
171 (make-variable-buffer-local 'rcirc-low-priority-flag)
173 (defvar rcirc-omit-mode nil
174 "Non-nil if Rcirc-Omit mode is enabled.
175 Use the command `rcirc-omit-mode' to change this variable.")
176 (make-variable-buffer-local 'rcirc-omit-mode)
178 (defcustom rcirc-time-format "%H:%M "
179 "Describes how timestamps are printed.
180 Used as the first arg to `format-time-string'."
181 :type 'string
182 :group 'rcirc)
184 (defcustom rcirc-input-ring-size 1024
185 "Size of input history ring."
186 :type 'integer
187 :group 'rcirc)
189 (defcustom rcirc-read-only-flag t
190 "Non-nil means make text in IRC buffers read-only."
191 :type 'boolean
192 :group 'rcirc)
194 (defcustom rcirc-buffer-maximum-lines nil
195 "The maximum size in lines for rcirc buffers.
196 Channel buffers are truncated from the top to be no greater than this
197 number. If zero or nil, no truncating is done."
198 :type '(choice (const :tag "No truncation" nil)
199 (integer :tag "Number of lines"))
200 :group 'rcirc)
202 (defcustom rcirc-scroll-show-maximum-output t
203 "If non-nil, scroll buffer to keep the point at the bottom of
204 the window."
205 :type 'boolean
206 :group 'rcirc)
208 (defcustom rcirc-authinfo nil
209 "List of authentication passwords.
210 Each element of the list is a list with a SERVER-REGEXP string
211 and a method symbol followed by method specific arguments.
213 The valid METHOD symbols are `nickserv', `chanserv' and
214 `bitlbee'.
216 The ARGUMENTS for each METHOD symbol are:
217 `nickserv': NICK PASSWORD [NICKSERV-NICK]
218 `chanserv': NICK CHANNEL PASSWORD
219 `bitlbee': NICK PASSWORD
220 `quakenet': ACCOUNT PASSWORD
222 Examples:
223 ((\"freenode\" nickserv \"bob\" \"p455w0rd\")
224 (\"freenode\" chanserv \"bob\" \"#bobland\" \"passwd99\")
225 (\"bitlbee\" bitlbee \"robert\" \"sekrit\")
226 (\"dal.net\" nickserv \"bob\" \"sekrit\" \"NickServ@services.dal.net\")
227 (\"quakenet.org\" quakenet \"bobby\" \"sekrit\"))"
228 :type '(alist :key-type (string :tag "Server")
229 :value-type (choice (list :tag "NickServ"
230 (const nickserv)
231 (string :tag "Nick")
232 (string :tag "Password"))
233 (list :tag "ChanServ"
234 (const chanserv)
235 (string :tag "Nick")
236 (string :tag "Channel")
237 (string :tag "Password"))
238 (list :tag "BitlBee"
239 (const bitlbee)
240 (string :tag "Nick")
241 (string :tag "Password"))
242 (list :tag "QuakeNet"
243 (const quakenet)
244 (string :tag "Account")
245 (string :tag "Password"))))
246 :group 'rcirc)
248 (defcustom rcirc-auto-authenticate-flag t
249 "Non-nil means automatically send authentication string to server.
250 See also `rcirc-authinfo'."
251 :type 'boolean
252 :group 'rcirc)
254 (defcustom rcirc-authenticate-before-join t
255 "Non-nil means authenticate to services before joining channels.
256 Currently only works with NickServ on some networks."
257 :version "24.1"
258 :type 'boolean
259 :group 'rcirc)
261 (defcustom rcirc-prompt "> "
262 "Prompt string to use in IRC buffers.
264 The following replacements are made:
265 %n is your nick.
266 %s is the server.
267 %t is the buffer target, a channel or a user.
269 Setting this alone will not affect the prompt;
270 use either M-x customize or also call `rcirc-update-prompt'."
271 :type 'string
272 :set 'rcirc-set-changed
273 :initialize 'custom-initialize-default
274 :group 'rcirc)
276 (defcustom rcirc-keywords nil
277 "List of keywords to highlight in message text."
278 :type '(repeat string)
279 :group 'rcirc)
281 (defcustom rcirc-ignore-list ()
282 "List of ignored nicks.
283 Use /ignore to list them, use /ignore NICK to add or remove a nick."
284 :type '(repeat string)
285 :group 'rcirc)
287 (defvar rcirc-ignore-list-automatic ()
288 "List of ignored nicks added to `rcirc-ignore-list' because of renaming.
289 When an ignored person renames, their nick is added to both lists.
290 Nicks will be removed from the automatic list on follow-up renamings or
291 parts.")
293 (defcustom rcirc-bright-nicks nil
294 "List of nicks to be emphasized.
295 See `rcirc-bright-nick' face."
296 :type '(repeat string)
297 :group 'rcirc)
299 (defcustom rcirc-dim-nicks nil
300 "List of nicks to be deemphasized.
301 See `rcirc-dim-nick' face."
302 :type '(repeat string)
303 :group 'rcirc)
305 (define-obsolete-variable-alias 'rcirc-print-hooks
306 'rcirc-print-functions "24.3")
307 (defcustom rcirc-print-functions nil
308 "Hook run after text is printed.
309 Called with 5 arguments, PROCESS, SENDER, RESPONSE, TARGET and TEXT."
310 :type 'hook
311 :group 'rcirc)
313 (defvar rcirc-authenticated-hook nil
314 "Hook run after successfully authenticated.")
316 (defcustom rcirc-always-use-server-buffer-flag nil
317 "Non-nil means messages without a channel target will go to the server buffer."
318 :type 'boolean
319 :group 'rcirc)
321 (defcustom rcirc-decode-coding-system 'utf-8
322 "Coding system used to decode incoming irc messages.
323 Set to 'undecided if you want the encoding of the incoming
324 messages autodetected."
325 :type 'coding-system
326 :group 'rcirc)
328 (defcustom rcirc-encode-coding-system 'utf-8
329 "Coding system used to encode outgoing irc messages."
330 :type 'coding-system
331 :group 'rcirc)
333 (defcustom rcirc-coding-system-alist nil
334 "Alist to decide a coding system to use for a channel I/O operation.
335 The format is ((PATTERN . VAL) ...).
336 PATTERN is either a string or a cons of strings.
337 If PATTERN is a string, it is used to match a target.
338 If PATTERN is a cons of strings, the car part is used to match a
339 target, and the cdr part is used to match a server.
340 VAL is either a coding system or a cons of coding systems.
341 If VAL is a coding system, it is used for both decoding and encoding
342 messages.
343 If VAL is a cons of coding systems, the car part is used for decoding,
344 and the cdr part is used for encoding."
345 :type '(alist :key-type (choice (string :tag "Channel Regexp")
346 (cons (string :tag "Channel Regexp")
347 (string :tag "Server Regexp")))
348 :value-type (choice coding-system
349 (cons (coding-system :tag "Decode")
350 (coding-system :tag "Encode"))))
351 :group 'rcirc)
353 (defcustom rcirc-multiline-major-mode 'fundamental-mode
354 "Major-mode function to use in multiline edit buffers."
355 :type 'function
356 :group 'rcirc)
358 (defcustom rcirc-nick-completion-format "%s: "
359 "Format string to use in nick completions.
361 The format string is only used when completing at the beginning
362 of a line. The string is passed as the first argument to
363 `format' with the nickname as the second argument."
364 :version "24.1"
365 :type 'string
366 :group 'rcirc)
368 (defcustom rcirc-kill-channel-buffers nil
369 "When non-nil, kill channel buffers when the server buffer is killed.
370 Only the channel buffers associated with the server in question
371 will be killed."
372 :version "24.3"
373 :type 'boolean
374 :group 'rcirc)
376 (defvar rcirc-nick nil)
378 (defvar rcirc-prompt-start-marker nil)
379 (defvar rcirc-prompt-end-marker nil)
381 (defvar rcirc-nick-table nil)
383 (defvar rcirc-recent-quit-alist nil
384 "Alist of nicks that have recently quit or parted the channel.")
386 (defvar rcirc-nick-syntax-table
387 (let ((table (make-syntax-table text-mode-syntax-table)))
388 (mapc (lambda (c) (modify-syntax-entry c "w" table))
389 "[]\\`_^{|}-")
390 (modify-syntax-entry ?' "_" table)
391 table)
392 "Syntax table which includes all nick characters as word constituents.")
394 ;; each process has an alist of (target . buffer) pairs
395 (defvar rcirc-buffer-alist nil)
397 (defvar rcirc-activity nil
398 "List of buffers with unviewed activity.")
400 (defvar rcirc-activity-string ""
401 "String displayed in mode line representing `rcirc-activity'.")
402 (put 'rcirc-activity-string 'risky-local-variable t)
404 (defvar rcirc-server-buffer nil
405 "The server buffer associated with this channel buffer.")
407 (defvar rcirc-target nil
408 "The channel or user associated with this buffer.")
410 (defvar rcirc-urls nil
411 "List of URLs seen in the current buffer and their start positions.")
412 (put 'rcirc-urls 'permanent-local t)
414 (defvar rcirc-timeout-seconds 600
415 "Kill connection after this many seconds if there is no activity.")
417 (defconst rcirc-id-string (concat "rcirc on GNU Emacs " emacs-version))
419 (defvar rcirc-startup-channels nil)
421 (defvar rcirc-server-name-history nil
422 "History variable for \\[rcirc] call.")
424 (defvar rcirc-server-port-history nil
425 "History variable for \\[rcirc] call.")
427 (defvar rcirc-nick-name-history nil
428 "History variable for \\[rcirc] call.")
430 (defvar rcirc-user-name-history nil
431 "History variable for \\[rcirc] call.")
433 ;;;###autoload
434 (defun rcirc (arg)
435 "Connect to all servers in `rcirc-server-alist'.
437 Do not connect to a server if it is already connected.
439 If ARG is non-nil, instead prompt for connection parameters."
440 (interactive "P")
441 (if arg
442 (let* ((server (completing-read "IRC Server: "
443 rcirc-server-alist
444 nil nil
445 (caar rcirc-server-alist)
446 'rcirc-server-name-history))
447 (server-plist (cdr (assoc-string server rcirc-server-alist)))
448 (port (read-string "IRC Port: "
449 (number-to-string
450 (or (plist-get server-plist :port)
451 rcirc-default-port))
452 'rcirc-server-port-history))
453 (nick (read-string "IRC Nick: "
454 (or (plist-get server-plist :nick)
455 rcirc-default-nick)
456 'rcirc-nick-name-history))
457 (user-name (read-string "IRC Username: "
458 (or (plist-get server-plist :user-name)
459 rcirc-default-user-name)
460 'rcirc-user-name-history))
461 (password (read-passwd "IRC Password: " nil
462 (plist-get server-plist :password)))
463 (channels (split-string
464 (read-string "IRC Channels: "
465 (mapconcat 'identity
466 (plist-get server-plist
467 :channels)
468 " "))
469 "[, ]+" t))
470 (encryption (rcirc-prompt-for-encryption server-plist)))
471 (rcirc-connect server port nick user-name
472 rcirc-default-full-name
473 channels password encryption))
474 ;; connect to servers in `rcirc-server-alist'
475 (let (connected-servers)
476 (dolist (c rcirc-server-alist)
477 (let ((server (car c))
478 (nick (or (plist-get (cdr c) :nick) rcirc-default-nick))
479 (port (or (plist-get (cdr c) :port) rcirc-default-port))
480 (user-name (or (plist-get (cdr c) :user-name)
481 rcirc-default-user-name))
482 (full-name (or (plist-get (cdr c) :full-name)
483 rcirc-default-full-name))
484 (channels (plist-get (cdr c) :channels))
485 (password (plist-get (cdr c) :password))
486 (encryption (plist-get (cdr c) :encryption))
487 contact)
488 (when server
489 (let (connected)
490 (dolist (p (rcirc-process-list))
491 (when (string= server (process-name p))
492 (setq connected p)))
493 (if (not connected)
494 (condition-case nil
495 (rcirc-connect server port nick user-name
496 full-name channels password encryption)
497 (quit (message "Quit connecting to %s" server)))
498 (with-current-buffer (process-buffer connected)
499 (setq contact (process-contact
500 (get-buffer-process (current-buffer)) :host))
501 (setq connected-servers
502 (cons (if (stringp contact) contact server)
503 connected-servers))))))))
504 (when connected-servers
505 (message "Already connected to %s"
506 (if (cdr connected-servers)
507 (concat (mapconcat 'identity (butlast connected-servers) ", ")
508 ", and "
509 (car (last connected-servers)))
510 (car connected-servers)))))))
512 ;;;###autoload
513 (defalias 'irc 'rcirc)
516 (defvar rcirc-process-output nil)
517 (defvar rcirc-topic nil)
518 (defvar rcirc-keepalive-timer nil)
519 (defvar rcirc-last-server-message-time nil)
520 (defvar rcirc-server nil) ; server provided by server
521 (defvar rcirc-server-name nil) ; server name given by 001 response
522 (defvar rcirc-timeout-timer nil)
523 (defvar rcirc-user-authenticated nil)
524 (defvar rcirc-user-disconnect nil)
525 (defvar rcirc-connecting nil)
526 (defvar rcirc-connection-info nil)
527 (defvar rcirc-process nil)
529 ;;;###autoload
530 (defun rcirc-connect (server &optional port nick user-name
531 full-name startup-channels password encryption)
532 (save-excursion
533 (message "Connecting to %s..." server)
534 (let* ((inhibit-eol-conversion)
535 (port-number (if port
536 (if (stringp port)
537 (string-to-number port)
538 port)
539 rcirc-default-port))
540 (nick (or nick rcirc-default-nick))
541 (user-name (or user-name rcirc-default-user-name))
542 (full-name (or full-name rcirc-default-full-name))
543 (startup-channels startup-channels)
544 (process (open-network-stream
545 server nil server port-number
546 :type (or encryption 'plain))))
547 ;; set up process
548 (set-process-coding-system process 'raw-text 'raw-text)
549 (switch-to-buffer (rcirc-generate-new-buffer-name process nil))
550 (set-process-buffer process (current-buffer))
551 (rcirc-mode process nil)
552 (set-process-sentinel process 'rcirc-sentinel)
553 (set-process-filter process 'rcirc-filter)
555 (setq-local rcirc-connection-info
556 (list server port nick user-name full-name startup-channels
557 password encryption))
558 (setq-local rcirc-process process)
559 (setq-local rcirc-server server)
560 (setq-local rcirc-server-name server) ; Update when we get 001 response.
561 (setq-local rcirc-buffer-alist nil)
562 (setq-local rcirc-nick-table (make-hash-table :test 'equal))
563 (setq-local rcirc-nick nick)
564 (setq-local rcirc-process-output nil)
565 (setq-local rcirc-startup-channels startup-channels)
566 (setq-local rcirc-last-server-message-time (current-time))
568 (setq-local rcirc-timeout-timer nil)
569 (setq-local rcirc-user-disconnect nil)
570 (setq-local rcirc-user-authenticated nil)
571 (setq-local rcirc-connecting t)
573 (add-hook 'auto-save-hook 'rcirc-log-write)
575 ;; identify
576 (unless (zerop (length password))
577 (rcirc-send-string process (concat "PASS " password)))
578 (rcirc-send-string process (concat "NICK " nick))
579 (rcirc-send-string process (concat "USER " user-name
580 " 0 * :" full-name))
582 ;; setup ping timer if necessary
583 (unless rcirc-keepalive-timer
584 (setq rcirc-keepalive-timer
585 (run-at-time 0 (/ rcirc-timeout-seconds 2) 'rcirc-keepalive)))
587 (message "Connecting to %s...done" server)
589 ;; return process object
590 process)))
592 (defmacro with-rcirc-process-buffer (process &rest body)
593 (declare (indent 1) (debug t))
594 `(with-current-buffer (process-buffer ,process)
595 ,@body))
597 (defmacro with-rcirc-server-buffer (&rest body)
598 (declare (indent 0) (debug t))
599 `(with-current-buffer rcirc-server-buffer
600 ,@body))
602 (defalias 'rcirc-float-time
603 (if (featurep 'xemacs)
604 'time-to-seconds
605 'float-time))
607 (defun rcirc-prompt-for-encryption (server-plist)
608 "Prompt the user for the encryption method to use.
609 SERVER-PLIST is the property list for the server."
610 (let ((msg "Encryption (default %s): ")
611 (choices '("plain" "tls"))
612 (default (or (plist-get server-plist :encryption)
613 'plain)))
614 (intern
615 (completing-read (format msg default)
616 choices nil t nil nil (symbol-name default)))))
618 (defun rcirc-keepalive ()
619 "Send keep alive pings to active rcirc processes.
620 Kill processes that have not received a server message since the
621 last ping."
622 (if (rcirc-process-list)
623 (mapc (lambda (process)
624 (with-rcirc-process-buffer process
625 (when (not rcirc-connecting)
626 (rcirc-send-ctcp process
627 rcirc-nick
628 (format "KEEPALIVE %f"
629 (rcirc-float-time))))))
630 (rcirc-process-list))
631 ;; no processes, clean up timer
632 (when (timerp rcirc-keepalive-timer)
633 (cancel-timer rcirc-keepalive-timer))
634 (setq rcirc-keepalive-timer nil)))
636 (defun rcirc-handler-ctcp-KEEPALIVE (process _target _sender message)
637 (with-rcirc-process-buffer process
638 (setq header-line-format (format "%f" (- (rcirc-float-time)
639 (string-to-number message))))))
641 (defvar rcirc-debug-buffer "*rcirc debug*")
642 (defvar rcirc-debug-flag nil
643 "If non-nil, write information to `rcirc-debug-buffer'.")
644 (defun rcirc-debug (process text)
645 "Add an entry to the debug log including PROCESS and TEXT.
646 Debug text is written to `rcirc-debug-buffer' if `rcirc-debug-flag'
647 is non-nil."
648 (when rcirc-debug-flag
649 (with-current-buffer (get-buffer-create rcirc-debug-buffer)
650 (goto-char (point-max))
651 (insert (concat
653 (format-time-string "%Y-%m-%dT%T ") (process-name process)
654 "] "
655 text)))))
657 (define-obsolete-variable-alias 'rcirc-sentinel-hooks
658 'rcirc-sentinel-functions "24.3")
659 (defvar rcirc-sentinel-functions nil
660 "Hook functions called when the process sentinel is called.
661 Functions are called with PROCESS and SENTINEL arguments.")
663 (defcustom rcirc-reconnect-delay 0
664 "The minimum interval in seconds between reconnect attempts.
665 When 0, do not auto-reconnect."
666 :version "25.1"
667 :type 'integer
668 :group 'rcirc)
670 (defvar rcirc-last-connect-time nil
671 "The last time the buffer was connected.")
673 (defun rcirc-sentinel (process sentinel)
674 "Called when PROCESS receives SENTINEL."
675 (let ((sentinel (replace-regexp-in-string "\n" "" sentinel)))
676 (rcirc-debug process (format "SENTINEL: %S %S\n" process sentinel))
677 (with-rcirc-process-buffer process
678 (dolist (buffer (cons nil (mapcar 'cdr rcirc-buffer-alist)))
679 (with-current-buffer (or buffer (current-buffer))
680 (rcirc-print process "rcirc.el" "ERROR" rcirc-target
681 (format "%s: %s (%S)"
682 (process-name process)
683 sentinel
684 (process-status process))
685 (not rcirc-target))
686 (rcirc-disconnect-buffer)))
687 (when (and (string= sentinel "deleted")
688 (< 0 rcirc-reconnect-delay))
689 (let ((now (current-time)))
690 (when (or (null rcirc-last-connect-time)
691 (< rcirc-reconnect-delay
692 (float-time (time-subtract now rcirc-last-connect-time))))
693 (setq rcirc-last-connect-time now)
694 (rcirc-cmd-reconnect nil))))
695 (run-hook-with-args 'rcirc-sentinel-functions process sentinel))))
697 (defun rcirc-disconnect-buffer (&optional buffer)
698 (with-current-buffer (or buffer (current-buffer))
699 ;; set rcirc-target to nil for each channel so cleanup
700 ;; doesn't happen when we reconnect
701 (setq rcirc-target nil)
702 (setq mode-line-process ":disconnected")))
704 (defun rcirc-process-list ()
705 "Return a list of rcirc processes."
706 (let (ps)
707 (mapc (lambda (p)
708 (when (buffer-live-p (process-buffer p))
709 (with-rcirc-process-buffer p
710 (when (eq major-mode 'rcirc-mode)
711 (setq ps (cons p ps))))))
712 (process-list))
713 ps))
715 (define-obsolete-variable-alias 'rcirc-receive-message-hooks
716 'rcirc-receive-message-functions "24.3")
717 (defvar rcirc-receive-message-functions nil
718 "Hook functions run when a message is received from server.
719 Function is called with PROCESS, COMMAND, SENDER, ARGS and LINE.")
720 (defun rcirc-filter (process output)
721 "Called when PROCESS receives OUTPUT."
722 (rcirc-debug process output)
723 (rcirc-reschedule-timeout process)
724 (with-rcirc-process-buffer process
725 (setq rcirc-last-server-message-time (current-time))
726 (setq rcirc-process-output (concat rcirc-process-output output))
727 (when (= (aref rcirc-process-output
728 (1- (length rcirc-process-output))) ?\n)
729 (mapc (lambda (line)
730 (rcirc-process-server-response process line))
731 (split-string rcirc-process-output "[\n\r]" t))
732 (setq rcirc-process-output nil))))
734 (defun rcirc-reschedule-timeout (process)
735 (with-rcirc-process-buffer process
736 (when (not rcirc-connecting)
737 (with-rcirc-process-buffer process
738 (when rcirc-timeout-timer (cancel-timer rcirc-timeout-timer))
739 (setq rcirc-timeout-timer (run-at-time rcirc-timeout-seconds nil
740 'rcirc-delete-process
741 process))))))
743 (defun rcirc-delete-process (process)
744 (delete-process process))
746 (defvar rcirc-trap-errors-flag t)
747 (defun rcirc-process-server-response (process text)
748 (if rcirc-trap-errors-flag
749 (condition-case err
750 (rcirc-process-server-response-1 process text)
751 (error
752 (rcirc-print process "RCIRC" "ERROR" nil
753 (format "\"%s\" %s" text err) t)))
754 (rcirc-process-server-response-1 process text)))
756 (defun rcirc-process-server-response-1 (process text)
757 (if (string-match "^\\(:\\([^ ]+\\) \\)?\\([^ ]+\\) \\(.+\\)$" text)
758 (let* ((user (match-string 2 text))
759 (sender (rcirc-user-nick user))
760 (cmd (match-string 3 text))
761 (args (match-string 4 text))
762 (handler (intern-soft (concat "rcirc-handler-" cmd))))
763 (string-match "^\\([^:]*\\):?\\(.+\\)?$" args)
764 (let* ((args1 (match-string 1 args))
765 (args2 (match-string 2 args))
766 (args (delq nil (append (split-string args1 " " t)
767 (list args2)))))
768 (if (not (fboundp handler))
769 (rcirc-handler-generic process cmd sender args text)
770 (funcall handler process sender args text))
771 (run-hook-with-args 'rcirc-receive-message-functions
772 process cmd sender args text)))
773 (message "UNHANDLED: %s" text)))
775 (defvar rcirc-responses-no-activity '("305" "306")
776 "Responses that don't trigger activity in the mode-line indicator.")
778 (defun rcirc-handler-generic (process response sender args _text)
779 "Generic server response handler."
780 (rcirc-print process sender response nil
781 (mapconcat 'identity (cdr args) " ")
782 (not (member response rcirc-responses-no-activity))))
784 (defun rcirc--connection-open-p (process)
785 (memq (process-status process) '(run open)))
787 (defun rcirc-send-string (process string)
788 "Send PROCESS a STRING plus a newline."
789 (let ((string (concat (encode-coding-string string rcirc-encode-coding-system)
790 "\n")))
791 (unless (rcirc--connection-open-p process)
792 (error "Network connection to %s is not open"
793 (process-name process)))
794 (rcirc-debug process string)
795 (process-send-string process string)))
797 (defun rcirc-send-privmsg (process target string)
798 (rcirc-send-string process (format "PRIVMSG %s :%s" target string)))
800 (defun rcirc-send-ctcp (process target request &optional args)
801 (let ((args (if args (concat " " args) "")))
802 (rcirc-send-privmsg process target
803 (format "\C-a%s%s\C-a" request args))))
805 (defun rcirc-buffer-process (&optional buffer)
806 "Return the process associated with channel BUFFER.
807 With no argument or nil as argument, use the current buffer."
808 (let ((buffer (or buffer (and (buffer-live-p rcirc-server-buffer)
809 rcirc-server-buffer))))
810 (if buffer
811 (with-current-buffer buffer rcirc-process)
812 rcirc-process)))
814 (defun rcirc-server-name (process)
815 "Return PROCESS server name, given by the 001 response."
816 (with-rcirc-process-buffer process
817 (or rcirc-server-name
818 (warn "server name for process %S unknown" process))))
820 (defun rcirc-nick (process)
821 "Return PROCESS nick."
822 (with-rcirc-process-buffer process
823 (or rcirc-nick rcirc-default-nick)))
825 (defun rcirc-buffer-nick (&optional buffer)
826 "Return the nick associated with BUFFER.
827 With no argument or nil as argument, use the current buffer."
828 (with-current-buffer (or buffer (current-buffer))
829 (with-current-buffer rcirc-server-buffer
830 (or rcirc-nick rcirc-default-nick))))
832 (defvar rcirc-max-message-length 420
833 "Messages longer than this value will be split.")
835 (defun rcirc-split-message (message)
836 "Split MESSAGE into chunks within `rcirc-max-message-length'."
837 ;; `rcirc-encode-coding-system' can have buffer-local value.
838 (let ((encoding rcirc-encode-coding-system))
839 (with-temp-buffer
840 (insert message)
841 (goto-char (point-min))
842 (let (result)
843 (while (not (eobp))
844 (goto-char (or (byte-to-position rcirc-max-message-length)
845 (point-max)))
846 ;; max message length is 512 including CRLF
847 (while (and (not (bobp))
848 (> (length (encode-coding-region
849 (point-min) (point) encoding t))
850 rcirc-max-message-length))
851 (forward-char -1))
852 (push (delete-and-extract-region (point-min) (point)) result))
853 (nreverse result)))))
855 (defun rcirc-send-message (process target message &optional noticep silent)
856 "Send TARGET associated with PROCESS a privmsg with text MESSAGE.
857 If NOTICEP is non-nil, send a notice instead of privmsg.
858 If SILENT is non-nil, do not print the message in any irc buffer."
859 (let ((response (if noticep "NOTICE" "PRIVMSG")))
860 (rcirc-get-buffer-create process target)
861 (dolist (msg (rcirc-split-message message))
862 (rcirc-send-string process (concat response " " target " :" msg))
863 (unless silent
864 (rcirc-print process (rcirc-nick process) response target msg)))))
866 (defvar rcirc-input-ring nil)
867 (defvar rcirc-input-ring-index 0)
869 (defun rcirc-prev-input-string (arg)
870 (ring-ref rcirc-input-ring (+ rcirc-input-ring-index arg)))
872 (defun rcirc-insert-prev-input ()
873 (interactive)
874 (when (<= rcirc-prompt-end-marker (point))
875 (delete-region rcirc-prompt-end-marker (point-max))
876 (insert (rcirc-prev-input-string 0))
877 (setq rcirc-input-ring-index (1+ rcirc-input-ring-index))))
879 (defun rcirc-insert-next-input ()
880 (interactive)
881 (when (<= rcirc-prompt-end-marker (point))
882 (delete-region rcirc-prompt-end-marker (point-max))
883 (setq rcirc-input-ring-index (1- rcirc-input-ring-index))
884 (insert (rcirc-prev-input-string -1))))
886 (defvar rcirc-server-commands
887 '("/admin" "/away" "/connect" "/die" "/error" "/info"
888 "/invite" "/ison" "/join" "/kick" "/kill" "/links"
889 "/list" "/lusers" "/mode" "/motd" "/names" "/nick"
890 "/notice" "/oper" "/part" "/pass" "/ping" "/pong"
891 "/privmsg" "/quit" "/rehash" "/restart" "/service" "/servlist"
892 "/server" "/squery" "/squit" "/stats" "/summon" "/time"
893 "/topic" "/trace" "/user" "/userhost" "/users" "/version"
894 "/wallops" "/who" "/whois" "/whowas")
895 "A list of user commands by IRC server.
896 The value defaults to RFCs 1459 and 2812.")
898 ;; /me and /ctcp are not defined by `defun-rcirc-command'.
899 (defvar rcirc-client-commands '("/me" "/ctcp")
900 "A list of user commands defined by IRC client rcirc.
901 The list is updated automatically by `defun-rcirc-command'.")
903 (defun rcirc-completion-at-point ()
904 "Function used for `completion-at-point-functions' in `rcirc-mode'."
905 (and (rcirc-looking-at-input)
906 (let* ((beg (save-excursion
907 ;; On some networks it is common to message or
908 ;; mention someone using @nick instead of just
909 ;; nick.
910 (if (re-search-backward "[[:space:]@]" rcirc-prompt-end-marker t)
911 (1+ (point))
912 rcirc-prompt-end-marker)))
913 (table (if (and (= beg rcirc-prompt-end-marker)
914 (eq (char-after beg) ?/))
915 (delete-dups
916 (nconc (sort (copy-sequence rcirc-client-commands)
917 'string-lessp)
918 (sort (copy-sequence rcirc-server-commands)
919 'string-lessp)))
920 (rcirc-channel-nicks (rcirc-buffer-process)
921 rcirc-target))))
922 (list beg (point) table))))
924 (defvar rcirc-completions nil)
925 (defvar rcirc-completion-start nil)
927 (defun rcirc-complete ()
928 "Cycle through completions from list of nicks in channel or IRC commands.
929 IRC command completion is performed only if ‘/’ is the first input char."
930 (interactive)
931 (unless (rcirc-looking-at-input)
932 (error "Point not located after rcirc prompt"))
933 (if (eq last-command this-command)
934 (setq rcirc-completions
935 (append (cdr rcirc-completions) (list (car rcirc-completions))))
936 (let ((completion-ignore-case t)
937 (table (rcirc-completion-at-point)))
938 (setq rcirc-completion-start (car table))
939 (setq rcirc-completions
940 (and rcirc-completion-start
941 (all-completions (buffer-substring rcirc-completion-start
942 (cadr table))
943 (nth 2 table))))))
944 (let ((completion (car rcirc-completions)))
945 (when completion
946 (delete-region rcirc-completion-start (point))
947 (insert
948 (cond
949 ((= (aref completion 0) ?/) (concat completion " "))
950 ((= rcirc-completion-start rcirc-prompt-end-marker)
951 (format rcirc-nick-completion-format completion))
952 (t completion))))))
954 (defun set-rcirc-decode-coding-system (coding-system)
955 "Set the decode coding system used in this channel."
956 (interactive "zCoding system for incoming messages: ")
957 (setq-local rcirc-decode-coding-system coding-system))
959 (defun set-rcirc-encode-coding-system (coding-system)
960 "Set the encode coding system used in this channel."
961 (interactive "zCoding system for outgoing messages: ")
962 (setq-local rcirc-encode-coding-system coding-system))
964 (defvar rcirc-mode-map
965 (let ((map (make-sparse-keymap)))
966 (define-key map (kbd "RET") 'rcirc-send-input)
967 (define-key map (kbd "M-p") 'rcirc-insert-prev-input)
968 (define-key map (kbd "M-n") 'rcirc-insert-next-input)
969 (define-key map (kbd "TAB") 'rcirc-complete)
970 (define-key map (kbd "C-c C-b") 'rcirc-browse-url)
971 (define-key map (kbd "C-c C-c") 'rcirc-edit-multiline)
972 (define-key map (kbd "C-c C-j") 'rcirc-cmd-join)
973 (define-key map (kbd "C-c C-k") 'rcirc-cmd-kick)
974 (define-key map (kbd "C-c C-l") 'rcirc-toggle-low-priority)
975 (define-key map (kbd "C-c C-d") 'rcirc-cmd-mode)
976 (define-key map (kbd "C-c C-m") 'rcirc-cmd-msg)
977 (define-key map (kbd "C-c C-r") 'rcirc-cmd-nick) ; rename
978 (define-key map (kbd "C-c C-o") 'rcirc-omit-mode)
979 (define-key map (kbd "C-c C-p") 'rcirc-cmd-part)
980 (define-key map (kbd "C-c C-q") 'rcirc-cmd-query)
981 (define-key map (kbd "C-c C-t") 'rcirc-cmd-topic)
982 (define-key map (kbd "C-c C-n") 'rcirc-cmd-names)
983 (define-key map (kbd "C-c C-w") 'rcirc-cmd-whois)
984 (define-key map (kbd "C-c C-x") 'rcirc-cmd-quit)
985 (define-key map (kbd "C-c TAB") ; C-i
986 'rcirc-toggle-ignore-buffer-activity)
987 (define-key map (kbd "C-c C-s") 'rcirc-switch-to-server-buffer)
988 (define-key map (kbd "C-c C-a") 'rcirc-jump-to-first-unread-line)
989 map)
990 "Keymap for rcirc mode.")
992 (defvar rcirc-short-buffer-name nil
993 "Generated abbreviation to use to indicate buffer activity.")
995 (defvar rcirc-mode-hook nil
996 "Hook run when setting up rcirc buffer.")
998 (defvar rcirc-last-post-time nil)
1000 (defvar rcirc-log-alist nil
1001 "Alist of lines to log to disk when `rcirc-log-flag' is non-nil.
1002 Each element looks like (FILENAME . TEXT).")
1004 (defvar rcirc-current-line 0
1005 "The current number of responses printed in this channel.
1006 This number is independent of the number of lines in the buffer.")
1008 (defun rcirc-mode (process target)
1009 ;; FIXME: Use define-derived-mode.
1010 "Major mode for IRC channel buffers.
1012 \\{rcirc-mode-map}"
1013 (kill-all-local-variables)
1014 (use-local-map rcirc-mode-map)
1015 (setq mode-name "rcirc")
1016 (setq major-mode 'rcirc-mode)
1017 (setq mode-line-process nil)
1019 (setq-local rcirc-input-ring
1020 ;; If rcirc-input-ring is already a ring with desired
1021 ;; size do not re-initialize.
1022 (if (and (ring-p rcirc-input-ring)
1023 (= (ring-size rcirc-input-ring)
1024 rcirc-input-ring-size))
1025 rcirc-input-ring
1026 (make-ring rcirc-input-ring-size)))
1027 (setq-local rcirc-server-buffer (process-buffer process))
1028 (setq-local rcirc-target target)
1029 (setq-local rcirc-topic nil)
1030 (setq-local rcirc-last-post-time (current-time))
1031 (setq-local fill-paragraph-function 'rcirc-fill-paragraph)
1032 (setq-local rcirc-recent-quit-alist nil)
1033 (setq-local rcirc-current-line 0)
1034 (setq-local rcirc-last-connect-time (current-time))
1036 (use-hard-newlines t)
1037 (setq-local rcirc-short-buffer-name nil)
1038 (setq-local rcirc-urls nil)
1040 ;; setup for omitting responses
1041 (setq buffer-invisibility-spec '())
1042 (setq buffer-display-table (make-display-table))
1043 (set-display-table-slot buffer-display-table 4
1044 (let ((glyph (make-glyph-code
1045 ?. 'font-lock-keyword-face)))
1046 (make-vector 3 glyph)))
1048 (dolist (i rcirc-coding-system-alist)
1049 (let ((chan (if (consp (car i)) (caar i) (car i)))
1050 (serv (if (consp (car i)) (cdar i) "")))
1051 (when (and (string-match chan (or target ""))
1052 (string-match serv (rcirc-server-name process)))
1053 (setq-local rcirc-decode-coding-system
1054 (if (consp (cdr i)) (cadr i) (cdr i)))
1055 (setq-local rcirc-encode-coding-system
1056 (if (consp (cdr i)) (cddr i) (cdr i))))))
1058 ;; setup the prompt and markers
1059 (setq-local rcirc-prompt-start-marker (point-max-marker))
1060 (setq-local rcirc-prompt-end-marker (point-max-marker))
1061 (rcirc-update-prompt)
1062 (goto-char rcirc-prompt-end-marker)
1064 (setq-local overlay-arrow-position (make-marker))
1066 ;; if the user changes the major mode or kills the buffer, there is
1067 ;; cleanup work to do
1068 (add-hook 'change-major-mode-hook 'rcirc-change-major-mode-hook nil t)
1069 (add-hook 'kill-buffer-hook 'rcirc-kill-buffer-hook nil t)
1071 ;; add to buffer list, and update buffer abbrevs
1072 (when target ; skip server buffer
1073 (let ((buffer (current-buffer)))
1074 (with-rcirc-process-buffer process
1075 (setq rcirc-buffer-alist (cons (cons target buffer)
1076 rcirc-buffer-alist))))
1077 (rcirc-update-short-buffer-names))
1079 (add-hook 'completion-at-point-functions
1080 'rcirc-completion-at-point nil 'local)
1082 (run-mode-hooks 'rcirc-mode-hook))
1084 (defun rcirc-update-prompt (&optional all)
1085 "Reset the prompt string in the current buffer.
1087 If ALL is non-nil, update prompts in all IRC buffers."
1088 (if all
1089 (mapc (lambda (process)
1090 (mapc (lambda (buffer)
1091 (with-current-buffer buffer
1092 (rcirc-update-prompt)))
1093 (with-rcirc-process-buffer process
1094 (mapcar 'cdr rcirc-buffer-alist))))
1095 (rcirc-process-list))
1096 (let ((inhibit-read-only t)
1097 (prompt (or rcirc-prompt "")))
1098 (mapc (lambda (rep)
1099 (setq prompt
1100 (replace-regexp-in-string (car rep) (cdr rep) prompt)))
1101 (list (cons "%n" (rcirc-buffer-nick))
1102 (cons "%s" (with-rcirc-server-buffer rcirc-server-name))
1103 (cons "%t" (or rcirc-target ""))))
1104 (save-excursion
1105 (delete-region rcirc-prompt-start-marker rcirc-prompt-end-marker)
1106 (goto-char rcirc-prompt-start-marker)
1107 (let ((start (point)))
1108 (insert-before-markers prompt)
1109 (set-marker rcirc-prompt-start-marker start)
1110 (when (not (zerop (- rcirc-prompt-end-marker
1111 rcirc-prompt-start-marker)))
1112 (add-text-properties rcirc-prompt-start-marker
1113 rcirc-prompt-end-marker
1114 (list 'face 'rcirc-prompt
1115 'read-only t 'field t
1116 'front-sticky t 'rear-nonsticky t))))))))
1118 (defun rcirc-set-changed (option value)
1119 "Set OPTION to VALUE and do updates after a customization change."
1120 (set-default option value)
1121 (cond ((eq option 'rcirc-prompt)
1122 (rcirc-update-prompt 'all))
1124 (error "Bad option %s" option))))
1126 (defun rcirc-channel-p (target)
1127 "Return t if TARGET is a channel name."
1128 (and target
1129 (not (zerop (length target)))
1130 (or (eq (aref target 0) ?#)
1131 (eq (aref target 0) ?&))))
1133 (defcustom rcirc-log-directory "~/.emacs.d/rcirc-log"
1134 "Directory to keep IRC logfiles."
1135 :type 'directory
1136 :group 'rcirc)
1138 (defcustom rcirc-log-flag nil
1139 "Non-nil means log IRC activity to disk.
1140 Logfiles are kept in `rcirc-log-directory'."
1141 :type 'boolean
1142 :group 'rcirc)
1144 (defun rcirc-kill-buffer-hook ()
1145 "Part the channel when killing an rcirc buffer.
1147 If `rcirc-kill-channel-buffers' is non-nil and the killed buffer
1148 is a server buffer, kills all of the channel buffers associated
1149 with it."
1150 (when (eq major-mode 'rcirc-mode)
1151 (when (and rcirc-log-flag
1152 rcirc-log-directory)
1153 (rcirc-log-write))
1154 (rcirc-clean-up-buffer "Killed buffer")
1155 (when (and rcirc-buffer-alist ;; it's a server buffer
1156 rcirc-kill-channel-buffers)
1157 (dolist (channel rcirc-buffer-alist)
1158 (kill-buffer (cdr channel))))))
1160 (defun rcirc-change-major-mode-hook ()
1161 "Part the channel when changing the major-mode."
1162 (rcirc-clean-up-buffer "Changed major mode"))
1164 (defun rcirc-clean-up-buffer (reason)
1165 (let ((buffer (current-buffer)))
1166 (rcirc-clear-activity buffer)
1167 (when (and (rcirc-buffer-process)
1168 (rcirc--connection-open-p (rcirc-buffer-process)))
1169 (with-rcirc-server-buffer
1170 (setq rcirc-buffer-alist
1171 (rassq-delete-all buffer rcirc-buffer-alist)))
1172 (rcirc-update-short-buffer-names)
1173 (if (rcirc-channel-p rcirc-target)
1174 (rcirc-send-string (rcirc-buffer-process)
1175 (concat "PART " rcirc-target " :" reason))
1176 (when rcirc-target
1177 (rcirc-remove-nick-channel (rcirc-buffer-process)
1178 (rcirc-buffer-nick)
1179 rcirc-target))))
1180 (setq rcirc-target nil)))
1182 (defun rcirc-generate-new-buffer-name (process target)
1183 "Return a buffer name based on PROCESS and TARGET.
1184 This is used for the initial name given to IRC buffers."
1185 (substring-no-properties
1186 (if target
1187 (concat target "@" (process-name process))
1188 (concat "*" (process-name process) "*"))))
1190 (defun rcirc-get-buffer (process target &optional server)
1191 "Return the buffer associated with the PROCESS and TARGET.
1193 If optional argument SERVER is non-nil, return the server buffer
1194 if there is no existing buffer for TARGET, otherwise return nil."
1195 (with-rcirc-process-buffer process
1196 (if (null target)
1197 (current-buffer)
1198 (let ((buffer (cdr (assoc-string target rcirc-buffer-alist t))))
1199 (or buffer (when server (current-buffer)))))))
1201 (defun rcirc-get-buffer-create (process target)
1202 "Return the buffer associated with the PROCESS and TARGET.
1203 Create the buffer if it doesn't exist."
1204 (let ((buffer (rcirc-get-buffer process target)))
1205 (if (and buffer (buffer-live-p buffer))
1206 (with-current-buffer buffer
1207 (when (not rcirc-target)
1208 (setq rcirc-target target))
1209 buffer)
1210 ;; create the buffer
1211 (with-rcirc-process-buffer process
1212 (let ((new-buffer (get-buffer-create
1213 (rcirc-generate-new-buffer-name process target))))
1214 (with-current-buffer new-buffer
1215 (rcirc-mode process target)
1216 (rcirc-put-nick-channel process (rcirc-nick process) target
1217 rcirc-current-line))
1218 new-buffer)))))
1220 (defun rcirc-send-input ()
1221 "Send input to target associated with the current buffer."
1222 (interactive)
1223 (if (< (point) rcirc-prompt-end-marker)
1224 ;; copy the line down to the input area
1225 (progn
1226 (forward-line 0)
1227 (let ((start (if (eq (point) (point-min))
1228 (point)
1229 (if (get-text-property (1- (point)) 'hard)
1230 (point)
1231 (previous-single-property-change (point) 'hard))))
1232 (end (next-single-property-change (1+ (point)) 'hard)))
1233 (goto-char (point-max))
1234 (insert (replace-regexp-in-string
1235 "\n\\s-+" " "
1236 (buffer-substring-no-properties start end)))))
1237 ;; process input
1238 (goto-char (point-max))
1239 (when (not (equal 0 (- (point) rcirc-prompt-end-marker)))
1240 ;; delete a trailing newline
1241 (when (eq (point) (point-at-bol))
1242 (delete-char -1))
1243 (let ((input (buffer-substring-no-properties
1244 rcirc-prompt-end-marker (point))))
1245 (dolist (line (split-string input "\n"))
1246 (rcirc-process-input-line line))
1247 ;; add to input-ring
1248 (save-excursion
1249 (ring-insert rcirc-input-ring input)
1250 (setq rcirc-input-ring-index 0))))))
1252 (defun rcirc-fill-paragraph (&optional justify)
1253 (interactive "P")
1254 (when (> (point) rcirc-prompt-end-marker)
1255 (save-restriction
1256 (narrow-to-region rcirc-prompt-end-marker (point-max))
1257 (let ((fill-column rcirc-max-message-length))
1258 (fill-region (point-min) (point-max) justify)))))
1260 (defun rcirc-process-input-line (line)
1261 (if (string-match "^/\\([^ ]+\\) ?\\(.*\\)$" line)
1262 (rcirc-process-command (match-string 1 line)
1263 (match-string 2 line)
1264 line)
1265 (rcirc-process-message line)))
1267 (defun rcirc-process-message (line)
1268 (if (not rcirc-target)
1269 (message "Not joined (no target)")
1270 (delete-region rcirc-prompt-end-marker (point))
1271 (rcirc-send-message (rcirc-buffer-process) rcirc-target line)
1272 (setq rcirc-last-post-time (current-time))))
1274 (defun rcirc-process-command (command args line)
1275 (if (eq (aref command 0) ?/)
1276 ;; "//text" will send "/text" as a message
1277 (rcirc-process-message (substring line 1))
1278 (let ((fun (intern-soft (concat "rcirc-cmd-" command)))
1279 (process (rcirc-buffer-process)))
1280 (newline)
1281 (with-current-buffer (current-buffer)
1282 (delete-region rcirc-prompt-end-marker (point))
1283 (if (string= command "me")
1284 (rcirc-print process (rcirc-buffer-nick)
1285 "ACTION" rcirc-target args)
1286 (rcirc-print process (rcirc-buffer-nick)
1287 "COMMAND" rcirc-target line))
1288 (set-marker rcirc-prompt-end-marker (point))
1289 (if (fboundp fun)
1290 (funcall fun args process rcirc-target)
1291 (rcirc-send-string process
1292 (concat command " :" args)))))))
1294 (defvar rcirc-parent-buffer nil)
1295 (make-variable-buffer-local 'rcirc-parent-buffer)
1296 (put 'rcirc-parent-buffer 'permanent-local t)
1297 (defvar rcirc-window-configuration nil)
1298 (defun rcirc-edit-multiline ()
1299 "Move current edit to a dedicated buffer."
1300 (interactive)
1301 (let ((pos (1+ (- (point) rcirc-prompt-end-marker))))
1302 (goto-char (point-max))
1303 (let ((text (buffer-substring-no-properties rcirc-prompt-end-marker
1304 (point)))
1305 (parent (buffer-name)))
1306 (delete-region rcirc-prompt-end-marker (point))
1307 (setq rcirc-window-configuration (current-window-configuration))
1308 (pop-to-buffer (concat "*multiline " parent "*"))
1309 (funcall rcirc-multiline-major-mode)
1310 (rcirc-multiline-minor-mode 1)
1311 (setq rcirc-parent-buffer parent)
1312 (insert text)
1313 (and (> pos 0) (goto-char pos))
1314 (message "Type C-c C-c to return text to %s, or C-c C-k to cancel" parent))))
1316 (defvar rcirc-multiline-minor-mode-map
1317 (let ((map (make-sparse-keymap)))
1318 (define-key map (kbd "C-c C-c") 'rcirc-multiline-minor-submit)
1319 (define-key map (kbd "C-x C-s") 'rcirc-multiline-minor-submit)
1320 (define-key map (kbd "C-c C-k") 'rcirc-multiline-minor-cancel)
1321 (define-key map (kbd "ESC ESC ESC") 'rcirc-multiline-minor-cancel)
1322 map)
1323 "Keymap for multiline mode in rcirc.")
1325 (define-minor-mode rcirc-multiline-minor-mode
1326 "Minor mode for editing multiple lines in rcirc.
1327 With a prefix argument ARG, enable the mode if ARG is positive,
1328 and disable it otherwise. If called from Lisp, enable the mode
1329 if ARG is omitted or nil."
1330 :init-value nil
1331 :lighter " rcirc-mline"
1332 :keymap rcirc-multiline-minor-mode-map
1333 :global nil
1334 :group 'rcirc
1335 (setq fill-column rcirc-max-message-length))
1337 (defun rcirc-multiline-minor-submit ()
1338 "Send the text in buffer back to parent buffer."
1339 (interactive)
1340 (untabify (point-min) (point-max))
1341 (let ((text (buffer-substring (point-min) (point-max)))
1342 (buffer (current-buffer))
1343 (pos (point)))
1344 (set-buffer rcirc-parent-buffer)
1345 (goto-char (point-max))
1346 (insert text)
1347 (kill-buffer buffer)
1348 (set-window-configuration rcirc-window-configuration)
1349 (goto-char (+ rcirc-prompt-end-marker (1- pos)))))
1351 (defun rcirc-multiline-minor-cancel ()
1352 "Cancel the multiline edit."
1353 (interactive)
1354 (kill-buffer (current-buffer))
1355 (set-window-configuration rcirc-window-configuration))
1357 (defun rcirc-any-buffer (process)
1358 "Return a buffer for PROCESS, either the one selected or the process buffer."
1359 (if rcirc-always-use-server-buffer-flag
1360 (process-buffer process)
1361 (let ((buffer (window-buffer)))
1362 (if (and buffer
1363 (with-current-buffer buffer
1364 (and (eq major-mode 'rcirc-mode)
1365 (eq (rcirc-buffer-process) process))))
1366 buffer
1367 (process-buffer process)))))
1369 (defcustom rcirc-response-formats
1370 '(("PRIVMSG" . "<%N> %m")
1371 ("NOTICE" . "-%N- %m")
1372 ("ACTION" . "[%N %m]")
1373 ("COMMAND" . "%m")
1374 ("ERROR" . "%fw!!! %m")
1375 (t . "%fp*** %fs%n %r %m"))
1376 "An alist of formats used for printing responses.
1377 The format is looked up using the response-type as a key;
1378 if no match is found, the default entry (with a key of t) is used.
1380 The entry's value part should be a string, which is inserted with
1381 the of the following escape sequences replaced by the described values:
1383 %m The message text
1384 %n The sender's nick
1385 %N The sender's nick (with face `rcirc-my-nick' or `rcirc-other-nick')
1386 %r The response-type
1387 %t The target
1388 %fw Following text uses the face `font-lock-warning-face'
1389 %fp Following text uses the face `rcirc-server-prefix'
1390 %fs Following text uses the face `rcirc-server'
1391 %f[FACE] Following text uses the face FACE
1392 %f- Following text uses the default face
1393 %% A literal `%' character"
1394 :type '(alist :key-type (choice (string :tag "Type")
1395 (const :tag "Default" t))
1396 :value-type string)
1397 :group 'rcirc)
1399 (defcustom rcirc-omit-responses
1400 '("JOIN" "PART" "QUIT" "NICK")
1401 "Responses which will be hidden when `rcirc-omit-mode' is enabled."
1402 :type '(repeat string)
1403 :group 'rcirc)
1405 (defun rcirc-format-response-string (process sender response target text)
1406 "Return a nicely-formatted response string, incorporating TEXT
1407 \(and perhaps other arguments). The specific formatting used
1408 is found by looking up RESPONSE in `rcirc-response-formats'."
1409 (with-temp-buffer
1410 (insert (or (cdr (assoc response rcirc-response-formats))
1411 (cdr (assq t rcirc-response-formats))))
1412 (goto-char (point-min))
1413 (let ((start (point-min))
1414 (sender (if (or (not sender)
1415 (string= (rcirc-server-name process) sender))
1417 sender))
1418 face)
1419 (while (re-search-forward "%\\(\\(f\\(.\\)\\)\\|\\(.\\)\\)" nil t)
1420 (rcirc-add-face start (match-beginning 0) face)
1421 (setq start (match-beginning 0))
1422 (replace-match
1423 (cl-case (aref (match-string 1) 0)
1424 (?f (setq face
1425 (cl-case (string-to-char (match-string 3))
1426 (?w 'font-lock-warning-face)
1427 (?p 'rcirc-server-prefix)
1428 (?s 'rcirc-server)
1429 (t nil)))
1431 (?n sender)
1432 (?N (let ((my-nick (rcirc-nick process)))
1433 (save-match-data
1434 (with-syntax-table rcirc-nick-syntax-table
1435 (rcirc-facify sender
1436 (cond ((string= sender my-nick)
1437 'rcirc-my-nick)
1438 ((and rcirc-bright-nicks
1439 (string-match
1440 (regexp-opt rcirc-bright-nicks
1441 'words)
1442 sender))
1443 'rcirc-bright-nick)
1444 ((and rcirc-dim-nicks
1445 (string-match
1446 (regexp-opt rcirc-dim-nicks
1447 'words)
1448 sender))
1449 'rcirc-dim-nick)
1451 'rcirc-other-nick)))))))
1452 (?m (propertize text 'rcirc-text text))
1453 (?r response)
1454 (?t (or target ""))
1455 (t (concat "UNKNOWN CODE:" (match-string 0))))
1456 t t nil 0)
1457 (rcirc-add-face (match-beginning 0) (match-end 0) face))
1458 (rcirc-add-face start (match-beginning 0) face))
1459 (buffer-substring (point-min) (point-max))))
1461 (defun rcirc-target-buffer (process sender response target _text)
1462 "Return a buffer to print the server response."
1463 (cl-assert (not (bufferp target)))
1464 (with-rcirc-process-buffer process
1465 (cond ((not target)
1466 (rcirc-any-buffer process))
1467 ((not (rcirc-channel-p target))
1468 ;; message from another user
1469 (if (or (string= response "PRIVMSG")
1470 (string= response "ACTION"))
1471 (rcirc-get-buffer-create process (if (string= sender rcirc-nick)
1472 target
1473 sender))
1474 (rcirc-get-buffer process target t)))
1475 ((or (rcirc-get-buffer process target)
1476 (rcirc-any-buffer process))))))
1478 (defvar rcirc-activity-types nil)
1479 (make-variable-buffer-local 'rcirc-activity-types)
1480 (defvar rcirc-last-sender nil)
1481 (make-variable-buffer-local 'rcirc-last-sender)
1483 (defcustom rcirc-omit-threshold 100
1484 "Number of lines since last activity from a nick before `rcirc-omit-responses' are omitted."
1485 :type 'integer
1486 :group 'rcirc)
1488 (defcustom rcirc-log-process-buffers nil
1489 "Non-nil if rcirc process buffers should be logged to disk."
1490 :group 'rcirc
1491 :type 'boolean
1492 :version "24.1")
1494 (defun rcirc-last-quit-line (process nick target)
1495 "Return the line number where NICK left TARGET.
1496 Returns nil if the information is not recorded."
1497 (let ((chanbuf (rcirc-get-buffer process target)))
1498 (when chanbuf
1499 (cdr (assoc-string nick (with-current-buffer chanbuf
1500 rcirc-recent-quit-alist))))))
1502 (defun rcirc-last-line (process nick target)
1503 "Return the line from the last activity from NICK in TARGET."
1504 (let ((line (or (cdr (assoc-string target
1505 (gethash nick (with-rcirc-server-buffer
1506 rcirc-nick-table)) t))
1507 (rcirc-last-quit-line process nick target))))
1508 (if line
1509 line
1510 ;;(message "line is nil for %s in %s" nick target)
1511 nil)))
1513 (defun rcirc-elapsed-lines (process nick target)
1514 "Return the number of lines since activity from NICK in TARGET."
1515 (let ((last-activity-line (rcirc-last-line process nick target)))
1516 (when (and last-activity-line
1517 (> last-activity-line 0))
1518 (- rcirc-current-line last-activity-line))))
1520 (defvar rcirc-markup-text-functions
1521 '(rcirc-markup-attributes
1522 rcirc-markup-my-nick
1523 rcirc-markup-urls
1524 rcirc-markup-keywords
1525 rcirc-markup-bright-nicks)
1527 "List of functions used to manipulate text before it is printed.
1529 Each function takes two arguments, SENDER, and RESPONSE. The
1530 buffer is narrowed with the text to be printed and the point is
1531 at the beginning of the `rcirc-text' propertized text.")
1533 (defun rcirc-print (process sender response target text &optional activity)
1534 "Print TEXT in the buffer associated with TARGET.
1535 Format based on SENDER and RESPONSE. If ACTIVITY is non-nil,
1536 record activity."
1537 (or text (setq text ""))
1538 (unless (and (or (member sender rcirc-ignore-list)
1539 (member (with-syntax-table rcirc-nick-syntax-table
1540 (when (string-match "^\\([^/]\\w*\\)[:,]" text)
1541 (match-string 1 text)))
1542 rcirc-ignore-list))
1543 ;; do not ignore if we sent the message
1544 (not (string= sender (rcirc-nick process))))
1545 (let* ((buffer (rcirc-target-buffer process sender response target text))
1546 (inhibit-read-only t))
1547 (with-current-buffer buffer
1548 (let ((moving (= (point) rcirc-prompt-end-marker))
1549 (old-point (point-marker))
1550 (fill-start (marker-position rcirc-prompt-start-marker)))
1552 (setq text (decode-coding-string text rcirc-decode-coding-system))
1553 (unless (string= sender (rcirc-nick process))
1554 ;; mark the line with overlay arrow
1555 (unless (or (marker-position overlay-arrow-position)
1556 (get-buffer-window (current-buffer))
1557 (member response rcirc-omit-responses))
1558 (set-marker overlay-arrow-position
1559 (marker-position rcirc-prompt-start-marker))))
1561 ;; temporarily set the marker insertion-type because
1562 ;; insert-before-markers results in hidden text in new buffers
1563 (goto-char rcirc-prompt-start-marker)
1564 (set-marker-insertion-type rcirc-prompt-start-marker t)
1565 (set-marker-insertion-type rcirc-prompt-end-marker t)
1567 (let ((start (point)))
1568 (insert (rcirc-format-response-string process sender response nil
1569 text)
1570 (propertize "\n" 'hard t))
1572 ;; squeeze spaces out of text before rcirc-text
1573 (fill-region fill-start
1574 (1- (or (next-single-property-change fill-start
1575 'rcirc-text)
1576 rcirc-prompt-end-marker)))
1578 ;; run markup functions
1579 (save-excursion
1580 (save-restriction
1581 (narrow-to-region start rcirc-prompt-start-marker)
1582 (goto-char (or (next-single-property-change start 'rcirc-text)
1583 (point)))
1584 (when (rcirc-buffer-process)
1585 (save-excursion (rcirc-markup-timestamp sender response))
1586 (dolist (fn rcirc-markup-text-functions)
1587 (save-excursion (funcall fn sender response)))
1588 (when rcirc-fill-flag
1589 (save-excursion (rcirc-markup-fill sender response))))
1591 (when rcirc-read-only-flag
1592 (add-text-properties (point-min) (point-max)
1593 '(read-only t front-sticky t))))
1594 ;; make text omittable
1595 (let ((last-activity-lines (rcirc-elapsed-lines process sender target)))
1596 (if (and (not (string= (rcirc-nick process) sender))
1597 (member response rcirc-omit-responses)
1598 (or (not last-activity-lines)
1599 (< rcirc-omit-threshold last-activity-lines)))
1600 (put-text-property (1- start) (1- rcirc-prompt-start-marker)
1601 'invisible 'rcirc-omit)
1602 ;; otherwise increment the line count
1603 (setq rcirc-current-line (1+ rcirc-current-line))))))
1605 (set-marker-insertion-type rcirc-prompt-start-marker nil)
1606 (set-marker-insertion-type rcirc-prompt-end-marker nil)
1608 ;; truncate buffer if it is very long
1609 (save-excursion
1610 (when (and rcirc-buffer-maximum-lines
1611 (> rcirc-buffer-maximum-lines 0)
1612 (= (forward-line (- rcirc-buffer-maximum-lines)) 0))
1613 (delete-region (point-min) (point))))
1615 ;; set the window point for buffers show in windows
1616 (walk-windows (lambda (w)
1617 (when (and (not (eq (selected-window) w))
1618 (eq (current-buffer)
1619 (window-buffer w))
1620 (>= (window-point w)
1621 rcirc-prompt-end-marker))
1622 (set-window-point w (point-max))))
1623 nil t)
1625 ;; restore the point
1626 (goto-char (if moving rcirc-prompt-end-marker old-point))
1628 ;; keep window on bottom line if it was already there
1629 (when rcirc-scroll-show-maximum-output
1630 (let ((window (get-buffer-window)))
1631 (when window
1632 (with-selected-window window
1633 (when (eq major-mode 'rcirc-mode)
1634 (when (<= (- (window-height)
1635 (count-screen-lines (window-point)
1636 (window-start))
1639 (recenter -1)))))))
1641 ;; flush undo (can we do something smarter here?)
1642 (buffer-disable-undo)
1643 (buffer-enable-undo))
1645 ;; record mode line activity
1646 (when (and activity
1647 (not rcirc-ignore-buffer-activity-flag)
1648 (not (and rcirc-dim-nicks sender
1649 (string-match (regexp-opt rcirc-dim-nicks) sender)
1650 (rcirc-channel-p target))))
1651 (rcirc-record-activity (current-buffer)
1652 (when (not (rcirc-channel-p rcirc-target))
1653 'nick)))
1655 (when (and rcirc-log-flag
1656 (or target
1657 rcirc-log-process-buffers))
1658 (rcirc-log process sender response target text))
1660 (sit-for 0) ; displayed text before hook
1661 (run-hook-with-args 'rcirc-print-functions
1662 process sender response target text)))))
1664 (defun rcirc-generate-log-filename (process target)
1665 (if target
1666 (rcirc-generate-new-buffer-name process target)
1667 (process-name process)))
1669 (defcustom rcirc-log-filename-function 'rcirc-generate-log-filename
1670 "A function to generate the filename used by rcirc's logging facility.
1672 It is called with two arguments, PROCESS and TARGET (see
1673 `rcirc-generate-new-buffer-name' for their meaning), and should
1674 return the filename, or nil if no logging is desired for this
1675 session.
1677 If the returned filename is absolute (`file-name-absolute-p'
1678 returns t), then it is used as-is, otherwise the resulting file
1679 is put into `rcirc-log-directory'.
1681 The filename is then cleaned using `convert-standard-filename' to
1682 guarantee valid filenames for the current OS."
1683 :group 'rcirc
1684 :type 'function)
1686 (defun rcirc-log (process sender response target text)
1687 "Record line in `rcirc-log', to be later written to disk."
1688 (let ((filename (funcall rcirc-log-filename-function process target)))
1689 (unless (null filename)
1690 (let ((cell (assoc-string filename rcirc-log-alist))
1691 (line (concat (format-time-string rcirc-time-format)
1692 (substring-no-properties
1693 (rcirc-format-response-string process sender
1694 response target text))
1695 "\n")))
1696 (if cell
1697 (setcdr cell (concat (cdr cell) line))
1698 (setq rcirc-log-alist
1699 (cons (cons filename line) rcirc-log-alist)))))))
1701 (defun rcirc-log-write ()
1702 "Flush `rcirc-log-alist' data to disk.
1704 Log data is written to `rcirc-log-directory', except for
1705 log-files with absolute names (see `rcirc-log-filename-function')."
1706 (dolist (cell rcirc-log-alist)
1707 (let ((filename (convert-standard-filename
1708 (expand-file-name (car cell)
1709 rcirc-log-directory)))
1710 (coding-system-for-write 'utf-8))
1711 (make-directory (file-name-directory filename) t)
1712 (with-temp-buffer
1713 (insert (cdr cell))
1714 (write-region (point-min) (point-max) filename t 'quiet))))
1715 (setq rcirc-log-alist nil))
1717 (defun rcirc-view-log-file ()
1718 "View logfile corresponding to the current buffer."
1719 (interactive)
1720 (find-file-other-window
1721 (expand-file-name (funcall rcirc-log-filename-function
1722 (rcirc-buffer-process) rcirc-target)
1723 rcirc-log-directory)))
1725 (defun rcirc-join-channels (process channels)
1726 "Join CHANNELS."
1727 (save-window-excursion
1728 (dolist (channel channels)
1729 (with-rcirc-process-buffer process
1730 (rcirc-cmd-join channel process)))))
1732 ;;; nick management
1733 (defvar rcirc-nick-prefix-chars "~&@%+")
1734 (defun rcirc-user-nick (user)
1735 "Return the nick from USER. Remove any non-nick junk."
1736 (save-match-data
1737 (if (string-match (concat "^[" rcirc-nick-prefix-chars
1738 "]?\\([^! ]+\\)!?") (or user ""))
1739 (match-string 1 user)
1740 user)))
1742 (defun rcirc-nick-channels (process nick)
1743 "Return list of channels for NICK."
1744 (with-rcirc-process-buffer process
1745 (mapcar (lambda (x) (car x))
1746 (gethash nick rcirc-nick-table))))
1748 (defun rcirc-put-nick-channel (process nick channel &optional line)
1749 "Add CHANNEL to list associated with NICK.
1750 Update the associated linestamp if LINE is non-nil.
1752 If the record doesn't exist, and LINE is nil, set the linestamp
1753 to zero."
1754 (let ((nick (rcirc-user-nick nick)))
1755 (with-rcirc-process-buffer process
1756 (let* ((chans (gethash nick rcirc-nick-table))
1757 (record (assoc-string channel chans t)))
1758 (if record
1759 (when line (setcdr record line))
1760 (puthash nick (cons (cons channel (or line 0))
1761 chans)
1762 rcirc-nick-table))))))
1764 (defun rcirc-nick-remove (process nick)
1765 "Remove NICK from table."
1766 (with-rcirc-process-buffer process
1767 (remhash nick rcirc-nick-table)))
1769 (defun rcirc-remove-nick-channel (process nick channel)
1770 "Remove the CHANNEL from list associated with NICK."
1771 (with-rcirc-process-buffer process
1772 (let* ((chans (gethash nick rcirc-nick-table))
1773 (newchans
1774 ;; instead of assoc-string-delete-all:
1775 (let ((record (assoc-string channel chans t)))
1776 (when record
1777 (setcar record 'delete)
1778 (assq-delete-all 'delete chans)))))
1779 (if newchans
1780 (puthash nick newchans rcirc-nick-table)
1781 (remhash nick rcirc-nick-table)))))
1783 (defun rcirc-channel-nicks (process target)
1784 "Return the list of nicks associated with TARGET sorted by last activity."
1785 (when target
1786 (if (rcirc-channel-p target)
1787 (with-rcirc-process-buffer process
1788 (let (nicks)
1789 (maphash
1790 (lambda (k v)
1791 (let ((record (assoc-string target v t)))
1792 (if record
1793 (setq nicks (cons (cons k (cdr record)) nicks)))))
1794 rcirc-nick-table)
1795 (mapcar (lambda (x) (car x))
1796 (sort nicks (lambda (x y)
1797 (let ((lx (or (cdr x) 0))
1798 (ly (or (cdr y) 0)))
1799 (< ly lx)))))))
1800 (list target))))
1802 (defun rcirc-ignore-update-automatic (nick)
1803 "Remove NICK from `rcirc-ignore-list'
1804 if NICK is also on `rcirc-ignore-list-automatic'."
1805 (when (member nick rcirc-ignore-list-automatic)
1806 (setq rcirc-ignore-list-automatic
1807 (delete nick rcirc-ignore-list-automatic)
1808 rcirc-ignore-list
1809 (delete nick rcirc-ignore-list))))
1811 (defun rcirc-nickname< (s1 s2)
1812 "Return t if IRC nickname S1 is less than S2, and nil otherwise.
1813 Operator nicknames (@) are considered less than voiced
1814 nicknames (+). Any other nicknames are greater than voiced
1815 nicknames. The comparison is case-insensitive."
1816 (setq s1 (downcase s1)
1817 s2 (downcase s2))
1818 (let* ((s1-op (eq ?@ (string-to-char s1)))
1819 (s2-op (eq ?@ (string-to-char s2))))
1820 (if s1-op
1821 (if s2-op
1822 (string< (substring s1 1) (substring s2 1))
1824 (if s2-op
1826 (string< s1 s2)))))
1828 (defun rcirc-sort-nicknames-join (input sep)
1829 "Return a string of sorted nicknames.
1830 INPUT is a string containing nicknames separated by SEP.
1831 This function does not alter the INPUT string."
1832 (let* ((parts (split-string input sep t))
1833 (sorted (sort parts 'rcirc-nickname<)))
1834 (mapconcat 'identity sorted sep)))
1836 ;;; activity tracking
1837 (defvar rcirc-track-minor-mode-map
1838 (let ((map (make-sparse-keymap)))
1839 (define-key map (kbd "C-c C-@") 'rcirc-next-active-buffer)
1840 (define-key map (kbd "C-c C-SPC") 'rcirc-next-active-buffer)
1841 map)
1842 "Keymap for rcirc track minor mode.")
1844 ;;;###autoload
1845 (define-minor-mode rcirc-track-minor-mode
1846 "Global minor mode for tracking activity in rcirc buffers.
1847 With a prefix argument ARG, enable the mode if ARG is positive,
1848 and disable it otherwise. If called from Lisp, enable the mode
1849 if ARG is omitted or nil."
1850 :init-value nil
1851 :lighter ""
1852 :keymap rcirc-track-minor-mode-map
1853 :global t
1854 :group 'rcirc
1855 (or global-mode-string (setq global-mode-string '("")))
1856 ;; toggle the mode-line channel indicator
1857 (if rcirc-track-minor-mode
1858 (progn
1859 (and (not (memq 'rcirc-activity-string global-mode-string))
1860 (setq global-mode-string
1861 (append global-mode-string '(rcirc-activity-string))))
1862 (add-hook 'window-configuration-change-hook
1863 'rcirc-window-configuration-change))
1864 (setq global-mode-string
1865 (delete 'rcirc-activity-string global-mode-string))
1866 (remove-hook 'window-configuration-change-hook
1867 'rcirc-window-configuration-change)))
1869 (or (assq 'rcirc-ignore-buffer-activity-flag minor-mode-alist)
1870 (setq minor-mode-alist
1871 (cons '(rcirc-ignore-buffer-activity-flag " Ignore") minor-mode-alist)))
1872 (or (assq 'rcirc-low-priority-flag minor-mode-alist)
1873 (setq minor-mode-alist
1874 (cons '(rcirc-low-priority-flag " LowPri") minor-mode-alist)))
1875 (or (assq 'rcirc-omit-mode minor-mode-alist)
1876 (setq minor-mode-alist
1877 (cons '(rcirc-omit-mode " Omit") minor-mode-alist)))
1879 (defun rcirc-toggle-ignore-buffer-activity ()
1880 "Toggle the value of `rcirc-ignore-buffer-activity-flag'."
1881 (interactive)
1882 (setq rcirc-ignore-buffer-activity-flag
1883 (not rcirc-ignore-buffer-activity-flag))
1884 (message (if rcirc-ignore-buffer-activity-flag
1885 "Ignore activity in this buffer"
1886 "Notice activity in this buffer"))
1887 (force-mode-line-update))
1889 (defun rcirc-toggle-low-priority ()
1890 "Toggle the value of `rcirc-low-priority-flag'."
1891 (interactive)
1892 (setq rcirc-low-priority-flag
1893 (not rcirc-low-priority-flag))
1894 (message (if rcirc-low-priority-flag
1895 "Activity in this buffer is low priority"
1896 "Activity in this buffer is normal priority"))
1897 (force-mode-line-update))
1899 (defun rcirc-omit-mode ()
1900 "Toggle the Rcirc-Omit mode.
1901 If enabled, \"uninteresting\" lines are not shown.
1902 Uninteresting lines are those whose responses are listed in
1903 `rcirc-omit-responses'."
1904 (interactive)
1905 (setq rcirc-omit-mode (not rcirc-omit-mode))
1906 (if rcirc-omit-mode
1907 (progn
1908 (add-to-invisibility-spec '(rcirc-omit . nil))
1909 (message "Rcirc-Omit mode enabled"))
1910 (remove-from-invisibility-spec '(rcirc-omit . nil))
1911 (message "Rcirc-Omit mode disabled"))
1912 (dolist (window (get-buffer-window-list (current-buffer)))
1913 (with-selected-window window
1914 (recenter (when (> (point) rcirc-prompt-start-marker) -1)))))
1916 (defun rcirc-switch-to-server-buffer ()
1917 "Switch to the server buffer associated with current channel buffer."
1918 (interactive)
1919 (unless (buffer-live-p rcirc-server-buffer)
1920 (error "No such buffer"))
1921 (switch-to-buffer rcirc-server-buffer))
1923 (defun rcirc-jump-to-first-unread-line ()
1924 "Move the point to the first unread line in this buffer."
1925 (interactive)
1926 (if (marker-position overlay-arrow-position)
1927 (goto-char overlay-arrow-position)
1928 (message "No unread messages")))
1930 (defun rcirc-bury-buffers ()
1931 "Bury all RCIRC buffers."
1932 (interactive)
1933 (dolist (buf (buffer-list))
1934 (when (eq 'rcirc-mode (with-current-buffer buf major-mode))
1935 (bury-buffer buf) ; buffers not shown
1936 (quit-windows-on buf)))) ; buffers shown in a window
1938 (defun rcirc-next-active-buffer (arg)
1939 "Switch to the next rcirc buffer with activity.
1940 With prefix ARG, go to the next low priority buffer with activity."
1941 (interactive "P")
1942 (let* ((pair (rcirc-split-activity rcirc-activity))
1943 (lopri (car pair))
1944 (hipri (cdr pair)))
1945 (if (or (and (not arg) hipri)
1946 (and arg lopri))
1947 (progn
1948 (switch-to-buffer (car (if arg lopri hipri)))
1949 (when (> (point) rcirc-prompt-start-marker)
1950 (recenter -1)))
1951 (rcirc-bury-buffers)
1952 (message "No IRC activity.%s"
1953 (if lopri
1954 (concat
1955 " Type C-u " (key-description (this-command-keys))
1956 " for low priority activity.")
1957 "")))))
1959 (define-obsolete-variable-alias 'rcirc-activity-hooks
1960 'rcirc-activity-functions "24.3")
1961 (defvar rcirc-activity-functions nil
1962 "Hook to be run when there is channel activity.
1964 Functions are called with a single argument, the buffer with the
1965 activity. Only run if the buffer is not visible and
1966 `rcirc-ignore-buffer-activity-flag' is non-nil.")
1968 (defun rcirc-record-activity (buffer &optional type)
1969 "Record BUFFER activity with TYPE."
1970 (with-current-buffer buffer
1971 (let ((old-activity rcirc-activity)
1972 (old-types rcirc-activity-types))
1973 (when (not (get-buffer-window (current-buffer) t))
1974 (setq rcirc-activity
1975 (sort (if (memq (current-buffer) rcirc-activity) rcirc-activity
1976 (cons (current-buffer) rcirc-activity))
1977 (lambda (b1 b2)
1978 (let ((t1 (with-current-buffer b1 rcirc-last-post-time))
1979 (t2 (with-current-buffer b2 rcirc-last-post-time)))
1980 (time-less-p t2 t1)))))
1981 (cl-pushnew type rcirc-activity-types)
1982 (unless (and (equal rcirc-activity old-activity)
1983 (member type old-types))
1984 (rcirc-update-activity-string)))))
1985 (run-hook-with-args 'rcirc-activity-functions buffer))
1987 (defun rcirc-clear-activity (buffer)
1988 "Clear the BUFFER activity."
1989 (setq rcirc-activity (remove buffer rcirc-activity))
1990 (with-current-buffer buffer
1991 (setq rcirc-activity-types nil)))
1993 (defun rcirc-clear-unread (buffer)
1994 "Erase the last read message arrow from BUFFER."
1995 (when (buffer-live-p buffer)
1996 (with-current-buffer buffer
1997 (set-marker overlay-arrow-position nil))))
1999 (defun rcirc-split-activity (activity)
2000 "Return a cons cell with ACTIVITY split into (lopri . hipri)."
2001 (let (lopri hipri)
2002 (dolist (buf activity)
2003 (with-current-buffer buf
2004 (if (and rcirc-low-priority-flag
2005 (not (member 'nick rcirc-activity-types)))
2006 (push buf lopri)
2007 (push buf hipri))))
2008 (cons (nreverse lopri) (nreverse hipri))))
2010 (defvar rcirc-update-activity-string-hook nil
2011 "Hook run whenever the activity string is updated.")
2013 ;; TODO: add mouse properties
2014 (defun rcirc-update-activity-string ()
2015 "Update mode-line string."
2016 (let* ((pair (rcirc-split-activity rcirc-activity))
2017 (lopri (car pair))
2018 (hipri (cdr pair)))
2019 (setq rcirc-activity-string
2020 (cond ((or hipri lopri)
2021 (concat (and hipri "[")
2022 (rcirc-activity-string hipri)
2023 (and hipri lopri ",")
2024 (and lopri
2025 (concat "("
2026 (rcirc-activity-string lopri)
2027 ")"))
2028 (and hipri "]")))
2029 ((not (null (rcirc-process-list)))
2030 "[]")
2031 (t "[]")))
2032 (run-hooks 'rcirc-update-activity-string-hook)))
2034 (defun rcirc-activity-string (buffers)
2035 (mapconcat (lambda (b)
2036 (let ((s (substring-no-properties (rcirc-short-buffer-name b))))
2037 (with-current-buffer b
2038 (dolist (type rcirc-activity-types)
2039 (rcirc-add-face 0 (length s)
2040 (cl-case type
2041 (nick 'rcirc-track-nick)
2042 (keyword 'rcirc-track-keyword))
2043 s)))
2045 buffers ","))
2047 (defun rcirc-short-buffer-name (buffer)
2048 "Return a short name for BUFFER to use in the mode line indicator."
2049 (with-current-buffer buffer
2050 (or rcirc-short-buffer-name (buffer-name))))
2052 (defun rcirc-visible-buffers ()
2053 "Return a list of the visible buffers that are in rcirc-mode."
2054 (let (acc)
2055 (walk-windows (lambda (w)
2056 (with-current-buffer (window-buffer w)
2057 (when (eq major-mode 'rcirc-mode)
2058 (push (current-buffer) acc)))))
2059 acc))
2061 (defvar rcirc-visible-buffers nil)
2062 (defun rcirc-window-configuration-change ()
2063 (unless (minibuffer-window-active-p (minibuffer-window))
2064 ;; delay this until command has finished to make sure window is
2065 ;; actually visible before clearing activity
2066 (add-hook 'post-command-hook 'rcirc-window-configuration-change-1)))
2068 (defun rcirc-window-configuration-change-1 ()
2069 ;; clear activity and overlay arrows
2070 (let* ((old-activity rcirc-activity)
2071 (hidden-buffers rcirc-visible-buffers))
2073 (setq rcirc-visible-buffers (rcirc-visible-buffers))
2075 (dolist (vbuf rcirc-visible-buffers)
2076 (setq hidden-buffers (delq vbuf hidden-buffers))
2077 ;; clear activity for all visible buffers
2078 (rcirc-clear-activity vbuf))
2080 ;; clear unread arrow from recently hidden buffers
2081 (dolist (hbuf hidden-buffers)
2082 (rcirc-clear-unread hbuf))
2084 ;; remove any killed buffers from list
2085 (setq rcirc-activity
2086 (delq nil (mapcar (lambda (buf) (when (buffer-live-p buf) buf))
2087 rcirc-activity)))
2088 ;; update the mode-line string
2089 (unless (equal old-activity rcirc-activity)
2090 (rcirc-update-activity-string)))
2092 (remove-hook 'post-command-hook 'rcirc-window-configuration-change-1))
2095 ;;; buffer name abbreviation
2096 (defun rcirc-update-short-buffer-names ()
2097 (let ((bufalist
2098 (apply 'append (mapcar (lambda (process)
2099 (with-rcirc-process-buffer process
2100 rcirc-buffer-alist))
2101 (rcirc-process-list)))))
2102 (dolist (i (rcirc-abbreviate bufalist))
2103 (when (buffer-live-p (cdr i))
2104 (with-current-buffer (cdr i)
2105 (setq rcirc-short-buffer-name (car i)))))))
2107 (defun rcirc-abbreviate (pairs)
2108 (apply 'append (mapcar 'rcirc-rebuild-tree (rcirc-make-trees pairs))))
2110 (defun rcirc-rebuild-tree (tree &optional acc)
2111 (let ((ch (char-to-string (car tree))))
2112 (dolist (x (cdr tree))
2113 (if (listp x)
2114 (setq acc (append acc
2115 (mapcar (lambda (y)
2116 (cons (concat ch (car y))
2117 (cdr y)))
2118 (rcirc-rebuild-tree x))))
2119 (setq acc (cons (cons ch x) acc))))
2120 acc))
2122 (defun rcirc-make-trees (pairs)
2123 (let (alist)
2124 (mapc (lambda (pair)
2125 (if (consp pair)
2126 (let* ((str (car pair))
2127 (data (cdr pair))
2128 (char (unless (zerop (length str))
2129 (aref str 0)))
2130 (rest (unless (zerop (length str))
2131 (substring str 1)))
2132 (part (if char (assq char alist))))
2133 (if part
2134 ;; existing partition
2135 (setcdr part (cons (cons rest data) (cdr part)))
2136 ;; new partition
2137 (setq alist (cons (if char
2138 (list char (cons rest data))
2139 data)
2140 alist))))
2141 (setq alist (cons pair alist))))
2142 pairs)
2143 ;; recurse into cdrs of alist
2144 (mapc (lambda (x)
2145 (when (and (listp x) (listp (cadr x)))
2146 (setcdr x (if (> (length (cdr x)) 1)
2147 (rcirc-make-trees (cdr x))
2148 (setcdr x (list (cl-cdadr x)))))))
2149 alist)))
2151 ;;; /commands these are called with 3 args: PROCESS, TARGET, which is
2152 ;; the current buffer/channel/user, and ARGS, which is a string
2153 ;; containing the text following the /cmd.
2155 (defmacro defun-rcirc-command (command argument docstring interactive-form
2156 &rest body)
2157 "Define a command."
2158 `(progn
2159 (add-to-list 'rcirc-client-commands ,(concat "/" (symbol-name command)))
2160 (defun ,(intern (concat "rcirc-cmd-" (symbol-name command)))
2161 (,@argument &optional process target)
2162 ,(concat docstring "\n\nNote: If PROCESS or TARGET are nil, the values given"
2163 "\nby `rcirc-buffer-process' and `rcirc-target' will be used.")
2164 ,interactive-form
2165 (let ((process (or process (rcirc-buffer-process)))
2166 (target (or target rcirc-target)))
2167 (ignore target) ; mark `target' variable as ignorable
2168 ,@body))))
2170 (defun-rcirc-command msg (message)
2171 "Send private MESSAGE to TARGET."
2172 (interactive "i")
2173 (if (null message)
2174 (progn
2175 (setq target (completing-read "Message nick: "
2176 (with-rcirc-server-buffer
2177 rcirc-nick-table)))
2178 (when (> (length target) 0)
2179 (setq message (read-string (format "Message %s: " target)))
2180 (when (> (length message) 0)
2181 (rcirc-send-message process target message))))
2182 (if (not (string-match "\\([^ ]+\\) \\(.+\\)" message))
2183 (message "Not enough args, or something.")
2184 (setq target (match-string 1 message)
2185 message (match-string 2 message))
2186 (rcirc-send-message process target message))))
2188 (defun-rcirc-command query (nick)
2189 "Open a private chat buffer to NICK."
2190 (interactive (list (completing-read "Query nick: "
2191 (with-rcirc-server-buffer rcirc-nick-table))))
2192 (let ((existing-buffer (rcirc-get-buffer process nick)))
2193 (switch-to-buffer (or existing-buffer
2194 (rcirc-get-buffer-create process nick)))
2195 (when (not existing-buffer)
2196 (rcirc-cmd-whois nick))))
2198 (defun-rcirc-command join (channels)
2199 "Join CHANNELS.
2200 CHANNELS is a comma- or space-separated string of channel names."
2201 (interactive "sJoin channels: ")
2202 (let* ((split-channels (split-string channels "[ ,]" t))
2203 (buffers (mapcar (lambda (ch)
2204 (rcirc-get-buffer-create process ch))
2205 split-channels))
2206 (channels (mapconcat 'identity split-channels ",")))
2207 (rcirc-send-string process (concat "JOIN " channels))
2208 (when (not (eq (selected-window) (minibuffer-window)))
2209 (dolist (b buffers) ;; order the new channel buffers in the buffer list
2210 (switch-to-buffer b)))))
2212 (defun-rcirc-command invite (nick-channel)
2213 "Invite NICK to CHANNEL."
2214 (interactive (list
2215 (concat
2216 (completing-read "Invite nick: "
2217 (with-rcirc-server-buffer rcirc-nick-table))
2219 (read-string "Channel: "))))
2220 (rcirc-send-string process (concat "INVITE " nick-channel)))
2222 ;; TODO: /part #channel reason, or consider removing #channel altogether
2223 (defun-rcirc-command part (channel)
2224 "Part CHANNEL."
2225 (interactive "sPart channel: ")
2226 (let ((channel (if (> (length channel) 0) channel target)))
2227 (rcirc-send-string process (concat "PART " channel " :" rcirc-id-string))))
2229 (defun-rcirc-command quit (reason)
2230 "Send a quit message to server with REASON."
2231 (interactive "sQuit reason: ")
2232 (rcirc-send-string process (concat "QUIT :"
2233 (if (not (zerop (length reason)))
2234 reason
2235 rcirc-id-string))))
2237 (defun-rcirc-command reconnect (_)
2238 "Reconnect to current server."
2239 (interactive "i")
2240 (with-rcirc-server-buffer
2241 (cond
2242 (rcirc-connecting (message "Already connecting"))
2243 ((process-live-p process) (message "Server process is alive"))
2244 (t (let ((conn-info rcirc-connection-info))
2245 (setf (nth 5 conn-info)
2246 (cl-remove-if-not #'rcirc-channel-p
2247 (mapcar #'car rcirc-buffer-alist)))
2248 (apply #'rcirc-connect conn-info))))))
2250 (defun-rcirc-command nick (nick)
2251 "Change nick to NICK."
2252 (interactive "i")
2253 (when (null nick)
2254 (setq nick (read-string "New nick: " (rcirc-nick process))))
2255 (rcirc-send-string process (concat "NICK " nick)))
2257 (defun-rcirc-command names (channel)
2258 "Display list of names in CHANNEL or in current channel if CHANNEL is nil.
2259 If called interactively, prompt for a channel when prefix arg is supplied."
2260 (interactive "P")
2261 (if (called-interactively-p 'interactive)
2262 (if channel
2263 (setq channel (read-string "List names in channel: " target))))
2264 (let ((channel (if (> (length channel) 0)
2265 channel
2266 target)))
2267 (rcirc-send-string process (concat "NAMES " channel))))
2269 (defun-rcirc-command topic (topic)
2270 "List TOPIC for the TARGET channel.
2271 With a prefix arg, prompt for new topic."
2272 (interactive "P")
2273 (if (and (called-interactively-p 'interactive) topic)
2274 (setq topic (read-string "New Topic: " rcirc-topic)))
2275 (rcirc-send-string process (concat "TOPIC " target
2276 (when (> (length topic) 0)
2277 (concat " :" topic)))))
2279 (defun-rcirc-command whois (nick)
2280 "Request information from server about NICK."
2281 (interactive (list
2282 (completing-read "Whois: "
2283 (with-rcirc-server-buffer rcirc-nick-table))))
2284 (rcirc-send-string process (concat "WHOIS " nick)))
2286 (defun-rcirc-command mode (args)
2287 "Set mode with ARGS."
2288 (interactive (list (concat (read-string "Mode nick or channel: ")
2289 " " (read-string "Mode: "))))
2290 (rcirc-send-string process (concat "MODE " args)))
2292 (defun-rcirc-command list (channels)
2293 "Request information on CHANNELS from server."
2294 (interactive "sList Channels: ")
2295 (rcirc-send-string process (concat "LIST " channels)))
2297 (defun-rcirc-command oper (args)
2298 "Send operator command to server."
2299 (interactive "sOper args: ")
2300 (rcirc-send-string process (concat "OPER " args)))
2302 (defun-rcirc-command quote (message)
2303 "Send MESSAGE literally to server."
2304 (interactive "sServer message: ")
2305 (rcirc-send-string process message))
2307 (defun-rcirc-command kick (arg)
2308 "Kick NICK from current channel."
2309 (interactive (list
2310 (concat (completing-read "Kick nick: "
2311 (rcirc-channel-nicks
2312 (rcirc-buffer-process)
2313 rcirc-target))
2314 (read-from-minibuffer "Kick reason: "))))
2315 (let* ((arglist (split-string arg))
2316 (argstring (concat (car arglist) " :"
2317 (mapconcat 'identity (cdr arglist) " "))))
2318 (rcirc-send-string process (concat "KICK " target " " argstring))))
2320 (defun rcirc-cmd-ctcp (args &optional process _target)
2321 (if (string-match "^\\([^ ]+\\)\\s-+\\(.+\\)$" args)
2322 (let* ((target (match-string 1 args))
2323 (request (upcase (match-string 2 args)))
2324 (function (intern-soft (concat "rcirc-ctcp-sender-" request))))
2325 (if (fboundp function) ;; use special function if available
2326 (funcall function process target request)
2327 (rcirc-send-ctcp process target request)))
2328 (rcirc-print process (rcirc-nick process) "ERROR" nil
2329 "usage: /ctcp NICK REQUEST")))
2331 (defun rcirc-ctcp-sender-PING (process target _request)
2332 "Send a CTCP PING message to TARGET."
2333 (let ((timestamp (format "%.0f" (rcirc-float-time))))
2334 (rcirc-send-ctcp process target "PING" timestamp)))
2336 (defun rcirc-cmd-me (args &optional process target)
2337 (rcirc-send-ctcp process target "ACTION" args))
2339 (defun rcirc-add-or-remove (set &rest elements)
2340 (dolist (elt elements)
2341 (if (and elt (not (string= "" elt)))
2342 (setq set (if (member-ignore-case elt set)
2343 (delete elt set)
2344 (cons elt set)))))
2345 set)
2347 (defun-rcirc-command ignore (nick)
2348 "Manage the ignore list.
2349 Ignore NICK, unignore NICK if already ignored, or list ignored
2350 nicks when no NICK is given. When listing ignored nicks, the
2351 ones added to the list automatically are marked with an asterisk."
2352 (interactive "sToggle ignoring of nick: ")
2353 (setq rcirc-ignore-list
2354 (apply #'rcirc-add-or-remove rcirc-ignore-list
2355 (split-string nick nil t)))
2356 (rcirc-print process nil "IGNORE" target
2357 (mapconcat
2358 (lambda (nick)
2359 (concat nick
2360 (if (member nick rcirc-ignore-list-automatic)
2361 "*" "")))
2362 rcirc-ignore-list " ")))
2364 (defun-rcirc-command bright (nick)
2365 "Manage the bright nick list."
2366 (interactive "sToggle emphasis of nick: ")
2367 (setq rcirc-bright-nicks
2368 (apply #'rcirc-add-or-remove rcirc-bright-nicks
2369 (split-string nick nil t)))
2370 (rcirc-print process nil "BRIGHT" target
2371 (mapconcat 'identity rcirc-bright-nicks " ")))
2373 (defun-rcirc-command dim (nick)
2374 "Manage the dim nick list."
2375 (interactive "sToggle deemphasis of nick: ")
2376 (setq rcirc-dim-nicks
2377 (apply #'rcirc-add-or-remove rcirc-dim-nicks
2378 (split-string nick nil t)))
2379 (rcirc-print process nil "DIM" target
2380 (mapconcat 'identity rcirc-dim-nicks " ")))
2382 (defun-rcirc-command keyword (keyword)
2383 "Manage the keyword list.
2384 Mark KEYWORD, unmark KEYWORD if already marked, or list marked
2385 keywords when no KEYWORD is given."
2386 (interactive "sToggle highlighting of keyword: ")
2387 (setq rcirc-keywords
2388 (apply #'rcirc-add-or-remove rcirc-keywords
2389 (split-string keyword nil t)))
2390 (rcirc-print process nil "KEYWORD" target
2391 (mapconcat 'identity rcirc-keywords " ")))
2394 (defun rcirc-add-face (start end name &optional object)
2395 "Add face NAME to the face text property of the text from START to END."
2396 (when name
2397 (let ((pos start)
2398 next prop)
2399 (while (< pos end)
2400 (setq prop (get-text-property pos 'font-lock-face object)
2401 next (next-single-property-change pos 'font-lock-face object end))
2402 (unless (member name (get-text-property pos 'font-lock-face object))
2403 (add-text-properties pos next
2404 (list 'font-lock-face (cons name prop)) object))
2405 (setq pos next)))))
2407 (defun rcirc-facify (string face)
2408 "Return a copy of STRING with FACE property added."
2409 (let ((string (or string "")))
2410 (rcirc-add-face 0 (length string) face string)
2411 string))
2413 (defvar rcirc-url-regexp
2414 (concat
2415 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
2416 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
2417 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
2418 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
2419 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
2420 (punct "!?:;.,"))
2421 (concat
2422 "\\(?:"
2423 ;; Match paired parentheses, e.g. in Wikipedia URLs:
2424 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)" "[" chars "]"
2425 "\\|"
2426 "[" chars punct "]+" "[" chars "]"
2427 "\\)"))
2428 (concat ;; XEmacs 21.4 doesn't support POSIX.
2429 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
2430 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
2431 "\\)")
2432 "Regexp matching URLs. Set to nil to disable URL features in rcirc.")
2434 ;; cf cl-remove-if-not
2435 (defun rcirc-condition-filter (condp lst)
2436 "Remove all items not satisfying condition CONDP in list LST.
2437 CONDP is a function that takes a list element as argument and returns
2438 non-nil if that element should be included. Returns a new list."
2439 (delq nil (mapcar (lambda (x) (and (funcall condp x) x)) lst)))
2441 (defun rcirc-browse-url (&optional arg)
2442 "Prompt for URL to browse based on URLs in buffer before point.
2444 If ARG is given, opens the URL in a new browser window."
2445 (interactive "P")
2446 (let* ((point (point))
2447 (filtered (rcirc-condition-filter
2448 (lambda (x) (>= point (cdr x)))
2449 rcirc-urls))
2450 (completions (mapcar (lambda (x) (car x)) filtered))
2451 (defaults (mapcar (lambda (x) (car x)) filtered)))
2452 (browse-url (completing-read "Rcirc browse-url: "
2453 completions nil nil (car defaults) nil defaults)
2454 arg)))
2456 (defun rcirc-markup-timestamp (_sender _response)
2457 (goto-char (point-min))
2458 (insert (rcirc-facify (format-time-string rcirc-time-format)
2459 'rcirc-timestamp)))
2461 (defun rcirc-markup-attributes (_sender _response)
2462 (while (re-search-forward "\\([\C-b\C-_\C-v]\\).*?\\(\\1\\|\C-o\\)" nil t)
2463 (rcirc-add-face (match-beginning 0) (match-end 0)
2464 (cl-case (char-after (match-beginning 1))
2465 (?\C-b 'bold)
2466 (?\C-v 'italic)
2467 (?\C-_ 'underline)))
2468 ;; keep the ^O since it could terminate other attributes
2469 (when (not (eq ?\C-o (char-before (match-end 2))))
2470 (delete-region (match-beginning 2) (match-end 2)))
2471 (delete-region (match-beginning 1) (match-end 1))
2472 (goto-char (match-beginning 1)))
2473 ;; remove the ^O characters now
2474 (goto-char (point-min))
2475 (while (re-search-forward "\C-o+" nil t)
2476 (delete-region (match-beginning 0) (match-end 0))))
2478 (defun rcirc-markup-my-nick (_sender response)
2479 (with-syntax-table rcirc-nick-syntax-table
2480 (while (re-search-forward (concat "\\b"
2481 (regexp-quote (rcirc-nick
2482 (rcirc-buffer-process)))
2483 "\\b")
2484 nil t)
2485 (rcirc-add-face (match-beginning 0) (match-end 0)
2486 'rcirc-nick-in-message)
2487 (when (string= response "PRIVMSG")
2488 (rcirc-add-face (point-min) (point-max)
2489 'rcirc-nick-in-message-full-line)
2490 (rcirc-record-activity (current-buffer) 'nick)))))
2492 (defun rcirc-markup-urls (_sender _response)
2493 (while (and rcirc-url-regexp ;; nil means disable URL catching
2494 (re-search-forward rcirc-url-regexp nil t))
2495 (let* ((start (match-beginning 0))
2496 (end (match-end 0))
2497 (url (match-string-no-properties 0))
2498 (link-text (buffer-substring-no-properties start end)))
2499 (make-button start end
2500 'face 'rcirc-url
2501 'follow-link t
2502 'rcirc-url url
2503 'action (lambda (button)
2504 (browse-url (button-get button 'rcirc-url))))
2505 ;; record the url if it is not already the latest stored url
2506 (when (not (string= link-text (caar rcirc-urls)))
2507 (push (cons link-text start) rcirc-urls)))))
2509 (defun rcirc-markup-keywords (sender response)
2510 (when (and (string= response "PRIVMSG")
2511 (not (string= sender (rcirc-nick (rcirc-buffer-process)))))
2512 (let* ((target (or rcirc-target ""))
2513 (keywords (delq nil (mapcar (lambda (keyword)
2514 (when (not (string-match keyword
2515 target))
2516 keyword))
2517 rcirc-keywords))))
2518 (when keywords
2519 (while (re-search-forward (regexp-opt keywords 'words) nil t)
2520 (rcirc-add-face (match-beginning 0) (match-end 0) 'rcirc-keyword)
2521 (rcirc-record-activity (current-buffer) 'keyword))))))
2523 (defun rcirc-markup-bright-nicks (_sender response)
2524 (when (and rcirc-bright-nicks
2525 (string= response "NAMES"))
2526 (with-syntax-table rcirc-nick-syntax-table
2527 (while (re-search-forward (regexp-opt rcirc-bright-nicks 'words) nil t)
2528 (rcirc-add-face (match-beginning 0) (match-end 0)
2529 'rcirc-bright-nick)))))
2531 (defun rcirc-markup-fill (_sender response)
2532 (when (not (string= response "372")) ; /motd
2533 (let ((fill-prefix
2534 (or rcirc-fill-prefix
2535 (make-string (- (point) (line-beginning-position)) ?\s)))
2536 (fill-column (- (cond ((null rcirc-fill-column) fill-column)
2537 ((functionp rcirc-fill-column)
2538 (funcall rcirc-fill-column))
2539 (t rcirc-fill-column))
2540 ;; make sure ... doesn't cause line wrapping
2541 3)))
2542 (fill-region (point) (point-max) nil t))))
2544 ;;; handlers
2545 ;; these are called with the server PROCESS, the SENDER, which is a
2546 ;; server or a user, depending on the command, the ARGS, which is a
2547 ;; list of strings, and the TEXT, which is the original server text,
2548 ;; verbatim
2549 (defun rcirc-handler-001 (process sender args text)
2550 (rcirc-handler-generic process "001" sender args text)
2551 (with-rcirc-process-buffer process
2552 (setq rcirc-connecting nil)
2553 (rcirc-reschedule-timeout process)
2554 (setq rcirc-server-name sender)
2555 (setq rcirc-nick (car args))
2556 (rcirc-update-prompt)
2557 (if rcirc-auto-authenticate-flag
2558 (if (and rcirc-authenticate-before-join
2559 ;; We have to ensure that there's an authentication
2560 ;; entry for that server. Else,
2561 ;; rcirc-authenticated-hook won't be triggered, and
2562 ;; autojoin won't happen at all.
2563 (let (auth-required)
2564 (dolist (s rcirc-authinfo auth-required)
2565 (when (string-match (car s) rcirc-server-name)
2566 (setq auth-required t)))))
2567 (progn
2568 (add-hook 'rcirc-authenticated-hook 'rcirc-join-channels-post-auth t t)
2569 (rcirc-authenticate))
2570 (rcirc-authenticate)
2571 (rcirc-join-channels process rcirc-startup-channels))
2572 (rcirc-join-channels process rcirc-startup-channels))))
2574 (defun rcirc-join-channels-post-auth (process)
2575 "Join `rcirc-startup-channels' after authenticating."
2576 (with-rcirc-process-buffer process
2577 (rcirc-join-channels process rcirc-startup-channels)))
2579 (defun rcirc-handler-PRIVMSG (process sender args text)
2580 (rcirc-check-auth-status process sender args text)
2581 (let ((target (if (rcirc-channel-p (car args))
2582 (car args)
2583 sender))
2584 (message (or (cadr args) "")))
2585 (if (string-match "^\C-a\\(.*\\)\C-a$" message)
2586 (rcirc-handler-CTCP process target sender (match-string 1 message))
2587 (rcirc-print process sender "PRIVMSG" target message t))
2588 ;; update nick linestamp
2589 (with-current-buffer (rcirc-get-buffer process target t)
2590 (rcirc-put-nick-channel process sender target rcirc-current-line))))
2592 (defun rcirc-handler-NOTICE (process sender args text)
2593 (rcirc-check-auth-status process sender args text)
2594 (let ((target (car args))
2595 (message (cadr args)))
2596 (if (string-match "^\C-a\\(.*\\)\C-a$" message)
2597 (rcirc-handler-CTCP-response process target sender
2598 (match-string 1 message))
2599 (rcirc-print process sender "NOTICE"
2600 (cond ((rcirc-channel-p target)
2601 target)
2602 ;;; -ChanServ- [#gnu] Welcome...
2603 ((string-match "\\[\\(#[^\] ]+\\)\\]" message)
2604 (match-string 1 message))
2605 (sender
2606 (if (string= sender (rcirc-server-name process))
2607 nil ; server notice
2608 sender)))
2609 message t))))
2611 (defun rcirc-check-auth-status (process sender args _text)
2612 "Check if the user just authenticated.
2613 If authenticated, runs `rcirc-authenticated-hook' with PROCESS as
2614 the only argument."
2615 (with-rcirc-process-buffer process
2616 (when (and (not rcirc-user-authenticated)
2617 rcirc-authenticate-before-join
2618 rcirc-auto-authenticate-flag)
2619 (let ((target (car args))
2620 (message (cadr args)))
2621 (when (or
2622 (and ;; nickserv
2623 (string= sender "NickServ")
2624 (string= target rcirc-nick)
2625 (member message
2626 (list
2627 (format "You are now identified for \C-b%s\C-b." rcirc-nick)
2628 (format "You are successfully identified as \C-b%s\C-b." rcirc-nick)
2629 "Password accepted - you are now recognized."
2631 (and ;; quakenet
2632 (string= sender "Q")
2633 (string= target rcirc-nick)
2634 (string-match "\\`You are now logged in as .+\\.\\'" message)))
2635 (setq rcirc-user-authenticated t)
2636 (run-hook-with-args 'rcirc-authenticated-hook process)
2637 (remove-hook 'rcirc-authenticated-hook 'rcirc-join-channels-post-auth t))))))
2639 (defun rcirc-handler-WALLOPS (process sender args _text)
2640 (rcirc-print process sender "WALLOPS" sender (car args) t))
2642 (defun rcirc-handler-JOIN (process sender args _text)
2643 (let ((channel (car args)))
2644 (with-current-buffer (rcirc-get-buffer-create process channel)
2645 ;; when recently rejoining, restore the linestamp
2646 (rcirc-put-nick-channel process sender channel
2647 (let ((last-activity-lines
2648 (rcirc-elapsed-lines process sender channel)))
2649 (when (and last-activity-lines
2650 (< last-activity-lines rcirc-omit-threshold))
2651 (rcirc-last-line process sender channel))))
2652 ;; reset mode-line-process in case joining a channel with an
2653 ;; already open buffer (after getting kicked e.g.)
2654 (setq mode-line-process nil))
2656 (rcirc-print process sender "JOIN" channel "")
2658 ;; print in private chat buffer if it exists
2659 (when (rcirc-get-buffer (rcirc-buffer-process) sender)
2660 (rcirc-print process sender "JOIN" sender channel))))
2662 ;; PART and KICK are handled the same way
2663 (defun rcirc-handler-PART-or-KICK (process _response channel _sender nick _args)
2664 (rcirc-ignore-update-automatic nick)
2665 (if (not (string= nick (rcirc-nick process)))
2666 ;; this is someone else leaving
2667 (progn
2668 (rcirc-maybe-remember-nick-quit process nick channel)
2669 (rcirc-remove-nick-channel process nick channel))
2670 ;; this is us leaving
2671 (mapc (lambda (n)
2672 (rcirc-remove-nick-channel process n channel))
2673 (rcirc-channel-nicks process channel))
2675 ;; if the buffer is still around, make it inactive
2676 (let ((buffer (rcirc-get-buffer process channel)))
2677 (when buffer
2678 (rcirc-disconnect-buffer buffer)))))
2680 (defun rcirc-handler-PART (process sender args _text)
2681 (let* ((channel (car args))
2682 (reason (cadr args))
2683 (message (concat channel " " reason)))
2684 (rcirc-print process sender "PART" channel message)
2685 ;; print in private chat buffer if it exists
2686 (when (rcirc-get-buffer (rcirc-buffer-process) sender)
2687 (rcirc-print process sender "PART" sender message))
2689 (rcirc-handler-PART-or-KICK process "PART" channel sender sender reason)))
2691 (defun rcirc-handler-KICK (process sender args _text)
2692 (let* ((channel (car args))
2693 (nick (cadr args))
2694 (reason (nth 2 args))
2695 (message (concat nick " " channel " " reason)))
2696 (rcirc-print process sender "KICK" channel message t)
2697 ;; print in private chat buffer if it exists
2698 (when (rcirc-get-buffer (rcirc-buffer-process) nick)
2699 (rcirc-print process sender "KICK" nick message))
2701 (rcirc-handler-PART-or-KICK process "KICK" channel sender nick reason)))
2703 (defun rcirc-maybe-remember-nick-quit (process nick channel)
2704 "Remember NICK as leaving CHANNEL if they recently spoke."
2705 (let ((elapsed-lines (rcirc-elapsed-lines process nick channel)))
2706 (when (and elapsed-lines
2707 (< elapsed-lines rcirc-omit-threshold))
2708 (let ((buffer (rcirc-get-buffer process channel)))
2709 (when buffer
2710 (with-current-buffer buffer
2711 (let ((record (assoc-string nick rcirc-recent-quit-alist t))
2712 (line (rcirc-last-line process nick channel)))
2713 (if record
2714 (setcdr record line)
2715 (setq rcirc-recent-quit-alist
2716 (cons (cons nick line)
2717 rcirc-recent-quit-alist))))))))))
2719 (defun rcirc-handler-QUIT (process sender args _text)
2720 (rcirc-ignore-update-automatic sender)
2721 (mapc (lambda (channel)
2722 ;; broadcast quit message each channel
2723 (rcirc-print process sender "QUIT" channel (apply 'concat args))
2724 ;; record nick in quit table if they recently spoke
2725 (rcirc-maybe-remember-nick-quit process sender channel))
2726 (rcirc-nick-channels process sender))
2727 (rcirc-nick-remove process sender))
2729 (defun rcirc-handler-NICK (process sender args _text)
2730 (let* ((old-nick sender)
2731 (new-nick (car args))
2732 (channels (rcirc-nick-channels process old-nick)))
2733 ;; update list of ignored nicks
2734 (rcirc-ignore-update-automatic old-nick)
2735 (when (member old-nick rcirc-ignore-list)
2736 (add-to-list 'rcirc-ignore-list new-nick)
2737 (add-to-list 'rcirc-ignore-list-automatic new-nick))
2738 ;; print message to nick's channels
2739 (dolist (target channels)
2740 (rcirc-print process sender "NICK" target new-nick))
2741 ;; update private chat buffer, if it exists
2742 (let ((chat-buffer (rcirc-get-buffer process old-nick)))
2743 (when chat-buffer
2744 (with-current-buffer chat-buffer
2745 (rcirc-print process sender "NICK" old-nick new-nick)
2746 (setq rcirc-target new-nick)
2747 (rename-buffer (rcirc-generate-new-buffer-name process new-nick)))))
2748 ;; remove old nick and add new one
2749 (with-rcirc-process-buffer process
2750 (let ((v (gethash old-nick rcirc-nick-table)))
2751 (remhash old-nick rcirc-nick-table)
2752 (puthash new-nick v rcirc-nick-table))
2753 ;; if this is our nick...
2754 (when (string= old-nick rcirc-nick)
2755 (setq rcirc-nick new-nick)
2756 (rcirc-update-prompt t)
2757 ;; reauthenticate
2758 (when rcirc-auto-authenticate-flag (rcirc-authenticate))))))
2760 (defun rcirc-handler-PING (process _sender args _text)
2761 (rcirc-send-string process (concat "PONG :" (car args))))
2763 (defun rcirc-handler-PONG (_process _sender _args _text)
2764 ;; do nothing
2767 (defun rcirc-handler-TOPIC (process sender args _text)
2768 (let ((topic (cadr args)))
2769 (rcirc-print process sender "TOPIC" (car args) topic)
2770 (with-current-buffer (rcirc-get-buffer process (car args))
2771 (setq rcirc-topic topic))))
2773 (defvar rcirc-nick-away-alist nil)
2774 (defun rcirc-handler-301 (process _sender args text)
2775 "RPL_AWAY"
2776 (let* ((nick (cadr args))
2777 (rec (assoc-string nick rcirc-nick-away-alist))
2778 (away-message (nth 2 args)))
2779 (when (or (not rec)
2780 (not (string= (cdr rec) away-message)))
2781 ;; away message has changed
2782 (rcirc-handler-generic process "AWAY" nick (cdr args) text)
2783 (if rec
2784 (setcdr rec away-message)
2785 (setq rcirc-nick-away-alist (cons (cons nick away-message)
2786 rcirc-nick-away-alist))))))
2788 (defun rcirc-handler-317 (process sender args _text)
2789 "RPL_WHOISIDLE"
2790 (let* ((nick (nth 1 args))
2791 (idle-secs (string-to-number (nth 2 args)))
2792 (idle-string
2793 (if (< idle-secs most-positive-fixnum)
2794 (format-seconds "%yy %dd %hh %mm %z%ss" idle-secs)
2795 "a very long time"))
2796 (signon-time (seconds-to-time (string-to-number (nth 3 args))))
2797 (signon-string (format-time-string "%c" signon-time))
2798 (message (format "%s idle for %s, signed on %s"
2799 nick idle-string signon-string)))
2800 (rcirc-print process sender "317" nil message t)))
2802 (defun rcirc-handler-332 (process _sender args _text)
2803 "RPL_TOPIC"
2804 (let ((buffer (or (rcirc-get-buffer process (cadr args))
2805 (rcirc-get-temp-buffer-create process (cadr args)))))
2806 (with-current-buffer buffer
2807 (setq rcirc-topic (nth 2 args)))))
2809 (defun rcirc-handler-333 (process sender args _text)
2810 "333 says who set the topic and when.
2811 Not in rfc1459.txt"
2812 (let ((buffer (or (rcirc-get-buffer process (cadr args))
2813 (rcirc-get-temp-buffer-create process (cadr args)))))
2814 (with-current-buffer buffer
2815 (let ((setter (nth 2 args))
2816 (time (current-time-string
2817 (seconds-to-time
2818 (string-to-number (cl-cadddr args))))))
2819 (rcirc-print process sender "TOPIC" (cadr args)
2820 (format "%s (%s on %s)" rcirc-topic setter time))))))
2822 (defun rcirc-handler-477 (process sender args _text)
2823 "ERR_NOCHANMODES"
2824 (rcirc-print process sender "477" (cadr args) (nth 2 args)))
2826 (defun rcirc-handler-MODE (process sender args _text)
2827 (let ((target (car args))
2828 (msg (mapconcat 'identity (cdr args) " ")))
2829 (rcirc-print process sender "MODE"
2830 (if (string= target (rcirc-nick process))
2832 target)
2833 msg)
2835 ;; print in private chat buffers if they exist
2836 (mapc (lambda (nick)
2837 (when (rcirc-get-buffer process nick)
2838 (rcirc-print process sender "MODE" nick msg)))
2839 (cddr args))))
2841 (defun rcirc-get-temp-buffer-create (process channel)
2842 "Return a buffer based on PROCESS and CHANNEL."
2843 (let ((tmpnam (concat " " (downcase channel) "TMP" (process-name process))))
2844 (get-buffer-create tmpnam)))
2846 (defun rcirc-handler-353 (process _sender args _text)
2847 "RPL_NAMREPLY"
2848 (let ((channel (nth 2 args))
2849 (names (or (nth 3 args) "")))
2850 (mapc (lambda (nick)
2851 (rcirc-put-nick-channel process nick channel))
2852 (split-string names " " t))
2853 ;; create a temporary buffer to insert the names into
2854 ;; rcirc-handler-366 (RPL_ENDOFNAMES) will handle it
2855 (with-current-buffer (rcirc-get-temp-buffer-create process channel)
2856 (goto-char (point-max))
2857 (insert (car (last args)) " "))))
2859 (defun rcirc-handler-366 (process sender args _text)
2860 "RPL_ENDOFNAMES"
2861 (let* ((channel (cadr args))
2862 (buffer (rcirc-get-temp-buffer-create process channel)))
2863 (with-current-buffer buffer
2864 (rcirc-print process sender "NAMES" channel
2865 (let ((content (buffer-substring (point-min) (point-max))))
2866 (rcirc-sort-nicknames-join content " "))))
2867 (kill-buffer buffer)))
2869 (defun rcirc-handler-433 (process sender args text)
2870 "ERR_NICKNAMEINUSE"
2871 (rcirc-handler-generic process "433" sender args text)
2872 (let* ((new-nick (concat (cadr args) "`")))
2873 (with-rcirc-process-buffer process
2874 (rcirc-cmd-nick new-nick nil process))))
2876 (defun rcirc-authenticate ()
2877 "Send authentication to process associated with current buffer.
2878 Passwords are stored in `rcirc-authinfo' (which see)."
2879 (interactive)
2880 (with-rcirc-server-buffer
2881 (dolist (i rcirc-authinfo)
2882 (let ((process (rcirc-buffer-process))
2883 (server (car i))
2884 (nick (nth 2 i))
2885 (method (cadr i))
2886 (args (cl-cdddr i)))
2887 (when (and (string-match server rcirc-server))
2888 (if (and (memq method '(nickserv chanserv bitlbee))
2889 (string-match nick rcirc-nick))
2890 ;; the following methods rely on the user's nickname.
2891 (cl-case method
2892 (nickserv
2893 (rcirc-send-privmsg
2894 process
2895 (or (cadr args) "NickServ")
2896 (concat "IDENTIFY " (car args))))
2897 (chanserv
2898 (rcirc-send-privmsg
2899 process
2900 "ChanServ"
2901 (format "IDENTIFY %s %s" (car args) (cadr args))))
2902 (bitlbee
2903 (rcirc-send-privmsg
2904 process
2905 "&bitlbee"
2906 (concat "IDENTIFY " (car args)))))
2907 ;; quakenet authentication doesn't rely on the user's nickname.
2908 ;; the variable `nick' here represents the Q account name.
2909 (when (eq method 'quakenet)
2910 (rcirc-send-privmsg
2911 process
2912 "Q@CServe.quakenet.org"
2913 (format "AUTH %s %s" nick (car args))))))))))
2915 (defun rcirc-handler-INVITE (process sender args _text)
2916 (rcirc-print process sender "INVITE" nil (mapconcat 'identity args " ") t))
2918 (defun rcirc-handler-ERROR (process sender args _text)
2919 (rcirc-print process sender "ERROR" nil (mapconcat 'identity args " ")))
2921 (defun rcirc-handler-CTCP (process target sender text)
2922 (if (string-match "^\\([^ ]+\\) *\\(.*\\)$" text)
2923 (let* ((request (upcase (match-string 1 text)))
2924 (args (match-string 2 text))
2925 (handler (intern-soft (concat "rcirc-handler-ctcp-" request))))
2926 (if (not (fboundp handler))
2927 (rcirc-print process sender "ERROR" target
2928 (format "%s sent unsupported ctcp: %s" sender text)
2930 (funcall handler process target sender args)
2931 (unless (or (string= request "ACTION")
2932 (string= request "KEEPALIVE"))
2933 (rcirc-print process sender "CTCP" target
2934 (format "%s" text) t))))))
2936 (defun rcirc-handler-ctcp-VERSION (process _target sender _args)
2937 (rcirc-send-string process
2938 (concat "NOTICE " sender
2939 " :\C-aVERSION " rcirc-id-string
2940 "\C-a")))
2942 (defun rcirc-handler-ctcp-ACTION (process target sender args)
2943 (rcirc-print process sender "ACTION" target args t))
2945 (defun rcirc-handler-ctcp-TIME (process _target sender _args)
2946 (rcirc-send-string process
2947 (concat "NOTICE " sender
2948 " :\C-aTIME " (current-time-string) "\C-a")))
2950 (defun rcirc-handler-CTCP-response (process _target sender message)
2951 (rcirc-print process sender "CTCP" nil message t))
2953 (defgroup rcirc-faces nil
2954 "Faces for rcirc."
2955 :group 'rcirc
2956 :group 'faces)
2958 (defface rcirc-my-nick ; font-lock-function-name-face
2959 '((((class color) (min-colors 88) (background light)) :foreground "Blue1")
2960 (((class color) (min-colors 88) (background dark)) :foreground "LightSkyBlue")
2961 (((class color) (min-colors 16) (background light)) :foreground "Blue")
2962 (((class color) (min-colors 16) (background dark)) :foreground "LightSkyBlue")
2963 (((class color) (min-colors 8)) :foreground "blue" :weight bold)
2964 (t :inverse-video t :weight bold))
2965 "Rcirc face for my messages."
2966 :group 'rcirc-faces)
2968 (defface rcirc-other-nick ; font-lock-variable-name-face
2969 '((((class grayscale) (background light))
2970 :foreground "Gray90" :weight bold :slant italic)
2971 (((class grayscale) (background dark))
2972 :foreground "DimGray" :weight bold :slant italic)
2973 (((class color) (min-colors 88) (background light)) :foreground "DarkGoldenrod")
2974 (((class color) (min-colors 88) (background dark)) :foreground "LightGoldenrod")
2975 (((class color) (min-colors 16) (background light)) :foreground "DarkGoldenrod")
2976 (((class color) (min-colors 16) (background dark)) :foreground "LightGoldenrod")
2977 (((class color) (min-colors 8)) :foreground "yellow" :weight light)
2978 (t :weight bold :slant italic))
2979 "Rcirc face for other users' messages."
2980 :group 'rcirc-faces)
2982 (defface rcirc-bright-nick
2983 '((((class grayscale) (background light))
2984 :foreground "LightGray" :weight bold :underline t)
2985 (((class grayscale) (background dark))
2986 :foreground "Gray50" :weight bold :underline t)
2987 (((class color) (min-colors 88) (background light)) :foreground "CadetBlue")
2988 (((class color) (min-colors 88) (background dark)) :foreground "Aquamarine")
2989 (((class color) (min-colors 16) (background light)) :foreground "CadetBlue")
2990 (((class color) (min-colors 16) (background dark)) :foreground "Aquamarine")
2991 (((class color) (min-colors 8)) :foreground "magenta")
2992 (t :weight bold :underline t))
2993 "Rcirc face for nicks matched by `rcirc-bright-nicks'."
2994 :group 'rcirc-faces)
2996 (defface rcirc-dim-nick
2997 '((t :inherit default))
2998 "Rcirc face for nicks in `rcirc-dim-nicks'."
2999 :group 'rcirc-faces)
3001 (defface rcirc-server ; font-lock-comment-face
3002 '((((class grayscale) (background light))
3003 :foreground "DimGray" :weight bold :slant italic)
3004 (((class grayscale) (background dark))
3005 :foreground "LightGray" :weight bold :slant italic)
3006 (((class color) (min-colors 88) (background light))
3007 :foreground "Firebrick")
3008 (((class color) (min-colors 88) (background dark))
3009 :foreground "chocolate1")
3010 (((class color) (min-colors 16) (background light))
3011 :foreground "red")
3012 (((class color) (min-colors 16) (background dark))
3013 :foreground "red1")
3014 (((class color) (min-colors 8) (background light)))
3015 (((class color) (min-colors 8) (background dark)))
3016 (t :weight bold :slant italic))
3017 "Rcirc face for server messages."
3018 :group 'rcirc-faces)
3020 (defface rcirc-server-prefix ; font-lock-comment-delimiter-face
3021 '((default :inherit rcirc-server)
3022 (((class grayscale)))
3023 (((class color) (min-colors 16)))
3024 (((class color) (min-colors 8) (background light))
3025 :foreground "red")
3026 (((class color) (min-colors 8) (background dark))
3027 :foreground "red1"))
3028 "Rcirc face for server prefixes."
3029 :group 'rcirc-faces)
3031 (defface rcirc-timestamp
3032 '((t :inherit default))
3033 "Rcirc face for timestamps."
3034 :group 'rcirc-faces)
3036 (defface rcirc-nick-in-message ; font-lock-keyword-face
3037 '((((class grayscale) (background light)) :foreground "LightGray" :weight bold)
3038 (((class grayscale) (background dark)) :foreground "DimGray" :weight bold)
3039 (((class color) (min-colors 88) (background light)) :foreground "Purple")
3040 (((class color) (min-colors 88) (background dark)) :foreground "Cyan1")
3041 (((class color) (min-colors 16) (background light)) :foreground "Purple")
3042 (((class color) (min-colors 16) (background dark)) :foreground "Cyan")
3043 (((class color) (min-colors 8)) :foreground "cyan" :weight bold)
3044 (t :weight bold))
3045 "Rcirc face for instances of your nick within messages."
3046 :group 'rcirc-faces)
3048 (defface rcirc-nick-in-message-full-line '((t :weight bold))
3049 "Rcirc face for emphasizing the entire message when your nick is mentioned."
3050 :group 'rcirc-faces)
3052 (defface rcirc-prompt ; comint-highlight-prompt
3053 '((((min-colors 88) (background dark)) :foreground "cyan1")
3054 (((background dark)) :foreground "cyan")
3055 (t :foreground "dark blue"))
3056 "Rcirc face for prompts."
3057 :group 'rcirc-faces)
3059 (defface rcirc-track-nick
3060 '((((type tty)) :inherit default)
3061 (t :inverse-video t))
3062 "Rcirc face used in the mode-line when your nick is mentioned."
3063 :group 'rcirc-faces)
3065 (defface rcirc-track-keyword '((t :weight bold))
3066 "Rcirc face used in the mode-line when keywords are mentioned."
3067 :group 'rcirc-faces)
3069 (defface rcirc-url '((t :weight bold))
3070 "Rcirc face used to highlight urls."
3071 :group 'rcirc-faces)
3073 (defface rcirc-keyword '((t :inherit highlight))
3074 "Rcirc face used to highlight keywords."
3075 :group 'rcirc-faces)
3078 ;; When using M-x flyspell-mode, only check words after the prompt
3079 (put 'rcirc-mode 'flyspell-mode-predicate 'rcirc-looking-at-input)
3080 (defun rcirc-looking-at-input ()
3081 "Returns true if point is past the input marker."
3082 (>= (point) rcirc-prompt-end-marker))
3085 (provide 'rcirc)
3087 ;;; rcirc.el ends here