aboutsummaryrefslogtreecommitdiff
path: root/evil-common.el
diff options
context:
space:
mode:
authorBet4 <0xbet4@gmail.com>2019-05-18 22:17:35 +0800
committerEivind Fonn <evfonn@gmail.com>2019-12-03 11:04:58 +0100
commitdf23fc18cfdc6b3792043784a888a63aa20d5df2 (patch)
tree1311de14b97793e22eeecf6728d539a8c69be3b5 /evil-common.el
parent6655dc5f762014192bca5ef55673cd781f76f679 (diff)
Fix the asymmetry between posn-at-point and posn-at-x-y when header line is enabled
Diffstat (limited to 'evil-common.el')
-rw-r--r--evil-common.el32
1 files changed, 32 insertions, 0 deletions
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`