Add 2012 to FSF copyright years for Emacs files
[bpt/emacs.git] / lisp / erc / erc.el
index 36097cf..7d85866 100644 (file)
@@ -1,6 +1,6 @@
 ;; erc.el --- An Emacs Internet Relay Chat client
 
-;; Copyright (C) 1997-2011 Free Software Foundation, Inc.
+;; Copyright (C) 1997-2012 Free Software Foundation, Inc.
 
 ;; Author: Alexander L. Belikoff (alexander@belikoff.net)
 ;; Contributors: Sergey Berezin (sergey.berezin@cs.cmu.edu),
@@ -1242,7 +1242,9 @@ Example:
        (erc-define-minor-mode
        ,mode
        ,(format "Toggle ERC %S mode.
-With arg, turn ERC %S mode on if and only if arg is positive.
+With a prefix argument ARG, enable %s if ARG is positive,
+and disable it otherwise.  If called from Lisp, enable the mode
+if ARG is omitted or nil.
 %s" name name doc)
        nil nil nil
        :global ,(not local-p) :group (quote ,group)
@@ -1555,26 +1557,33 @@ symbol, it may have these values:
 (defun erc-generate-new-buffer-name (server port target &optional proc)
   "Create a new buffer name based on the arguments."
   (when (numberp port) (setq port (number-to-string port)))
-  (let* ((buf-name (or target
-                      (or (let ((name (concat server ":" port)))
-                            (when (> (length name) 1)
-                              name))
-                          ; This fallback should in fact never happen
-                          "*erc-server-buffer*"))))
+  (let ((buf-name (or target
+                      (or (let ((name (concat server ":" port)))
+                            (when (> (length name) 1)
+                              name))
+                          ;; This fallback should in fact never happen
+                          "*erc-server-buffer*")))
+        buffer-name)
     ;; Reuse existing buffers, but not if the buffer is a connected server
     ;; buffer and not if its associated with a different server than the
     ;; current ERC buffer.
-    (if (and erc-reuse-buffers
-            (get-buffer buf-name)
-            (or target
-                (with-current-buffer (get-buffer buf-name)
-                  (and (erc-server-buffer-p)
-                       (not (erc-server-process-alive)))))
-            (with-current-buffer (get-buffer buf-name)
-              (and (string= erc-session-server server)
-                   (erc-port-equal erc-session-port port))))
-       buf-name
-      (generate-new-buffer-name buf-name))))
+    ;; if buf-name is taken by a different connection (or by something !erc)
+    ;; then see if "buf-name/server" meets the same criteria
+    (dolist (candidate (list buf-name (concat buf-name "/" server)))
+      (if (and (not buffer-name)
+               erc-reuse-buffers
+               (get-buffer candidate)
+               (or target
+                   (with-current-buffer (get-buffer candidate)
+                     (and (erc-server-buffer-p)
+                          (not (erc-server-process-alive)))))
+               (with-current-buffer (get-buffer candidate)
+                 (and (string= erc-session-server server)
+                      (erc-port-equal erc-session-port port))))
+          (setq buffer-name candidate)))
+    ;; if buffer-name is unset, neither candidate worked out for us,
+    ;; fallback to the old <N> uniquification method:
+    (or buffer-name (generate-new-buffer-name buf-name)) ))
 
 (defun erc-get-buffer-create (server port target &optional proc)
   "Create a new buffer based on the arguments."
@@ -2362,7 +2371,7 @@ If STRING is nil, the function does nothing."
        (cond ((integerp elt)           ; POSITION
               (incf (car list) shift))
              ((or (atom elt)           ; nil, EXTENT
-                  ;; (eq t (car elt))  ; (t HIGH . LOW)
+                  ;; (eq t (car elt))  ; (t . TIME)
                   (markerp (car elt))) ; (MARKER . DISTANCE)
               nil)
              ((integerp (car elt))     ; (BEGIN . END)
@@ -2617,7 +2626,7 @@ VALUE is computed by evaluating the rest of LINE in Lisp."
 (defun erc-cmd-default (line)
   "Fallback command.
 
-Commands for which no erc-cmd-xxx exists, are tunnelled through
+Commands for which no erc-cmd-xxx exists, are tunneled through
 this function.  LINE is sent to the server verbatim, and
 therefore has to contain the command itself as well."
   (erc-log (format "cmd: DEFAULT: %s" line))
@@ -3992,7 +4001,7 @@ and as second argument the event parsed as a vector."
        (not (string-match "^\C-a\\ACTION.*\C-a$" message))))
 
 (defun erc-format-privmessage (nick msg privp msgp)
-  "Format a PRIVMSG in an insertible fashion."
+  "Format a PRIVMSG in an insertable fashion."
   (let* ((mark-s (if msgp (if privp "*" "<") "-"))
         (mark-e (if msgp (if privp "*" ">") "-"))
         (str    (format "%s%s%s %s" mark-s nick mark-e msg))
@@ -5788,7 +5797,7 @@ If it doesn't exist, create it."
   "Give information about the nickname at `point'.
 
 If called interactively, give a human readable message in the
-minibuffer.  If called programatically, return the corresponding
+minibuffer.  If called programmatically, return the corresponding
 entry of `channel-members'."
   (interactive)
   (require 'thingatpt)
@@ -6493,4 +6502,3 @@ Otherwise, connect to HOST:PORT as USER and /join CHANNEL."
 ;; indent-tabs-mode: t
 ;; tab-width: 8
 ;; End:
-