Inhibit childframe display when moving point (#21)

(only in at-point mode)
This commit is contained in:
Yuan Fu 2019-10-03 00:38:32 -04:00
parent 8be8ef42d0
commit fb983d973e
No known key found for this signature in database
GPG Key ID: 56E19BC57664A442

View File

@ -125,6 +125,9 @@ Run inside the new buffer.")
Each function runs inside the new frame and receives the main frame as argument.") Each function runs inside the new frame and receives the main frame as argument.")
;;;;; Function ;;;;; Function
(defvar eldoc-box--inhibit-childframe nil
"If non-nil, inhibit display of childframe.")
(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.")
@ -293,42 +296,62 @@ FRAME is the childframe, WINDOW is the primary window."
;; move position ;; move position
(set-frame-position frame (car pos) (cdr pos)))) (set-frame-position frame (car pos) (cdr pos))))
(defvar eldoc-box--inhibit-childframe-timer nil
"When this timer is on, inhibit childframe display.
Intended for follow-cursor to disable display when moving cursor.")
(defun eldoc-box--inhibit-childframe-for (sec)
"Inhibit display of childframe for SEC seconds."
(when eldoc-box--inhibit-childframe-timer
(cancel-timer eldoc-box--inhibit-childframe-timer))
(eldoc-box-quit-frame)
(setq eldoc-box--inhibit-childframe t
eldoc-box--inhibit-childframe-timer
(run-with-timer sec nil
(lambda ()
(setq eldoc-box--inhibit-childframe nil)))))
(defun eldoc-box--follow-cursor () (defun eldoc-box--follow-cursor ()
"Make childframe follow cursor in at-point mode." "Make childframe follow cursor in at-point mode."
(when (frame-live-p eldoc-box--frame) (if (not (equal this-command #'self-insert-command))
(eldoc-box--update-childframe-geometry (eldoc-box--inhibit-childframe-for 0.2)
eldoc-box--frame (frame-selected-window eldoc-box--frame)))) (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.
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) (if eldoc-box--inhibit-childframe
(before-make-frame-hook nil) ;; if inhibit display, do nothing
(parameter (append eldoc-box-frame-parameters eldoc-box--frame
`((default-minibuffer-frame . ,(selected-frame)) (let* ((after-make-frame-functions nil)
(minibuffer . ,(minibuffer-window)) (before-make-frame-hook nil)
(left-fringe . ,(frame-char-width))))) (parameter (append eldoc-box-frame-parameters
window frame `((default-minibuffer-frame . ,(selected-frame))
(main-frame (selected-frame))) (minibuffer . ,(minibuffer-window))
(if (and eldoc-box--frame (frame-live-p eldoc-box--frame)) (left-fringe . ,(frame-char-width)))))
(progn (setq frame eldoc-box--frame) window frame
(setq window (frame-selected-window frame)) (main-frame (selected-frame)))
;; in case the main frame changed (if (and eldoc-box--frame (frame-live-p eldoc-box--frame))
(set-frame-parameter frame 'parent-frame main-frame)) (progn (setq frame eldoc-box--frame)
(setq window (display-buffer-in-child-frame (setq window (frame-selected-window frame))
buffer ;; in case the main frame changed
`((child-frame-parameters . ,parameter)))) (set-frame-parameter frame 'parent-frame main-frame))
(setq frame (window-frame window))) (setq window (display-buffer-in-child-frame
(set-face-attribute 'fringe frame :background nil :inherit 'eldoc-box-body) buffer
(fringe-mode 3) `((child-frame-parameters . ,parameter))))
(set-window-dedicated-p window t) (setq frame (window-frame window)))
(redirect-frame-focus frame (frame-parent frame)) (set-face-attribute 'fringe frame :background nil :inherit 'eldoc-box-body)
(set-face-attribute 'internal-border frame :inherit 'eldoc-box-border) (fringe-mode 3)
;; set size (set-window-dedicated-p window t)
(eldoc-box--update-childframe-geometry frame window) (redirect-frame-focus frame (frame-parent frame))
(setq eldoc-box--frame frame) (set-face-attribute 'internal-border frame :inherit 'eldoc-box-border)
(run-hook-with-args 'eldoc-box-frame-hook main-frame) ;; set size
(make-frame-visible frame))) (eldoc-box--update-childframe-geometry frame window)
(setq eldoc-box--frame frame)
(run-hook-with-args 'eldoc-box-frame-hook main-frame)
(make-frame-visible frame))))
;;;;; ElDoc ;;;;; ElDoc