diff --git a/evil-commands.el b/evil-commands.el index 583f6c10..0a9bb0b9 100644 --- a/evil-commands.el +++ b/evil-commands.el @@ -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." @@ -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."