
running resyntax in a GitHub Action (headless Linux install) flames out because we need GTK?! :eyes:

cc @notjack :point_up:

btw the screenshot is not ideal — it appears that export PATH=...
alone is causing the problem. What you don’t see is that the next line is a call to resyntax analyze --directory dir-name-here

Use xvfb to run it


But why does it need GUI? It’s a code transformation tool, no?

Oh, it’s used for indenting stuff: https://github.com/jackfirth/resyntax/blob/master/refactoring-result.rkt.

Well, all I can say is that fmt
doesn’t require GUI, and probably could be used as a drop-in replacement for framework
’s indenter.

Is there a way to preserve the newlines in fmt
?
I’m experimenting with plugging it into resyntax.

See https://github.com/sorawee/fmt/issues/20. Preserving newlines kinda defeats the purpose of code formatting (in the traditional sense where you want code to stay within the page width limit).

It does preserve consecutive newlines where number of newlines > 1, though, since that’s usually intentional.

I can’t speak for @notjack but in the current state it looks like resyntax wants to maintain the programs newlines and is more concerned with the indentation of those lines.

So with framework it would format like this: The define form supports a shorthand for defining functions (including function-returning functions).
3 (define err
4 (lambda (s)
5 (cons 'err s)))
3 (define (err s)
4 (cons 'err s))
Using fmt
the output (in the second chunk there) the code is all on one line.

This may not be a great example. I have another which has lets in it.

Reading the issue now …

Right. The decision to only indent code could be intentional. But it could also be an artifact since earlier code formatters don’t handle comments, and only code indenters do, so there were not many choices.

Probably dumb question/idea: What if fmt
(and/or pprint-compact
) added the concept of a hard line break (similar to CTRL+ENTER in some word processors or an HTML <br>
element). And then what if there were some read option that preserves newlines as hard breaks. Would that make fmt
act as an indenter-only?

(I’ve only glanced at your code quickly/shallowly so no idea if this even makes sense.)

is there an equivalent to python3 -m http.server
in Racket?

As in a way to load in a module on start or as in a way to start a simple static file web server?

Yes, I’m just looking for the specific incantation. I’m sure others will jump in with the exact answer soon if I don’t.

Loading in a module is one of many flags (-l
, -t
, -e
, -p
come to mind). I would have to go digging for the static web server; not an area I’m familiar with

I’m 70% sure that I’ve done it before from the cli like you are doing there though

e.g., my slack archive viewer is run with racket -l slack-archive-viewer

I’ve wanted to make a raco webserver
(or some such name) to do the same as that python to just serve some static files, but I’ve been to lazy to work it out.

https://github.com/racket/web-server/blob/master/web-server-lib/web-server/main.rkt suggests maybe racket -l webserver
; https://docs.racket-lang.org/web-server/run.html#%28part._command-line-tools%29 suggests something else entirely

But I can’t tell because while both hang, neither tells me what port anything is happening on

I think those both just serve a servlet module though?

Ok, not plt-web-server
; I think you’re right @samdphillips. I finally found this after passing the port explicitly.

python -m http.server
serves whatever static files are in the current working directory.

This behemoth serves static file, but has no directory listing: racket -l racket/base -l web-server/servlet -l web-server/servlet-env -e '(serve/servlet (lambda _ (response/xexpr (list (string->symbol "html")))) #:extra-files-paths (list ".") #:servlet-path "")'
(I hopped some hoops to avoid using quotes, since quotes-in-quotes are annoying in the shell. But yeah, this could be made easier, and add the directory listing at the same time.)

I can put that on a wishlist. There’s no technical difficulty to preserve newlines. Right now, newlines are explicitly stripped away. So to preserve them, it only requires removing the code to strip the newlines.
The challenging paer is that the formatting combinators assume an invariant that these newlines are stripped away. Without this invariant, formatting doesn’t work properly. I will try to see what I can do to relax this restriction, but it’s not my priority.

Every once in a while the package server still gets in this state where it’s looking for the master
branch on my package’s github repo (which uses main
instead) which causes the build to fail. (https://pkgd.racket-lang.org/pkgn/search?q=splitflap) git: could not find requested reference
reference: master
repo: otherjoel/splitflap.git

The package sources in question are all set to, e.g. <https://github.com/otherjoel/splitflap.git?path=splitflap#main>

The problem is on the client side, and it’s fixed for the upcoming v8.3 release.

Ok I stole it and made a raco command. I’ll put it on the pkg server in a few https://github.com/samdphillips/raco-static-web


Lol nice. I’m trying to hack the files listing in, but that’s somehow proving harder (or I’m making it to complicated)

I think that’s where I gave up last time I looked at this. I think there is builtin servlet that can do it, but you have to do a little bit extra to make it work.

see https://github.com/jackfirth/resyntax/issues/124 :slightly_frowning_face:

Resyntax tries very hard to preserve the formatting of the existing code as much as possible. What I would need from fmt
is the ability to format a syntax object only partially. Specifically, I want to format a syntax object but preserve the formatting of any syntax-original?
subforms inside the syntax object, so that only the indentation of those forms are changed.

I have an improved version… could still use to take command-line args like http.server
, but I need to stop for now.

Quick scribble question: How do I create a @tech
link to the KeyEvent definition in 2htdp/universe
?

I’ll take a look in a bit. I added a README and gave you credits.

@tech[#:doc '(lib "teachpack/teachpack.scrbl")]{KeyEvent}

Thanks — that takes me to the docs from htdp/world
, though (i.e., teachpack/world.html#(tech._keyevent)
)

but if I try #:doc '(lib "teachpack/2htdp/scribblings/universe.scrbl")
, it complains that the tag is undefined

@sorawee Of course, please don’t even bother adding to a wishlist if it would be awkward, square-peg/round-hole! (I thought maybe at the level of pprint-compact
that v-append
or something like it could handle hard breaks…? But I don’t really understand how that all works.)

An indenter (not full reformatter) for say racket-lang is not terribly difficult — assuming something has already tokenized (or at least done some char classification as does Emacs), and you have a few handy functions for things like next/prev/up/down sexp. I think that’s the aspect that can come either from framework
(which is kind of heavy if that’s all one needs from it), or from module-lexer plus writing some of those “sexp nav” functions.

ok, for future reference, it’s @tech[#:doc '(lib "teachpack/teachpack.scrbl") #:tag-prefixes '("2htdp" "world")]{KeyEvent}
— I have zero clue why that works, but it does…

Oh, I see. I’s because the 2htdp
documentation uses an explicit layer of tagging, which lets it define some of the the same terms in different ways within different sections. That’s not typical.