Subject: bug#25349: 25.1.90; erc join -vs- passwords

From: Tom Tromey <[email-masked]>
Date: Wed, 04 Jan 2017 08:13:16 -0700

>>>>> "Tom" == Tom Tromey <[email-masked]> writes:

Tom> I'm using erc and joining a channel that has a channel password.
Tom> I've tried to put the password in my ~/.authinfo.  However, there
Tom> are two erc bugs that prevent this from working.

This patch seems to work for me.

Tom

diff --git a/lisp/erc/erc-join.el b/lisp/erc/erc-join.el
index 151ea15..9474b11 100644
--- a/lisp/erc/erc-join.el
+++ b/lisp/erc/erc-join.el
@@ -129,7 +129,7 @@ erc-autojoin-after-ident
       (setq erc--autojoin-timer
 	    (erc-cancel-timer erc--autojoin-timer)))
   (when (eq erc-autojoin-timing 'ident)
-    (let ((server (or erc-server-announced-name erc-session-server))
+    (let ((server (or erc-session-server erc-server-announced-name))
 	  (joined (mapcar (lambda (buf)
 			    (with-current-buffer buf (erc-default-target)))
 			  (erc-channel-list erc-server-process))))
@@ -166,27 +166,12 @@ erc-autojoin-channels
   ;; Return nil to avoid stomping on any other hook funcs.
   nil)
 
-(defun erc-server-join-channel (server channel)
-  (let* ((secret (plist-get (nth 0 (auth-source-search
-				    :max 1
-				    :host server
-				    :port "irc"
-				    :user channel))
-			    :secret))
-	 (password (if (functionp secret)
-		       (funcall secret)
-		     secret)))
-    (erc-server-send (concat "JOIN " channel
-			     (if password
-				 (concat " " password)
-			       "")))))
-
 (defun erc-autojoin-add (proc parsed)
   "Add the channel being joined to `erc-autojoin-channels-alist'."
   (let* ((chnl (erc-response.contents parsed))
 	 (nick (car (erc-parse-user (erc-response.sender parsed))))
 	 (server (with-current-buffer (process-buffer proc)
-		   (or erc-server-announced-name erc-session-server))))
+		   (or erc-session-server erc-server-announced-name))))
     (when (erc-current-nick-p nick)
       (when (and erc-autojoin-domain-only
 		 (string-match "[^.\n]+\\.\\([^.\n]+\\.[^.\n]+\\)$" server))
@@ -209,7 +194,7 @@ erc-autojoin-remove
   (let* ((chnl (car (erc-response.command-args parsed)))
 	 (nick (car (erc-parse-user (erc-response.sender parsed))))
 	 (server (with-current-buffer (process-buffer proc)
-		   (or erc-server-announced-name erc-session-server))))
+		   (or erc-session-server erc-server-announced-name))))
     (when (erc-current-nick-p nick)
       (when (and erc-autojoin-domain-only
 		 (string-match "[^.\n]+\\.\\([^.\n]+\\.[^.\n]+\\)$" server))
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 3dcb7ef..3cc9f52 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -3022,6 +3022,23 @@ erc-cmd-HELP
 (defalias 'erc-cmd-H 'erc-cmd-HELP)
 (put 'erc-cmd-HELP 'process-not-needed t)
 
+(defun erc-server-join-channel (server channel &optional secret)
+  (let* ((secret (or secret
+		     (plist-get (nth 0 (auth-source-search
+					:max 1
+					:host server
+					:port "irc"
+					:user channel))
+				:secret)))
+	 (password (if (functionp secret)
+		       (funcall secret)
+		     secret)))
+    (erc-log (format "cmd: JOIN: %s" channel))
+    (erc-server-send (concat "JOIN " channel
+			     (if password
+				 (concat " " password)
+			       "")))))
+
 (defun erc-cmd-JOIN (channel &optional key)
   "Join the channel given in CHANNEL, optionally with KEY.
 If CHANNEL is specified as \"-invite\", join the channel to which you
@@ -3041,10 +3058,9 @@ erc-cmd-JOIN
         (if (erc-member-ignore-case chnl joined-channels)
             (switch-to-buffer (car (erc-member-ignore-case chnl
                                                            joined-channels)))
-          (erc-log (format "cmd: JOIN: %s" chnl))
-          (erc-server-send (if (and chnl key)
-                               (format "JOIN %s %s" chnl key)
-                             (format "JOIN %s" chnl)))))))
+	  (let ((server (with-current-buffer (process-buffer erc-server-process)
+			  (or erc-session-server erc-server-announced-name))))
+	    (erc-server-join-channel server chnl key))))))
   t)
 
 (defalias 'erc-cmd-CHANNEL 'erc-cmd-JOIN)