Always display shell buffers at bottom of frame in dedicated window

Inspired by https://www.masteringemacs.org/article/demystifying-emacs-window-manager.
This commit is contained in:
Daniel Borchmann 2023-02-11 19:33:19 +01:00
parent daa7882732
commit aec896c939
No known key found for this signature in database
GPG Key ID: 784AA8DF0CCDF625
2 changed files with 11 additions and 12 deletions

View File

@ -28,25 +28,24 @@
;; idea to split the current window is from ;; idea to split the current window is from
;; http://howardism.org/Technical/Emacs/eshell-fun.html ;; http://howardism.org/Technical/Emacs/eshell-fun.html
(interactive "P") (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 ;; bury buffer; reopen with current working directory if arg is given
(progn (progn
(bury-buffer) (bury-buffer)
(delete-window)
(and arg (db/run-or-hide-eshell arg))) (and arg (db/run-or-hide-eshell arg)))
(if-let ((eshell-window (db/find-window-by-buffer-mode 'eshell-mode))) (if-let ((eshell-window (db/find-window-by-buffer-mode 'eshell-mode)))
(select-window eshell-window) (select-window eshell-window)
;; open eshell ;; open eshell
(let ((current-dir (expand-file-name default-directory)) (let* ((current-dir (expand-file-name default-directory))
(height (/ (window-total-height) 3))) (height (/ (frame-text-lines) 3)))
(split-window-vertically (- height)) (select-window (split-window (frame-root-window) (- height) 'below))
(other-window 1)
(eshell 1) (eshell 1)
(when arg (when arg
(end-of-line) (end-of-line)
(eshell-kill-input) (eshell-kill-input)
(insert (format "cd '%s'" current-dir)) (insert (format "cd '%s'" current-dir))
(eshell-send-input)))))) (eshell-send-input))))
(set-window-dedicated-p (selected-window) t)))
(defun eshell-clear-buffer () (defun eshell-clear-buffer ()
"Clear terminal." "Clear terminal."

View File

@ -75,15 +75,15 @@ If already in `*ansi-term*' buffer, bury it."
(if-let ((shell-window (db/find-window-by-buffer-mode 'shell-mode))) (if-let ((shell-window (db/find-window-by-buffer-mode 'shell-mode)))
(select-window shell-window) (select-window shell-window)
;; open shell in buffer with height of ⅓ of current window ;; open shell in buffer with height of ⅓ of current window
(let ((height (/ (window-total-height) 3))) (let ((height (/ (frame-text-lines) 3)))
(shell) (select-window (split-window (frame-root-window) (- height) 'below))
(enlarge-window (- height (window-total-height))))))) (shell)))
(set-window-dedicated-p (selected-window) t)))
(if (not arg) (if (not arg)
;; toggle shell window ;; toggle shell window
(if (not (derived-mode-p 'shell-mode)) (if (not (derived-mode-p 'shell-mode))
(change-to-shell) (change-to-shell)
(bury-buffer) (bury-buffer))
(delete-window))
;; unconditionally go to shell, and also change to cwd ;; unconditionally go to shell, and also change to cwd
(let ((current-dir (expand-file-name default-directory))) (let ((current-dir (expand-file-name default-directory)))