From 4c88ceecc62f810b928619a3aacacfafd15ccd8d Mon Sep 17 00:00:00 2001 From: Yuan Fu Date: Tue, 13 Aug 2019 13:44:28 +0800 Subject: [PATCH] Add buffer and frame hooks --- README.org | 3 +++ eldoc-box.el | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/README.org b/README.org index d2cc9da..70568ef 100644 --- a/README.org +++ b/README.org @@ -23,6 +23,9 @@ It is also available on [[https://melpa.org/#/eldoc-box][MELPA]] ** Face - =eldoc-box-border= :: Adjust =:background= of this face for border color. - =eldoc-box-body= :: Default face used by childframe. I suggest to use a nice Sans Serif font such as Source Sans Pro, and a lighter or darker background. +** Hooks +- =eldoc-box-buffer-hook= :: Hook run after buffer for doc is setup.Run inside the new buffer. +- =eldoc-box-frame-hook= :: Hook run after doc frame is setup but just before it is made visible.Each function runs inside the child frame and receives the main frame as argument. ** Variable - =eldoc-box-max-pixel-width= & =eldoc-box-max-pixel-height= :: Set them according to the screen resolution of your machine. - =eldoc-box-only-multi-line= :: Set this to non-nil and eldoc-box only display multi-line message in childframe. One line messages are left in minibuffer. diff --git a/eldoc-box.el b/eldoc-box.el index cb934b0..387adaf 100644 --- a/eldoc-box.el +++ b/eldoc-box.el @@ -116,6 +116,14 @@ It will be passes with two arguments: WIDTH and HEIGHT of the childframe.") (defvar eldoc-box-fringe-use-same-bg t "T means fringe's background color is set to as same as that of default.") +(defvar eldoc-box-buffer-hook nil + "Hook run after buffer for doc is setup. +Run inside the new buffer.") + +(defvar eldoc-box-frame-hook nil + "Hook run after doc frame is setup but just before it is made visible. +Each function runs inside the new frame and receives the main frame as argument.") + ;;;;; Function (defvar eldoc-box--frame nil ;; A backstage variable "The frame to display doc.") @@ -186,7 +194,8 @@ You can use C-g to hide the doc." (setq eldoc-box-hover-mode t) (erase-buffer) (insert str) - (goto-char (point-min))) + (goto-char (point-min)) + (run-hook-with-args 'eldoc-box-buffer-hook)) (eldoc-box--get-frame doc-buffer)))) @@ -307,6 +316,7 @@ Checkout `lsp-ui-doc--make-frame', `lsp-ui-doc--move-frame'." ;; set size (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)))