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