diff --git a/modules/tools/eshell/autoload/eshell.el b/modules/tools/eshell/autoload/eshell.el index 15b5b4494..c37316df7 100644 --- a/modules/tools/eshell/autoload/eshell.el +++ b/modules/tools/eshell/autoload/eshell.el @@ -25,6 +25,13 @@ ;; Library ;; +(defun +eshell--add-buffer (buf) + (ring-remove+insert+extend +eshell-buffers buf)) + +(defun +eshell--remove-buffer (buf) + (when-let* ((idx (ring-member +eshell-buffers buf))) + (ring-remove +eshell-buffers idx))) + (defun +eshell--current-git-branch () (let ((branch (car (cl-loop for match in (split-string (shell-command-to-string "git branch") "\n") if (string-match-p "^\*" match) @@ -33,12 +40,11 @@ (format " [%s]" (substring branch 2)) ""))) -;;;###autoload -(defun +eshell-prompt () - "Generate the prompt string for eshell. Use for `eshell-prompt-function'." - (concat (propertize (abbreviate-file-name (eshell/pwd)) 'face '+eshell-prompt-pwd) - (propertize (+eshell--current-git-branch) 'face '+eshell-prompt-git-branch) - (propertize " λ " 'face '+eshell-prompt-char))) +(defun +eshell-delete-window () + (if (one-window-p) + (unless (doom-real-buffer-p (progn (previous-buffer) (current-buffer))) + (switch-to-buffer (doom-fallback-buffer))) + (delete-window))) (defun +eshell-get-or-create-buffer () (or (cl-loop for buf in (ring-elements +eshell-buffers) @@ -47,6 +53,13 @@ return buf) (generate-new-buffer +eshell-buffer-name))) +;;;###autoload +(defun +eshell-prompt () + "Generate the prompt string for eshell. Use for `eshell-prompt-function'." + (concat (propertize (abbreviate-file-name (eshell/pwd)) 'face '+eshell-prompt-pwd) + (propertize (+eshell--current-git-branch) 'face '+eshell-prompt-git-branch) + (propertize " λ " 'face '+eshell-prompt-char))) + ;; ;; Commands @@ -59,9 +72,7 @@ (let ((buf (+eshell-get-or-create-buffer))) (with-current-buffer buf (unless (eq major-mode 'eshell-mode) (eshell-mode))) - (if (eq major-mode 'eshell-mode) - (pop-to-buffer buf) - (switch-to-buffer buf)) + (switch-to-buffer buf) (when command (+eshell-run-command command)))) @@ -109,17 +120,12 @@ module to be loaded." ;; Hooks ;; -(defun +eshell--add-buffer (buf) - (ring-remove+insert+extend +eshell-buffers buf)) - -(defun +eshell--remove-buffer (buf) - (when-let* ((idx (ring-member +eshell-buffers buf))) - (ring-remove +eshell-buffers idx))) - ;;;###autoload (defun +eshell|init () "Keep track of eshell buffers." (let ((buf (current-buffer))) + (remove-hook 'kill-buffer-query-functions #'doom|protect-visible-buffers t) + (add-hook 'kill-buffer-hook #'+eshell-delete-window nil t) (dolist (buf (ring-elements +eshell-buffers)) (unless (buffer-live-p buf) (+eshell--remove-buffer buf))) @@ -149,13 +155,15 @@ delete." (delete-char arg))) ;;;###autoload -(defun +eshell/split () +(defun +eshell/split-below () + "Create a new eshell window below the current one." (interactive) (select-window (split-window-vertically)) (+eshell/open)) ;;;###autoload -(defun +eshell/vsplit () +(defun +eshell/split-right () + "Create a new eshell window to the right of the current one." (interactive) (select-window (split-window-horizontally)) (+eshell/open))