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.
This commit is contained in:
parent
750d7629e1
commit
4fec3eb698
8 changed files with 150 additions and 91 deletions
|
@ -26,14 +26,14 @@
|
||||||
:desc "Open project scratch buffer" "X" #'doom/switch-to-scratch-buffer
|
:desc "Open project scratch buffer" "X" #'doom/switch-to-scratch-buffer
|
||||||
|
|
||||||
(:when (featurep! :term term)
|
(:when (featurep! :term term)
|
||||||
:desc "Terminal" "`" #'+term/open
|
:desc "Toggle term popup" "`" #'+term/toggle
|
||||||
:desc "Terminal in popup" "~" #'+term/open-popup-in-project)
|
:desc "Open term here" "~" #'+term/here)
|
||||||
(:when (featurep! :term vterm)
|
(:when (featurep! :term vterm)
|
||||||
:desc "Terminal" "`" #'+vterm/open
|
:desc "Toggle vterm popup" "`" #'+vterm/toggle
|
||||||
:desc "Terminal in popup" "~" #'+vterm/open-popup-in-project)
|
:desc "Open vterm here" "~" #'+vterm/here)
|
||||||
(:when (featurep! :term eshell)
|
(:when (featurep! :term eshell)
|
||||||
:desc "Eshell" "`" #'+eshell/open
|
:desc "Toggle eshell popup" "`" #'+eshell/toggle
|
||||||
:desc "Eshell in popup" "~" #'+eshell/open-popup)
|
:desc "Open eshell here" "~" #'+eshell/here)
|
||||||
|
|
||||||
(:prefix ("l" . "<localleader>")) ; bound locally
|
(:prefix ("l" . "<localleader>")) ; bound locally
|
||||||
(:prefix ("!" . "checkers")) ; bound by flycheck
|
(:prefix ("!" . "checkers")) ; bound by flycheck
|
||||||
|
|
|
@ -694,14 +694,14 @@
|
||||||
:desc "Project sidebar" "p" #'+treemacs/toggle
|
:desc "Project sidebar" "p" #'+treemacs/toggle
|
||||||
:desc "Find file in project sidebar" "P" #'+treemacs/find-file)
|
:desc "Find file in project sidebar" "P" #'+treemacs/find-file)
|
||||||
(:when (featurep! :term term)
|
(:when (featurep! :term term)
|
||||||
:desc "Terminal" "t" #'+term/open
|
:desc "Toggle terminal popup" "t" #'+term/toggle
|
||||||
:desc "Terminal in popup" "T" #'+term/open-popup-in-project)
|
:desc "Open terminal here" "T" #'+term/here)
|
||||||
(:when (featurep! :term vterm)
|
(:when (featurep! :term vterm)
|
||||||
:desc "Terminal" "t" #'+vterm/open
|
:desc "Toggle vterm popup" "t" #'+vterm/toggle
|
||||||
:desc "Terminal in popup" "T" #'+vterm/open-popup-in-project)
|
:desc "Open vterm here" "T" #'+vterm/here)
|
||||||
(:when (featurep! :term eshell)
|
(:when (featurep! :term eshell)
|
||||||
:desc "Eshell" "e" #'+eshell/open
|
:desc "Toggle eshell popup" "e" #'+eshell/toggle
|
||||||
:desc "Eshell in popup" "E" #'+eshell/open-popup)
|
:desc "Open eshell here" "E" #'+eshell/here)
|
||||||
(:when (featurep! :collab floobits)
|
(:when (featurep! :collab floobits)
|
||||||
(:prefix ("f" . "floobits")
|
(:prefix ("f" . "floobits")
|
||||||
"c" #'floobits-clear-highlights
|
"c" #'floobits-clear-highlights
|
||||||
|
|
|
@ -78,48 +78,79 @@
|
||||||
;; Commands
|
;; Commands
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +eshell/open (arg &optional command)
|
(defun +eshell/toggle (arg &optional command)
|
||||||
|
"Toggle eshell popup window at project's root.
|
||||||
|
|
||||||
|
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")
|
||||||
|
(let ((eshell-buffer (get-buffer-create "*doom:eshell-popup*"))
|
||||||
|
(target-project (or (doom-project-root) default-directory))
|
||||||
|
confirm-kill-processes
|
||||||
|
current-prefix-arg)
|
||||||
|
(when arg
|
||||||
|
(when-let (win (get-buffer-window eshell-buffer))
|
||||||
|
(delete-window win))
|
||||||
|
(when (buffer-live-p eshell-buffer)
|
||||||
|
(kill-buffer eshell-buffer)))
|
||||||
|
(if-let (win (get-buffer-window eshell-buffer))
|
||||||
|
(if (eq (selected-window) win)
|
||||||
|
(let (confirm-kill-processes)
|
||||||
|
(delete-window win)
|
||||||
|
(ignore-errors (kill-buffer eshell-buffer)))
|
||||||
|
(select-window win))
|
||||||
|
(with-current-buffer (pop-to-buffer eshell-buffer)
|
||||||
|
(if (eq major-mode 'eshell-mode)
|
||||||
|
(run-hooks 'eshell-mode-hook)
|
||||||
|
(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)
|
||||||
|
(delete-region (match-end 0) (point-max)))
|
||||||
|
(eshell-send-input))))
|
||||||
|
(when command
|
||||||
|
(+eshell-run-command command buf))))))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun +eshell/here (arg &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 (or (if arg default-directory (doom-project-root))
|
(let* ((default-directory
|
||||||
default-directory))
|
(if arg
|
||||||
|
default-directory
|
||||||
|
(or (doom-project-root) default-directory)))
|
||||||
(buf (+eshell--unused-buffer)))
|
(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)
|
||||||
(eshell-mode))
|
(eshell-mode))
|
||||||
(if command (+eshell-run-command command buf)))
|
(when command
|
||||||
|
(+eshell-run-command command buf)))
|
||||||
buf))
|
buf))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +eshell/open-popup (arg &optional command)
|
(defun +eshell/frame (arg &optional command)
|
||||||
"Open eshell in a popup window."
|
"Open a frame dedicated to eshell.
|
||||||
(interactive "P")
|
|
||||||
(let* ((default-directory (or (if arg default-directory (doom-project-root))
|
|
||||||
default-directory))
|
|
||||||
(buf (+eshell--unused-buffer)))
|
|
||||||
(with-current-buffer (pop-to-buffer buf)
|
|
||||||
(if (eq major-mode 'eshell-mode)
|
|
||||||
(run-hooks 'eshell-mode-hook)
|
|
||||||
(eshell-mode))
|
|
||||||
(if command (+eshell-run-command command buf)))
|
|
||||||
buf))
|
|
||||||
|
|
||||||
;;;###autoload
|
Once the eshell process is killed, the previous frame layout is restored."
|
||||||
(defun +eshell/open-fullscreen (arg &optional command)
|
|
||||||
"Open eshell in a separate workspace. Requires the (:ui workspaces)
|
|
||||||
module to be loaded."
|
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
(let ((default-directory (or (if arg default-directory (doom-project-root))
|
(let ((default-directory (or (if arg default-directory (doom-project-root))
|
||||||
default-directory))
|
default-directory))
|
||||||
(buf (+eshell--unused-buffer 'new)))
|
(buf (+eshell--unused-buffer 'new)))
|
||||||
(set-frame-parameter nil 'saved-wconf (current-window-configuration))
|
(unless (frame-parameter nil 'saved-wconf)
|
||||||
|
(set-frame-parameter nil 'saved-wconf (current-window-configuration)))
|
||||||
(delete-other-windows)
|
(delete-other-windows)
|
||||||
(with-current-buffer (switch-to-buffer buf)
|
(with-current-buffer (switch-to-buffer buf)
|
||||||
(eshell-mode)
|
(eshell-mode)
|
||||||
(if command (+eshell-run-command command buf)))
|
(when command
|
||||||
|
(+eshell-run-command command buf)))
|
||||||
buf))
|
buf))
|
||||||
|
|
||||||
|
|
||||||
|
@ -267,7 +298,7 @@ delete."
|
||||||
(cond ((and (one-window-p t)
|
(cond ((and (one-window-p t)
|
||||||
(window-configuration-p (frame-parameter nil 'saved-wconf)))
|
(window-configuration-p (frame-parameter nil 'saved-wconf)))
|
||||||
(set-window-configuration (frame-parameter nil 'saved-wconf))
|
(set-window-configuration (frame-parameter nil 'saved-wconf))
|
||||||
(set-frame-parameter win 'saved-wconf nil))
|
(set-frame-parameter nil 'saved-wconf nil))
|
||||||
((one-window-p)
|
((one-window-p)
|
||||||
(let ((prev (save-window-excursion (previous-buffer))))
|
(let ((prev (save-window-excursion (previous-buffer))))
|
||||||
(unless (and prev (doom-real-buffer-p prev))
|
(unless (and prev (doom-real-buffer-p prev))
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
;;; term/eshell/config.el -*- lexical-binding: t; -*-
|
;;; term/eshell/config.el -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
;; see:
|
;; see:
|
||||||
;; + `+eshell/open': open in current buffer
|
;; + `+eshell/here': open eshell in the current window
|
||||||
;; + `+eshell/open-popup': open in a popup
|
;; + `+eshell/toggle': toggles an eshell popup
|
||||||
;; + `+eshell/open-fullscreen': open eshell fullscreen (will restore window
|
;; + `+eshell/frame': converts the current frame into an eshell-dedicated
|
||||||
;; config when quitting the last eshell buffer)
|
;; frame. Once the last eshell process is killed, the old frame configuration
|
||||||
|
;; is restored.
|
||||||
|
|
||||||
(defvar +eshell-config-dir
|
(defvar +eshell-config-dir
|
||||||
(expand-file-name "eshell/" doom-private-dir)
|
(expand-file-name "eshell/" doom-private-dir)
|
||||||
|
@ -32,7 +33,7 @@ like fasd and bd. Note that you may overwrite these in your
|
||||||
`eshell-aliases-file'. This is here to provide an alternative, elisp-centric way
|
`eshell-aliases-file'. This is here to provide an alternative, elisp-centric way
|
||||||
to define your aliases.
|
to define your aliases.
|
||||||
|
|
||||||
You should use `det-eshell-alias!' to change this.")
|
You should use `set-eshell-alias!' to change this.")
|
||||||
|
|
||||||
;;
|
;;
|
||||||
(defvar eshell-directory-name (concat doom-etc-dir "eshell"))
|
(defvar eshell-directory-name (concat doom-etc-dir "eshell"))
|
||||||
|
|
|
@ -1,33 +1,50 @@
|
||||||
;;; term/term/autoload.el -*- lexical-binding: t; -*-
|
;;; term/term/autoload.el -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +term/open (arg)
|
(defun +term/toggle (arg)
|
||||||
"Open a terminal buffer in the current window. If ARG (universal argument) is
|
"Toggle a persistent terminal popup window at project's root.
|
||||||
non-nil, cd into the current project's root."
|
|
||||||
|
If popup is visible but unselected, select it.
|
||||||
|
|
||||||
|
If prefix ARG, recreate term buffer in the current project's root."
|
||||||
|
(interactive "P")
|
||||||
|
(require 'multi-term)
|
||||||
|
(let ((default-directory (or (doom-project-root) default-directory))
|
||||||
|
(multi-term-dedicated-buffer-name "doom:term-popup")
|
||||||
|
(multi-term-dedicated-select-after-open-p t)
|
||||||
|
confirm-kill-processes
|
||||||
|
current-prefix-arg)
|
||||||
|
(cl-letf (((symbol-function #'multi-term-dedicated-get-window)
|
||||||
|
(lambda () (setq multi-term-dedicated-window
|
||||||
|
(display-buffer-in-side-window
|
||||||
|
multi-term-dedicated-buffer
|
||||||
|
`((window-height . ,multi-term-dedicated-window-height)))))))
|
||||||
|
(when arg
|
||||||
|
(when (multi-term-window-exist-p multi-term-dedicated-window)
|
||||||
|
(delete-window multi-term-dedicated-window))
|
||||||
|
(when (multi-term-buffer-exist-p multi-term-dedicated-buffer)
|
||||||
|
(when-let (process (get-buffer-process multi-term-dedicated-buffer))
|
||||||
|
(kill-process process))
|
||||||
|
(kill-buffer multi-term-dedicated-buffer)))
|
||||||
|
(if (multi-term-dedicated-exist-p)
|
||||||
|
(if (eq (selected-window) multi-term-dedicated-window)
|
||||||
|
(multi-term-dedicated-close)
|
||||||
|
(select-window multi-term-dedicated-window))
|
||||||
|
(multi-term-dedicated-open)))))
|
||||||
|
|
||||||
|
;;;###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")
|
(interactive "P")
|
||||||
(let ((default-directory
|
(let ((default-directory
|
||||||
(if arg
|
(if arg
|
||||||
(or (doom-project-root) default-directory)
|
default-directory
|
||||||
default-directory)))
|
(or (doom-project-root) default-directory))))
|
||||||
;; Doom's switch-buffer hooks prevent themselves from triggering when
|
;; Doom's switch-buffer hooks prevent themselves from triggering when
|
||||||
;; switching from buffer A back to A. Because `multi-term' uses `set-buffer'
|
;; 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
|
;; before `switch-to-buffer', the hooks don't trigger, so we use this
|
||||||
;; roundabout way to trigger them properly.
|
;; roundabout way to trigger them properly.
|
||||||
(switch-to-buffer (save-window-excursion (multi-term)))))
|
(switch-to-buffer (save-window-excursion (multi-term)))))
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun +term/open-popup (arg)
|
|
||||||
"Open a terminal popup window. If ARG (universal argument) is
|
|
||||||
non-nil, cd into the current project's root."
|
|
||||||
(interactive "P")
|
|
||||||
(let ((default-directory
|
|
||||||
(if arg
|
|
||||||
(or (doom-project-root) default-directory)
|
|
||||||
default-directory)))
|
|
||||||
(pop-to-buffer (save-window-excursion (multi-term)))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun +term/open-popup-in-project ()
|
|
||||||
"Open a terminal popup window in the root of the current project."
|
|
||||||
(interactive)
|
|
||||||
(+term/open-popup t))
|
|
||||||
|
|
|
@ -6,3 +6,4 @@
|
||||||
|
|
||||||
;;;###package term
|
;;;###package term
|
||||||
(add-hook 'term-mode-hook #'doom|mark-buffer-as-real)
|
(add-hook 'term-mode-hook #'doom|mark-buffer-as-real)
|
||||||
|
(add-hook 'term-mode-hook #'hide-mode-line-mode)
|
||||||
|
|
|
@ -18,10 +18,8 @@ alpha and requires a component be compiled (=vterm-module.sh=).
|
||||||
|
|
||||||
The following commands are available to open it:
|
The following commands are available to open it:
|
||||||
|
|
||||||
+ ~+vterm/open~ (=SPC o t=): Opens vterm in the current window.
|
+ ~+vterm/toggle~ (=SPC o t=): Toggle vterm pop up window in the current project
|
||||||
+ ~+vterm/open-popup~ (no keybind): Opens vterm in a pop up window.
|
+ ~+vterm/here~ (=SPC o T=): Opens vterm in the current window
|
||||||
+ ~+vterm/open-popup-in-project~ (=SPC o T=): Opens vterm from the project root
|
|
||||||
in a pop up window.
|
|
||||||
|
|
||||||
** Module Flags
|
** Module Flags
|
||||||
This module provides no flags.
|
This module provides no flags.
|
||||||
|
|
|
@ -1,37 +1,48 @@
|
||||||
;;; term/vterm/autoload.el -*- lexical-binding: t; -*-
|
;;; term/vterm/autoload.el -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +vterm/open (arg)
|
(defun +vterm/toggle (arg)
|
||||||
"Open a terminal buffer in the current window. If ARG (universal argument) is
|
"Toggles a terminal popup window at project root.
|
||||||
non-nil, cd into the current project's root."
|
|
||||||
|
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 "*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.
|
;; This hack forces vterm to redraw, fixing strange artefacting in the tty.
|
||||||
;; Don't ask me why it works.
|
|
||||||
(save-window-excursion
|
(save-window-excursion
|
||||||
(pop-to-buffer "*scratch*"))
|
(pop-to-buffer "*scratch*"))
|
||||||
(let ((default-directory
|
(let ((default-directory
|
||||||
(if arg
|
(if arg
|
||||||
(or (doom-project-root) default-directory)
|
default-directory
|
||||||
default-directory)))
|
(or (doom-project-root) default-directory))))
|
||||||
(vterm)))
|
(vterm)))
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun +vterm/open-popup (arg)
|
|
||||||
"Open a terminal popup window. If ARG (universal argument) is
|
|
||||||
non-nil, cd into 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 ((default-directory
|
|
||||||
(if arg
|
|
||||||
(or (doom-project-root) default-directory)
|
|
||||||
default-directory)))
|
|
||||||
(vterm-other-window)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun +vterm/open-popup-in-project ()
|
|
||||||
"Open a terminal popup window in the root of the current project."
|
|
||||||
(interactive)
|
|
||||||
(+vterm/open-popup t))
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue