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