From d2a81a7c62cfb3f3831386ec75dca47024a0abd6 Mon Sep 17 00:00:00 2001 From: Greg Hendershott Date: Thu, 26 Sep 2024 13:15:17 -0400 Subject: [PATCH] Improve formatting for eldoc-box We don't want visual-line-mode enabled. We don't need the default markdown functions. AFAICT the only way to handle this is with a somewhat ugly hack, as discussed in the comment. --- racket-xp.el | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/racket-xp.el b/racket-xp.el index b7fd8694..81ee04ff 100644 --- a/racket-xp.el +++ b/racket-xp.el @@ -294,9 +294,7 @@ commands directly to whatever keys you prefer. nil t) (add-hook 'eldoc-documentation-functions #'racket-xp-eldoc-point - nil t)) - (when (boundp 'eldoc-box-buffer-hook) - (setq-local eldoc-box-buffer-hook nil))) + nil t))) (t (racket-show nil) (racket--xp-clear) @@ -324,6 +322,34 @@ commands directly to whatever keys you prefer. hook t)))))) +;; We do want to customize `eldoc-box-buffer-hook' because: +;; +;; - We don't want the default markdown adjustments (best case they do +;; unnecessary work, worst case they might mis-format some things) +;; +;; - We want to disable `visual-line-mode'. +;; +;; Although a buffer-local hook is the usual way to handle something +;; like this, it doesn't work for eldoc-box-buffer-hook, because the +;; hook with /its/ buffer current, not ours. So we must resort to +;; munging the global hook, and either doing something special for us, +;; or doing the original default (so it keeps working when used by +;; other modes that do use markdown docs). Sort of the moral +;; equivalent of advising the hook. +(defvar racket--orig-eldoc-box-buffer-hook nil) +(defun racket-xp-eldoc-box-buffer-hook () + (if (next-single-property-change (point-min) 'racket-xp-eldoc) + (visual-line-mode -1) + (run-hook-with-args 'racket--orig-eldoc-box-buffer-hook))) +(eval-after-load 'eldoc-box + (when (boundp 'eldoc-box-buffer-hook) + (unless (member #'racket-xp-eldoc-box-buffer-hook + eldoc-box-buffer-hook) + (setq racket--orig-eldoc-box-buffer-hook + eldoc-box-buffer-hook) + (setq eldoc-box-buffer-hook + (list #'racket-xp-eldoc-box-buffer-hook))))) + ;;; Change hook and idle timer (defvar-local racket--xp-annotate-idle-timer nil) @@ -666,12 +692,18 @@ racket-xp-doc and help-echo text properties added by ('summary (racket--cmd/await nil `(bluebox ,tag))) ('complete (racket--path+anchor->string path anchor))))) (when (or help-echo str) - (racket--eldoc-do-callback callback thing (concat help-echo str)))))) + (racket--eldoc-do-callback callback thing + (propertize + (concat help-echo str) + 'racket-xp-eldoc t)))))) (_ (pcase (racket--get-text-property/bounds pos 'help-echo) (`(,str ,beg ,end) (let ((thing (buffer-substring-no-properties beg end))) - (racket--eldoc-do-callback callback thing str))))))) + (racket--eldoc-do-callback callback thing + (propertize + str + 'racket-xp-eldoc t)))))))) (defun racket--get-text-property/bounds (pos prop) "Like `get-text-property' but also returning the bounds."