Skip to content

Commit

Permalink
Improve formatting for eldoc-box
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
greghendershott committed Sep 26, 2024
1 parent 35f3817 commit d2a81a7
Showing 1 changed file with 37 additions and 5 deletions.
42 changes: 37 additions & 5 deletions racket-xp.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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."
Expand Down

0 comments on commit d2a81a7

Please sign in to comment.