* [PATCH] erc: fix erc-reuse-buffers behavior
@ 2020-07-07 7:20 Mingde (Matthew) Zeng
2020-07-07 16:17 ` Mingde (Matthew) Zeng
2020-07-09 19:05 ` Mingde (Matthew) Zeng
0 siblings, 2 replies; 4+ messages in thread
From: Mingde (Matthew) Zeng @ 2020-07-07 7:20 UTC (permalink / raw)
To: emacs-devel; +Cc: bandali
By definition of erc-reuse-buffers, if non-nil it should create a
new buffer when joining channels with same names on different
servers. The current behavior of erc-reuse-buffers is:
1. when non-nil, it will always reuse the same channel buffer,
resulting in server A's channel gets reconnected to the channel with
the same name of server B.
2. when nil, the buffer-name of the joined channel is
'#channel/server'. However if one tries to '/join #channel' from the
server buffer, it creates a new empty buffer with buffer-name
'#channel', instead of opening the already-joined channel buffer.
* lisp/erc/erc.el (erc-generate-new-buffer-name): since `target' is
always non-nil, buffer-name is non-nil, erc-reuse-buffers is t, it
will always use the first candidate, resulting in behavior 1. This is
now fixed, and both channel buffers with the same name will be formated
'#channel/serverA' and '#channel/serverB' for the sake of consistency.
* lisp/erc/erc.el (erc-cmd-JOIN): with some refactoring, it ensures
the joined channel buffer is selected and thereby fixes behavior 2.
Signed-off-by: Mingde (Matthew) Zeng <matthewzmd@gmail.com>
---
lisp/erc/erc.el | 38 +++++++++++++++++++++++---------------
1 file changed, 23 insertions(+), 15 deletions(-)
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 3880778794..f0ace765d9 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -1622,14 +1622,20 @@ symbol, it may have these values:
(if (and (not buffer-name)
erc-reuse-buffers
(or (not (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 (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)))
+ (setq buffer-name candidate)
+ (when (and erc-reuse-buffers (get-buffer buf-name))
+ ;; a new buffer will be created with the name buf-name/server, rename
+ ;; the existing name-duplicated buffer with the same format as well
+ (with-current-buffer (get-buffer buf-name)
+ (when (derived-mode-p 'erc-mode) ; ensure it's an erc buffer
+ (rename-buffer
+ (concat buf-name "/" (or erc-session-server erc-server-announced-name))))))))
;; 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 (concat buf-name "/" server)))))
@@ -3097,16 +3103,18 @@ were most recently invited. See also `invitation'."
(setq chnl (erc-ensure-channel-name channel)))
(when chnl
;; Prevent double joining of same channel on same server.
- (let ((joined-channels
- (mapcar #'(lambda (chanbuf)
- (with-current-buffer chanbuf (erc-default-target)))
- (erc-channel-list erc-server-process))))
- (if (erc-member-ignore-case chnl joined-channels)
- (switch-to-buffer (car (erc-member-ignore-case chnl
- joined-channels)))
- (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))))))
+ (let* ((joined-channels
+ (mapcar #'(lambda (chanbuf)
+ (with-current-buffer chanbuf (erc-default-target)))
+ (erc-channel-list erc-server-process)))
+ (server (with-current-buffer (process-buffer erc-server-process)
+ (or erc-session-server erc-server-announced-name)))
+ (chnl-name (car (erc-member-ignore-case chnl joined-channels))))
+ (if chnl-name
+ (switch-to-buffer (if (get-buffer chnl-name)
+ chnl-name
+ (concat chnl-name "/" server)))
+ (erc-server-join-channel server chnl key)))))
t)
(defalias 'erc-cmd-CHANNEL 'erc-cmd-JOIN)
--
Mingde (Matthew) Zeng
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] erc: fix erc-reuse-buffers behavior
2020-07-07 7:20 [PATCH] erc: fix erc-reuse-buffers behavior Mingde (Matthew) Zeng
@ 2020-07-07 16:17 ` Mingde (Matthew) Zeng
2020-07-07 16:40 ` Amin Bandali
2020-07-09 19:05 ` Mingde (Matthew) Zeng
1 sibling, 1 reply; 4+ messages in thread
From: Mingde (Matthew) Zeng @ 2020-07-07 16:17 UTC (permalink / raw)
To: emacs-devel
If this can potentially be merged, can someone send me the copyright assignment please?
Mingde (Matthew) Zeng <matthewzmd@gmail.com> writes:
> By definition of erc-reuse-buffers, if non-nil it should create a
> new buffer when joining channels with same names on different
> servers. The current behavior of erc-reuse-buffers is:
> 1. when non-nil, it will always reuse the same channel buffer,
> resulting in server A's channel gets reconnected to the channel with
> the same name of server B.
> 2. when nil, the buffer-name of the joined channel is
> '#channel/server'. However if one tries to '/join #channel' from the
> server buffer, it creates a new empty buffer with buffer-name
> '#channel', instead of opening the already-joined channel buffer.
>
> * lisp/erc/erc.el (erc-generate-new-buffer-name): since `target' is
> always non-nil, buffer-name is non-nil, erc-reuse-buffers is t, it
> will always use the first candidate, resulting in behavior 1. This is
> now fixed, and both channel buffers with the same name will be formated
> '#channel/serverA' and '#channel/serverB' for the sake of consistency.
>
> * lisp/erc/erc.el (erc-cmd-JOIN): with some refactoring, it ensures
> the joined channel buffer is selected and thereby fixes behavior 2.
>
> Signed-off-by: Mingde (Matthew) Zeng <matthewzmd@gmail.com>
> ---
> lisp/erc/erc.el | 38 +++++++++++++++++++++++---------------
> 1 file changed, 23 insertions(+), 15 deletions(-)
>
> diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
> index 3880778794..f0ace765d9 100644
> --- a/lisp/erc/erc.el
> +++ b/lisp/erc/erc.el
> @@ -1622,14 +1622,20 @@ symbol, it may have these values:
> (if (and (not buffer-name)
> erc-reuse-buffers
> (or (not (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 (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)))
> + (setq buffer-name candidate)
> + (when (and erc-reuse-buffers (get-buffer buf-name))
> + ;; a new buffer will be created with the name buf-name/server, rename
> + ;; the existing name-duplicated buffer with the same format as well
> + (with-current-buffer (get-buffer buf-name)
> + (when (derived-mode-p 'erc-mode) ; ensure it's an erc buffer
> + (rename-buffer
> + (concat buf-name "/" (or erc-session-server erc-server-announced-name))))))))
> ;; 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 (concat buf-name "/" server)))))
> @@ -3097,16 +3103,18 @@ were most recently invited. See also `invitation'."
> (setq chnl (erc-ensure-channel-name channel)))
> (when chnl
> ;; Prevent double joining of same channel on same server.
> - (let ((joined-channels
> - (mapcar #'(lambda (chanbuf)
> - (with-current-buffer chanbuf (erc-default-target)))
> - (erc-channel-list erc-server-process))))
> - (if (erc-member-ignore-case chnl joined-channels)
> - (switch-to-buffer (car (erc-member-ignore-case chnl
> - joined-channels)))
> - (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))))))
> + (let* ((joined-channels
> + (mapcar #'(lambda (chanbuf)
> + (with-current-buffer chanbuf (erc-default-target)))
> + (erc-channel-list erc-server-process)))
> + (server (with-current-buffer (process-buffer erc-server-process)
> + (or erc-session-server erc-server-announced-name)))
> + (chnl-name (car (erc-member-ignore-case chnl joined-channels))))
> + (if chnl-name
> + (switch-to-buffer (if (get-buffer chnl-name)
> + chnl-name
> + (concat chnl-name "/" server)))
> + (erc-server-join-channel server chnl key)))))
> t)
>
> (defalias 'erc-cmd-CHANNEL 'erc-cmd-JOIN)
--
Mingde (Matthew) Zeng
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] erc: fix erc-reuse-buffers behavior
2020-07-07 7:20 [PATCH] erc: fix erc-reuse-buffers behavior Mingde (Matthew) Zeng
2020-07-07 16:17 ` Mingde (Matthew) Zeng
@ 2020-07-09 19:05 ` Mingde (Matthew) Zeng
1 sibling, 0 replies; 4+ messages in thread
From: Mingde (Matthew) Zeng @ 2020-07-09 19:05 UTC (permalink / raw)
To: Mingde (Matthew) Zeng; +Cc: bandali, emacs-devel
Mingde (Matthew) Zeng <matthewzmd@gmail.com> writes:
> By definition of erc-reuse-buffers, if non-nil it should create a
> new buffer when joining channels with same names on different
> servers. The current behavior of erc-reuse-buffers is:
> 1. when non-nil, it will always reuse the same channel buffer,
> resulting in server A's channel gets reconnected to the channel with
> the same name of server B.
> 2. when nil, the buffer-name of the joined channel is
> '#channel/server'. However if one tries to '/join #channel' from the
> server buffer, it creates a new empty buffer with buffer-name
> '#channel', instead of opening the already-joined channel buffer.
>
> * lisp/erc/erc.el (erc-generate-new-buffer-name): since `target' is
> always non-nil, buffer-name is non-nil, erc-reuse-buffers is t, it
> will always use the first candidate, resulting in behavior 1. This is
> now fixed, and both channel buffers with the same name will be formated
> '#channel/serverA' and '#channel/serverB' for the sake of consistency.
>
> * lisp/erc/erc.el (erc-cmd-JOIN): with some refactoring, it ensures
> the joined channel buffer is selected and thereby fixes behavior 2.
>
> Signed-off-by: Mingde (Matthew) Zeng <matthewzmd@gmail.com>
> ---
> lisp/erc/erc.el | 38 +++++++++++++++++++++++---------------
> 1 file changed, 23 insertions(+), 15 deletions(-)
>
> diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
> index 3880778794..f0ace765d9 100644
> --- a/lisp/erc/erc.el
> +++ b/lisp/erc/erc.el
> @@ -1622,14 +1622,20 @@ symbol, it may have these values:
> (if (and (not buffer-name)
> erc-reuse-buffers
> (or (not (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 (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)))
> + (setq buffer-name candidate)
> + (when (and erc-reuse-buffers (get-buffer buf-name))
I discovered an edge case and a minor adjustment will need to be made along this line.
Will submit a new patch after I receive and sign the copyright assignment form from assign@gnu.org - they're not very responding right now for some reason.
Matthew
> + ;; a new buffer will be created with the name buf-name/server, rename
> + ;; the existing name-duplicated buffer with the same format as well
> + (with-current-buffer (get-buffer buf-name)
> + (when (derived-mode-p 'erc-mode) ; ensure it's an erc buffer
> + (rename-buffer
> + (concat buf-name "/" (or erc-session-server erc-server-announced-name))))))))
> ;; 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 (concat buf-name "/" server)))))
> @@ -3097,16 +3103,18 @@ were most recently invited. See also `invitation'."
> (setq chnl (erc-ensure-channel-name channel)))
> (when chnl
> ;; Prevent double joining of same channel on same server.
> - (let ((joined-channels
> - (mapcar #'(lambda (chanbuf)
> - (with-current-buffer chanbuf (erc-default-target)))
> - (erc-channel-list erc-server-process))))
> - (if (erc-member-ignore-case chnl joined-channels)
> - (switch-to-buffer (car (erc-member-ignore-case chnl
> - joined-channels)))
> - (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))))))
> + (let* ((joined-channels
> + (mapcar #'(lambda (chanbuf)
> + (with-current-buffer chanbuf (erc-default-target)))
> + (erc-channel-list erc-server-process)))
> + (server (with-current-buffer (process-buffer erc-server-process)
> + (or erc-session-server erc-server-announced-name)))
> + (chnl-name (car (erc-member-ignore-case chnl joined-channels))))
> + (if chnl-name
> + (switch-to-buffer (if (get-buffer chnl-name)
> + chnl-name
> + (concat chnl-name "/" server)))
> + (erc-server-join-channel server chnl key)))))
> t)
>
> (defalias 'erc-cmd-CHANNEL 'erc-cmd-JOIN)
--
Mingde (Matthew) Zeng
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-07-09 19:05 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-07-07 7:20 [PATCH] erc: fix erc-reuse-buffers behavior Mingde (Matthew) Zeng
2020-07-07 16:17 ` Mingde (Matthew) Zeng
2020-07-07 16:40 ` Amin Bandali
2020-07-09 19:05 ` Mingde (Matthew) Zeng
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.