emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/racket-mode ec8b5142ab: Further improve use with eldoc-box


From: ELPA Syncer
Subject: [nongnu] elpa/racket-mode ec8b5142ab: Further improve use with eldoc-box
Date: Tue, 1 Oct 2024 13:01:33 -0400 (EDT)

branch: elpa/racket-mode
commit ec8b5142abaaef8335c23b98c18dee1f960b6e0b
Author: Greg Hendershott <git@greghendershott.com>
Commit: Greg Hendershott <git@greghendershott.com>

    Further improve use with eldoc-box
    
    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.)
---
 racket-scribble-anchor.el |  7 +++----
 racket-xp.el              | 49 ++++++++++++++++++++++++++++++-----------------
 2 files changed, 34 insertions(+), 22 deletions(-)

diff --git a/racket-scribble-anchor.el b/racket-scribble-anchor.el
index 62a7b60e80..26393d6e75 100644
--- a/racket-scribble-anchor.el
+++ b/racket-scribble-anchor.el
@@ -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))))))
@@ -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))
@@ -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))))
diff --git a/racket-xp.el b/racket-xp.el
index 8f0ef2f38e..a80c23007d 100644
--- a/racket-xp.el
+++ b/racket-xp.el
@@ -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
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]