Skip to content

How to make fmt work with inline images in DrRacket? [enhancement] #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
maueroats opened this issue Sep 5, 2024 · 2 comments
Open

Comments

@maueroats
Copy link

Running the simple version of the formatter on code with inline images in DrRacket makes the images disappear, just like copy and pasting would.

It would be nice if there were a way to run the formatter and retain the inline images.

For completeness, here is the reformatter quickscript that I am using (which is obviously the root cause of the error).

(define-script reformat
  #:label "Reformat"
  (λ (selection #:definitions defs)
    (define txt (send defs get-text))  ;; <--- but what else could I do?
    (define new-txt (program-format txt))
    (send defs begin-edit-sequence)
    (send defs erase)
    (send defs insert new-txt)
    (send defs end-edit-sequence)
    #f))
@Metaxal
Copy link

Metaxal commented Sep 5, 2024

Filtering out the images and placing them back into the formatted code sounds pretty tricky to me.

But perhaps you can just format only the selected portion of the code?
That would just amount to:

(define-script reformat
  #:label "Reformat"
  (λ (selection)
    (program-format selection)))

If the images are only at the top level, it may be possible to split the formatting by blocks and avoid the locations with images, but I haven't dealt much with non-text-only code, so I don't know from the top of my head how to do that.

@jackfirth
Copy link
Contributor

You'll also need to pass in the column number of the selection as the #:indent argument, so that fmt knows how much indentation to use when adding newlines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants