Move eshell popup function to `db-eshell'

That's where it belongs.
This commit is contained in:
Daniel - 2020-06-26 23:08:00 +02:00
parent 32b424de24
commit 5009eb39f9
No known key found for this signature in database
GPG Key ID: 1C7071A75BB72D64
3 changed files with 30 additions and 28 deletions

View File

@ -556,7 +556,6 @@
db/delete-trailing-whitespace-maybe db/delete-trailing-whitespace-maybe
db/show-current-org-task db/show-current-org-task
db/run-or-hide-shell db/run-or-hide-shell
db/run-or-hide-eshell
db/run-or-hide-ansi-term db/run-or-hide-ansi-term
db/hex-to-ascii db/hex-to-ascii
db/text-to-hex db/text-to-hex
@ -2201,7 +2200,8 @@ With given ARG, display files in `db/important-document-path."
(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 (eshell-clear-buffer :commands (db/run-or-hide-eshell
eshell-clear-buffer
eshell/default-prompt-function eshell/default-prompt-function
eshell/gst eshell/gst
eshell-insert-history eshell-insert-history

View File

@ -8,16 +8,44 @@
;;; Code: ;;; Code:
(require 'subr-x)
(require 'seq) (require 'seq)
(require 'eshell) (require 'eshell)
(require 'em-basic) (require 'em-basic)
(require 'em-dirs) (require 'em-dirs)
(require 'em-hist) (require 'em-hist)
(autoload 'magit-status "magit") (autoload 'magit-status "magit")
(autoload 'db/find-window-by-buffer-mode "db-utils")
;; Various ;; Various
(defun db/run-or-hide-eshell (arg)
"Opens an eshell buffer if not already in one, and otherwise
returns to where we have been before."
;; idea to split the current window is from
;; http://howardism.org/Technical/Emacs/eshell-fun.html
(interactive "P")
(if (string= "eshell-mode" major-mode)
;; bury buffer; reopen with current working directory if arg is given
(progn
(bury-buffer)
(delete-window)
(and arg (db/run-or-hide-eshell arg)))
(if-let ((eshell-window (db/find-window-by-buffer-mode 'eshell-mode)))
(select-window eshell-window)
;; open eshell
(let ((current-dir (expand-file-name default-directory))
(height (/ (window-total-height) 3)))
(split-window-vertically (- height))
(other-window 1)
(eshell 1)
(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."
(interactive) (interactive)

View File

@ -50,32 +50,6 @@ If already in `*ansi-term*' buffer, bury it."
(interactive) (interactive)
(find-file user-init-file)) (find-file user-init-file))
(defun db/run-or-hide-eshell (arg)
"Opens an eshell buffer if not already in one, and otherwise
returns to where we have been before."
;; idea to split the current window is from
;; http://howardism.org/Technical/Emacs/eshell-fun.html
(interactive "P")
(if (string= "eshell-mode" major-mode)
;; bury buffer; reopen with current working directory if arg is given
(progn
(bury-buffer)
(delete-window)
(and arg (db/run-or-hide-eshell arg)))
(if-let ((eshell-window (db/find-window-by-buffer-mode 'eshell-mode)))
(select-window eshell-window)
;; open eshell
(let ((current-dir (expand-file-name default-directory))
(height (/ (window-total-height) 3)))
(split-window-vertically (- height))
(other-window 1)
(eshell 1)
(when arg
(end-of-line)
(eshell-kill-input)
(insert (format "cd '%s'" current-dir))
(eshell-send-input))))))
(defun db/run-or-hide-shell () (defun db/run-or-hide-shell ()
"Opens an shell buffer if not already in one, and otherwise "Opens an shell buffer if not already in one, and otherwise
returns to where we have been before." returns to where we have been before."