Skip to content

Commit

Permalink
Further improve use with eldoc-box
Browse files Browse the repository at this point in the history
1. Enable truncate-lines, as does racket-describe-mode. Avoids extra
line breaks and line continuation marks in the fringe. Example where
this helps: Set racket-xp-eldoc-level to 'complete, and get a hover
for the Racket require or provide forms.

2. Instead of copy-pasta-ing most of eldoc-box-buffer-setup, actually
call it, but within a cl-letf that "no-op"s visual-line-mode and
eldoc-box-buffer-hook. Although this may seem too clever, it should be
more resilient to eldoc-box-buffer-setup changing internally in
beneficial or neutral ways; no ongoing copy-pasta. (In the less-likely
worst case where it adds some new undesired behavior, sure, we will
have to neuter that using a technique like cl-letf.)
  • Loading branch information
greghendershott committed Oct 1, 2024
1 parent 325c14d commit ec8b514
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 22 deletions.
7 changes: 3 additions & 4 deletions racket-scribble-anchor.el
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
(kill-buffer buf)))
(with-current-buffer (get-buffer-create name)
(goto-char (point-min))
;; width 76 for company-quickhelp-mode
(racket--scribble-path+anchor-insert path anchor 76)
(racket--scribble-path+anchor-insert path anchor)
(goto-char (point-min))
(setq buffer-read-only t)
(current-buffer))))))
Expand Down Expand Up @@ -57,7 +56,7 @@ Uses `racket--path+anchor-cache'."
(ring-insert racket--path+anchor-ring item)
str))))

(defun racket--scribble-path+anchor-insert (path anchor &optional width)
(defun racket--scribble-path+anchor-insert (path anchor)
(let* ((tramp-verbose 2) ;avoid excessive tramp messages
(dom (racket--html-file->dom path))
(dom (racket--elements-for-anchor dom anchor))
Expand All @@ -68,7 +67,7 @@ Uses `racket--path+anchor-cache'."
(save-excursion
(let ((shr-use-fonts nil)
(shr-external-rendering-functions `((span . ,#'racket-render-tag-span)))
(shr-width width))
(shr-width 76))
(shr-insert-document dom)))
(while (re-search-forward (string racket--scribble-temp-nbsp) nil t)
(replace-match " " t t))))
Expand Down
49 changes: 31 additions & 18 deletions racket-xp.el
Original file line number Diff line number Diff line change
Expand Up @@ -1270,24 +1270,37 @@ else returns STR."

;;; eldoc-box

(defun racket-xp-eldoc-box-buffer-setup-function (_original-buffer)
"Avoid the default markdown adjustments and `visual-line-mode'."
;; First we need to replicate most of `eldoc-box-buffer-setup'. We
;; might even need to update this, if that evolves. (Although not my
;; ideal design choice, I appreciate the eldoc-box author took time
;; to do something for us; so let's work with it.)
(setq mode-line-format nil)
(setq header-line-format nil)
(setq-local cursor-type t)
(when (and (bound-and-true-p global-tab-line-mode)
(boundp 'tab-line-format))
(setq tab-line-format nil))
(buffer-face-set 'eldoc-box-body)
(when (boundp 'eldoc-box-hover-mode)
(setq eldoc-box-hover-mode t))
;; Finally what we care about: Avoid `eldoc-buffer-setup-hook', and,
;; disable `visual-line-mode'.
(visual-line-mode -1))
(defun racket-xp-eldoc-box-buffer-setup-function (original-buffer)
"Called by eldoc-box with its child frame buffer current.
Although most of `eldoc-box-buffer-setup' is necessary for
eldoc-box to work correctly, we want to avoid two default
behaviors:
1. It runs `eldoc-buffer-hook' functions to massage markdown; N/A.
2. It enables `visual-line-mode', which might add line breaks.
To further avoid extra line breaks and continuation marks in the
fringe, we also want to enable `truncate-lines', as does
`racket-describe-mode'.
Extra line breaks are especially bad when `racket-xp-eldoc-level'
is \\='complete and we're showing a fragment of full Racket
documentation HTML, which makes heavy use of HTML tables, and
we've worked hard to help shr to convert these correctly."
(when (and (fboundp 'eldoc-box-buffer-setup)
(boundp 'eldoc-box-buffer-hook))
;; Call `eldoc-box-buffer-setup' for most of the work it does --
;; but during the dynamic extent of the call, "disable"
;; visual-line-mode and the hook.
(cl-letf (((symbol-function #'visual-line-mode) #'ignore)
((default-value 'eldoc-box-buffer-hook) nil))
(eldoc-box-buffer-setup original-buffer))
;; Although the above should suffice, belt+suspenders.
(visual-line-mode -1)
;; Finally, enable `truncate-lines'.
(setq-local truncate-lines t)))

;;; Mode line status

Expand Down

0 comments on commit ec8b514

Please sign in to comment.