greghendershott / racket-mode

Emacs major and minor modes for Racket: edit, REPL, check-syntax, debug, profile, and more.

Home Page:https://www.racket-mode.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Emacs 30 update `shr-heading`, which breaks `racket-describe`

dalugm opened this issue · comments

commented

After Emacs master's this commit

emacs-mirror/emacs@d41a5e4#diff-4da858868c50b11b923f4c1aa26611fb8502ca83edb2a7bfedda28cb260792f0R1275-R1279

 (defun shr-heading (dom &rest types)
   (shr-ensure-paragraph)
-  (apply #'shr-fontize-dom dom types)
+  (let ((start (point))
+	     (level (string-to-number
+		         (string-remove-prefix "shr-h" (symbol-name (car types))))))
+   (apply #'shr-fontize-dom dom types)
+   (put-text-property start (pos-eol) 'outline-level level))
   (shr-ensure-paragraph))

shr-heading now checks types while racket-render-tag-heading only passes a face.

Changing code like this solves my problem for now:

;; (defconst racket--shr-headings
;;   '((h1 (variable-pitch (:height 2.00)))
;;     (h2 (variable-pitch (:height 1.90)))
;;     (h3 (variable-pitch (:height 1.75)))
;;     (h4 (variable-pitch (:height 1.60)))
;;     (h5 (variable-pitch (:height 1.45)))
;;     (h6 (variable-pitch (:height 1.40)))
;;     (h7 (variable-pitch (:height 1.15)))))

;; (defun racket-render-tag-heading (dom)
;;   (let* ((tag  (car dom))
;;          (face (or (when-let (v (assq tag racket--shr-headings))
;;                      (cadr v))
;;                    `(variable-pitch (:weight bold)))))
;;     (shr-heading dom face)))

(defconst racket--shr-headings
  '((shr-h1 (variable-pitch (:height 2.00)))
    (shr-h2 (variable-pitch (:height 1.90)))
    (shr-h3 (variable-pitch (:height 1.75)))
    (shr-h4 (variable-pitch (:height 1.60)))
    (shr-h5 (variable-pitch (:height 1.45)))
    (shr-h6 (variable-pitch (:height 1.40)))
    (shr-h7 (variable-pitch (:height 1.15)))))

(defun racket-render-tag-heading (dom)
  (let* ((tag (intern (concat "shr-" (symbol-name (car dom)))))
         (types (or (assq tag racket--shr-headings)
                    '(shr-h5 (variable-pitch (:weight bold))))))
    (apply #'shr-heading dom types)))

But I don't know whether it will affect other codes...

Thanks for the report!

I do build Emacs from source periodically; I can check directly.

I'll need a little time to reload my brain with the details.

IIRC, all I'm doing is substituting other faces for the shr-hN faces. In my experience trying this with lots of Racket documentation, I found the shr-hN faces to be distracting and unhelpful. It was better to go with a plainer appearance for level headings: Just the variable-pitch face with slightly varying heights.

Given that intent, I might look at changing this to avoid calling shr-heading (if it now insists on a shr-hN face as the first "type"). Instead I might call shr-ensure-paragraph and shr-fontize-dom directly. I could also add the new outline-level text property in case that's handy for something/someone.

p.s. If it were possible to "let bind" faces or setq-local faces (like you can variables) that would be a cleaner way to do what I want here -- just temporarily change the values of the shr-hN faces, or change them locally in my buffer. I am pretty sure that's not possible, but I'll double-check.

Given that intent, I might look at changing this to avoid calling shr-heading (if it now insists on a shr-hN face as the first "type"). Instead I might call shr-ensure-paragraph and shr-fontize-dom directly. I could also add the new outline-level text property in case that's handy for something/someone.

I did that in commit e4a5dff.

I tested in:

  • Emacs 28.2 debian package
  • Emacs 30.0.50 built from source fetched a few days ago (including the commit emacs-mirror/emacs@d41a5e4 you mention above)

I'll merge that when the CI tests finish.

Thanks again for the heads-up report!

commented

Thank you, works great for me!