2019-05-18 23:41:18 -04:00
|
|
|
;;; term/vterm/autoload.el -*- lexical-binding: t; -*-
|
2019-01-27 03:45:29 +08:00
|
|
|
|
|
|
|
;;;###autoload
|
2019-06-11 07:51:16 +02:00
|
|
|
(defun +vterm/toggle (arg)
|
|
|
|
"Toggles a terminal popup window at project root.
|
|
|
|
|
2021-05-24 13:53:51 -04:00
|
|
|
If prefix ARG is non-nil, recreate vterm buffer in the current project's root.
|
|
|
|
|
|
|
|
Returns the vterm buffer."
|
2019-01-27 03:45:29 +08:00
|
|
|
(interactive "P")
|
2021-05-11 17:05:23 -05:00
|
|
|
(+vterm--configure-project-root-and-display
|
|
|
|
arg
|
|
|
|
(lambda()
|
|
|
|
(let ((buffer-name
|
|
|
|
(format "*doom:vterm-popup:%s*"
|
|
|
|
(if (bound-and-true-p persp-mode)
|
|
|
|
(safe-persp-name (get-current-persp))
|
|
|
|
"main")))
|
|
|
|
confirm-kill-processes
|
|
|
|
current-prefix-arg)
|
|
|
|
(when arg
|
|
|
|
(let ((buffer (get-buffer buffer-name))
|
|
|
|
(window (get-buffer-window buffer-name)))
|
|
|
|
(when (buffer-live-p buffer)
|
|
|
|
(kill-buffer buffer))
|
|
|
|
(when (window-live-p window)
|
|
|
|
(delete-window window))))
|
|
|
|
(if-let (win (get-buffer-window buffer-name))
|
2021-09-21 14:57:00 +03:00
|
|
|
(delete-window win)
|
2021-05-11 17:05:23 -05:00
|
|
|
(let ((buffer (get-buffer-create buffer-name)))
|
|
|
|
(with-current-buffer buffer
|
|
|
|
(unless (eq major-mode 'vterm-mode)
|
2022-01-29 20:41:02 -05:00
|
|
|
(vterm-mode)))
|
2021-05-24 13:53:51 -04:00
|
|
|
(pop-to-buffer buffer)))
|
|
|
|
(get-buffer buffer-name)))))
|
2019-01-27 03:45:29 +08:00
|
|
|
|
|
|
|
;;;###autoload
|
2019-06-11 07:51:16 +02:00
|
|
|
(defun +vterm/here (arg)
|
|
|
|
"Open a terminal buffer in the current window at project root.
|
|
|
|
|
2021-05-24 13:53:51 -04:00
|
|
|
If prefix ARG is non-nil, cd into `default-directory' instead of project root.
|
|
|
|
|
|
|
|
Returns the vterm buffer."
|
2019-01-27 03:45:29 +08:00
|
|
|
(interactive "P")
|
2021-05-11 17:05:23 -05:00
|
|
|
(+vterm--configure-project-root-and-display
|
|
|
|
arg
|
|
|
|
(lambda()
|
|
|
|
(require 'vterm)
|
2021-05-24 13:53:51 -04:00
|
|
|
;; HACK forces vterm to redraw, fixing strange artefacting in the tty.
|
2021-05-11 17:05:23 -05:00
|
|
|
(save-window-excursion
|
|
|
|
(pop-to-buffer "*scratch*"))
|
|
|
|
(let (display-buffer-alist)
|
|
|
|
(vterm vterm-buffer-name)))))
|
|
|
|
|
|
|
|
(defun +vterm--configure-project-root-and-display (arg display-fn)
|
|
|
|
"Sets the environment variable PROOT and displays a terminal using `display-fn`.
|
|
|
|
|
2021-05-24 13:53:51 -04:00
|
|
|
If prefix ARG is non-nil, cd into `default-directory' instead of project root.
|
|
|
|
|
|
|
|
Returns the vterm buffer."
|
2019-03-13 20:20:19 -04:00
|
|
|
(unless (fboundp 'module-load)
|
|
|
|
(user-error "Your build of Emacs lacks dynamic modules support and cannot load vterm"))
|
2020-03-04 17:10:07 -05:00
|
|
|
(let* ((project-root (or (doom-project-root) default-directory))
|
|
|
|
(default-directory
|
|
|
|
(if arg
|
|
|
|
default-directory
|
2021-05-11 17:05:23 -05:00
|
|
|
project-root)))
|
2020-03-04 17:10:07 -05:00
|
|
|
(setenv "PROOT" project-root)
|
2022-01-29 20:41:02 -05:00
|
|
|
(funcall display-fn)))
|