Enable run-or-hide semantics for project-eshell buffers

This commit is contained in:
Daniel Borchmann 2025-09-19 19:24:22 +02:00
parent 10273424b1
commit 35532188f0
No known key found for this signature in database
GPG Key ID: 50EA937BF472ADD1
3 changed files with 14 additions and 41 deletions

View File

@ -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>" 'scroll-lock-mode)
(bind-key "<XF86Back>" #'winner-undo)
(bind-key "<XF86Forward>" #'winner-redo)
(bind-key "<f1>" #'project-eshell)
(bind-key "<f1>" #'db/run-or-hide-project-eshell)
(bind-key "<f2>" #'db/frequently-used-features-prefix)
(bind-key "<f5>" #'project-find-regexp)
(bind-key "<f6>" #'text-scale-adjust)

View File

@ -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)

View File

@ -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))
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))
(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))))))
(delete-window))))
(defun eshell-clear-buffer ()
"Clear terminal."