Add customizable eldoc-box-offset

* eldoc-box.el (eldoc-box-offset): New option.
(eldoc-box--default-upper-corner-position-function): Use
eldoc-box-position-function
This commit is contained in:
Trevor Richards 2022-02-11 23:57:46 -08:00 committed by Yuan Fu
parent 13d207d408
commit 3efb59ab78
No known key found for this signature in database
GPG Key ID: 56E19BC57664A442

View File

@ -115,6 +115,14 @@ Set it to a function with no argument
if you want to dynamically change the maximum height." if you want to dynamically change the maximum height."
:type 'number) :type 'number)
(defcustom eldoc-box-offset '(16 16 16)
"Sets left, right & top offset of the doc childframe.
Its value should be a list: (left right top)"
:type '(list
(integer :tag "Left")
(integer :tag "Right")
(integer :tag "Top")))
(defvar eldoc-box-position-function #'eldoc-box--default-upper-corner-position-function (defvar eldoc-box-position-function #'eldoc-box--default-upper-corner-position-function
"Eldoc-box uses this function to set childframe's position. "Eldoc-box uses this function to set childframe's position.
This should be a function that returns a (X . Y) cons cell. This should be a function that returns a (X . Y) cons cell.
@ -207,13 +215,15 @@ Intended for internal use."
"The default function to set childframe position. "The default function to set childframe position.
Used by `eldoc-box-position-function'. Used by `eldoc-box-position-function'.
Position is calculated base on WIDTH and HEIGHT of childframe text window" Position is calculated base on WIDTH and HEIGHT of childframe text window"
(cons (pcase (eldoc-box--window-side) ; x position + a little padding (16) (pcase-let ((`(,offset-l ,offset-r ,offset-t) eldoc-box-offset))
;; display doc on right (cons (pcase (eldoc-box--window-side) ; x position + offset
('left (- (frame-outer-width (selected-frame)) width 16)) ;; display doc on right
;; display doc on left ('left (- (frame-outer-width (selected-frame)) width offset-r))
('right 16)) ;; display doc on left
;; y position + a little padding (16) ('right offset-l))
16)) ;; y position + v-offset
offset-t)
))
(defun eldoc-box--point-position-relative-to-native-frame (&optional point window) (defun eldoc-box--point-position-relative-to-native-frame (&optional point window)
"Return (X . Y) as the coordinate of POINT in WINDOW. "Return (X . Y) as the coordinate of POINT in WINDOW.