From 35532188f09c28d5247c573efc31181baea05651 Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Fri, 19 Sep 2025 19:24:22 +0200 Subject: [PATCH] Enable run-or-hide semantics for project-eshell buffers --- init.el | 4 ++-- site-lisp/db-customize.el | 2 +- site-lisp/db-eshell.el | 49 +++++++++------------------------------ 3 files changed, 14 insertions(+), 41 deletions(-) diff --git a/init.el b/init.el index cdfa60f..b832ee8 100644 --- a/init.el +++ b/init.el @@ -2756,7 +2756,7 @@ Note that this workaround is incomplete, as explained in this comment." (add-hook 'shell-mode-hook 'with-editor-export-editor))) (use-package db-eshell - :commands (db/run-or-hide-eshell + :commands (db/run-or-hide-project-eshell eshell-clear-buffer eshell/default-prompt-function pcomplete/git)) @@ -3091,7 +3091,7 @@ Note that this workaround is incomplete, as explained in this comment." (bind-key "" 'scroll-lock-mode) (bind-key "" #'winner-undo) (bind-key "" #'winner-redo) - (bind-key "" #'project-eshell) + (bind-key "" #'db/run-or-hide-project-eshell) (bind-key "" #'db/frequently-used-features-prefix) (bind-key "" #'project-find-regexp) (bind-key "" #'text-scale-adjust) diff --git a/site-lisp/db-customize.el b/site-lisp/db-customize.el index 7512e52..f96355d 100644 --- a/site-lisp/db-customize.el +++ b/site-lisp/db-customize.el @@ -155,7 +155,7 @@ in the main agenda view." ("Main Org File" ?o db/find-default-org-file) ("EMMS" ?M emms) ("Shell" ?s project-shell) - ("EShell" ?e project-eshell) + ("EShell" ?e db/run-or-hide-project-eshell) ("Project" ?p project-switch-project) ("Refile File" ?r db/find-default-refile-file) ("Goto Currnet Clock" ?c db/org-clock-goto-first-open-checkbox) diff --git a/site-lisp/db-eshell.el b/site-lisp/db-eshell.el index 76c4eed..57826f0 100644 --- a/site-lisp/db-eshell.el +++ b/site-lisp/db-eshell.el @@ -16,50 +16,23 @@ (require 'em-basic) (require 'em-dirs) (require 'em-hist) +(require 'project) (autoload 'magit-status "magit") ;; Various -(defun db/run-or-hide-eshell (arg) - "Opens an eshell buffer if not already in one. +(defun db/run-or-hide-project-eshell () + "Opens an eshell buffer in the current project if not already in one. -Otherwise moves the cursor to the window where we have been before. - -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." - (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))))) - - (if (and (not arg) - (in-eshell-buffer-p)) - (progn - (bury-buffer) - (delete-window)) - - (unless (in-eshell-buffer-p) - (if-let ((eshell-window (cl-find-if (lambda (window) - (with-current-buffer (window-buffer window) - (in-eshell-buffer-p))) - (window-list-1)))) - (select-window eshell-window) - ;; No running eshell found, open new one. - (--if-let (display-buffer (let ((eshell-buffer-name "*eshell*")) (eshell))) - (select-window it) - (error "Could not start eshell (`display-buffer' returned nil)")))) - - (when arg - (end-of-line) - (eshell-kill-input) - (insert (format "cd '%s'" current-dir)) - (eshell-send-input)))))) +Otherwise moves the cursor to the window where we have been before. The +eshell instance is started via `project-eshell'." + (interactive) + (if (not (derived-mode-p 'eshell-mode)) + (project-eshell) + (progn + (bury-buffer) + (delete-window)))) (defun eshell-clear-buffer () "Clear terminal."