From aec896c939791ffa09993d7a6a8b2f4f8bcf42f1 Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Sat, 11 Feb 2023 19:33:19 +0100 Subject: [PATCH] Always display shell buffers at bottom of frame in dedicated window Inspired by https://www.masteringemacs.org/article/demystifying-emacs-window-manager. --- site-lisp/db-eshell.el | 13 ++++++------- site-lisp/db-utils.el | 10 +++++----- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/site-lisp/db-eshell.el b/site-lisp/db-eshell.el index 58eeba5..e068598 100644 --- a/site-lisp/db-eshell.el +++ b/site-lisp/db-eshell.el @@ -28,25 +28,24 @@ ;; idea to split the current window is from ;; http://howardism.org/Technical/Emacs/eshell-fun.html (interactive "P") - (if (string= "eshell-mode" major-mode) + (if (derived-mode-p 'eshell-mode) ;; bury buffer; reopen with current working directory if arg is given (progn (bury-buffer) - (delete-window) (and arg (db/run-or-hide-eshell arg))) (if-let ((eshell-window (db/find-window-by-buffer-mode 'eshell-mode))) (select-window eshell-window) ;; open eshell - (let ((current-dir (expand-file-name default-directory)) - (height (/ (window-total-height) 3))) - (split-window-vertically (- height)) - (other-window 1) + (let* ((current-dir (expand-file-name default-directory)) + (height (/ (frame-text-lines) 3))) + (select-window (split-window (frame-root-window) (- height) 'below)) (eshell 1) (when arg (end-of-line) (eshell-kill-input) (insert (format "cd '%s'" current-dir)) - (eshell-send-input)))))) + (eshell-send-input)))) + (set-window-dedicated-p (selected-window) t))) (defun eshell-clear-buffer () "Clear terminal." diff --git a/site-lisp/db-utils.el b/site-lisp/db-utils.el index d383f08..4b0cc86 100644 --- a/site-lisp/db-utils.el +++ b/site-lisp/db-utils.el @@ -75,15 +75,15 @@ If already in `*ansi-term*' buffer, bury it." (if-let ((shell-window (db/find-window-by-buffer-mode 'shell-mode))) (select-window shell-window) ;; open shell in buffer with height of ⅓ of current window - (let ((height (/ (window-total-height) 3))) - (shell) - (enlarge-window (- height (window-total-height))))))) + (let ((height (/ (frame-text-lines) 3))) + (select-window (split-window (frame-root-window) (- height) 'below)) + (shell))) + (set-window-dedicated-p (selected-window) t))) (if (not arg) ;; toggle shell window (if (not (derived-mode-p 'shell-mode)) (change-to-shell) - (bury-buffer) - (delete-window)) + (bury-buffer)) ;; unconditionally go to shell, and also change to cwd (let ((current-dir (expand-file-name default-directory)))