New function erc-switch-to-buffer-other-window

* lisp/erc/erc.el (erc-switch-to-buffer): Factor out the buffer choice
implementation from here ...
(erc--switch-to-buffer): ... to here.
(erc-switch-to-buffer-other-window): New function, like
`erc-switch-to-buffer', but uses `switch-to-buffer-other-window'
instead, to open the buffer in another window.
This commit is contained in:
Amin Bandali 2020-04-13 23:21:34 -04:00
parent f84aed5fd2
commit 38f7538d8f
No known key found for this signature in database
GPG key ID: 8B44A0CDC7B956F2
2 changed files with 33 additions and 19 deletions

View file

@ -1647,6 +1647,11 @@ adjacent to an apostrophe, like "nick's".
*** Set 'erc-button-url-regexp' to 'browse-url-button-regexp' *** Set 'erc-button-url-regexp' to 'browse-url-button-regexp'
which better handles surrounding pair of parentheses. which better handles surrounding pair of parentheses.
---
*** New function 'erc-switch-to-buffer-other-window'
which is like 'erc-switch-to-buffer', but opens the buffer in another
window.
** EUDC ** EUDC
--- ---

View file

@ -1762,29 +1762,38 @@ nil."
res))) res)))
(define-obsolete-function-alias 'erc-iswitchb 'erc-switch-to-buffer "25.1") (define-obsolete-function-alias 'erc-iswitchb 'erc-switch-to-buffer "25.1")
(defun erc--switch-to-buffer (&optional arg)
(read-buffer "Switch to ERC buffer: "
(when (boundp 'erc-modified-channels-alist)
(buffer-name (caar (last erc-modified-channels-alist))))
t
;; Only allow ERC buffers in the same session.
(let ((proc (unless arg erc-server-process)))
(lambda (bufname)
(let ((buf (if (consp bufname)
(cdr bufname) (get-buffer bufname))))
(when buf
(erc--buffer-p buf (lambda () t) proc)
(with-current-buffer buf
(and (derived-mode-p 'erc-mode)
(or (null proc)
(eq proc erc-server-process))))))))))
(defun erc-switch-to-buffer (&optional arg) (defun erc-switch-to-buffer (&optional arg)
"Prompt for a ERC buffer to switch to. "Prompt for an ERC buffer to switch to.
When invoked with prefix argument, use all erc buffers. Without prefix When invoked with prefix argument, use all ERC buffers. Without
ARG, allow only buffers related to same session server. prefix ARG, allow only buffers related to same session server.
If `erc-track-mode' is in enabled, put the last element of If `erc-track-mode' is in enabled, put the last element of
`erc-modified-channels-alist' in front of the buffer list." `erc-modified-channels-alist' in front of the buffer list."
(interactive "P") (interactive "P")
(switch-to-buffer (switch-to-buffer (erc--switch-to-buffer arg)))
(read-buffer "Switch to ERC buffer: " (defun erc-switch-to-buffer-other-window (&optional arg)
(when (boundp 'erc-modified-channels-alist) "Prompt for an ERC buffer to switch to in another window.
(buffer-name (caar (last erc-modified-channels-alist)))) When invoked with prefix argument, use all ERC buffers. Without
t prefix ARG, allow only buffers related to same session server.
;; Only allow ERC buffers in the same session. If `erc-track-mode' is in enabled, put the last element of
(let ((proc (unless arg erc-server-process))) `erc-modified-channels-alist' in front of the buffer list."
(lambda (bufname) (interactive "P")
(let ((buf (if (consp bufname) (switch-to-buffer-other-window (erc--switch-to-buffer arg)))
(cdr bufname) (get-buffer bufname))))
(when buf
(erc--buffer-p buf (lambda () t) proc)
(with-current-buffer buf
(and (derived-mode-p 'erc-mode)
(or (null proc)
(eq proc erc-server-process)))))))))))
(defun erc-channel-list (proc) (defun erc-channel-list (proc)
"Return a list of channel buffers. "Return a list of channel buffers.