Follow cursor when in at-point mode

Instead of disappear.
This commit is contained in:
Yuan Fu 2019-06-08 12:07:18 +08:00
parent f292d28712
commit 2a198c4d3e
No known key found for this signature in database
GPG Key ID: 56E19BC57664A442

View File

@ -154,10 +154,13 @@ You can use C-g to hide the doc."
eldoc-box-position-function eldoc-box-position-function
#'eldoc-box--default-at-point-position-function) #'eldoc-box--default-at-point-position-function)
(setq-local eldoc-box-clear-with-C-g t) (setq-local eldoc-box-clear-with-C-g t)
;; always kill frame instead of using maybe-cleanup
(remove-hook 'pre-command-hook #'eldoc-pre-command-refresh-echo-area t) (remove-hook 'pre-command-hook #'eldoc-pre-command-refresh-echo-area t)
(add-hook 'pre-command-hook #'eldoc-box-quit-frame t t)) ;; (add-hook 'pre-command-hook #'eldoc-box-quit-frame t t)
(add-hook 'post-command-hook #'eldoc-box--follow-cursor t t))
(add-hook 'pre-command-hook #'eldoc-pre-command-refresh-echo-area t) (add-hook 'pre-command-hook #'eldoc-pre-command-refresh-echo-area t)
(remove-hook 'pre-command-hook #'eldoc-box-quit-frame t) ;; (remove-hook 'pre-command-hook #'eldoc-box-quit-frame t)
(remove-hook 'post-command-hook #'eldoc-box--follow-cursor t)
(kill-local-variable 'eldoc-box-position-function) (kill-local-variable 'eldoc-box-position-function)
(kill-local-variable 'eldoc-box-clear-with-C-g)) (kill-local-variable 'eldoc-box-clear-with-C-g))
(message "Enable eldoc-box-hover-mode first"))) (message "Enable eldoc-box-hover-mode first")))
@ -242,14 +245,29 @@ WINDOW nil means use selected window."
;; normal, just return y + em ;; normal, just return y + em
(+ y em))))) (+ y em)))))
(defun eldoc-box--default-at-point-position-function (width height) (defun eldoc-box--update-childframe-geometry (frame window)
"Set `eldoc-box-position-function' to this function to have childframe appear under point. "Update the size and the position of childframe.
Position is calculated base on WIDTH and HEIGHT of childframe text window." FRAME is the childframe, WINDOW is the primary window."
(let* ((pos (eldoc-box--default-at-point-position-function-1 width height)) (let* ((size
(x (car pos)) (window-text-pixel-size
(y (cdr pos))) window nil nil
(cons (or (eldoc-box--at-point-x-by-company) x) (if (functionp eldoc-box-max-pixel-width) (funcall eldoc-box-max-pixel-width) eldoc-box-max-pixel-width)
y))) (if (functionp eldoc-box-max-pixel-height) (funcall eldoc-box-max-pixel-height) eldoc-box-max-pixel-height)
t))
(width (car size))
(height (cdr size))
(width (+ width (frame-char-width frame))) ; add margin
(frame-resize-pixelwise t)
(pos (funcall eldoc-box-position-function width height)))
(set-frame-size frame width height t)
;; move position
(set-frame-position frame (car pos) (cdr pos))))
(defun eldoc-box--follow-cursor ()
"Make childframe follow cursor in at-point mode."
(when (frame-live-p eldoc-box--frame)
(eldoc-box--update-childframe-geometry
eldoc-box--frame (frame-selected-window eldoc-box--frame))))
(defun eldoc-box--get-frame (buffer) (defun eldoc-box--get-frame (buffer)
"Return a childframe displaying BUFFER. "Return a childframe displaying BUFFER.
@ -280,20 +298,7 @@ Checkout `lsp-ui-doc--make-frame', `lsp-ui-doc--move-frame'."
:font (face-attribute 'eldoc-box-body :font main-frame)) :font (face-attribute 'eldoc-box-body :font main-frame))
;; set size ;; set size
(let* ((size (eldoc-box--update-childframe-geometry frame window)
(window-text-pixel-size
window nil nil
(if (functionp eldoc-box-max-pixel-width) (funcall eldoc-box-max-pixel-width) eldoc-box-max-pixel-width)
(if (functionp eldoc-box-max-pixel-height) (funcall eldoc-box-max-pixel-height) eldoc-box-max-pixel-height)
t))
(width (car size))
(height (cdr size))
(width (+ width (frame-char-width frame))) ; add margin
(frame-resize-pixelwise t)
(pos (funcall eldoc-box-position-function width height)))
(set-frame-size frame width height t)
;; move position
(set-frame-position frame (car pos) (cdr pos)))
(setq eldoc-box--frame frame) (setq eldoc-box--frame frame)
(make-frame-visible frame))) (make-frame-visible frame)))