Enable run-or-hide semantics for project-eshell buffers
This commit is contained in:
parent
10273424b1
commit
35532188f0
4
init.el
4
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)))
|
(add-hook 'shell-mode-hook 'with-editor-export-editor)))
|
||||||
|
|
||||||
(use-package db-eshell
|
(use-package db-eshell
|
||||||
:commands (db/run-or-hide-eshell
|
:commands (db/run-or-hide-project-eshell
|
||||||
eshell-clear-buffer
|
eshell-clear-buffer
|
||||||
eshell/default-prompt-function
|
eshell/default-prompt-function
|
||||||
pcomplete/git))
|
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 "<Scroll_Lock>" 'scroll-lock-mode)
|
||||||
(bind-key "<XF86Back>" #'winner-undo)
|
(bind-key "<XF86Back>" #'winner-undo)
|
||||||
(bind-key "<XF86Forward>" #'winner-redo)
|
(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 "<f2>" #'db/frequently-used-features-prefix)
|
||||||
(bind-key "<f5>" #'project-find-regexp)
|
(bind-key "<f5>" #'project-find-regexp)
|
||||||
(bind-key "<f6>" #'text-scale-adjust)
|
(bind-key "<f6>" #'text-scale-adjust)
|
||||||
|
|||||||
@ -155,7 +155,7 @@ in the main agenda view."
|
|||||||
("Main Org File" ?o db/find-default-org-file)
|
("Main Org File" ?o db/find-default-org-file)
|
||||||
("EMMS" ?M emms)
|
("EMMS" ?M emms)
|
||||||
("Shell" ?s project-shell)
|
("Shell" ?s project-shell)
|
||||||
("EShell" ?e project-eshell)
|
("EShell" ?e db/run-or-hide-project-eshell)
|
||||||
("Project" ?p project-switch-project)
|
("Project" ?p project-switch-project)
|
||||||
("Refile File" ?r db/find-default-refile-file)
|
("Refile File" ?r db/find-default-refile-file)
|
||||||
("Goto Currnet Clock" ?c db/org-clock-goto-first-open-checkbox)
|
("Goto Currnet Clock" ?c db/org-clock-goto-first-open-checkbox)
|
||||||
|
|||||||
@ -16,50 +16,23 @@
|
|||||||
(require 'em-basic)
|
(require 'em-basic)
|
||||||
(require 'em-dirs)
|
(require 'em-dirs)
|
||||||
(require 'em-hist)
|
(require 'em-hist)
|
||||||
|
(require 'project)
|
||||||
(autoload 'magit-status "magit")
|
(autoload 'magit-status "magit")
|
||||||
|
|
||||||
|
|
||||||
;; Various
|
;; Various
|
||||||
|
|
||||||
(defun db/run-or-hide-eshell (arg)
|
(defun db/run-or-hide-project-eshell ()
|
||||||
"Opens an eshell buffer if not already in one.
|
"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.
|
Otherwise moves the cursor to the window where we have been before. The
|
||||||
|
eshell instance is started via `project-eshell'."
|
||||||
The buffer's name has to start with “*eshell-side*” to be recognized by
|
(interactive)
|
||||||
this function. Otherwise the current buffer is not treated as an eshell
|
(if (not (derived-mode-p 'eshell-mode))
|
||||||
buffer.
|
(project-eshell)
|
||||||
|
(progn
|
||||||
When ARG is given, change to `default-directory' after switching to the
|
(bury-buffer)
|
||||||
eshell buffer."
|
(delete-window))))
|
||||||
(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))))))
|
|
||||||
|
|
||||||
(defun eshell-clear-buffer ()
|
(defun eshell-clear-buffer ()
|
||||||
"Clear terminal."
|
"Clear terminal."
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user