From 9ec76b688891e9b39d34e2aecc55fc87134600ac Mon Sep 17 00:00:00 2001 From: Howard Abrams Date: Fri, 21 Oct 2022 22:09:55 -0700 Subject: [PATCH] Adding multi-vterm to create project-specific vterms --- ha-remoting.org | 100 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 74 insertions(+), 26 deletions(-) diff --git a/ha-remoting.org b/ha-remoting.org index 0aa873c..a93017d 100644 --- a/ha-remoting.org +++ b/ha-remoting.org @@ -111,33 +111,70 @@ Actually the =win-name= in this case is optional, as it will use a good default. ** VTerm - I'm not giving up on Eshell, but I am playing around with [[https://github.com/akermu/emacs-libvterm][vterm]], and it is pretty good, but I use it primarily as a more reliable approach for remote terminal sessions. VTerm has an issue (at least for me) with ~M-Backspace~ not deleting the previous word, and yeah, I want to make sure that both keystrokes do the same thing. #+begin_src emacs-lisp -(use-package vterm - :init - (setq vterm-shell "/usr/local/bin/bash") - ;; Granted, I seldom pop out to the shell except during code demonstrations, - ;; but I like how C-p/C-n jumps up to each prompt entry using this setting - ;; that works with my prompt: - (setq vterm-use-vterm-prompt-detection-method nil - term-prompt-regexp "^.* $ ") - :config - (dolist (k '("" "")) - (define-key vterm-mode-map (kbd k) - (lambda () (interactive) (vterm-send-key (kbd "C-w"))))) + (use-package vterm + :init + ;; Granted, I seldom pop out to the shell except during code demonstrations, + ;; but I like how C-p/C-n jumps up to each prompt entry using this setting + ;; that works with my prompt: + (setq vterm-use-vterm-prompt-detection-method nil + term-prompt-regexp "^.* $ ") - (advice-add 'vterm-copy-mode :after 'evil-normal-state)) + :config + (dolist (k '("" "")) + (define-key vterm-mode-map (kbd k) + (lambda () (interactive) (vterm-send-key (kbd "C-w"))))) + + ;; Enter copy mode? Go to Evil's normal state to move around: + (advice-add 'vterm-copy-mode :after 'evil-normal-state) + + ;; I don't know if I need any of these ... yet. Because when I am in a shell, + ;; I default to Emacs keybindings... + ;; (setq vterm-keymap-exceptions nil) + ;; (evil-define-key 'insert vterm-mode-map (kbd "C-e") #'vterm--self-insert) + ;; (evil-define-key 'insert vterm-mode-map (kbd "C-f") #'vterm--self-insert) + ;; (evil-define-key 'insert vterm-mode-map (kbd "C-a") #'vterm--self-insert) + ;; (evil-define-key 'insert vterm-mode-map (kbd "C-v") #'vterm--self-insert) + ;; (evil-define-key 'insert vterm-mode-map (kbd "C-b") #'vterm--self-insert) + ;; (evil-define-key 'insert vterm-mode-map (kbd "C-w") #'vterm--self-insert) + ;; (evil-define-key 'insert vterm-mode-map (kbd "C-u") #'vterm--self-insert) + ;; (evil-define-key 'insert vterm-mode-map (kbd "C-d") #'vterm--self-insert) + ;; (evil-define-key 'insert vterm-mode-map (kbd "C-n") #'vterm--self-insert) + ;; (evil-define-key 'insert vterm-mode-map (kbd "C-m") #'vterm--self-insert) + ;; (evil-define-key 'insert vterm-mode-map (kbd "C-p") #'vterm--self-insert) + ;; (evil-define-key 'insert vterm-mode-map (kbd "C-j") #'vterm--self-insert) + ;; (evil-define-key 'insert vterm-mode-map (kbd "C-k") #'vterm--self-insert) + ;; (evil-define-key 'insert vterm-mode-map (kbd "C-r") #'vterm--self-insert) + ;; (evil-define-key 'insert vterm-mode-map (kbd "C-t") #'vterm--self-insert) + ;; (evil-define-key 'insert vterm-mode-map (kbd "C-g") #'vterm--self-insert) + ;; (evil-define-key 'insert vterm-mode-map (kbd "C-c") #'vterm--self-insert) + ;; (evil-define-key 'insert vterm-mode-map (kbd "C-SPC") #'vterm--self-insert) + ;; (evil-define-key 'normal vterm-mode-map (kbd "C-d") #'vterm--self-insert) + ;; (evil-define-key 'normal vterm-mode-map (kbd ",c") #'multi-vterm) + ;; (evil-define-key 'normal vterm-mode-map (kbd ",n") #'multi-vterm-next) + ;; (evil-define-key 'normal vterm-mode-map (kbd ",p") #'multi-vterm-prev) + ;; (evil-define-key 'normal vterm-mode-map (kbd "i") #'evil-insert-resume) + ;; (evil-define-key 'normal vterm-mode-map (kbd "o") #'evil-insert-resume) + ;; (evil-define-key 'normal vterm-mode-map (kbd "") #'evil-insert-resume) + + :hook + (vterm-mode . (lambda () + (setq-local evil-insert-state-cursor 'box) + (evil-insert-state)))) #+end_src -The advantage of running terminals in Emacs is the ability to copy text without a mouse. For that, hit ~C-c C-t~ to enter a special copy-mode. If I go into this mode, I might as well also go into normal mode to move the cursor. +The advantage of running terminals in Emacs is the ability to copy text without a mouse. For that, hit ~C-c C-t~ to enter a special copy-mode. If I go into this mode, I might as well also go into normal mode to move the cursor. To exit the copy-mode (and copy the selected text to the clipboard), hit ~Return~. -*Note:* To exit the copy-mode (and copy the selected text to the clipboard), hit ~Return~. - -Hrm. Seems that I might want a function to copy the output of the last command to a register, or even an org-capture... +*** Multi Vterm +The [[https://github.com/suonlight/multi-vterm][multi-vterm]] project adds functions for renaming =vterm= instances. +#+begin_src emacs-lisp + (use-package multi-vterm) +#+end_src +Keybindings at the end of this file. ** Variables Let's begin by defining some variables used for communication between the functions. @@ -403,15 +440,26 @@ This file, so far, as been good-enough for a Vanilla Emacs installation, but to #+begin_src emacs-lisp (ha-leader + "a s" '(:ignore t :which-key "ssh") + "a s o" '("overcloud" . ha-ssh-overcloud) + "a s l" '("local shell" . ha-shell) + "a s s" '("remote shell" . ha-ssh) + "a s q" '("quit shell" . ha-ssh-exit) + "a s f" '("find-file" . ha-ssh-find-file) + "a s r" '("find-root" . ha-ssh-find-root) - "a s" '(:ignore t :which-key "ssh") - "a s v" '("vterm" . vterm) - "a s o" '("overcloud" . ha-ssh-overcloud) - "a s l" '("local shell" . ha-shell) - "a s s" '("remote shell" . ha-ssh) - "a s q" '("quit shell" . ha-ssh-exit) - "a s f" '("find-file" . ha-ssh-find-file) - "a s r" '("find-root" . ha-ssh-find-root)) + "a v" '(:ignore t :which-key "vterm") + "a v v" '("vterm" . multi-vterm) + "a v j" '("next vterm" . multi-vterm-next) + "a v k" '("prev vterm" . multi-vterm-prev) + "a v p" '("project vterm" . multi-vterm-project) + "a v r" '("rename" . multi-vterm-rename-buffer) + + "a v d" '(:ignore t :which-key "dedicated") + "a v d o" '("open" . multi-vterm-dedicated-open) + "a v d s" '("switch" . multi-vterm-dedicated-select) + "a v d t" '("toggle" . multi-vterm-dedicated-toggle) + "a v d x" '("close" . multi-vterm-dedicated-close)) #+end_src * Technical Artifacts :noexport: