diff --git a/README.org b/README.org index 22d9bc2..badaccf 100644 --- a/README.org +++ b/README.org @@ -39,6 +39,7 @@ It is also available on [[https://melpa.org/#/eldoc-box][MELPA]]. - =eldoc-box-fringe-use-same-bg= :: Whether to set fringe’s background color to as same as that of default. Default to t. - =eldoc-box-self-insert-command-list= :: By default =eldoc-box-hover-at-point-mode= only keeps childframe display while you are typing (ie, when =this-command= is =self-insert-command=). But if you bind something else to your keys, eldoc-box can’t recognize it and will hide childframe when you type. Add your command to this list so eldoc-box won’t hide childframe when this command is called. - =eldoc-box-lighter= :: Lighter displayed on the mode line. +- =eldoc-box-use-extra-commands-map= :: Set this to non-nil, and =eldoc-box-extra-commands-map= will be activated when childframe is visible, deactivated when the frame is invisble. =eldoc-box-extra-commands-map= makes ~scroll-other-window~, ~scroll-other-window-down~, ~beginning-of-buffer-other-window~ and ~end-of-buffer-other-window~ activated on the eldoc-box's childframe. When eldoc-box's childframe is invisible, these commands will behave as they are. ** Use with eglot diff --git a/eldoc-box.el b/eldoc-box.el index e35f162..8704af4 100644 --- a/eldoc-box.el +++ b/eldoc-box.el @@ -62,6 +62,7 @@ ;; - ‘eldoc-box-cleanup-interval’ ;; - ‘eldoc-box-fringe-use-same-bg’ ;; - ‘eldoc-box-self-insert-command-list’ +;; - ‘eldoc-box-use-extra-commands-map’ ;;; Code: @@ -117,6 +118,10 @@ This separator is used for the documentation shown in ‘eldoc-box-bover-mode’ but not ‘eldoc-box-help-at-point’." :type 'string) +(defcustom eldoc-box-use-extra-commands-map nil + "If non-nil, use `eldoc-box-extra-commands-map' when doc frame is visible." + :type 'boolean) + (defvar eldoc-box-frame-parameters '(;; make the childframe unseen when first created (left . -1) @@ -209,6 +214,11 @@ See `eldoc-box-inhibit-display-when-moving'." (defun eldoc-box-quit-frame () "Hide documentation childframe." (interactive) + ;; Remove `eldoc-box-extra-commands-map'. + (when eldoc-box-use-extra-commands-map + (dolist (mode '(eldoc-box-hover-mode eldoc-box-hover-at-point-mode)) + (setq minor-mode-overriding-map-alist + (assq-delete-all mode minor-mode-overriding-map-alist)))) (when (and eldoc-box--frame (frame-live-p eldoc-box--frame)) (make-frame-invisible eldoc-box--frame t))) @@ -281,6 +291,8 @@ If (point) != last point, cleanup frame.") ;; Please compiler. (defvar eldoc-box-hover-mode) +(defvar eldoc-box-extra-commands-map) + (defun eldoc-box--display (str) "Display STR in childframe. STR has to be a proper documentation, not empty string, not nil, etc." @@ -456,8 +468,14 @@ Checkout `lsp-ui-doc--make-frame', `lsp-ui-doc--move-frame'." (set-face-background 'child-frame-border (face-attribute 'eldoc-box-border :background) frame)) - ;; set size + ;; Set size. (eldoc-box--update-childframe-geometry frame window) + ;; Make extra commands available when `eldoc-box--frame' visible only. + (when eldoc-box-use-extra-commands-map + (dolist (mode '(eldoc-box-hover-mode eldoc-box-hover-at-point-mode)) + (setf (alist-get mode minor-mode-overriding-map-alist) + eldoc-box-extra-commands-map))) + ;; Set frame. (setq eldoc-box--frame frame) (with-selected-frame frame (run-hook-with-args 'eldoc-box-frame-hook main-frame)) @@ -590,6 +608,44 @@ display the docs in echo area depending on (when (eldoc-box--eldoc-message-function "%s" doc) (eldoc-display-in-echo-area docs interactive)))) +(defun eldoc-box-scroll-up (&optional n) + "Scroll text of eldoc-box window upward N lines." + (interactive "p") + (with-selected-frame eldoc-box--frame + (with-current-buffer eldoc-box--buffer + (scroll-up n)))) + +(defun eldoc-box-scroll-down (&optional n) + "Scroll text of eldoc-box window down N lines." + (interactive "p") + (eldoc-box-scroll-up (- (or n 1)))) + +(defun eldoc-box-end (&optional n) + "Scroll text of eldoc-box window to the end. + +With numeric arg N, put window N/10 of the way from the end." + (interactive "P") + (with-selected-frame eldoc-box--frame + (with-current-buffer eldoc-box--buffer + (with-no-warnings + (end-of-buffer n))))) + +(defun eldoc-box-beginning (&optional n) + "Scroll text of eldoc-box window to the beginning. + +With numeric arg N, put window N/10 of the way from the beginning." + (interactive "P") + (eldoc-box-end (- 10 (if (numberp n) n 0)))) + +(defvar eldoc-box-extra-commands-map + (let ((map (make-sparse-keymap))) + (define-key map [remap scroll-other-window] #'eldoc-box-scroll-up) + (define-key map [remap scroll-other-window-down] #'eldoc-box-scroll-down) + (define-key map [remap beginning-of-buffer-other-window] #'eldoc-box-beginning) + (define-key map [remap end-of-buffer-other-window] #'eldoc-box-end) + map) + "Extra commands keymap for `eldoc-box'.") + ;;;###autoload (define-minor-mode eldoc-box-hover-mode "Display hover documentations in a childframe.