Skip to content

Commit

Permalink
Hooks approach
Browse files Browse the repository at this point in the history
  • Loading branch information
tomdl89 committed May 23, 2024
1 parent 8856e2b commit a10cc9e
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions evil-commands.el
Original file line number Diff line number Diff line change
Expand Up @@ -4399,21 +4399,26 @@ The \"!\" argument means to sort in reverse order."

(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-keep-pred ()
(eq 'evil-window-digit-argument this-command))

(defun evil--window-reset-digit ()
(setq evil--window-digit 0)
(remove-hook 'post-command-hook #'evil--window-reset-digit))

(defun evil--window-on-exit ()
(add-hook 'post-command-hook #'evil--window-reset-digit))

(defun evil-window-digit-argument ()
"Like `digit-argument' but maintains the window map."
(interactive)
(evil-window-digit) ;; i.e. reset if necessary
(unless (eq 'evil-window-digit-argument last-command)
(set-transient-map evil-window-map #'evil--window-keep-pred #'evil--window-on-exit))
(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)))
(setq evil--window-digit (+ (* 10 evil--window-digit) digit))))

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

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

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

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

(evil-define-command evil-window-set-height (count)
"Set the height of the current window to COUNT."
Expand Down

0 comments on commit a10cc9e

Please sign in to comment.