aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--evil-commands.el4
-rw-r--r--evil-common.el32
2 files changed, 34 insertions, 2 deletions
diff --git a/evil-commands.el b/evil-commands.el
index 2f8464d..b816b1e 100644
--- a/evil-commands.el
+++ b/evil-commands.el
@@ -956,7 +956,7 @@ If the scroll count is zero the command scrolls half the screen."
(signal 'beginning-of-buffer nil))
(when (zerop count)
(setq count (/ (1- (window-height)) 2)))
- (let ((xy (posn-x-y (posn-at-point))))
+ (let ((xy (evil-posn-x-y (posn-at-point))))
(condition-case nil
(progn
(scroll-down count)
@@ -984,7 +984,7 @@ If the scroll count is zero the command scrolls half the screen."
;; 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)
diff --git a/evil-common.el b/evil-common.el
index 5596d92..575f19f 100644
--- a/evil-common.el
+++ b/evil-common.el
@@ -871,6 +871,38 @@ Inhibits echo area messages, mode line updates and cursor changes."
"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)
+ "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)
+ (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`.
This should give the same results no matter where on the line `beg`