Open term popups in current dir, instead of project-root
CDing into the project root can be accomplished with external tools, e.g. cd $(git rev-parse --show-toplevel) cd $(hg root) cd $(npm root) Any of which could be aliased. Also, +vterm/toggle and term/toggle define the PROOT environment variable, so `cd $PROOT` will work too. On the other hand, CDing to the current file/folder requires that the shell be made aware of the file/directory of some Emacs state, which is a little trickier to deal with, so I made that the default behavior for +term/toggle, +vterm/toggle and +eshell/toggle.
This commit is contained in:
parent
2835314022
commit
9c842bfad8
3 changed files with 24 additions and 51 deletions
|
@ -79,10 +79,7 @@
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +eshell/toggle (arg &optional command)
|
(defun +eshell/toggle (arg &optional command)
|
||||||
"Toggle eshell popup window at project's root.
|
"Toggle eshell popup window."
|
||||||
|
|
||||||
Changes the PWD to the PWD of the buffer this command is executed from a new
|
|
||||||
project (or if prefix ARG was present)."
|
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
(let ((eshell-buffer
|
(let ((eshell-buffer
|
||||||
(get-buffer-create
|
(get-buffer-create
|
||||||
|
@ -90,7 +87,6 @@ project (or if prefix ARG was present)."
|
||||||
(if (bound-and-true-p persp-mode)
|
(if (bound-and-true-p persp-mode)
|
||||||
(safe-persp-name (get-current-persp))
|
(safe-persp-name (get-current-persp))
|
||||||
"main"))))
|
"main"))))
|
||||||
(target-project (or (doom-project-root) default-directory))
|
|
||||||
confirm-kill-processes
|
confirm-kill-processes
|
||||||
current-prefix-arg)
|
current-prefix-arg)
|
||||||
(when arg
|
(when arg
|
||||||
|
@ -114,30 +110,16 @@ project (or if prefix ARG was present)."
|
||||||
(if (eq major-mode 'eshell-mode)
|
(if (eq major-mode 'eshell-mode)
|
||||||
(run-hooks 'eshell-mode-hook)
|
(run-hooks 'eshell-mode-hook)
|
||||||
(eshell-mode))
|
(eshell-mode))
|
||||||
(let ((old-project (doom-project-root)))
|
|
||||||
(when (and old-project
|
|
||||||
target-project
|
|
||||||
(not (file-equal-p old-project target-project)))
|
|
||||||
(setq default-directory target-project)
|
|
||||||
(with-silent-modifications
|
|
||||||
(goto-char (point-max))
|
|
||||||
(when (re-search-backward eshell-prompt-regexp nil t)
|
|
||||||
(delete-region (match-end 0) (point-max)))
|
|
||||||
(eshell-send-input))))
|
|
||||||
(when command
|
(when command
|
||||||
(+eshell-run-command command eshell-buffer))))))
|
(+eshell-run-command command eshell-buffer))))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +eshell/here (arg &optional command)
|
(defun +eshell/here (&optional command)
|
||||||
"Open eshell in the current buffer."
|
"Open eshell in the current buffer."
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
(when (eq major-mode 'eshell-mode)
|
(when (eq major-mode 'eshell-mode)
|
||||||
(user-error "Already in an eshell buffer"))
|
(user-error "Already in an eshell buffer"))
|
||||||
(let* ((default-directory
|
(let ((buf (+eshell--unused-buffer)))
|
||||||
(if arg
|
|
||||||
default-directory
|
|
||||||
(or (doom-project-root) default-directory)))
|
|
||||||
(buf (+eshell--unused-buffer)))
|
|
||||||
(with-current-buffer (switch-to-buffer buf)
|
(with-current-buffer (switch-to-buffer buf)
|
||||||
(if (eq major-mode 'eshell-mode)
|
(if (eq major-mode 'eshell-mode)
|
||||||
(run-hooks 'eshell-mode-hook)
|
(run-hooks 'eshell-mode-hook)
|
||||||
|
@ -147,14 +129,12 @@ project (or if prefix ARG was present)."
|
||||||
buf))
|
buf))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +eshell/frame (arg &optional command)
|
(defun +eshell/frame (&optional command)
|
||||||
"Open a frame dedicated to eshell.
|
"Open a frame dedicated to eshell.
|
||||||
|
|
||||||
Once the eshell process is killed, the previous frame layout is restored."
|
Once the eshell process is killed, the previous frame layout is restored."
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
(let ((default-directory (or (if arg default-directory (doom-project-root))
|
(let ((buf (+eshell--unused-buffer 'new)))
|
||||||
default-directory))
|
|
||||||
(buf (+eshell--unused-buffer 'new)))
|
|
||||||
(unless (frame-parameter nil 'saved-wconf)
|
(unless (frame-parameter nil 'saved-wconf)
|
||||||
(set-frame-parameter nil 'saved-wconf (current-window-configuration)))
|
(set-frame-parameter nil 'saved-wconf (current-window-configuration)))
|
||||||
(delete-other-windows)
|
(delete-other-windows)
|
||||||
|
|
|
@ -9,15 +9,13 @@
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +term/toggle (arg)
|
(defun +term/toggle (arg)
|
||||||
"Toggle a persistent terminal popup window at project's root.
|
"Toggle a persistent terminal popup window.
|
||||||
|
|
||||||
If popup is visible but unselected, select it.
|
If popup is visible but unselected, select it.
|
||||||
|
If prefix ARG, recreate the term buffer."
|
||||||
If prefix ARG, recreate term buffer in the current project's root."
|
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
(require 'multi-term)
|
(require 'multi-term)
|
||||||
(let ((default-directory (or (doom-project-root) default-directory))
|
(let ((multi-term-dedicated-select-after-open-p t)
|
||||||
(multi-term-dedicated-select-after-open-p t)
|
|
||||||
(multi-term-dedicated-buffer-name
|
(multi-term-dedicated-buffer-name
|
||||||
(format "doom:term-popup:%s"
|
(format "doom:term-popup:%s"
|
||||||
(if (bound-and-true-p persp-mode)
|
(if (bound-and-true-p persp-mode)
|
||||||
|
@ -36,6 +34,7 @@ If prefix ARG, recreate term buffer in the current project's root."
|
||||||
(when (bound-and-true-p evil-local-mode)
|
(when (bound-and-true-p evil-local-mode)
|
||||||
(evil-change-to-initial-state))
|
(evil-change-to-initial-state))
|
||||||
(goto-char (point-max)))
|
(goto-char (point-max)))
|
||||||
|
(setenv "PROOT" (or (doom-project-root) default-directory))
|
||||||
(with-current-buffer buffer
|
(with-current-buffer buffer
|
||||||
(doom|mark-buffer-as-real)
|
(doom|mark-buffer-as-real)
|
||||||
(multi-term-internal))
|
(multi-term-internal))
|
||||||
|
@ -46,18 +45,11 @@ If prefix ARG, recreate term buffer in the current project's root."
|
||||||
(select-window window)))))))
|
(select-window window)))))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +term/here (arg)
|
(defun +term/here ()
|
||||||
"Open a terminal buffer in the current window at project's root.
|
"Open a terminal buffer in the current window."
|
||||||
|
(interactive)
|
||||||
If prefix ARG is non-nil, cd into `default-directory' instead of the project
|
;; Doom's switch-buffer hooks prevent themselves from triggering when
|
||||||
root."
|
;; switching from buffer A back to A. Because `multi-term' uses `set-buffer'
|
||||||
(interactive "P")
|
;; before `switch-to-buffer', the hooks don't trigger, so we use this
|
||||||
(let ((default-directory
|
;; roundabout way to trigger them properly.
|
||||||
(if arg
|
(switch-to-buffer (save-window-excursion (multi-term))))
|
||||||
default-directory
|
|
||||||
(or (doom-project-root) default-directory))))
|
|
||||||
;; Doom's switch-buffer hooks prevent themselves from triggering when
|
|
||||||
;; switching from buffer A back to A. Because `multi-term' uses `set-buffer'
|
|
||||||
;; before `switch-to-buffer', the hooks don't trigger, so we use this
|
|
||||||
;; roundabout way to trigger them properly.
|
|
||||||
(switch-to-buffer (save-window-excursion (multi-term)))))
|
|
||||||
|
|
|
@ -8,10 +8,11 @@ If prefix ARG is non-nil, recreate vterm buffer in the current project's root."
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
(unless (fboundp 'module-load)
|
(unless (fboundp 'module-load)
|
||||||
(user-error "Your build of Emacs lacks dynamic modules support and cannot load vterm"))
|
(user-error "Your build of Emacs lacks dynamic modules support and cannot load vterm"))
|
||||||
(let ((buffer-name (format "*doom:vterm-popup:%s*"
|
(let ((buffer-name
|
||||||
(if (bound-and-true-p persp-mode)
|
(format "*doom:vterm-popup:%s*"
|
||||||
(safe-persp-name (get-current-persp))
|
(if (bound-and-true-p persp-mode)
|
||||||
"main")))
|
(safe-persp-name (get-current-persp))
|
||||||
|
"main")))
|
||||||
confirm-kill-processes
|
confirm-kill-processes
|
||||||
current-prefix-arg)
|
current-prefix-arg)
|
||||||
(when arg
|
(when arg
|
||||||
|
@ -29,8 +30,8 @@ If prefix ARG is non-nil, recreate vterm buffer in the current project's root."
|
||||||
(evil-change-to-initial-state))
|
(evil-change-to-initial-state))
|
||||||
(goto-char (point-max)))
|
(goto-char (point-max)))
|
||||||
(require 'vterm)
|
(require 'vterm)
|
||||||
(let* ((default-directory (or (doom-project-root) default-directory))
|
(setenv "PROOT" (or (doom-project-root) default-directory))
|
||||||
(buffer (get-buffer-create buffer-name)))
|
(let ((buffer (get-buffer-create buffer-name)))
|
||||||
(with-current-buffer buffer
|
(with-current-buffer buffer
|
||||||
(doom|mark-buffer-as-real)
|
(doom|mark-buffer-as-real)
|
||||||
(vterm-mode))
|
(vterm-mode))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue