aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2007-03-10 19:32:23 +0000
committerEli Zaretskii2007-03-10 19:32:23 +0000
commit8216fbaf631cd0fad845d75f8ae723d31aadb81f (patch)
treeed559045ed85dfd7192c77e82c07bc540590d7f9
parent7a78ffeca93b7d2026e30ccbe57a66778b14f846 (diff)
downloademacs-8216fbaf631cd0fad845d75f8ae723d31aadb81f.tar.gz
emacs-8216fbaf631cd0fad845d75f8ae723d31aadb81f.zip
(rcirc-timeout-seconds): New variable.
(rcirc-keepalive-seconds): Remove variable. (rcirc-server-name, rcirc-timeout-timer, rcirc-connecting) (rcirc-process, rcirc-user-disconnect): New variables. (rcirc-connect): Initalize new variables. (rcirc-keepalive): Don't send keepalive pings before connection is completed. (rcirc-sentinel): Do mark all channels with activity when connection is dropped. Run hook with process buffer local. (rcirc-reschedule-timeout, rcirc-delete-process): New functions. (rcirc-buffer-process): Return value of rcirc-process if rcirc-server-buffer is nil. (rcirc-server-name): Return the reported server name. (rcirc-update-prompt): Simplify computation of the server name. (rcirc-format-response-string): Likewise. (rcirc-handler-001): Mark server as connected, record the reported server name, and schedule a timeout. (rcirc-track-nick): Add a spec for the tty class. (rcirc-user-non-nick): Remove function. (rcirc-nick-prefix-chars): Add variable. (rcirc-user-nick): Use above variable.
-rw-r--r--lisp/ChangeLog24
-rw-r--r--lisp/net/rcirc.el94
2 files changed, 83 insertions, 35 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 94f76541c06..2636c1f4872 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,27 @@
12007-03-10 Ryan Yeske <rcyeske@gmail.com>
2
3 * net/rcirc.el (rcirc-timeout-seconds): New variable.
4 (rcirc-keepalive-seconds): Remove variable.
5 (rcirc-server-name, rcirc-timeout-timer, rcirc-connecting)
6 (rcirc-process, rcirc-user-disconnect): New variables.
7 (rcirc-connect): Initalize new variables.
8 (rcirc-keepalive): Don't send keepalive pings before connection is
9 completed.
10 (rcirc-sentinel): Do mark all channels with activity when
11 connection is dropped. Run hook with process buffer local.
12 (rcirc-reschedule-timeout, rcirc-delete-process): New functions.
13 (rcirc-buffer-process): Return value of rcirc-process if
14 rcirc-server-buffer is nil.
15 (rcirc-server-name): Return the reported server name.
16 (rcirc-update-prompt): Simplify computation of the server name.
17 (rcirc-format-response-string): Likewise.
18 (rcirc-handler-001): Mark server as connected, record the reported
19 server name, and schedule a timeout.
20 (rcirc-track-nick): Add a spec for the tty class.
21 (rcirc-user-non-nick): Remove function.
22 (rcirc-nick-prefix-chars): Add variable.
23 (rcirc-user-nick): Use above variable.
24
12007-03-10 Johan Bockg,be(Brd <bojohan@dd.chalmers.se> 252007-03-10 Johan Bockg,be(Brd <bojohan@dd.chalmers.se>
2 26
3 * icomplete.el (icomplete-tidy, icomplete-exhibit): Bind 27 * icomplete.el (icomplete-tidy, icomplete-exhibit): Bind
diff --git a/lisp/net/rcirc.el b/lisp/net/rcirc.el
index ac2c886a976..dc346695ce2 100644
--- a/lisp/net/rcirc.el
+++ b/lisp/net/rcirc.el
@@ -312,9 +312,8 @@ and the cdr part is used for encoding."
312 "List of urls seen in the current buffer.") 312 "List of urls seen in the current buffer.")
313(put 'rcirc-urls 'permanent-local t) 313(put 'rcirc-urls 'permanent-local t)
314 314
315(defvar rcirc-keepalive-seconds 60 315(defvar rcirc-timeout-seconds 60
316 "Number of seconds between keepalive pings. 316 "Kill connection after this many seconds if there is no activity.")
317If nil, do not send keepalive pings.")
318 317
319(defconst rcirc-id-string (concat "rcirc on GNU Emacs " emacs-version)) 318(defconst rcirc-id-string (concat "rcirc on GNU Emacs " emacs-version))
320 319
@@ -357,7 +356,12 @@ If ARG is non-nil, prompt for a server to connect to."
357(defvar rcirc-topic nil) 356(defvar rcirc-topic nil)
358(defvar rcirc-keepalive-timer nil) 357(defvar rcirc-keepalive-timer nil)
359(defvar rcirc-last-server-message-time nil) 358(defvar rcirc-last-server-message-time nil)
360(defvar rcirc-server nil) 359(defvar rcirc-server nil) ; server provided by server
360(defvar rcirc-server-name nil) ; server name given by 001 response
361(defvar rcirc-timeout-timer nil)
362(defvar rcirc-user-disconnect nil)
363(defvar rcirc-connecting nil)
364(defvar rcirc-process nil)
361 365
362;;;###autoload 366;;;###autoload
363(defun rcirc-connect (&optional server port nick user-name full-name startup-channels) 367(defun rcirc-connect (&optional server port nick user-name full-name startup-channels)
@@ -374,7 +378,7 @@ If ARG is non-nil, prompt for a server to connect to."
374 (user-name (or user-name rcirc-default-user-name)) 378 (user-name (or user-name rcirc-default-user-name))
375 (full-name (or full-name rcirc-default-user-full-name)) 379 (full-name (or full-name rcirc-default-user-full-name))
376 (startup-channels startup-channels) 380 (startup-channels startup-channels)
377 (process (open-network-stream server nil server port-number))) 381 (process (make-network-process :name server :host server :service port-number)))
378 ;; set up process 382 ;; set up process
379 (set-process-coding-system process 'raw-text 'raw-text) 383 (set-process-coding-system process 'raw-text 'raw-text)
380 (switch-to-buffer (rcirc-generate-new-buffer-name process nil)) 384 (switch-to-buffer (rcirc-generate-new-buffer-name process nil))
@@ -382,8 +386,12 @@ If ARG is non-nil, prompt for a server to connect to."
382 (rcirc-mode process nil) 386 (rcirc-mode process nil)
383 (set-process-sentinel process 'rcirc-sentinel) 387 (set-process-sentinel process 'rcirc-sentinel)
384 (set-process-filter process 'rcirc-filter) 388 (set-process-filter process 'rcirc-filter)
389 (make-local-variable 'rcirc-process)
390 (setq rcirc-process process)
385 (make-local-variable 'rcirc-server) 391 (make-local-variable 'rcirc-server)
386 (setq rcirc-server server) 392 (setq rcirc-server server)
393 (make-local-variable 'rcirc-server-name)
394 (setq rcirc-server-name server) ; update when we get 001 response
387 (make-local-variable 'rcirc-buffer-alist) 395 (make-local-variable 'rcirc-buffer-alist)
388 (setq rcirc-buffer-alist nil) 396 (setq rcirc-buffer-alist nil)
389 (make-local-variable 'rcirc-nick-table) 397 (make-local-variable 'rcirc-nick-table)
@@ -396,6 +404,12 @@ If ARG is non-nil, prompt for a server to connect to."
396 (setq rcirc-startup-channels startup-channels) 404 (setq rcirc-startup-channels startup-channels)
397 (make-local-variable 'rcirc-last-server-message-time) 405 (make-local-variable 'rcirc-last-server-message-time)
398 (setq rcirc-last-server-message-time (current-time)) 406 (setq rcirc-last-server-message-time (current-time))
407 (make-local-variable 'rcirc-timeout-timer)
408 (setq rcirc-timeout-timer nil)
409 (make-local-variable 'rcirc-user-disconnect)
410 (setq rcirc-user-disconnect nil)
411 (make-local-variable 'rcirc-connecting)
412 (setq rcirc-connecting t)
399 413
400 ;; identify 414 ;; identify
401 (rcirc-send-string process (concat "NICK " nick)) 415 (rcirc-send-string process (concat "NICK " nick))
@@ -404,10 +418,9 @@ If ARG is non-nil, prompt for a server to connect to."
404 full-name)) 418 full-name))
405 419
406 ;; setup ping timer if necessary 420 ;; setup ping timer if necessary
407 (when rcirc-keepalive-seconds 421 (unless rcirc-keepalive-timer
408 (unless rcirc-keepalive-timer 422 (setq rcirc-keepalive-timer
409 (setq rcirc-keepalive-timer 423 (run-at-time 0 (/ rcirc-timeout-seconds 2) 'rcirc-keepalive)))
410 (run-at-time 0 rcirc-keepalive-seconds 'rcirc-keepalive))))
411 424
412 (message "Connecting to %s...done" server) 425 (message "Connecting to %s...done" server)
413 426
@@ -430,12 +443,11 @@ Kill processes that have not received a server message since the
430last ping." 443last ping."
431 (if (rcirc-process-list) 444 (if (rcirc-process-list)
432 (mapc (lambda (process) 445 (mapc (lambda (process)
433 (with-rcirc-process-buffer process 446 (with-rcirc-process-buffer process
434 (if (> (cadr (time-since rcirc-last-server-message-time)) 447 (when (not rcirc-connecting)
435 rcirc-keepalive-seconds) 448 (rcirc-send-string process (concat "PING " (rcirc-server-name process))))))
436 (kill-process process)
437 (rcirc-send-string process (concat "PING " rcirc-server)))))
438 (rcirc-process-list)) 449 (rcirc-process-list))
450 ;; no processes, clean up timer
439 (cancel-timer rcirc-keepalive-timer) 451 (cancel-timer rcirc-keepalive-timer)
440 (setq rcirc-keepalive-timer nil))) 452 (setq rcirc-keepalive-timer nil)))
441 453
@@ -472,12 +484,12 @@ Functions are called with PROCESS and SENTINEL arguments.")
472 (format "%s: %s (%S)" 484 (format "%s: %s (%S)"
473 (process-name process) 485 (process-name process)
474 sentinel 486 sentinel
475 (process-status process)) t) 487 (process-status process)) (not rcirc-target))
476 ;; remove the prompt from buffers 488 ;; remove the prompt from buffers
477 (let ((inhibit-read-only t)) 489 (let ((inhibit-read-only t))
478 (delete-region rcirc-prompt-start-marker 490 (delete-region rcirc-prompt-start-marker
479 rcirc-prompt-end-marker))))) 491 rcirc-prompt-end-marker))))
480 (run-hook-with-args 'rcirc-sentinel-hooks process sentinel))) 492 (run-hook-with-args 'rcirc-sentinel-hooks process sentinel))))
481 493
482(defun rcirc-process-list () 494(defun rcirc-process-list ()
483 "Return a list of rcirc processes." 495 "Return a list of rcirc processes."
@@ -496,6 +508,7 @@ Function is called with PROCESS, COMMAND, SENDER, ARGS and LINE.")
496(defun rcirc-filter (process output) 508(defun rcirc-filter (process output)
497 "Called when PROCESS receives OUTPUT." 509 "Called when PROCESS receives OUTPUT."
498 (rcirc-debug process output) 510 (rcirc-debug process output)
511 (rcirc-reschedule-timeout process)
499 (with-rcirc-process-buffer process 512 (with-rcirc-process-buffer process
500 (setq rcirc-last-server-message-time (current-time)) 513 (setq rcirc-last-server-message-time (current-time))
501 (setq rcirc-process-output (concat rcirc-process-output output)) 514 (setq rcirc-process-output (concat rcirc-process-output output))
@@ -506,6 +519,19 @@ Function is called with PROCESS, COMMAND, SENDER, ARGS and LINE.")
506 (split-string rcirc-process-output "[\n\r]" t)) 519 (split-string rcirc-process-output "[\n\r]" t))
507 (setq rcirc-process-output nil)))) 520 (setq rcirc-process-output nil))))
508 521
522(defun rcirc-reschedule-timeout (process)
523 (with-rcirc-process-buffer process
524 (when (not rcirc-connecting)
525 (with-rcirc-process-buffer process
526 (when rcirc-timeout-timer (cancel-timer rcirc-timeout-timer))
527 (setq rcirc-timeout-timer (run-at-time rcirc-timeout-seconds nil
528 'rcirc-delete-process
529 process))))))
530
531(defun rcirc-delete-process (process)
532 (message "delete process %S" process)
533 (delete-process process))
534
509(defvar rcirc-trap-errors-flag t) 535(defvar rcirc-trap-errors-flag t)
510(defun rcirc-process-server-response (process text) 536(defun rcirc-process-server-response (process text)
511 (if rcirc-trap-errors-flag 537 (if rcirc-trap-errors-flag
@@ -557,15 +583,16 @@ Function is called with PROCESS, COMMAND, SENDER, ARGS and LINE.")
557(defun rcirc-buffer-process (&optional buffer) 583(defun rcirc-buffer-process (&optional buffer)
558 "Return the process associated with channel BUFFER. 584 "Return the process associated with channel BUFFER.
559With no argument or nil as argument, use the current buffer." 585With no argument or nil as argument, use the current buffer."
560 (get-buffer-process (if buffer 586 (or (get-buffer-process (if buffer
561 (with-current-buffer buffer 587 (with-current-buffer buffer
562 rcirc-server-buffer) 588 rcirc-server-buffer)
563 rcirc-server-buffer))) 589 rcirc-server-buffer))
590 rcirc-process))
564 591
565(defun rcirc-server-name (process) 592(defun rcirc-server-name (process)
566 "Return PROCESS server name, given by the 001 response." 593 "Return PROCESS server name, given by the 001 response."
567 (with-rcirc-process-buffer process 594 (with-rcirc-process-buffer process
568 (or rcirc-server rcirc-default-server))) 595 (or rcirc-server-name rcirc-default-server)))
569 596
570(defun rcirc-nick (process) 597(defun rcirc-nick (process)
571 "Return PROCESS nick." 598 "Return PROCESS nick."
@@ -790,7 +817,7 @@ If ALL is non-nil, update prompts in all IRC buffers."
790 (setq prompt 817 (setq prompt
791 (replace-regexp-in-string (car rep) (cdr rep) prompt))) 818 (replace-regexp-in-string (car rep) (cdr rep) prompt)))
792 (list (cons "%n" (rcirc-buffer-nick)) 819 (list (cons "%n" (rcirc-buffer-nick))
793 (cons "%s" (with-rcirc-server-buffer (or rcirc-server ""))) 820 (cons "%s" (with-rcirc-server-buffer rcirc-server-name))
794 (cons "%t" (or rcirc-target "")))) 821 (cons "%t" (or rcirc-target ""))))
795 (save-excursion 822 (save-excursion
796 (delete-region rcirc-prompt-start-marker rcirc-prompt-end-marker) 823 (delete-region rcirc-prompt-start-marker rcirc-prompt-end-marker)
@@ -1079,9 +1106,7 @@ is found by looking up RESPONSE in `rcirc-response-formats'."
1079 "%") 1106 "%")
1080 ((or (eq key ?n) (eq key ?N)) 1107 ((or (eq key ?n) (eq key ?N))
1081 ;; %n/%N -- nick 1108 ;; %n/%N -- nick
1082 (let ((nick (concat (if (string= (with-rcirc-process-buffer 1109 (let ((nick (concat (if (string= (rcirc-server-name process)
1083 process
1084 rcirc-server)
1085 sender) 1110 sender)
1086 "" 1111 ""
1087 sender) 1112 sender)
@@ -1302,19 +1327,15 @@ record activity."
1302 (rcirc-cmd-join channel process))))) 1327 (rcirc-cmd-join channel process)))))
1303 1328
1304;;; nick management 1329;;; nick management
1330(defvar rcirc-nick-prefix-chars "~&@%+")
1305(defun rcirc-user-nick (user) 1331(defun rcirc-user-nick (user)
1306 "Return the nick from USER. Remove any non-nick junk." 1332 "Return the nick from USER. Remove any non-nick junk."
1307 (save-match-data 1333 (save-match-data
1308 (if (string-match "^[@%+]?\\([^! ]+\\)!?" (or user "")) 1334 (if (string-match (concat "^[" rcirc-nick-prefix-chars
1335 "]?\\([^! ]+\\)!?") (or user ""))
1309 (match-string 1 user) 1336 (match-string 1 user)
1310 user))) 1337 user)))
1311 1338
1312(defun rcirc-user-non-nick (user)
1313 "Return the non-nick portion of USER."
1314 (if (string-match "^[@+]?[^! ]+!?\\(.*\\)" (or user ""))
1315 (match-string 1 user)
1316 user))
1317
1318(defun rcirc-nick-channels (process nick) 1339(defun rcirc-nick-channels (process nick)
1319 "Return list of channels for NICK." 1340 "Return list of channels for NICK."
1320 (with-rcirc-process-buffer process 1341 (with-rcirc-process-buffer process
@@ -2009,7 +2030,9 @@ in this buffer.")
2009 (rcirc-handler-generic process "001" sender args text) 2030 (rcirc-handler-generic process "001" sender args text)
2010 ;; set the real server name 2031 ;; set the real server name
2011 (with-rcirc-process-buffer process 2032 (with-rcirc-process-buffer process
2012 (setq rcirc-server sender) 2033 (setq rcirc-connecting nil)
2034 (rcirc-reschedule-timeout process)
2035 (setq rcirc-server-name sender)
2013 (setq rcirc-nick (car args)) 2036 (setq rcirc-nick (car args))
2014 (rcirc-update-prompt) 2037 (rcirc-update-prompt)
2015 (when rcirc-auto-authenticate-flag (rcirc-authenticate)) 2038 (when rcirc-auto-authenticate-flag (rcirc-authenticate))
@@ -2419,7 +2442,8 @@ Passwords are stored in `rcirc-authinfo' (which see)."
2419 :group 'rcirc-faces) 2442 :group 'rcirc-faces)
2420 2443
2421(defface rcirc-track-nick 2444(defface rcirc-track-nick
2422 '((t (:inverse-video t))) 2445 '((((type tty)) (:inherit default))
2446 (t (:inverse-video t)))
2423 "The face used in the mode-line when your nick is mentioned." 2447 "The face used in the mode-line when your nick is mentioned."
2424 :group 'rcirc-faces) 2448 :group 'rcirc-faces)
2425 2449