From ec87e8c7f865d10f8f0910fbd4916d9f02b9b8a9 Mon Sep 17 00:00:00 2001 From: Yuan Fu Date: Sat, 2 Nov 2019 00:10:11 -0400 Subject: [PATCH] Simplify position-finding code --- eldoc-box.el | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/eldoc-box.el b/eldoc-box.el index 85b5eb9..d2901ee 100644 --- a/eldoc-box.el +++ b/eldoc-box.el @@ -242,21 +242,17 @@ Position is calculated base on WIDTH and HEIGHT of childframe text window" ;; y position + a little padding (16) 16)) -(defun eldoc-box--point-position-relative-to-native-frame (&optional position window) - "Return (X . Y) as the coordinate of POSITION in WINDOW. +(defun eldoc-box--point-position-relative-to-native-frame (&optional point window) + "Return (X . Y) as the coordinate of POINT in WINDOW. The coordinate is relative to the native frame. WINDOW nil means use selected window." - (let* ((window (window-normalize-window window t)) - (pos-in-window - (pos-visible-in-window-p - (or position (window-point window)) window t))) - (when pos-in-window - ;; change absolute to relative to native frame - (let ((edges (window-edges window t nil t))) - (cons (+ (nth 0 edges) (nth 0 pos-in-window)) ; x - (+ (nth 1 edges) (nth 1 pos-in-window) - (- (window-header-line-height window)))))))) ; y + (let* ((pos (pos (posn-at-point point window))) + (x-y (posn-x-y pos)) + (window (posn-window pos)) + (edges (window-body-pixel-edges window))) + (cons (+ (car x-y) (car edges)) + (+ (cdr x-y) (cadr edges))))) (defun eldoc-box--default-at-point-position-function-1 (width height) "See `eldoc-box--default-at-point-position-function'."