Subject: Re: bug#29533: Fwd: [Feature Request] ERC: let erc-join-channel support to select channels from history or a defined list

From: stardiviner <[email-masked]>
Date: Thu, 14 May 2020 11:38:48 +0800

Stefan Kangas <[email-masked]> writes:

> stardiviner <[email-masked]> writes:
>
>> When I press [C-c C-j] (erc-join-channel), the advice is added on function,
>> but seems not working. Don't know why, do you have any clue?
>
> I don't usually use erc, so I'll have to leave that for someone else.
>
> Best regards,
> Stefan Kangas

Ok, I applied changes on Emacs source code, but when I try to commit, I got
following warning which stops me creating commit.

```
  1 git … commit --
lisp/erc/erc.el:4018: indent with spaces.
+                       (regexp :tag "Name")
lisp/erc/erc.el:4019: indent with spaces.
+                       (repeat :tag "Channels"
lisp/erc/erc.el:4020: indent with spaces.
+                               (string :tag "Name")))))
lisp/erc/erc.el:4046: indent with spaces.
+          (completing-read "Select a server: "
lisp/erc/erc.el:4047: indent with spaces.
+                           (mapcar 'car erc-join-channels-alist))
lisp/erc/erc.el:4048: indent with spaces.
+          erc-join-channels-alist)))))
```

I didi an google search, but still don't know how to set this. Shouldn't it be
space-indented?

And here is my patch diff. How should I submit this patch to Emacs/erc ?

#+begin_src diff
Staged changes (1)
modified   lisp/erc/erc.el
@@ -1161,7 +1161,7 @@ erc-mode-map
     (define-key map "\C-c\C-e" 'erc-toggle-ctcp-autoresponse)
     (define-key map "\C-c\C-f" 'erc-toggle-flood-control)
     (define-key map "\C-c\C-i" 'erc-invite-only-mode)
- -    (define-key map "\C-c\C-j" 'erc-join-channel)
+    (define-key map "\C-c\C-j" 'erc-join-channel-select)
     (define-key map "\C-c\C-n" 'erc-channel-names)
     (define-key map "\C-c\C-o" 'erc-get-channel-mode-from-keypress)
     (define-key map "\C-c\C-p" 'erc-part-from-channel)
@@ -3993,6 +3993,34 @@ erc-input-action
     (if (not (string-match "^\\s-*$" action))
         (erc-send-action (erc-default-target) action))))
 
+(defcustom erc-join-channels-alist nil
+  "Alist of channels to select when you join channels.
+
+Every element in the alist has the form (SERVER . CHANNELS).
+SERVER is a regexp matching the server, and channels is the
+list of channels to join.
+
+If the channel(s) require channel keys for joining, the passwords
+are found via auth-source.  For instance, if you use ~/.authinfo
+as your auth-source backend, then put something like the
+following in that file:
+
+machine irc.example.net login \"#fsf\" password sEcReT
+
+Customize this variable to set the value for your first connect.
+Once you are connected and join and part channels, this alist
+keeps track of what channels you are on, and will join them
+again when you get disconnected.  When you restart Emacs, however,
+those changes are lost, and the customization you saved the last
+time is used again."
+  :group 'erc-join
+  :type '(repeat (cons :tag "Server"
+                       (regexp :tag "Name")
+                       (repeat :tag "Channels"
+                               (string :tag "Name")))))
+
+(setq erc-join-channels-alist '(("*.freenode.net" "#emacs" "#org-mode")))
+
 (defun erc-join-channel (channel &optional key)
   "Join CHANNEL.
 
@@ -4008,6 +4036,17 @@ erc-join-channel
       (read-from-minibuffer "Channel key (RET for none): " nil))))
   (erc-cmd-JOIN channel (when (>= (length key) 1) key)))
 
+(defun erc-join-channel-select ()
+  "Select a channel to join from alist of channels to."
+  (interactive)
+  (erc-join-channel
+   (completing-read
+    "Select a channel: "
+    (cdr (assoc
+          (completing-read "Select a server: "
+                           (mapcar 'car erc-join-channels-alist))
+          erc-join-channels-alist)))))
+
 (defun erc-part-from-channel (reason)
   "Part from the current channel and prompt for a REASON."
   (interactive
#+end_src

- -- 
[ stardiviner ]
       I try to make every word tell the meaning that I want to express.

       Blog: https://stardiviner.github.io/
       IRC(freenode): stardiviner, Matrix: stardiviner
       GPG: F09F650D7D674819892591401B5DF1C95AE89AC3