From 20a9eb20e612c3afb1e82e00edde861e19f5c971 Mon Sep 17 00:00:00 2001 From: Tim McCarthy Date: Sat, 21 Jun 2025 10:05:12 -0700 Subject: [PATCH] Update eshell popup code --- emacs/init.el | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/emacs/init.el b/emacs/init.el index c124c9c..df04ff5 100644 --- a/emacs/init.el +++ b/emacs/init.el @@ -512,7 +512,7 @@ "\\*Flycheck errors\\*" help-mode compilation-mode - "\\*eshell.*\\*" eshell-mode)) + "\\*eshell-popup\\*" eshell-mode)) (defun my/popper-window-height (window) "Make eshell popups take half the frame height, otherwise defer to popper--fit-window-height" @@ -922,6 +922,13 @@ (global-set-key (kbd "C-c a") 'aider-transient-menu)) ;;; Eshell ;;;; Eshell +(require 'cl-lib) +(defun find-window-matching (regexp) + "Find a visible window displaying a buffer whose name matches REGEXP." + (cl-loop for window in (window-list) + when (string-match regexp (buffer-name (window-buffer window))) + thereis window)) + (use-package eshell :bind (("M-`" . my/eshell-toggle)) :config @@ -938,11 +945,24 @@ If in eshell, call `popper-toggle`. If not in eshell but in a project, call `project-eshell`. Otherwise, call `eshell`." (interactive) - (if (derived-mode-p 'eshell-mode) + (if (find-window-matching "\\*.*eshell-popup\\*$") (popper-toggle) (if (project-current) - (project-eshell) - (eshell)))) + (my/project-eshell-popup) + (my/eshell-popup default-directory "*eshell-popup*")))) + + (defun my/eshell-popup (directory name) + (defvar eshell-buffer-name) + (let* ((default-directory directory) + (eshell-buffer-name name) + (eshell-buffer (get-buffer eshell-buffer-name))) + (if eshell-buffer + (pop-to-buffer eshell-buffer (bound-and-true-p display-comint-buffer-action)) + (eshell t)))) + + (defun my/project-eshell-popup () + (my/eshell-popup (project-root (project-current t)) + (project-prefixed-buffer-name "eshell-popup"))) (defun eshell/ec (&rest args) "Substitute for emacsclient alias from inside eshell"