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

pretty-print not happening despite `racket-pretty-print` set to `t`? #689

Closed dbp closed 11 months ago

dbp commented 11 months ago

I am using doom-emacs, which I don't think messes with the mode much (though I just switched to it, so might be wrong!). I noticed that in the REPL, structs are not pretty printed; I've seen this in emacs before, and the little poking made it seem like the racket-pretty-print variable should maybe control that? either way, reproduction is here:

> (require racket/pretty)
> (apply hash (build-list 20 (lambda (x) x)))
'#hash((0 . 1) (2 . 3) (4 . 5) (6 . 7) (8 . 9) (10 . 11) (12 . 13) (14 . 15) (16 . 17) (18 . 19))
> (pretty-print (apply hash (build-list 20 (lambda (x) x))))
'#hash((0 . 1)
       (2 . 3)
       (4 . 5)
       (6 . 7)
       (8 . 9)
       (10 . 11)
       (12 . 13)
       (14 . 15)
       (16 . 17)
       (18 . 19))

I would have expected those to have been identical?

(Or if I shouldn't have, is there some setting so that I can get that behavior?)

((alist-get 'racket-mode package-alist))
((emacs-version "29.1")
 (system-type darwin)
 (x-gtk-use-system-tooltips UNDEFINED)
 (major-mode help-mode)
 (racket--el-source-dir "/Users/dbp/.config/emacs/.local/straight/build-29.1/racket-mode/")
 (racket--rkt-source-dir "/Users/dbp/.config/emacs/.local/straight/build-29.1/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 "~/.config/emacs/.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)
   (racket-mode-debugger . info)
   (sequence-specialization . info)
   (* . fatal)))
 (racket-show-functions
  (racket-show-pseudo-tooltip)))
(enabled-minor-modes
 (+popup-mode)
 (auto-composition-mode)
 (auto-compression-mode)
 (auto-encryption-mode)
 (auto-fill-mode)
 (auto-save-mode)
 (better-jumper-local-mode)
 (better-jumper-mode)
 (buffer-read-only)
 (column-number-mode)
 (delete-selection-mode)
 (doom-modeline-mode)
 (electric-indent-mode)
 (eros-mode)
 (file-name-shadow-mode)
 (font-lock-mode)
 (gcmh-mode)
 (general-override-mode)
 (global-company-mode)
 (global-eldoc-mode)
 (global-flycheck-mode)
 (global-font-lock-mode)
 (global-git-commit-mode)
 (global-hl-line-mode)
 (global-so-long-mode)
 (global-visual-line-mode)
 (hl-line-mode)
 (isearch-fold-quotes-mode)
 (line-number-mode)
 (marginalia-mode)
 (menu-bar-mode)
 (mouse-wheel-mode)
 (ns-auto-titlebar-mode)
 (override-global-mode)
 (persp-mode)
 (projectile-mode)
 (recentf-mode)
 (save-place-mode)
 (savehist-mode)
 (semantic-minor-modes-format)
 (server-mode)
 (shell-dirtrack-mode)
 (show-paren-mode)
 (size-indication-mode)
 (smartparens-global-mode)
 (solaire-global-mode)
 (solaire-mode)
 (transient-mark-mode)
 (undo-fu-mode)
 (undo-fu-session-global-mode)
 (vertico-mode)
 (visual-line-mode)
 (volatile-highlights-mode)
 (which-key-mode)
 (window-divider-mode)
 (winner-mode)
 (ws-butler-global-mode)
 (yas-global-mode)
 (yas-minor-mode))
(disabled-minor-modes
 (+emacs-lisp-ert-mode)
 (+emacs-lisp-non-package-mode)
 (+org-pretty-mode)
 (+popup-buffer-mode)
 (abbrev-mode)
 (anzu-mode)
 (auto-fill-function)
 (auto-revert-mode)
 (auto-revert-tail-mode)
 (auto-save-visited-mode)
 (blink-cursor-mode)
 (buffer-face-mode)
 (bug-reference-mode)
 (bug-reference-prog-mode)
 (button-mode)
 (cl-old-struct-compat-mode)
 (comint-fontify-input-mode)
 (company-mode)
 (company-search-mode)
 (compilation-minor-mode)
 (compilation-shell-minor-mode)
 (completion-in-region-mode)
 (consult-preview-at-point-mode)
 (context-menu-mode)
 (cursor-face-highlight-mode)
 (cursor-intangible-mode)
 (cursor-sensor-mode)
 (dash-fontify-mode)
 (defining-kbd-macro)
 (diff-auto-refine-mode)
 (diff-minor-mode)
 (dired-hide-details-mode)
 (display-line-numbers-mode)
 (dtrt-indent-global-mode)
 (dtrt-indent-mode)
 (eldoc-mode)
 (electric-layout-mode)
 (electric-quote-mode)
 (flycheck-mode)
 (flycheck-popup-tip-mode)
 (flymake-mode)
 (general-override-local-mode)
 (git-commit-mode)
 (git-gutter-mode)
 (global-anzu-mode)
 (global-auto-revert-mode)
 (global-dash-fontify-mode)
 (global-display-line-numbers-mode)
 (global-git-gutter-mode)
 (global-goto-address-mode)
 (global-hide-mode-line-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-vi-tilde-fringe-mode)
 (global-whitespace-mode)
 (global-whitespace-newline-mode)
 (goto-address-mode)
 (goto-address-prog-mode)
 (header-line-indent-mode)
 (hide-mode-line-mode)
 (highlight-numbers-mode)
 (highlight-quoted-mode)
 (hl-todo-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)
 (lost-selection-mode)
 (magit-auto-revert-mode)
 (magit-blame-mode)
 (magit-blame-read-only-mode)
 (magit-blob-mode)
 (magit-todos-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)
 (merlin-mode)
 (mml-mode)
 (next-error-follow-minor-mode)
 (org-capture-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)
 (pcre-mode)
 (prettify-symbols-mode)
 (racket-smart-open-bracket-mode)
 (racket-xp-mode)
 (rainbow-delimiters-mode)
 (read-extended-command-mode)
 (reveal-mode)
 (rxt--read-pcre-mode)
 (rxt-global-mode)
 (rxt-mode)
 (semantic-highlight-edits-mode)
 (semantic-highlight-func-mode)
 (semantic-mode)
 (semantic-show-parser-state-mode)
 (semantic-show-unmatched-syntax-mode)
 (semantic-stickyfunc-mode)
 (sh-electric-here-document-mode)
 (shell-command-with-editor-mode)
 (shell-highlight-undef-mode)
 (show-smartparens-global-mode)
 (show-smartparens-mode)
 (smartparens-global-strict-mode)
 (smartparens-mode)
 (smartparens-strict-mode)
 (smerge-mode)
 (so-long-minor-mode)
 (tab-bar-history-mode)
 (tab-bar-mode)
 (temp-buffer-resize-mode)
 (text-scale-mode)
 (tool-bar-mode)
 (tooltip-mode)
 (transient-resume-mode)
 (treesit-explore-mode)
 (treesit-inspect-mode)
 (undelete-frame-mode)
 (undo-fu-session-mode)
 (url-handler-mode)
 (use-hard-newlines)
 (utop-minor-mode)
 (vc-dir-git-mode)
 (vc-parent-buffer)
 (vi-tilde-fringe-mode)
 (view-mode)
 (visible-mode)
 (which-function-mode)
 (whitespace-mode)
 (whitespace-newline-mode)
 (with-editor-mode)
 (ws-butler-mode)
 (xref-etags-mode))
greghendershott commented 11 months ago

Thanks for the report.

You can create a REPL buffer two ways:

  1. From a racket-run command. This is the main, intended use case for the REPL.

  2. From a racket-repl command. As its doc string says, you can do this but there are caveats.

Show a Racket REPL buffer in some window.

IMPORTANT

The main, intended use of Racket Mode's REPL is that you find-file some specific .rkt file, then run it using racket-run or racket-run-module-at-point. The resulting REPL will correspond to those definitions and match your expectations.

If you really want to start a REPL for no file in particular, then you could use this racket-repl command. But the resulting REPL will have a minimal "#lang racket/base" namespace. You could enter "(require racket)" if you want the equivalent of "#lang racket". You could also "(require racket/enter)" if you want things like "enter!". But in some sense you'd be "using it wrong". If you actually don't want to use Racket Mode's REPL as intended, then consider using a plain Emacs shell buffer to run command-line Racket.

Although the doc string doesn't include this among the caveats, a bunch of settings get conveyed from Emacs variables to the Racket Mode back end process as part of a run command. These include:

This doesn't happen with the racket-repl command.

So that's the explanation, and you have an idea for a work-around.


Instead?

dbp commented 11 months ago

Ahh -- that helps clarify a lot. I think if there were a message along the lines of "Running racket-repl on its own has limited settings; you may want to use racket-run on a buffer instead" or something like that when you ran the standalone, that might be helpful.

(Also, most of the time you want contents of the file... it just so happens that I was testing out some stuff that I hadn't written into a file, so didn't need that, or I probably wouldn't have gotten myself into this trouble.)

greghendershott commented 11 months ago

I just pushed a commit 5a69b3f to a topic branch, which does one option I mentioned above: Change racket-repl into a command that just runs a certain "init" file. (The name and contents of which a user can customize, of course).

This seems so obviously the right thing to do instead, that I'm a little suspicious and want to sleep on it before merging. :smile: But it worked well in my initial testing, and I think this is at least in the right ballpark.

greghendershott commented 11 months ago

I went through a few rounds of dog-fooding this and fine-tuning, but ended up merging what I described above.

This addresses the specific issue you reported.

It also allows customizing a .rkt (or for that matter .rhm or whatever extension file with a #lang line) which is the file run when you M-x racket-repl. So it acts as a kind of little init file. I think in the past a few people have asked for something like this.

dbp commented 11 months ago

Thank you! This is great.