From f2f98c3ac59397c16d5eec2db1db82fafa4e299a Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Fri, 7 Mar 2025 20:24:41 +0100 Subject: [PATCH] Do not restrict shell buffer display to frame sides Give buffers running ephemeral `eshell` or `shell` sessions a name that is different from the default name chosen by these commands, and only restrict those ephemeral shell buffers to be displayed at the side. This way, running the commands `eshell` and `shell` will yield windows can be handled like any others and can be used for long-running sessions. --- init.el | 4 ++-- site-lisp/db-eshell.el | 14 +++++++------- site-lisp/db-utils.el | 12 ++++++------ 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/init.el b/init.el index ff76be6..c8c0673 100644 --- a/init.el +++ b/init.el @@ -322,14 +322,14 @@ ;; Inspired by masteringemacs and ;; https://www.gnu.org/software/emacs/manual/html_node/elisp/Frame-Layouts-with-Side-Windows.html (add-to-list 'display-buffer-alist - '("^\\*eshell\\*" + '("^\\*eshell-side\\*" display-buffer-in-side-window (side . bottom) (slot . -1) (window-height . 0.33) (window-parameters . ((no-other-window . t))))) (add-to-list 'display-buffer-alist - '("^\\*shell\\*" + '("^\\*shell-side\\*" display-buffer-in-side-window (side . bottom) (slot . 1) diff --git a/site-lisp/db-eshell.el b/site-lisp/db-eshell.el index 2551a7f..83debbe 100644 --- a/site-lisp/db-eshell.el +++ b/site-lisp/db-eshell.el @@ -26,17 +26,17 @@ Otherwise moves the cursor to the window where we have been before. -The buffer's name has to start with “*eshell*” to be recognized -by this function. Otherwise the current buffer is not treated as -an eshell buffer. +The buffer's name has to start with “*eshell-side*” to be recognized by +this function. Otherwise the current buffer is not treated as an eshell +buffer. -When ARG is given, change to `default-directory' after switching -to the eshell buffer." +When ARG is given, change to `default-directory' after switching to the +eshell buffer." (interactive "P") (let ((current-dir (expand-file-name default-directory))) (cl-flet ((in-eshell-buffer-p () (and (derived-mode-p 'eshell-mode) - (string-match-p "^\\*eshell\\*" (buffer-name))))) + (string-match-p "^\\*eshell-side\\*" (buffer-name))))) (if (and (not arg) (in-eshell-buffer-p)) @@ -49,7 +49,7 @@ to the eshell buffer." (window-list-1)))) (select-window eshell-window) ;; No running eshell found, open new one. - (--if-let (display-buffer (eshell 1)) + (--if-let (display-buffer (let ((eshell-buffer-name "*eshell-side*")) (eshell))) (select-window it) (error "Could not start eshell (`display-buffer' returned nil)")))) diff --git a/site-lisp/db-utils.el b/site-lisp/db-utils.el index a8d9b02..61f19ef 100644 --- a/site-lisp/db-utils.el +++ b/site-lisp/db-utils.el @@ -75,9 +75,9 @@ If already in *ansi-term* buffer, bury it." Otherwise, closes the current shell window. -The buffer's name has to start with “*shell*” to be recognized -by this function. Otherwise the current buffer is not treated as -a shell buffer. +The buffer's name has to start with “*shell-side*” to be recognized by +this function. Otherwise the current buffer is not treated as a shell +buffer. With ARG, switch to `default-directory' of the current buffer first." (interactive "P") @@ -85,16 +85,16 @@ With ARG, switch to `default-directory' of the current buffer first." (if-let ((shell-window (cl-find-if (lambda (window) (with-current-buffer (window-buffer window) (and (derived-mode-p 'shell-mode) - (string-match-p "^\\*shell\\*" (buffer-name))))) + (string-match-p "^\\*shell-side\\*" (buffer-name))))) (window-list-1)))) (select-window shell-window) - (--if-let (display-buffer (shell)) + (--if-let (display-buffer (shell (get-buffer-create "*shell-side*"))) (select-window it) (error "Could not start shell (`display-buffer' returned nil)"))))) (if (not arg) ;; toggle shell window (if (and (derived-mode-p 'shell-mode) - (string-match-p "^\\*shell\\*" (buffer-name))) + (string-match-p "^\\*shell-side\\*" (buffer-name))) (bury-buffer) (change-to-shell))