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:
Henrik Lissner
2019-06-17 19:18:51 +02:00
parent 2835314022
commit 9c842bfad8
3 changed files with 24 additions and 51 deletions

View File

@@ -9,15 +9,13 @@
;;;###autoload
(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 prefix ARG, recreate term buffer in the current project's root."
If prefix ARG, recreate the term buffer."
(interactive "P")
(require 'multi-term)
(let ((default-directory (or (doom-project-root) default-directory))
(multi-term-dedicated-select-after-open-p t)
(let ((multi-term-dedicated-select-after-open-p t)
(multi-term-dedicated-buffer-name
(format "doom:term-popup:%s"
(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)
(evil-change-to-initial-state))
(goto-char (point-max)))
(setenv "PROOT" (or (doom-project-root) default-directory))
(with-current-buffer buffer
(doom|mark-buffer-as-real)
(multi-term-internal))
@@ -46,18 +45,11 @@ If prefix ARG, recreate term buffer in the current project's root."
(select-window window)))))))
;;;###autoload
(defun +term/here (arg)
"Open a terminal buffer in the current window at project's root.
If prefix ARG is non-nil, cd into `default-directory' instead of the project
root."
(interactive "P")
(let ((default-directory
(if arg
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)))))
(defun +term/here ()
"Open a terminal buffer in the current window."
(interactive)
;; 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))))