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

Documentation in describe-mode isn't justified in the presence of line numbers #627

Closed countvajhula closed 2 years ago

countvajhula commented 2 years ago

With global-line-numbers-mode enabled, describe buffers open with line numbers in the leftmost column. This causes the documentation to spill text over on each line, probably because it is estimating the line width without taking the line numbers column into account.

Before, with line numbers:

Screen Shot 2022-06-27 at 12 48 56 PM

A workaround is to disable line numbers in racket-describe-mode buffers:

(defun my-disable-line-numbers ()
  (display-line-numbers-mode -1))

(use-package racket-mode
  :hook (... (racket-describe-mode . my-disable-line-numbers)))

After, without line numbers:

Screen Shot 2022-06-27 at 12 51 35 PM

Possible solutions, either: (a) disable line numbers upon entry to racket-describe-mode, or (b) take the line numbers column width into account. Of these, (b) would probably be the more robust solution, as it could be general and handle "all" cases where there may be things taking up column-width on the screen that aren't reflected in just the buffer contents.

((alist-get 'racket-mode package-alist))
((emacs-version "27.1")
 (system-type darwin)
 (x-gtk-use-system-tooltips UNDEFINED)
 (major-mode racket-mode)
 (racket--el-source-dir "/Users/siddhartha/.emacs.d/straight/build/racket-mode/")
 (racket--rkt-source-dir "/Users/siddhartha/.emacs.d/straight/build/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/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)
   (racket-mode-debugger . info)
   (sequence-specialization . info)
   (* . fatal)))
 (racket-show-functions
  (racket-show-pseudo-tooltip)))
(enabled-minor-modes
 (auto-composition-mode)
 (auto-compression-mode)
 (auto-encryption-mode)
 (auto-fill-mode)
 (auto-save-mode)
 (buffer-ring-mode)
 (column-number-mode)
 (company-box-mode)
 (company-mode)
 (company-prescient-mode)
 (counsel-mode)
 (display-line-numbers-mode)
 (eldoc-mode)
 (electric-indent-mode)
 (evil-collection-unimpaired-mode)
 (evil-commentary-mode)
 (evil-goggles-mode)
 (evil-local-mode)
 (evil-matchit-mode)
 (evil-mc-mode)
 (evil-mode)
 (evil-surround-mode)
 (file-name-shadow-mode)
 (font-lock-mode)
 (general-override-mode)
 (global-auto-revert-mode)
 (global-company-mode)
 (global-display-line-numbers-mode)
 (global-eldoc-mode)
 (global-evil-collection-unimpaired-mode)
 (global-evil-matchit-mode)
 (global-evil-mc-mode)
 (global-evil-surround-mode)
 (global-font-lock-mode)
 (global-git-commit-mode)
 (global-tree-sitter-mode)
 (global-undo-tree-mode)
 (global-visual-line-mode)
 (global-whitespace-mode)
 (hs-minor-mode)
 (ivy-mode)
 (ivy-prescient-mode)
 (ivy-rich-mode)
 (mac-mouse-wheel-mode)
 (magit-auto-revert-mode)
 (menu-bar-mode)
 (override-global-mode)
 (prescient-persist-mode)
 (projectile-mode)
 (racket-xp-mode)
 (recentf-mode)
 (semantic-minor-modes-format)
 (shell-dirtrack-mode)
 (show-paren-mode)
 (straight-package-neutering-mode)
 (straight-use-package-mode)
 (symex-editing-mode)
 (symex-mode)
 (telephone-line-mode)
 (tooltip-mode)
 (transient-mark-mode)
 (undo-tree-mode)
 (visual-line-mode)
 (winner-mode)
 (yas-global-mode)
 (yas-minor-mode))
(disabled-minor-modes
 (abbrev-mode)
 (ace-window-display-mode)
 (ace-window-mode)
 (adaptive-wrap-prefix-mode)
 (all-the-icons-dired-mode)
 (archive-subfile-mode)
 (auto-fill-function)
 (auto-revert-mode)
 (auto-revert-tail-mode)
 (auto-save-visited-mode)
 (avy-linum-mode)
 (beacon-mode)
 (blink-cursor-mode)
 (buffer-face-mode)
 (buffer-read-only)
 (caps-lock-mode)
 (centaur-tabs-local-mode)
 (centaur-tabs-mode)
 (cider--debug-mode)
 (cider-auto-test-mode)
 (cider-enlighten-mode)
 (cider-mode)
 (cider-popup-buffer-mode)
 (cl-old-struct-compat-mode)
 (company-search-mode)
 (compilation-minor-mode)
 (compilation-shell-minor-mode)
 (completion-in-region-mode)
 (dash-fontify-mode)
 (defining-kbd-macro)
 (delete-selection-mode)
 (desktop-save-mode)
 (diff-auto-refine-mode)
 (diff-minor-mode)
 (dired-hide-details-mode)
 (dired-isearch-filenames-mode)
 (dired-omit-mode)
 (edebug-mode)
 (edebug-x-mode)
 (electric-layout-mode)
 (electric-quote-mode)
 (enriched-mode)
 (erc-irccontrols-mode)
 (erc-keep-place-mode)
 (erc-move-to-prompt-mode)
 (erc-noncommands-mode)
 (erc-readonly-mode)
 (erc-scrolltobottom-mode)
 (erc-smiley-mode)
 (erc-unmorse-mode)
 (evil-cleverparens-mode)
 (evil-collection-magit-toggle-text-minor-mode)
 (flyspell-mode)
 (geiser-autodoc-mode)
 (geiser-mode)
 (geiser-smart-tab-mode)
 (general-override-local-mode)
 (git-commit-mode)
 (git-timemachine-mode)
 (global-dash-fontify-mode)
 (global-hl-line-mode)
 (global-linum-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-whitespace-newline-mode)
 (hl-line-mode)
 (horizontal-scroll-bar-mode)
 (ibuffer-auto-mode)
 (image-minor-mode)
 (isearch-mode)
 (ispell-minor-mode)
 (ivy-rich-project-root-cache-mode)
 (jedi-mode)
 (jit-lock-debug-mode)
 (line-number-mode)
 (linum-mode)
 (lispy-goto-mode)
 (lispy-mode)
 (lispy-other-mode)
 (mac-auto-ascii-mode)
 (mac-auto-operator-composition-mode)
 (mac-font-panel-mode)
 (macrostep-mode)
 (magit-blame-mode)
 (magit-blame-read-only-mode)
 (magit-blob-mode)
 (magit-wip-after-apply-mode)
 (magit-wip-after-save-local-mode)
 (magit-wip-after-save-mode)
 (magit-wip-before-change-mode)
 (magit-wip-initial-backup-mode)
 (magit-wip-mode)
 (mail-abbrevs-mode)
 (mml-mode)
 (mouse-wheel-mode)
 (next-error-follow-minor-mode)
 (org-cdlatex-mode)
 (org-list-checkbox-radio-mode)
 (org-src-mode)
 (org-table-follow-field-mode)
 (org-table-header-line-mode)
 (orgtbl-mode)
 (outline-minor-mode)
 (overwrite-mode)
 (paragraph-indent-minor-mode)
 (paredit-mode)
 (prettify-symbols-mode)
 (racket-smart-open-bracket-mode)
 (rectangle-mark-mode)
 (reveal-mode)
 (rigpa-char-mode)
 (rigpa-line-mode)
 (rigpa-word-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)
 (slime-autodoc-mode)
 (slime-edit-value-mode)
 (slime-editing-mode)
 (slime-fuzzy-target-buffer-completions-mode)
 (slime-macroexpansion-minor-mode)
 (slime-mode)
 (slime-popup-buffer-mode)
 (slime-repl-map-mode)
 (slime-repl-read-mode)
 (slime-trace-dialog-autofollow-mode)
 (slime-trace-dialog-hide-details-mode)
 (slime-trace-dialog-minor-mode)
 (smartparens-global-mode)
 (smartparens-global-strict-mode)
 (smartparens-mode)
 (smartparens-strict-mode)
 (smerge-mode)
 (sr-modeline)
 (sr-popviewer-mode)
 (sr-tabs-mode)
 (sr-term-char-minor-mode)
 (sr-term-line-minor-mode)
 (straight-live-modifications-mode)
 (straight-symlink-emulation-mode)
 (tab-bar-history-mode)
 (tab-bar-mode)
 (tar-subfile-mode)
 (temp-buffer-resize-mode)
 (text-scale-mode)
 (tool-bar-mode)
 (transient-resume-mode)
 (tree-sitter-hl-mode)
 (tree-sitter-mode)
 (undo-tree-visualizer-selection-mode)
 (unify-8859-on-decoding-mode)
 (unify-8859-on-encoding-mode)
 (url-handler-mode)
 (use-hard-newlines)
 (vc-parent-buffer)
 (view-mode)
 (visible-mode)
 (which-function-mode)
 (whitespace-mode)
 (whitespace-newline-mode)
 (window-divider-mode)
 (with-editor-mode)
 (xref-etags-mode))
greghendershott commented 2 years ago

Since I haven't used line numbering like this, I'm reading up to get familiar. What I've learned:

With global-line-numbers-mode enabled,

Do you actually mean global-display-line-numbers-mode? I'm not trying to be picky. I want to make sure there's not some third line numbering mode out there.

greghendershott commented 2 years ago

Never mind -- in your work-around you mention display-line-number-mode, so it was just a typo earlier, and you definitely do mean the new/improved mode.

greghendershott commented 2 years ago

From my limited research, so far, I don't see that the display-line-numbers mechanism reveals the necessary width information, such that racket-describe-mode could tell shr (which does the HTML layout) that the effective window-width is smaller.

Instead, racket-describe-mode could disable display-line-numbers-mode -- to do the work-around you describe, but do it automatically for you. Something like (using code that will work in older Emacs):

  (when (and (boundp 'display-line-numbers-mode)
             display-line-numbers-mode
             (fboundp 'display-line-numbers-mode))
    (display-line-numbers-mode -1))

Anyway that's my least-worst idea, for now.

countvajhula commented 2 years ago

Just confirming, apologies for the typo! I did mean global-display-line-numbers-mode 😄

greghendershott commented 2 years ago

No worries. :smile: If I'd already known more about the line number modes in Emacs, my brain probably would have auto-corrected the typo and not even noticed it.

Interestingly, display-line-numbers-mode, the variable, is defined even back in Emacs 25.2, but it has no effect. And for example transient (the menu system for magit) does (setq display-line-number-mode); this disables line-numbers in newer Emacs, and is a no-op in older ones.

I think I'll stick with the idea of disabling the minor mode -- and extend that idea to include linum-mode, too. Say with a little DRY macro:

  (cl-macrolet ((disable (id) `(and (boundp ',id) ,id (fboundp ',id) (,id -1))))
    (disable linum-mode)
    (disable display-line-numbers-mode))