Rename to eldoc-box

This commit is contained in:
Yuan Fu 2018-12-11 09:15:00 -05:00
parent 8a11b796d4
commit 77250ae7da
No known key found for this signature in database
GPG Key ID: 1CF5ECABEC37A901

View File

@ -1,4 +1,4 @@
;;; eglot-doc.el --- Display documentation in childframe -*- lexical-binding: t; -*- ;;; eldoc-box.el --- Display documentation in childframe -*- lexical-binding: t; -*-
;; Copyright (C) 2018 Yuan Fu ;; Copyright (C) 2018 Yuan Fu
@ -32,14 +32,14 @@
;;;; Userland ;;;; Userland
;;;;; Variable ;;;;; Variable
(defface eglot-doc-border '((((background dark)) . (:background "white")) (defface eldoc-box-border '((((background dark)) . (:background "white"))
(((background light)) . (:background "dark"))) (((background light)) . (:background "dark")))
"The border color used in childframe.") "The border color used in childframe.")
(defface eglot-doc-body '((t . (:background nil))) (defface eldoc-box-body '((t . (:background nil)))
"Body face used in eglot doc childframe. Only :background is used.") "Body face used in eglot doc childframe. Only :background is used.")
(defvar eglot-doc-frame-parameters (defvar eldoc-box-frame-parameters
'( '(
;; (left . -1) ;; (left . -1)
(no-accept-focus . t) (no-accept-focus . t)
@ -68,56 +68,56 @@
(desktop-dont-save . t)) (desktop-dont-save . t))
"Frame parameters used to create the frame.") "Frame parameters used to create the frame.")
(defvar eglot-doc-max-pixel-width 800 (defvar eldoc-box-max-pixel-width 800
"Maximum width of doc childframw in pixel.") "Maximum width of doc childframw in pixel.")
(defvar eglot-doc-max-pixel-height 1400 (defvar eldoc-box-max-pixel-height 1400
"Maximum height of doc childframw in pixel.") "Maximum height of doc childframw in pixel.")
;;;;; Function ;;;;; Function
(defun eglot-doc-help-at-point () (defun eldoc-box-help-at-point ()
"Display hover info at point in a childframe." "Display hover info at point in a childframe."
(interactive) (interactive)
(eldoc-message (funcall eldoc-documentation-function))) (eldoc-message (funcall eldoc-documentation-function)))
(defun eglot-doc-quit-frame () (defun eldoc-box-quit-frame ()
"Hide childframe used by eglot doc." "Hide childframe used by eglot doc."
(interactive) (interactive)
;; TODO ;; TODO
(when eglot-doc--frame (when eldoc-box--frame
(delete-frame eglot-doc--frame t))) (delete-frame eldoc-box--frame t)))
;;;; Backstage ;;;; Backstage
;;;;; Variable ;;;;; Variable
(defvar eglot-doc--frame nil (defvar eldoc-box--frame nil
"The frame to display doc.") "The frame to display doc.")
(defvar eglot-doc--buffer "*eglot-doc*" (defvar eldoc-box--buffer "*eldoc-box*"
"The buffer used to display eglot doc.") "The buffer used to display eglot doc.")
;;;;; Function ;;;;; Function
(defun eglot-doc--display (str) (defun eldoc-box--display (str)
"Display STR in childframe." "Display STR in childframe."
(let ((doc-buffer (get-buffer-create eglot-doc--buffer))) (let ((doc-buffer (get-buffer-create eldoc-box--buffer)))
(with-current-buffer doc-buffer (with-current-buffer doc-buffer
(setq mode-line-format nil) (setq mode-line-format nil)
(erase-buffer) (erase-buffer)
(insert str) (insert str)
(eglot-doc--get-frame doc-buffer)) (eldoc-box--get-frame doc-buffer))
(eglot-doc--inject-quit-func))) (eldoc-box--inject-quit-func)))
(defun eglot-doc-quit-hook () (defun eldoc-box-quit-hook ()
"Quit eglot doc childframe and remove self from hook." "Quit eglot doc childframe and remove self from hook."
(eglot-doc-quit-frame) (eldoc-box-quit-frame)
(remove-hook 'pre-command-hook #'eglot-doc-quit-hook t)) (remove-hook 'pre-command-hook #'eldoc-box-quit-hook t))
(defun eglot-doc--inject-quit-func () (defun eldoc-box--inject-quit-func ()
"Inject quit function into `pre-command-hook' so doing anything will quit eglot doc childframe." "Inject quit function into `pre-command-hook' so doing anything will quit eglot doc childframe."
(add-hook 'pre-command-hook #'eglot-doc-quit-hook t t)) (add-hook 'pre-command-hook #'eldoc-box-quit-hook t t))
(defun eglot-doc--window-side () (defun eldoc-box--window-side ()
"Return 'left if the selected window is on the left, "Return 'left if the selected window is on the left,
'right if on the right. Return 'left if there is only one window." 'right if on the right. Return 'left if there is only one window."
(let ((left-window(window-at 0 0))) (let ((left-window(window-at 0 0)))
@ -125,12 +125,12 @@
'left 'left
'right))) 'right)))
(defun eglot-doc--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'."
(let* ((after-make-frame-functions nil) (let* ((after-make-frame-functions nil)
(before-make-frame-hook nil) (before-make-frame-hook nil)
(parameter (append eglot-doc-frame-parameters (parameter (append eldoc-box-frame-parameters
`((default-minibuffer-frame . ,(selected-frame)) `((default-minibuffer-frame . ,(selected-frame))
(minibuffer . ,(minibuffer-window)) (minibuffer . ,(minibuffer-window))
(left-fringe . ,(frame-char-width))))) (left-fringe . ,(frame-char-width)))))
@ -141,43 +141,43 @@ Checkout `lsp-ui-doc--make-frame', `lsp-ui-doc--move-frame'."
(main-frame (selected-frame))) (main-frame (selected-frame)))
(set-window-dedicated-p window t) (set-window-dedicated-p window t)
(redirect-frame-focus frame (frame-parent frame)) (redirect-frame-focus frame (frame-parent frame))
(set-face-attribute 'internal-border frame :inherit 'eglot-doc-border) (set-face-attribute 'internal-border frame :inherit 'eldoc-box-border)
(set-face-attribute 'default frame :background (face-attribute 'eglot-doc-body :background main-frame)) (set-face-attribute 'default frame :background (face-attribute 'eldoc-box-body :background main-frame))
;; set size ;; set size
(let* ((size (let* ((size
(window-text-pixel-size (window-text-pixel-size
window nil nil window nil nil
eglot-doc-max-pixel-width eldoc-box-max-pixel-width
eglot-doc-max-pixel-height t)) eldoc-box-max-pixel-height t))
(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))
(set-frame-size frame width height t) (set-frame-size frame width height t)
;; move position ;; move position
(set-frame-position frame (pcase (eglot-doc--window-side) ; x position + a little padding (16) (set-frame-position frame (pcase (eldoc-box--window-side) ; x position + a little padding (16)
;; display doc on right ;; display doc on right
('left (- (frame-outer-width main-frame) width 16)) ('left (- (frame-outer-width main-frame) width 16))
;; display doc on left ;; display doc on left
('right 16)) ('right 16))
;; y position + a little padding (16) ;; y position + a little padding (16)
16)) 16))
(setq eglot-doc--frame frame))) (setq eldoc-box--frame frame)))
;;;;; ElDoc ;;;;; ElDoc
(defun eglot-doc--eldoc-message-function (str &rest args) (defun eldoc-box--eldoc-message-function (str &rest args)
"Frontend for eldoc. Display STR in childframe and ARGS works like `message'." "Frontend for eldoc. Display STR in childframe and ARGS works like `message'."
(when str (when str
(eglot-doc-quit-frame) (eldoc-box-quit-frame)
(eglot-doc--display (apply #'format str args)))) (eldoc-box--display (apply #'format str args))))
(define-minor-mode eglot-doc-hover-mode (define-minor-mode eldoc-box-hover-mode
"Displays hover documentations in a childframe. This mode is buffer local." "Displays hover documentations in a childframe. This mode is buffer local."
:lighter " EGLOT-DOC" :lighter " ELDOC-BOX"
(if eglot-doc-hover-mode (if eldoc-box-hover-mode
(setq-local eldoc-message-function #'eglot-doc--eldoc-message-function) (setq-local eldoc-message-function #'eldoc-box--eldoc-message-function)
(setq-local eldoc-message-function #'eldoc-minibuffer-message))) (setq-local eldoc-message-function #'eldoc-minibuffer-message)))
(provide 'eglot-doc) (provide 'eldoc-box)
;;; eglot-doc.el ends here ;;; eldoc-box.el ends here