fix(wpcarro/emacs): Debug vterm-mgt.el
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
This commit is contained in:
parent
59755aa1ea
commit
5159413681
3 changed files with 28 additions and 9 deletions
|
|
@ -168,7 +168,8 @@ If there is no currently focused item, add X to the beginning of XS."
|
||||||
(if curr-i
|
(if curr-i
|
||||||
(progn
|
(progn
|
||||||
(struct-set! cycle xs (-insert-at curr-i x (cycle-xs xs)) xs)
|
(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)))
|
(when curr-i (struct-set! cycle current-index (1+ curr-i) xs)))
|
||||||
(progn
|
(progn
|
||||||
(struct-set! cycle xs (cons x (cycle-xs xs)) xs)
|
(struct-set! cycle xs (cons x (cycle-xs xs)) xs)
|
||||||
|
|
|
||||||
|
|
@ -246,6 +246,9 @@
|
||||||
|
|
||||||
(general-define-key
|
(general-define-key
|
||||||
:keymaps '(vterm-mode-map)
|
: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-n" #'vterm-mgt-instantiate
|
||||||
"C-S-w" #'vterm-mgt-kill
|
"C-S-w" #'vterm-mgt-kill
|
||||||
"<C-tab>" #'vterm-mgt-next
|
"<C-tab>" #'vterm-mgt-next
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@
|
||||||
This function should be called from a buffer running vterm."
|
This function should be called from a buffer running vterm."
|
||||||
(interactive)
|
(interactive)
|
||||||
(vterm-mgt--assert-vterm-buffer)
|
(vterm-mgt--assert-vterm-buffer)
|
||||||
|
(vterm-mgt-reconcile-state)
|
||||||
(cycle-focus-item (current-buffer) vterm-mgt--instances)
|
(cycle-focus-item (current-buffer) vterm-mgt--instances)
|
||||||
(switch-to-buffer (cycle-next vterm-mgt--instances))
|
(switch-to-buffer (cycle-next vterm-mgt--instances))
|
||||||
(when vterm-mgt-scroll-on-focus (end-of-buffer)))
|
(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."
|
This function should be called from a buffer running vterm."
|
||||||
(interactive)
|
(interactive)
|
||||||
(vterm-mgt--assert-vterm-buffer)
|
(vterm-mgt--assert-vterm-buffer)
|
||||||
|
(vterm-mgt-reconcile-state)
|
||||||
(cycle-focus-item (current-buffer) vterm-mgt--instances)
|
(cycle-focus-item (current-buffer) vterm-mgt--instances)
|
||||||
(switch-to-buffer (cycle-prev vterm-mgt--instances))
|
(switch-to-buffer (cycle-prev vterm-mgt--instances))
|
||||||
(when vterm-mgt-scroll-on-focus (end-of-buffer)))
|
(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'.
|
newly created instance is added to `vterm-mgt--instances'.
|
||||||
|
|
||||||
If however you must call `vterm', if you'd like to cycle through vterm
|
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
|
instances, make sure you call `vterm-mgt-reconcile-state' to allow vterm-mgt
|
||||||
collect any untracked vterm instances."
|
to collect any untracked vterm instances."
|
||||||
(interactive)
|
(interactive)
|
||||||
(let ((buffer (vterm)))
|
(vterm-mgt-reconcile-state)
|
||||||
|
(let ((buffer (vterm t)))
|
||||||
(cycle-append buffer vterm-mgt--instances)
|
(cycle-append buffer vterm-mgt--instances)
|
||||||
(cycle-focus-item 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."
|
This function should be called from a buffer running vterm."
|
||||||
(interactive)
|
(interactive)
|
||||||
(vterm-mgt--assert-vterm-buffer)
|
(vterm-mgt--assert-vterm-buffer)
|
||||||
(let ((buffer (current-buffer)))
|
(let* ((buffer (current-buffer)))
|
||||||
(cycle-remove buffer vterm-mgt--instances)
|
(when (kill-buffer buffer)
|
||||||
(kill-buffer buffer)))
|
(vterm-mgt-reconcile-state))))
|
||||||
|
|
||||||
(defun vterm-mgt-find-or-create ()
|
(defun vterm-mgt-find-or-create ()
|
||||||
"Call `switch-to-buffer' on a focused vterm instance if there is one.
|
"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
|
there are no items in the cycle, call `vterm-mgt-instantiate' to create a vterm
|
||||||
instance."
|
instance."
|
||||||
(interactive)
|
(interactive)
|
||||||
|
(vterm-mgt-reconcile-state)
|
||||||
(if (cycle-empty? vterm-mgt--instances)
|
(if (cycle-empty? vterm-mgt--instances)
|
||||||
(vterm-mgt-instantiate)
|
(vterm-mgt-instantiate)
|
||||||
(if (cycle-focused? vterm-mgt--instances)
|
(if (cycle-focused? vterm-mgt--instances)
|
||||||
|
|
@ -110,9 +114,9 @@ instance."
|
||||||
This function should be called from a buffer running vterm."
|
This function should be called from a buffer running vterm."
|
||||||
(interactive "SRename vterm buffer: ")
|
(interactive "SRename vterm buffer: ")
|
||||||
(vterm-mgt--assert-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.
|
"Fill `vterm-mgt--instances' with the existing vterm buffers.
|
||||||
|
|
||||||
If for whatever reason, the state of `vterm-mgt--instances' is corrupted and
|
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?)
|
(-filter #'vterm-mgt--instance?)
|
||||||
cycle-from-list)))
|
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)
|
(provide 'vterm-mgt)
|
||||||
;;; vterm-mgt.el ends here
|
;;; vterm-mgt.el ends here
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue