Rework eldoc-box--window-side
* eldoc-box.el: (eldoc-box--window-side): Use distance to judge whether the active window is the left window. (eldoc-box--inhibit-childframe-for): Whitespace change.
This commit is contained in:
parent
e58ecc4699
commit
049eacfd98
33
eldoc-box.el
33
eldoc-box.el
@ -292,6 +292,7 @@ If point != last point, hide the childframe.")
|
|||||||
|
|
||||||
;; Please compiler.
|
;; Please compiler.
|
||||||
(defvar eldoc-box-hover-mode)
|
(defvar eldoc-box-hover-mode)
|
||||||
|
|
||||||
(defun eldoc-box--display (str)
|
(defun eldoc-box--display (str)
|
||||||
"Display STR in childframe.
|
"Display STR in childframe.
|
||||||
STR has to be a proper documentation, not empty string, not nil, etc."
|
STR has to be a proper documentation, not empty string, not nil, etc."
|
||||||
@ -315,19 +316,24 @@ STR has to be a proper documentation, not empty string, not nil, etc."
|
|||||||
(run-hook-with-args 'eldoc-box-buffer-hook))
|
(run-hook-with-args 'eldoc-box-buffer-hook))
|
||||||
(eldoc-box--get-frame doc-buffer)))
|
(eldoc-box--get-frame doc-buffer)))
|
||||||
|
|
||||||
|
|
||||||
(defun eldoc-box--window-side ()
|
(defun eldoc-box--window-side ()
|
||||||
"Return the side of the selected window.
|
"Return the side of the selected window.
|
||||||
Symbol ‘left’ if the selected window is on the left, ‘right’ if
|
Symbol ‘left’ if the selected window is on the left, ‘right’ if
|
||||||
on the right. Return ‘left’ if there is only one window."
|
on the right. Return ‘left’ if there is only one window."
|
||||||
;; Get the window at point (x, y), where x = 0, y = the y coordinate
|
;; Calculate the left and right distances to the frame edge of the
|
||||||
;; of point. If this window is the selected window, the selected
|
;; active window. If the left distance is less than or equal to the
|
||||||
;; window is on the left, otherwise the selected window is on the
|
;; right distance, it indicates that the active window is on the left.
|
||||||
;; right.
|
;; Otherwise, it is on the right.
|
||||||
(let* ((y (cdr (posn-x-y (posn-at-point))))
|
(let* ((window-left (nth 0 (window-absolute-pixel-edges)))
|
||||||
(top (nth 1 (window-absolute-pixel-edges (selected-window))))
|
(window-right (nth 2 (window-absolute-pixel-edges)))
|
||||||
(left-window (window-at-x-y 0 (+ y top))))
|
(frame-left (nth 0 (frame-edges)))
|
||||||
(if (eq left-window (selected-window))
|
(frame-right (nth 2 (frame-edges)))
|
||||||
|
(distance-left (- window-left frame-left))
|
||||||
|
(distance-right (- frame-right window-right)))
|
||||||
|
;; When `distance-left' equals `distance-right', it means there is
|
||||||
|
;; only one window in current frame, or the current active window
|
||||||
|
;; occupies the entire frame horizontally, return left.
|
||||||
|
(if (<= distance-left distance-right)
|
||||||
'left
|
'left
|
||||||
'right)))
|
'right)))
|
||||||
|
|
||||||
@ -388,6 +394,7 @@ base on WIDTH and HEIGHT of childframe text window."
|
|||||||
(y (cdr pos)))
|
(y (cdr pos)))
|
||||||
(cons (or (eldoc-box--at-point-x-by-company) x)
|
(cons (or (eldoc-box--at-point-x-by-company) x)
|
||||||
y)))
|
y)))
|
||||||
|
|
||||||
(defun eldoc-box--update-childframe-geometry (frame window)
|
(defun eldoc-box--update-childframe-geometry (frame window)
|
||||||
"Update the size and the position of childframe.
|
"Update the size and the position of childframe.
|
||||||
FRAME is the childframe, WINDOW is the primary window."
|
FRAME is the childframe, WINDOW is the primary window."
|
||||||
@ -471,14 +478,12 @@ Checkout `lsp-ui-doc--make-frame', `lsp-ui-doc--move-frame'."
|
|||||||
(set-face-background 'child-frame-border
|
(set-face-background 'child-frame-border
|
||||||
(face-attribute 'eldoc-box-border :background)
|
(face-attribute 'eldoc-box-border :background)
|
||||||
frame))
|
frame))
|
||||||
;; set size
|
|
||||||
(eldoc-box--update-childframe-geometry frame window)
|
(eldoc-box--update-childframe-geometry frame window)
|
||||||
(setq eldoc-box--frame frame)
|
(setq eldoc-box--frame frame)
|
||||||
(with-selected-frame frame
|
(with-selected-frame frame
|
||||||
(run-hook-with-args 'eldoc-box-frame-hook main-frame))
|
(run-hook-with-args 'eldoc-box-frame-hook main-frame))
|
||||||
(make-frame-visible frame))))
|
(make-frame-visible frame))))
|
||||||
|
|
||||||
|
|
||||||
;;;;; ElDoc
|
;;;;; ElDoc
|
||||||
|
|
||||||
(defvar eldoc-box--cleanup-timer nil
|
(defvar eldoc-box--cleanup-timer nil
|
||||||
@ -607,7 +612,7 @@ display the docs in echo area depending on
|
|||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(define-minor-mode eldoc-box-hover-mode
|
(define-minor-mode eldoc-box-hover-mode
|
||||||
"Displays hover documentations in a childframe.
|
"Display hover documentations in a childframe.
|
||||||
The default position of childframe is upper corner."
|
The default position of childframe is upper corner."
|
||||||
:lighter eldoc-box-lighter
|
:lighter eldoc-box-lighter
|
||||||
(if eldoc-box-hover-mode
|
(if eldoc-box-hover-mode
|
||||||
@ -619,7 +624,7 @@ The default position of childframe is upper corner."
|
|||||||
;;;###autoload
|
;;;###autoload
|
||||||
(define-minor-mode eldoc-box-hover-at-point-mode
|
(define-minor-mode eldoc-box-hover-at-point-mode
|
||||||
"A convenient minor mode to display doc at point.
|
"A convenient minor mode to display doc at point.
|
||||||
You can use \[keyboard-quit] to hide the doc."
|
You can use \\[keyboard-quit] to hide the doc."
|
||||||
:lighter eldoc-box-lighter
|
:lighter eldoc-box-lighter
|
||||||
(if eldoc-box-hover-at-point-mode
|
(if eldoc-box-hover-at-point-mode
|
||||||
(progn (when eldoc-box-hover-mode
|
(progn (when eldoc-box-hover-mode
|
||||||
@ -648,7 +653,7 @@ instead."
|
|||||||
(interactive)
|
(interactive)
|
||||||
(eldoc-box-help-at-point))
|
(eldoc-box-help-at-point))
|
||||||
|
|
||||||
;;;; Comany compatibility
|
;;;; Company compatibility
|
||||||
;;
|
;;
|
||||||
|
|
||||||
;; see also `eldoc-box--default-at-point-position-function'
|
;; see also `eldoc-box--default-at-point-position-function'
|
||||||
|
Loading…
Reference in New Issue
Block a user