Support childframe at point

This commit is contained in:
Yuan Fu 2018-12-20 09:57:30 -05:00
parent 1738ccae4c
commit c4af2c7e23
No known key found for this signature in database
GPG Key ID: 1CF5ECABEC37A901

View File

@ -100,6 +100,11 @@ Consider your machine's screen's resolution when setting this variable.
Set it to a function with no argument 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.")
(defvar eldoc-box-position-function #'eldoc-box--default-upper-corner-position-function
"Eldoc-box uses this function to set childframe's position.
This should be a function that returns a (X . Y) cons cell.
It will be passes with two arguments: WIDTH and HEIGHT of the childframe.")
;;;;; Function ;;;;; Function
(defvar eldoc-box--frame nil ;; A backstage variable (defvar eldoc-box--frame nil ;; A backstage variable
"The frame to display doc.") "The frame to display doc.")
@ -152,6 +157,26 @@ if you want to dynamically change the maximum height.")
'left 'left
'right))) 'right)))
(defun eldoc-box--default-upper-corner-position-function (width _)
"The default function to set childframe position.
Used by `eldoc-box-position-function'.
Position is calculated base on WIDTH and HEIGHT of chilframe text window"
(cons (pcase (eldoc-box--window-side) ; x position + a little padding (16)
;; display doc on right
('left (- (frame-outer-width (selected-frame)) width 16))
;; display doc on left
('right 16))
;; y position + a little padding (16)
16))
(defun eldoc-box--default-at-point-position-function (width _)
"Set `eldoc-box-position-function' to this function to have childframe appear under point.
Position is calculated base on WIDTH and HEIGHT of chilframe text window"
(let ((point-pos (window-absolute-pixel-position)))
(cons (+ 16 (car point-pos)) (- (min (cdr point-pos)
(frame-outer-width (selected-frame)))
16))))
(defun eldoc-box--get-frame (buffer) (defun eldoc-box--get-frame (buffer)
"Return a childframe displaying BUFFER. "Return a childframe displaying BUFFER.
Checkout `lsp-ui-doc--make-frame', `lsp-ui-doc--move-frame'." Checkout `lsp-ui-doc--make-frame', `lsp-ui-doc--move-frame'."
@ -182,18 +207,14 @@ Checkout `lsp-ui-doc--make-frame', `lsp-ui-doc--move-frame'."
(width (car size)) (width (car size))
(height (cdr size)) (height (cdr size))
(width (+ width (frame-char-width frame))) ; add margin (width (+ width (frame-char-width frame))) ; add margin
(frame-resize-pixelwise t)) (frame-resize-pixelwise t)
(pos (funcall eldoc-box-position-function width height)))
(set-frame-size frame width height t) (set-frame-size frame width height t)
;; move position ;; move position
(set-frame-position frame (pcase (eldoc-box--window-side) ; x position + a little padding (16) (set-frame-position frame (car pos) (cdr pos)))
;; display doc on right
('left (- (frame-outer-width main-frame) width 16))
;; display doc on left
('right 16))
;; y position + a little padding (16)
16))
(setq eldoc-box--frame frame))) (setq eldoc-box--frame frame)))
;;;;; ElDoc ;;;;; ElDoc
(defvar eldoc-box--cleanup-timer nil (defvar eldoc-box--cleanup-timer nil