greghendershott / racket-mode

Emacs major and minor modes for Racket: edit, REPL, check-syntax, debug, profile, packages, and more.
https://www.racket-mode.com/
GNU General Public License v3.0
682 stars 93 forks source link

Issue viewing r5rs documents using `racket-xp-describe` #649

Closed j-minster closed 1 year ago

j-minster commented 1 year ago

Hello Greg. I've come across an issue when using #lang sicp (found here). I try to view the documentation for a certain function from that '#lang' (say define), I place my point on define in my source buffer, then hit my binding for racket-xp-describe. This results in an empty shr buffer. It does not, for example, give this error when not using #lang sicp. Say I am using #lang racket and try to look at the docs for define, racket-xp-describe drops me into a lovely rendered buffer with exactly what I want.

Anyway, here is the backtrace, for when I use #lang sicp and want documentation:

Debugger entered--Lisp error: (wrong-type-argument listp "")
  shr-descend("")
  shr-insert-document("")
  racket--describe-insert-dom("/Applications/Racket v8.6/doc/r5rs/r5rs-std/r5rs-Z-H-8.html" "%_idx_194" "")
  racket--do-describe(("/Applications/Racket v8.6/doc/r5rs/r5rs-std/r5rs-Z-H-8.html" . "%_idx_194") nil "define")
  racket-xp-describe(nil)
  funcall-interactively(racket-xp-describe nil)
  command-execute(racket-xp-describe)

I traced it back to racket-describe.el, line 80, where racket--scribble-path->shr-dom is called on path. Here is the r5rs package whose documentation I'm trying to view: (link). I swapped the offending function for racket--html-file->dom and the issue seems resolved. I am not proficient enough in Elisp to properly fix this (ie. differentiate somehow between scribble docs and html, then pick the appropriate function), hence this issue rather than a pull-request. It seems as though the package does have proper scribble-formatted docs, but that either they're not being accessed or the 'plain html' docs are not handled correctly.

Let me know if you need more from me.

Thanks for all your work.

Here is the output of bug-report:

((alist-get 'racket-mode package-alist))
((emacs-version "28.2")
 (system-type darwin)
 (x-gtk-use-system-tooltips UNDEFINED)
 (major-mode emacs-lisp-mode)
 (racket--el-source-dir "/Users/jackminster/.emacs.d/.local/straight/build-28.2/racket-mode/")
 (racket--rkt-source-dir "/Users/jackminster/.emacs.d/.local/straight/build-28.2/racket-mode/racket/")
 (racket-program "racket")
 (racket-command-timeout 10)
 (racket-path-from-emacs-to-racket-function UNDEFINED)
 (racket-path-from-racket-to-emacs-function UNDEFINED)
 (racket-browse-url-function racket-browse-url-using-temporary-file)
 (racket-documentation-search-location "https://docs.racket-lang.org/search/index.html?q=%s")
 (racket-xp-after-change-refresh-delay 1)
 (racket-xp-mode-lighter
  (:eval
   (racket--xp-mode-lighter)))
 (racket-xp-highlight-unused-regexp "^[^_]")
 (racket-repl-buffer-name-function nil)
 (racket-submodules-to-run
  ((test)
   (main)))
 (racket-memory-limit 2048)
 (racket-error-context medium)
 (racket-repl-history-directory "~/.emacs.d/.local/cache/racket-mode/")
 (racket-history-filter-regexp "\\`\\s *\\'")
 (racket-images-inline t)
 (racket-imagemagick-props nil)
 (racket-images-keep-last 100)
 (racket-images-system-viewer "open")
 (racket-pretty-print t)
 (racket-use-repl-submit-predicate nil)
 (racket-pretty-print t)
 (racket-indent-curly-as-sequence t)
 (racket-indent-sequence-depth 0)
 (racket-pretty-lambda nil)
 (racket-smart-open-bracket-enable nil)
 (racket-module-forms "\\s(\\(?:module[*+]?\\|library\\)")
 (racket-logger-config
  ((cm-accomplice . warning)
   (GC . info)
   (module-prefetch . warning)
   (optimizer . info)
   (racket/contract . error)
   (sequence-specialization . info)
   (* . fatal)))
 (racket-show-functions
  (racket-show-pseudo-tooltip)))
(enabled-minor-modes
 (+lsp-optimization-mode)
 (+popup-mode)
 (auto-composition-mode)
 (auto-compression-mode)
 (auto-encryption-mode)
 (auto-fill-mode)
 (auto-save-mode)
 (auto-save-visited-mode)
 (better-jumper-local-mode)
 (better-jumper-mode)
 (corfu-doc-mode)
 (corfu-mode)
 (display-battery-mode)
 (display-line-numbers-mode)
 (display-time-mode)
 (eldoc-mode)
 (electric-indent-mode)
 (eros-mode)
 (evil-escape-mode)
 (evil-goggles-mode)
 (evil-local-mode)
 (evil-mode)
 (evil-snipe-local-mode)
 (evil-snipe-mode)
 (evil-snipe-override-local-mode)
 (evil-snipe-override-mode)
 (evil-surround-mode)
 (file-name-shadow-mode)
 (font-lock-mode)
 (gcmh-mode)
 (general-override-mode)
 (global-corfu-mode)
 (global-eldoc-mode)
 (global-evil-surround-mode)
 (global-font-lock-mode)
 (global-git-commit-mode)
 (global-hl-line-mode)
 (global-org-modern-mode)
 (global-so-long-mode)
 (global-undo-fu-session-mode)
 (highlight-numbers-mode)
 (highlight-quoted-mode)
 (hl-line-mode)
 (hl-todo-mode)
 (lin-global-mode)
 (lin-mode)
 (line-number-mode)
 (mac-mouse-wheel-mode)
 (marginalia-mode)
 (ns-auto-titlebar-mode)
 (outline-minor-mode)
 (override-global-mode)
 (persp-mode)
 (projectile-mode)
 (pyvenv-tracking-mode)
 (rainbow-delimiters-mode)
 (recentf-mode)
 (save-place-mode)
 (savehist-mode)
 (semantic-minor-modes-format)
 (shell-dirtrack-mode)
 (show-paren-mode)
 (smartparens-global-mode)
 (smartparens-mode)
 (transient-mark-mode)
 (undo-fu-mode)
 (undo-fu-session-mode)
 (vertico-mode)
 (vertico-multiform-mode)
 (which-key-mode)
 (windmove-mode)
 (window-divider-mode)
 (winner-mode)
 (ws-butler-global-mode)
 (ws-butler-mode)
 (yas-global-mode)
 (yas-minor-mode))
(disabled-minor-modes
 (+emacs-lisp-ert-mode)
 (+emacs-lisp-non-package-mode)
 (+popup-buffer-mode)
 (abbrev-mode)
 (ace-window-display-mode)
 (ace-window-mode)
 (archive-subfile-mode)
 (auto-fill-function)
 (auto-revert-mode)
 (auto-revert-tail-mode)
 (avy-linum-mode)
 (blink-cursor-mode)
 (buffer-face-mode)
 (buffer-read-only)
 (button-mode)
 (cl-old-struct-compat-mode)
 (column-number-mode)
 (compilation-minor-mode)
 (compilation-shell-minor-mode)
 (completion-in-region-mode)
 (consult-notes-denote-mode)
 (consult-notes-org-roam-mode)
 (consult-preview-at-point-mode)
 (context-menu-mode)
 (cursor-intangible-mode)
 (cursor-sensor-mode)
 (dash-fontify-mode)
 (defining-kbd-macro)
 (denote-dired-mode)
 (diff-auto-refine-mode)
 (diff-minor-mode)
 (dired-hide-details-mode)
 (dired-isearch-filenames-mode)
 (doom-big-font-mode)
 (dtrt-indent-global-mode)
 (dtrt-indent-mode)
 (edit-indirect--overlay)
 (eglot--managed-mode)
 (electric-layout-mode)
 (electric-quote-mode)
 (ert--current-run-stats)
 (eshell-arg-mode)
 (eshell-command-mode)
 (eshell-proc-mode)
 (eshell-prompt-mode)
 (eshell-var-mode)
 (flymake-mode)
 (flyspell-mode)
 (format-all-mode)
 (general-override-local-mode)
 (git-commit-mode)
 (git-gutter-mode)
 (global-auto-revert-mode)
 (global-dash-fontify-mode)
 (global-display-line-numbers-mode)
 (global-git-gutter-mode)
 (global-hl-todo-mode)
 (global-prettify-symbols-mode)
 (global-reveal-mode)
 (global-semantic-highlight-edits-mode)
 (global-semantic-highlight-func-mode)
 (global-semantic-show-parser-state-mode)
 (global-semantic-show-unmatched-syntax-mode)
 (global-semantic-stickyfunc-mode)
 (global-tree-sitter-mode)
 (global-ts-fold-mode)
 (global-visual-line-mode)
 (global-whitespace-mode)
 (global-whitespace-newline-mode)
 (horizontal-scroll-bar-mode)
 (hs-minor-mode)
 (ibuffer-auto-mode)
 (indent-tabs-mode)
 (isearch-mode)
 (ispell-minor-mode)
 (jit-lock-debug-mode)
 (lock-file-mode)
 (mac-auto-ascii-mode)
 (mac-auto-operator-composition-mode)
 (mac-font-panel-mode)
 (mail-abbrevs-mode)
 (markdown-live-preview-mode)
 (menu-bar-mode)
 (mml-mode)
 (mouse-wheel-mode)
 (next-error-follow-minor-mode)
 (org-capture-mode)
 (org-cdlatex-mode)
 (org-list-checkbox-radio-mode)
 (org-modern-mode)
 (org-src-mode)
 (org-table-follow-field-mode)
 (org-table-header-line-mode)
 (orgtbl-mode)
 (overwrite-mode)
 (paragraph-indent-minor-mode)
 (prettify-symbols-mode)
 (prot-simple-monocle)
 (pyvenv-mode)
 (racket-smart-open-bracket-mode)
 (racket-xp-mode)
 (rcirc-ignore-buffer-activity-flag)
 (rcirc-low-priority-flag)
 (rcirc-multiline-minor-mode)
 (rcirc-omit-mode)
 (rcirc-track-minor-mode)
 (rectangle-mark-mode)
 (reveal-mode)
 (rich-minority-mode)
 (rst-minor-mode)
 (semantic-highlight-edits-mode)
 (semantic-highlight-func-mode)
 (semantic-mode)
 (semantic-show-parser-state-mode)
 (semantic-show-unmatched-syntax-mode)
 (semantic-stickyfunc-mode)
 (server-mode)
 (sh-electric-here-document-mode)
 (shell-command-with-editor-mode)
 (show-smartparens-global-mode)
 (show-smartparens-mode)
 (size-indication-mode)
 (smartparens-global-strict-mode)
 (smartparens-strict-mode)
 (so-long-minor-mode)
 (solaire-global-mode)
 (solaire-mode)
 (tab-bar-history-mode)
 (tab-bar-mode)
 (table-fixed-width-mode)
 (table-mode-indicator)
 (tar-subfile-mode)
 (temp-buffer-resize-mode)
 (text-scale-mode)
 (tool-bar-mode)
 (tooltip-mode)
 (transient-resume-mode)
 (tree-sitter-hl-mode)
 (tree-sitter-mode)
 (ts-fold-mode)
 (unify-8859-on-decoding-mode)
 (unify-8859-on-encoding-mode)
 (url-handler-mode)
 (use-hard-newlines)
 (vc-parent-buffer)
 (view-mode)
 (visible-mode)
 (visual-line-mode)
 (whitespace-mode)
 (whitespace-newline-mode)
 (with-editor-mode)
 (xref-etags-mode))
greghendershott commented 1 year ago

Thanks for reporting!

The support for racket-describe (as well as for getting a brief doc buffer when you press C-h while using company-mode auto-completion) is assuming HTML produced by Scribble. For example it tries to extract the inner main div, not the surrounding apparatus like the TOC left nav bar that doesn't work very well in shr buffers.

It looks like it should be simple to make sure there is a fallback path for other HTML pages generated by other tools, such as the ones for r5rs.

In fact I already pushed a commit (to a topic branch, not yet merged to the main branch) that I believe handles this. I might just sleep on it and test it a bit, before merging.