Subject: 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:32:56 +0800

Noam Postavsky <[email-masked]> writes:

> stardiviner <[email-masked]> writes:
>
>> ;;; original code
>> (defun erc-join-channel (channel &optional key)
>>   "Join CHANNEL.
>>
>> If `point' is at the beginning of a channel name, use that as default."
>>   (interactive
>>    (list [...]
>
>> (defun erc-join-channel-select (args)
>>   "Select a channel to join from alist of channels to."
>>   (let ((channel (completing-read
>>                   "Select a channel: "
>>                   (cdr (assoc
>>                         (completing-read "Select a server: "
>>                                          (mapcar 'car erc-join-channels-alist))
>>                         erc-join-channels-alist)))))
>>     (setq args (list channel))))
>
>> (advice-add 'erc-join-channel :filter-args 'erc-join-channel-select)
>
>> 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 think advice doesn't affect interactive calls the way you expect.  I
> forget the details of it, but anyway it's probably better to just remap
> instead, along the lines of:
>
>     (defun erc-join-channel-select ()
>       "Select a channel to join from alist of channels to."
>       (erj-join-channel
>        (completing-read
>         "Select a channel: "
>         (cdr (assoc
>               (completing-read "Select a server: "
>                                (mapcar 'car erc-join-channels-alist))
>               erc-join-channels-alist)))))
>
>     (define-key erc-mode-map [remap erc-join-channel] 'erc-join-channel-select)

Thanks, I apply you solution, I changed erc's default [C-c C-j] keybinding to new command.

- -- 
[ 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