about summary refs log tree commit diff
path: root/users
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2021-12-24T16·47-0500
committerclbot <clbot@tvl.fyi>2021-12-24T16·54+0000
commit51594136816e52ffd27111d96463685a37b52792 (patch)
tree5953363fdec6b8983ad0230dba6706c419333dfc /users
parent59755aa1ea16459c85c3086d51b3467f8948a705 (diff)
fix(wpcarro/emacs): Debug vterm-mgt.el r/3348
TL;DR:
- vterm-mgt-repopulate-cycle -> vterm-mgt-reconcile-state
- call vterm-mgt-reconcile-state everywhere to ensure state is consistent
- prevent vterm from swalling EXWM KBD (C-S-f)
- support vterm-mgt-select
- prevent type error in cycle-append
- pass t to (vterm t) to ensure it isn't a find-or-create

Change-Id: I0f6d20b8d4b7533c7f56baf796ca3467a85ec770
Reviewed-on: https://cl.tvl.fyi/c/depot/+/4563
Reviewed-by: wpcarro <wpcarro@gmail.com>
Autosubmit: wpcarro <wpcarro@gmail.com>
Tested-by: BuildkiteCI
Diffstat (limited to 'users')
-rw-r--r--users/wpcarro/emacs/.emacs.d/wpc/cycle.el3
-rw-r--r--users/wpcarro/emacs/.emacs.d/wpc/keybindings.el3
-rw-r--r--users/wpcarro/emacs/.emacs.d/wpc/vterm-mgt.el31
3 files changed, 28 insertions, 9 deletions
diff --git a/users/wpcarro/emacs/.emacs.d/wpc/cycle.el b/users/wpcarro/emacs/.emacs.d/wpc/cycle.el
index e683f3c201cf..a1853ece1431 100644
--- a/users/wpcarro/emacs/.emacs.d/wpc/cycle.el
+++ b/users/wpcarro/emacs/.emacs.d/wpc/cycle.el
@@ -168,7 +168,8 @@ If there is no currently focused item, add X to the beginning of XS."
       (if curr-i
           (progn
             (struct-set! cycle xs (-insert-at curr-i x (cycle-xs xs)) xs)
-            (when (>= prev-i curr-i) (struct-set! cycle previous-index (1+ prev-i) xs))
+            (when (and prev-i (>= prev-i curr-i))
+              (struct-set! cycle previous-index (1+ prev-i) xs))
             (when curr-i (struct-set! cycle current-index (1+ curr-i) xs)))
         (progn
           (struct-set! cycle xs (cons x (cycle-xs xs)) xs)
diff --git a/users/wpcarro/emacs/.emacs.d/wpc/keybindings.el b/users/wpcarro/emacs/.emacs.d/wpc/keybindings.el
index 44e0d0706406..78ec1ceb5e02 100644
--- a/users/wpcarro/emacs/.emacs.d/wpc/keybindings.el
+++ b/users/wpcarro/emacs/.emacs.d/wpc/keybindings.el
@@ -246,6 +246,9 @@
 
 (general-define-key
  :keymaps '(vterm-mode-map)
+ ;; For some reason vterm captures this KBD instead of EXWM
+ "C-S-f" nil
+ "s-x" #'vterm-mgt-select
  "C-S-n" #'vterm-mgt-instantiate
  "C-S-w" #'vterm-mgt-kill
  "<C-tab>" #'vterm-mgt-next
diff --git a/users/wpcarro/emacs/.emacs.d/wpc/vterm-mgt.el b/users/wpcarro/emacs/.emacs.d/wpc/vterm-mgt.el
index 79a02f98e82a..bef07bd809e9 100644
--- a/users/wpcarro/emacs/.emacs.d/wpc/vterm-mgt.el
+++ b/users/wpcarro/emacs/.emacs.d/wpc/vterm-mgt.el
@@ -54,6 +54,7 @@
 This function should be called from a buffer running vterm."
   (interactive)
   (vterm-mgt--assert-vterm-buffer)
+  (vterm-mgt-reconcile-state)
   (cycle-focus-item (current-buffer) vterm-mgt--instances)
   (switch-to-buffer (cycle-next vterm-mgt--instances))
   (when vterm-mgt-scroll-on-focus (end-of-buffer)))
@@ -63,6 +64,7 @@ This function should be called from a buffer running vterm."
 This function should be called from a buffer running vterm."
   (interactive)
   (vterm-mgt--assert-vterm-buffer)
+  (vterm-mgt-reconcile-state)
   (cycle-focus-item (current-buffer) vterm-mgt--instances)
   (switch-to-buffer (cycle-prev vterm-mgt--instances))
   (when vterm-mgt-scroll-on-focus (end-of-buffer)))
@@ -74,10 +76,11 @@ Prefer calling this function instead of `vterm'.  This function ensures that the
   newly created instance is added to `vterm-mgt--instances'.
 
 If however you must call `vterm', if you'd like to cycle through vterm
-  instances, make sure you call `vterm-mgt-populate-cycle' to allow vterm-mgt to
-  collect any untracked vterm instances."
+  instances, make sure you call `vterm-mgt-reconcile-state' to allow vterm-mgt
+  to collect any untracked vterm instances."
   (interactive)
-  (let ((buffer (vterm)))
+  (vterm-mgt-reconcile-state)
+  (let ((buffer (vterm t)))
     (cycle-append buffer vterm-mgt--instances)
     (cycle-focus-item buffer vterm-mgt--instances)))
 
@@ -86,9 +89,9 @@ If however you must call `vterm', if you'd like to cycle through vterm
 This function should be called from a buffer running vterm."
   (interactive)
   (vterm-mgt--assert-vterm-buffer)
-  (let ((buffer (current-buffer)))
-    (cycle-remove buffer vterm-mgt--instances)
-    (kill-buffer buffer)))
+  (let* ((buffer (current-buffer)))
+    (when (kill-buffer buffer)
+      (vterm-mgt-reconcile-state))))
 
 (defun vterm-mgt-find-or-create ()
   "Call `switch-to-buffer' on a focused vterm instance if there is one.
@@ -97,6 +100,7 @@ When `cycle-focused?' returns nil, focus the first item in the cycle.  When
 there are no items in the cycle, call `vterm-mgt-instantiate' to create a vterm
 instance."
   (interactive)
+  (vterm-mgt-reconcile-state)
   (if (cycle-empty? vterm-mgt--instances)
       (vterm-mgt-instantiate)
     (if (cycle-focused? vterm-mgt--instances)
@@ -110,9 +114,9 @@ instance."
 This function should be called from a buffer running vterm."
   (interactive "SRename vterm buffer: ")
   (vterm-mgt--assert-vterm-buffer)
-  (rename-buffer (format "vterm<%s>" name)))
+  (rename-buffer (format "*vterm*<%s>" name)))
 
-(defun vterm-mgt-repopulate-cycle ()
+(defun vterm-mgt-reconcile-state ()
   "Fill `vterm-mgt--instances' with the existing vterm buffers.
 
 If for whatever reason, the state of `vterm-mgt--instances' is corrupted and
@@ -124,5 +128,16 @@ If for whatever reason, the state of `vterm-mgt--instances' is corrupted and
              (-filter #'vterm-mgt--instance?)
              cycle-from-list)))
 
+(defun vterm-mgt-select ()
+  "Select a vterm instance by name from the list in `vterm-mgt--instances'."
+  (interactive)
+  (vterm-mgt-reconcile-state)
+  (switch-to-buffer
+   (buffer-find-or-create
+    (completing-read "Switch to vterm: "
+                     (->> vterm-mgt--instances
+                          cycle-to-list
+                          (-map #'buffer-name))))))
+
 (provide 'vterm-mgt)
 ;;; vterm-mgt.el ends here