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