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