From 2f8e3ec042bbdcf301d570c2a7f18e8805bfc57e Mon Sep 17 00:00:00 2001 From: Siddhartha Date: Fri, 23 Jul 2021 14:56:38 -0700 Subject: [PATCH 1/3] Use text scale in calculating visible window height (fix #1497) --- evil-commands.el | 4 ++-- evil-common.el | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/evil-commands.el b/evil-commands.el index ac88186f..7bd93bc3 100644 --- a/evil-commands.el +++ b/evil-commands.el @@ -1043,7 +1043,7 @@ If the scroll count is zero the command scrolls half the screen." (when (= (point-min) (line-beginning-position)) (signal 'beginning-of-buffer nil)) (when (zerop count) - (setq count (/ (window-body-height) 2))) + (setq count (/ (evil-window-visible-height) 2))) (let ((xy (evil-posn-x-y (posn-at-point)))) (condition-case nil (progn @@ -1067,7 +1067,7 @@ If the scroll count is zero the command scrolls half the screen." (setq evil-scroll-count count) (when (eobp) (signal 'end-of-buffer nil)) (when (zerop count) - (setq count (/ (window-body-height) 2))) + (setq count (/ (evil-window-visible-height) 2))) ;; BUG #660: First check whether the eob is visible. ;; In that case we do not scroll but merely move point. (if (<= (point-max) (window-end)) diff --git a/evil-common.el b/evil-common.el index b68e1cab..7f3a0cff 100644 --- a/evil-common.el +++ b/evil-common.el @@ -3980,6 +3980,18 @@ PROPERTIES is a property-list which supports the following properties: (evil-motion-state)) (switch-to-buffer-other-window buf)))) +;;; Window + +(defun evil-window-visible-height (&optional window) + "The visible height of WINDOW in lines. + +If no WINDOW is specified, use the selected one." + (let ((window (or window (selected-window)))) + (save-window-excursion + (select-window window) + (let ((current-scale (expt text-scale-mode-step text-scale-mode-amount))) + (round (/ (window-body-height) current-scale)))))) + (provide 'evil-common) ;;; evil-common.el ends here From c9f991364d189b30f92b4f73cb3e046e289fda8d Mon Sep 17 00:00:00 2001 From: Siddhartha Date: Fri, 23 Jul 2021 18:52:16 -0700 Subject: [PATCH 2/3] minor improvement to decouple two actions taken during scrolling --- evil-commands.el | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/evil-commands.el b/evil-commands.el index 7bd93bc3..982b04f9 100644 --- a/evil-commands.el +++ b/evil-commands.el @@ -1070,25 +1070,28 @@ If the scroll count is zero the command scrolls half the screen." (setq count (/ (evil-window-visible-height) 2))) ;; BUG #660: First check whether the eob is visible. ;; In that case we do not scroll but merely move point. - (if (<= (point-max) (window-end)) + (if (pos-visible-in-window-p (point-max)) (with-no-warnings (next-line count nil)) (let ((xy (evil-posn-x-y (posn-at-point)))) (condition-case nil (progn (scroll-up count) - (let* ((wend (window-end nil t)) - (p (posn-at-x-y (car xy) (cdr xy))) + (let* ((p (posn-at-x-y (car xy) (cdr xy))) (margin (max 0 (- scroll-margin (cdr (posn-col-row p)))))) + ;; return point to its original window-relative + ;; position prior to scrolling (goto-char (posn-point p)) ;; ensure point is not within the scroll-margin (when (> margin 0) (with-no-warnings (next-line margin)) - (recenter scroll-margin)) - (when (<= (point-max) wend) - (save-excursion - (goto-char (point-max)) - (recenter (- (max 1 scroll-margin))))))) + (recenter scroll-margin))) + ;; once the end of the buffer is visible, ensure it + ;; is positioned near the bottom of the window + (when (pos-visible-in-window-p (point-max)) + (save-excursion + (goto-char (point-max)) + (recenter (- (max 1 scroll-margin)))))) (end-of-buffer (goto-char (point-max)) (recenter (- (max 1 scroll-margin))))))))) From e8489861e3ce08420f6f391f9a6d576a4bb2f428 Mon Sep 17 00:00:00 2001 From: Siddhartha Date: Wed, 17 Nov 2021 19:50:31 -0800 Subject: [PATCH 3/3] add missing import --- evil-common.el | 1 + 1 file changed, 1 insertion(+) diff --git a/evil-common.el b/evil-common.el index 7f3a0cff..0515ba47 100644 --- a/evil-common.el +++ b/evil-common.el @@ -30,6 +30,7 @@ (require 'thingatpt) (require 'cl-lib) (require 'calc) +(require 'face-remap) ;;; Code: