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