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
681 stars 93 forks source link

Bitmaps not render in the REPL with the HTDP #709

Closed akaml closed 5 months ago

akaml commented 5 months ago

Hi. I have a problem with displaying bitmap images in repl when using #lang htdp/bsl. One of the reproduction options is to load an image from a file(via the bitmap function) or to call already defined bitmap image in the repl If you create images using the functions of forming simple shapes (rect, circle, etc.), then the shapes are displayed correctly, the problem arises with bitmap. I checked the image cache and found an svg file with a bitmap embedded via base64. It seems that there is a problem with the display itself in emacs. I tried different versions of racket - the problem remains The code for reproduction: issue.txt

drracket emacs

Package

metadata
(#s(package-desc racket-mode
                 (20240418 1446)
                 "Racket editing, REPL, and more"
                 ((emacs
                   (25 1)))
                 nil nil "c:/Users/admin/AppData/Roaming/.emacs.d/elpa/racket-mode-20240418.1446"
                 ((:url . "https://www.racket-mode.com/")
                  (:maintainer "Greg Hendershott")
                  (:maintainers
                   ("Greg Hendershott"))
                  (:authors
                   ("Greg Hendershott" . "racket-mode-author@greghendershott.com"))
                  (:commit . "d5f4007fd2c2604673125035f4852dce1b639b33"))
                 nil))
package-archives
(("melpa" . "https://melpa.org/packages/")
 ("gnu" . "https://elpa.gnu.org/packages/")
 ("nongnu" . "https://elpa.nongnu.org/nongnu/"))
racket--el-source-dir
"c:/Users/admin/AppData/Roaming/.emacs.d/elpa/racket-mode-20240418.1446/"
racket--rkt-source-dir
"c:/Users/admin/AppData/Roaming/.emacs.d/elpa/racket-mode-20240418.1446/racket/"

System values

emacs-version
"29.3"
major-mode
help-mode
system-type
windows-nt
display-graphic-p
t

Buffer values

after-change-functions
nil
before-change-functions
nil
completion-at-point-functions
(tags-completion-at-point-function)
eldoc-documentation-function
eldoc-documentation-default
font-lock-defaults
nil
pre-command-hook
(tooltip-hide)
post-command-hook
(global-font-lock-mode-check-buffers global-eldoc-mode-check-buffers global-display-line-numbers-mode-check-buffers mode-local-post-major-mode-change)
post-self-insert-hook
(electric-indent-post-self-insert-function blink-paren-post-self-insert-function)
xref-backend-functions
(etags--xref-backend)

Racket Mode values

racket--cmd-open-p
t
racket-after-run-hook
nil
racket-back-end-configurations
((:directory "/" :racket-program nil :remote-source-dir nil :restart-watch-directories nil :windows t))
racket-before-run-hook
(racket-ansi-color-context-reset)
racket-browse-url-function
browse-url
racket-command-timeout
10
racket-documentation-search-location
"https://docs.racket-lang.org/search/index.html?q=%s"
racket-error-context
medium
racket-expand-hiding
standard
racket-hash-lang-mode-hook
nil
racket-hash-lang-module-language-hook
nil
racket-hash-lang-token-face-alist
((constant . font-lock-constant-face)
 (error . error)
 (other . font-lock-doc-face)
 (keyword . font-lock-keyword-face)
 (hash-colon-keyword . racket-keyword-argument-face)
 (at . font-lock-doc-face))
racket-history-filter-regexp
"\\`\\s *\\'"
racket-imagemagick-props
nil
racket-images-inline
t
racket-images-keep-last
100
racket-images-system-viewer
"display"
racket-indent-curly-as-sequence
t
racket-indent-sequence-depth
0
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-memory-limit
2048
racket-mode-hook
nil
racket-module-forms
"\\s(\\(?:module[*+]?\\|library\\)"
racket-pretty-lambda
nil
racket-pretty-print
t
racket-program
"Racket.exe"
racket-repl-buffer-name-function
nil
racket-repl-command-file
"c:/Users/admin/AppData/Roaming/.emacs.d/racket-mode/repl.rkt"
racket-repl-history-directory
"~/.emacs.d/racket-mode/"
racket-repl-mode-hook
nil
racket-sexp-comment-fade
0.5
racket-shell-or-terminal-function
racket-shell
racket-show-functions
(racket-show-pseudo-tooltip)
racket-smart-open-bracket-enable
nil
racket-submodules-to-run
((test)
 (main))
racket-use-repl-submit-predicate
nil
racket-xp-add-binding-faces
nil
racket-xp-after-change-refresh-delay
1
racket-xp-highlight-unused-regexp
"^[^_]"
racket-xp-mode-lighter
(:eval
 (racket--xp-mode-lighter))

Minor modes

enabled
((auto-composition-mode)
 (auto-compression-mode)
 (auto-encryption-mode)
 (blink-cursor-mode)
 (buffer-read-only)
 (display-line-numbers-mode)
 (electric-indent-mode)
 (file-name-shadow-mode)
 (font-lock-mode)
 (global-display-line-numbers-mode)
 (global-eldoc-mode)
 (global-font-lock-mode)
 (isearch-fold-quotes-mode)
 (line-number-mode)
 (menu-bar-mode)
 (mouse-wheel-mode)
 (semantic-minor-modes-format)
 (shell-dirtrack-mode)
 (show-paren-mode)
 (tooltip-mode)
 (transient-mark-mode))
Disabled minor modes
disabled
((abbrev-mode)
 (auto-fill-function)
 (auto-fill-mode)
 (auto-save-mode)
 (auto-save-visited-mode)
 (buffer-face-mode)
 (button-mode)
 (cl-old-struct-compat-mode)
 (column-number-mode)
 (comint-fontify-input-mode)
 (compilation-minor-mode)
 (compilation-shell-minor-mode)
 (completion-in-region-mode)
 (context-menu-mode)
 (cursor-face-highlight-mode)
 (defining-kbd-macro)
 (display-fill-column-indicator-mode)
 (eldoc-mode)
 (electric-layout-mode)
 (electric-pair-mode)
 (electric-quote-mode)
 (ggtags-mode)
 (ggtags-navigation-mode)
 (global-display-fill-column-indicator-mode)
 (global-prettify-symbols-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-visual-line-mode)
 (header-line-indent-mode)
 (horizontal-scroll-bar-mode)
 (hs-minor-mode)
 (indent-tabs-mode)
 (isearch-mode)
 (jit-lock-debug-mode)
 (lock-file-mode)
 (lost-selection-mode)
 (next-error-follow-minor-mode)
 (overwrite-mode)
 (paragraph-indent-minor-mode)
 (prettify-symbols-mode)
 (racket-hash-lang-repl-mode)
 (racket-smart-open-bracket-mode)
 (racket-xp-mode)
 (read-extended-command-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-highlight-undef-mode)
 (size-indication-mode)
 (tab-bar-history-mode)
 (tab-bar-mode)
 (temp-buffer-resize-mode)
 (text-scale-mode)
 (tool-bar-mode)
 (treesit-explore-mode)
 (treesit-inspect-mode)
 (undelete-frame-mode)
 (url-handler-mode)
 (use-hard-newlines)
 (view-mode)
 (visible-mode)
 (visual-line-mode)
 (window-divider-mode)
 (xref-etags-mode))
greghendershott commented 5 months ago

Thanks for the excellent, clear report!

One of the reproduction options is to load an image from a file(via the bitmap function) or to call already defined bitmap image in the repl. If you create images using the functions of forming simple shapes (rect, circle, etc.), then the shapes are displayed correctly, the problem arises with bitmap.

I checked the image cache and found an svg file with a bitmap embedded via base64. It seems that there is a problem with the display itself in emacs.

Interesting! Thank you for narrowing that down.

Although I can't reproduce this (I do see the image) on Emacs 28.2 on Linux, you're using Windows.

I'll try Windows, later; assuming I can reproduce it there: This seems specific to the Windows version of Emacs -- it has some problem handling SVGs with embedded bitmaps?

If so, this might need to get fixed, properly, in Emacs for Windows. But maybe there is some work-around I can supply for you meanwhile??


Quick background about the image handling:

Currently the Racket Mode back end uses Racket's file/convertible to convert image objects. It asks for SVG when the Emacs front end reports 'svg in both the image-types and image-types-available-p lists. Otherwise it asks for PNG. (The preference for SVG is because it can be much smaller/faster for vector graphics. See e.g. #470. And with no downside for bitmap graphics... usually.)

There's no option to prefer PNG exposed, for you to try here. I could add something like that. However, even if it helps work around this shortcoming in Emacs for Windows, it would be at the cost of bloating graphics handling generally. So... I'm not immediately sure what's best to do...

akaml commented 5 months ago

Thanks for the answer! Apparently, the problem is with the emacs build. I used vanilla versions of emacs from the gnu website (tested on versions 28 and 29), but after installing via msys2, the problem went away At first I thought that the problem was in imagemagick, but it turned out that the msys2 version was built without its support. Support for image types: image-types => emacs 28.2(vanila): (svg png gif tiff jpeg xpm xbm ppm) emacs 29.3(msys2): (bmp svg webgl png gif tiff jpeg xpm xbm ppm) Of the interesting differences, I can only notice the lack of bmp support in the vanilla version I also had a problem opening images embedded in svg outside of racket-mode on vanilla versions

akaml commented 5 months ago

@greghendershott FYI: I ran the code from the issue-709 branch - the problem on the vanilla version is fixed when (setq racket-images-do-not-use-svg t). Thanks!

greghendershott commented 5 months ago

Support for image types: image-types => emacs 28.2(vanila): (svg png gif tiff jpeg xpm xbm ppm) emacs 29.3(msys2): (bmp svg webgl png gif tiff jpeg xpm xbm ppm)

Interesting; so the problematic version advertises itself as supporting svg -- and does generally for vector ops -- but apparently there's a hole in the implementation where it doesn't support embedded bitmaps.

greghendershott commented 5 months ago

FYI: I ran the code from the issue-709 branch - the problem on the vanilla version is fixed when (setq racket-images-do-not-use-svg t). Thanks!

Great. I'll merge that.

Aside from being a work-around for this specific case, this might be useful for anyone who can't use or prefers not to use svg.