Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix behavior of evil-scroll-up and evil-scroll-down #1154

Open
wants to merge 3 commits into
base: master
from
Open
Changes from 2 commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -920,8 +920,8 @@ 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 (/ (1- (window-height)) 2)))
(let ((xy (posn-x-y (posn-at-point))))
(setq count (/ (window-body-height) 2)))
(let ((xy (evil-posn-x-y (posn-at-point))))
(condition-case nil
(progn
(scroll-down count)
@@ -944,12 +944,12 @@ 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 (/ (1- (window-height)) 2)))
(setq count (/ (window-body-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))
(with-no-warnings (next-line count nil))
(let ((xy (posn-x-y (posn-at-point))))
(let ((xy (evil-posn-x-y (posn-at-point))))
(condition-case nil
(progn
(scroll-up count)
@@ -864,9 +864,37 @@ Inhibits echo area messages, mode line updates and cursor changes."
`(let ((evil-no-display t))
,@body))

(defun evil-num-visible-lines ()
"Returns the number of currently visible lines."
(- (window-height) 1))
(defvar evil-cached-header-line-height nil
"Cached height of the header line.")

(defun evil-header-line-height ()
"Return the height of the header line.
If there is no header line, return nil."
(let ((posn (posn-at-x-y 0 0)))
(when (eq (posn-area posn) 'header-line)
(cdr (posn-object-width-height posn)))))

(defun evil-posn-x-y (position)

This comment has been minimized.

Copy link
@Alexander-Shukaev

Alexander-Shukaev Jun 7, 2019

Contributor

Should be macro to avoid unnecessary branching.

This comment has been minimized.

Copy link
@bet4it

bet4it Jun 22, 2019

Author

Can you give an example about this?

"Return the x and y coordinates in POSITION.
This function returns y offset from the top of the buffer area including
the header line. This definition could be changed in future.
Note: On Emacs 22 and 23, y offset, returned by `posn-at-point' and taken
by `posn-at-x-y', is relative to the top of the buffer area including
the header line.
However, on Emacs 24, y offset returned by `posn-at-point' is relative to
the text area excluding the header line, while y offset taken by
`posn-at-x-y' is relative to the buffer area including the header line.
This asymmetry is by design according to GNU Emacs team.
This function fixes the asymmetry between them on Emacs 24 and later versions.
Borrowed from mozc.el."
(let ((xy (posn-x-y position)))
(when (and (> emacs-major-version 24) header-line-format)
This conversation was marked as resolved by bet4it

This comment has been minimized.

Copy link
@dzop

dzop Jul 15, 2019

Contributor

Why do do we need this emacs-major-version check if the minimum supported version of Emacs is 24.1?

'((emacs "24.1")

This comment has been minimized.

Copy link
@bet4it

bet4it Jul 15, 2019

Author

You are right. I learned it from

evil/evil-commands.el

Lines 3749 to 3751 in 297b8f3

(let ((count (- new-size (if horizontal (window-width) (window-height)))))
(if (>= emacs-major-version 24)
(enlarge-window count horizontal)

but support for Emacs < 24 was dropped in 2cad471.

I have removed these code.

(setcdr xy (+ (cdr xy)
(or evil-cached-header-line-height
(setq evil-cached-header-line-height (evil-header-line-height))
0))))
xy))

(defun evil-count-lines (beg end)
"Return absolute line-number-difference betweeen `beg` and `end`.
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.