doomemacs/modules/term/vterm/autoload.el
Henrik Lissner 4fec3eb698
Revise term/vterm/eshell commands & keybinds
The semantics of SPC o t and SPC o T (or SPC o e and SPC o E in eshell's
case) have been reversed.

The lowercase keybind toggles the popup (and the prefix arg forciby
recreates the popup), and the uppercase keybind switches to that
terminal in the current buffer (whose prefix arg will open the terminal
in default-directory, rather than the project root).

- +{term,vterm,eshell}/open have been replaced with +X/here commands and
  are bound to SPC o T (and SPC o E in eshell's case).
- +{term,vterm,eshell}/popup* have been replaced with +x/toggle commands
  and are bound to SPC o t (and SPC o e in eshell's case).

The "toggle" behavior will do as the name implies, except will select
the popup if it is visible but unfocused.
2019-06-11 07:53:50 +02:00

48 lines
1.8 KiB
EmacsLisp

;;; term/vterm/autoload.el -*- lexical-binding: t; -*-
;;;###autoload
(defun +vterm/toggle (arg)
"Toggles a terminal popup window at project root.
If prefix ARG is non-nil, recreate vterm buffer in the current project's root."
(interactive "P")
(unless (fboundp 'module-load)
(user-error "Your build of Emacs lacks dynamic modules support and cannot load vterm"))
(let ((buffer-name "*doom:vterm-popup*")
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))
(if (eq (selected-window) win)
(delete-window win)
(select-window win))
(let* ((default-directory (or (doom-project-root) default-directory))
(buffer (get-buffer-create buffer-name)))
(with-current-buffer buffer
(vterm-mode))
(pop-to-buffer buffer)))))
;;;###autoload
(defun +vterm/here (arg)
"Open a terminal buffer in the current window at project root.
If prefix ARG is non-nil, cd into `default-directory' instead of project root."
(interactive "P")
(unless (fboundp 'module-load)
(user-error "Your build of Emacs lacks dynamic modules support and cannot load vterm"))
(when (eq major-mode 'vterm-mode)
(user-error "Already in a vterm buffer"))
;; This hack forces vterm to redraw, fixing strange artefacting in the tty.
(save-window-excursion
(pop-to-buffer "*scratch*"))
(let ((default-directory
(if arg
default-directory
(or (doom-project-root) default-directory))))
(vterm)))