Skip to content

Commit

Permalink
Introduce evil-window-digit
Browse files Browse the repository at this point in the history
  • Loading branch information
tomdl89 committed May 22, 2024
1 parent 0b134d3 commit 8856e2b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
30 changes: 26 additions & 4 deletions evil-commands.el
Original file line number Diff line number Diff line change
Expand Up @@ -4397,6 +4397,24 @@ The \"!\" argument means to sort in reverse order."

;;; Window navigation

(defvar evil--window-digit 0)

(defun evil-window-digit ()
(if (eq 'evil-window-digit-argument last-command)
evil--window-digit
(setq evil--window-digit 0)))

(defun evil-window-digit-argument ()
"Like `digit-argument' but maintains the window map."
(interactive)
(evil-window-digit) ;; i.e. reset if necessary
(let* ((char (if (integerp last-command-event)
last-command-event
(get last-command-event 'ascii-character)))
(digit (- (logand char ?\177) ?0)))
(setq evil--window-digit (+ (* 10 evil--window-digit) digit))
(set-transient-map evil-window-map)))

(defmacro evil-save-side-windows (&rest body)
"Toggle side windows, evaluate BODY, restore side windows."
(declare (indent defun) (debug (&rest form)))
Expand Down Expand Up @@ -4659,25 +4677,29 @@ and open a new buffer name or edit a certain FILE."
"Increase current window height by COUNT."
:repeat nil
(interactive "p")
(enlarge-window count))
(let ((win-count (evil-window-digit)))
(enlarge-window (* count (if (< 0 win-count) win-count 1)))))

(evil-define-command evil-window-decrease-height (count)
"Decrease current window height by COUNT."
:repeat nil
(interactive "p")
(enlarge-window (- count)))
(let ((win-count (evil-window-digit)))
(enlarge-window (- (* count (if (< 0 win-count) win-count 1))))))

(evil-define-command evil-window-increase-width (count)
"Increase current window width by COUNT."
:repeat nil
(interactive "p")
(enlarge-window count t))
(let ((win-count (evil-window-digit)))
(enlarge-window (* count (if (< 0 win-count) win-count 1)) t)))

(evil-define-command evil-window-decrease-width (count)
"Decrease current window width by COUNT."
:repeat nil
(interactive "p")
(enlarge-window (- count) t))
(let ((win-count (evil-window-digit)))
(enlarge-window (- (* count (if (< 0 win-count) win-count 1))) t)))

(evil-define-command evil-window-set-height (count)
"Set the height of the current window to COUNT."
Expand Down
10 changes: 10 additions & 0 deletions evil-maps.el
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,16 @@
(define-key evil-window-map [C-up] 'evil-window-up)
(define-key evil-window-map [C-left] 'evil-window-left)
(define-key evil-window-map [C-right] 'evil-window-right)
(define-key evil-window-map "0" 'evil-window-digit-argument)
(define-key evil-window-map "1" 'evil-window-digit-argument)
(define-key evil-window-map "2" 'evil-window-digit-argument)
(define-key evil-window-map "3" 'evil-window-digit-argument)
(define-key evil-window-map "4" 'evil-window-digit-argument)
(define-key evil-window-map "5" 'evil-window-digit-argument)
(define-key evil-window-map "6" 'evil-window-digit-argument)
(define-key evil-window-map "7" 'evil-window-digit-argument)
(define-key evil-window-map "8" 'evil-window-digit-argument)
(define-key evil-window-map "9" 'evil-window-digit-argument)

(when (featurep 'tab-bar)
(define-key evil-motion-state-map "gt" 'evil-tab-next)
Expand Down

0 comments on commit 8856e2b

Please sign in to comment.