mirror of
https://git.sr.ht/~magic_rb/dotfiles
synced 2024-12-02 13:06:11 +01:00
2 KiB
2 KiB
VTerm
(defun pos-at-prompt (pos)
(and
(>= (line-number-at-pos pos) (line-number-at-pos (vterm--get-cursor-point)))
(>= pos (vterm--get-prompt-point)) (<= pos (vterm--get-end-of-line))))
(defun move-cursor (amount)
(message "%s" amount)
(if (< amount 0)
(cl-loop repeat (* amount -1) do (vterm-send-left))
(cl-loop repeat amount do (vterm-send-right))))
(defun delete-selection-evilterm ()
(when (and
(pos-at-prompt (point))
(pos-at-prompt (mark)))
(let ((amount (- (max (point) (mark)) (vterm--get-cursor-point))))
(progn
(deactivate-mark)
(move-cursor amount)
(cl-loop repeat (- (max (point) (mark)) (min (point) (mark))) do (vterm-send-backspace))
))
(message "No selection")))
(defun move-cursor-to-point ()
(when (pos-at-prompt (point))
(move-cursor (- (point) (vterm--get-cursor-point)))))
(evil-define-key 'normal vterm-mode-map
(kbd "d") (lambda () (interactive) (delete-selection-evilterm)))
(evil-define-key 'normal vterm-mode-map
(kbd "i") (lambda () (interactive) (move-cursor-to-point) (evil-insert 1)))
(evil-define-key 'normal vterm-mode-map
(kbd "<left>") (lambda () (interactive) (vterm-send-left)))
(evil-define-key 'normal vterm-mode-map
(kbd "<right>") (lambda () (interactive) (vterm-send-right)))
(evil-define-key 'normal vterm-mode-map
(kbd "<up>") (lambda () (interactive) (vterm-send-up)))
(evil-define-key 'normal vterm-mode-map
(kbd "<down>") (lambda () (interactive) (vterm-send-down)))
(evil-define-key 'insert vterm-mode-map
(kbd "<left>") (lambda () (interactive) (vterm-send-left)))
(evil-define-key 'insert vterm-mode-map
(kbd "<right>") (lambda () (interactive) (vterm-send-right)))
(evil-define-key 'insert vterm-mode-map
(kbd "<up>") (lambda () (interactive) (vterm-send-up)))
(evil-define-key 'insert vterm-mode-map
(kbd "<down>") (lambda () (interactive) (vterm-send-down)))