emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

emacs-27 38f7538 1/2: New function erc-switch-to-buffer-other-window


From: Amin Bandali
Subject: emacs-27 38f7538 1/2: New function erc-switch-to-buffer-other-window
Date: Tue, 14 Apr 2020 00:34:21 -0400 (EDT)

branch: emacs-27
commit 38f7538d8f62ee287e8271d048f1230d840c11a0
Author: Amin Bandali <address@hidden>
Commit: Amin Bandali <address@hidden>

    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.
---
 etc/NEWS        |  5 +++++
 lisp/erc/erc.el | 47 ++++++++++++++++++++++++++++-------------------
 2 files changed, 33 insertions(+), 19 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index f4edfaf..f3ef798 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1647,6 +1647,11 @@ adjacent to an apostrophe, like "nick's".
 *** Set 'erc-button-url-regexp' to 'browse-url-button-regexp'
 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
 
 ---
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 5c63382..cc5226b 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -1762,29 +1762,38 @@ nil."
        res)))
 
 (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)
-  "Prompt for a ERC buffer to switch to.
-When invoked with prefix argument, use all erc buffers.  Without prefix
-ARG, allow only buffers related to same session server.
+  "Prompt for an ERC buffer to switch to.
+When invoked with prefix argument, use all ERC buffers.  Without
+prefix ARG, allow only buffers related to same session server.
 If `erc-track-mode' is in enabled, put the last element of
 `erc-modified-channels-alist' in front of the buffer list."
   (interactive "P")
-  (switch-to-buffer
-   (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)))))))))))
+  (switch-to-buffer (erc--switch-to-buffer arg)))
+(defun erc-switch-to-buffer-other-window (&optional arg)
+  "Prompt for an ERC buffer to switch to in another window.
+When invoked with prefix argument, use all ERC buffers.  Without
+prefix ARG, allow only buffers related to same session server.
+If `erc-track-mode' is in enabled, put the last element of
+`erc-modified-channels-alist' in front of the buffer list."
+  (interactive "P")
+  (switch-to-buffer-other-window (erc--switch-to-buffer arg)))
 
 (defun erc-channel-list (proc)
   "Return a list of channel buffers.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]