Skip to content
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

Run Resyntax on various files #433

Merged
merged 2 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 15 additions & 23 deletions scribble-lib/scribble/acmart.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,8 @@
#:rest pre-content?
institution?)]
[institution? (-> any/c boolean?)]
[email (->* ()
#:rest (listof pre-content?)
email?)]
[email-string (->* ()
#:rest (listof string?)
email?)]
[email (-> pre-content? ... email?)]
[email-string (-> string? ... email?)]
[email? (-> any/c boolean?)]
[affiliation (->* ()
(#:position (or/c pre-content? #f)
Expand Down Expand Up @@ -256,23 +252,19 @@
#:date [date #f]
#:short [short #f]
. str)
(let ([content (decode-content str)])
(make-title-decl (prefix->string prefix)
(convert-tag tag content)
version
(let* ([s (convert-part-style 'title style)]
[s (if date
(make-style (style-name s)
(cons (make-document-date date)
(style-properties s)))
s)]
[s (if short
(make-style (style-name s)
(cons (short-title short)
(style-properties s)))
s)])
s)
content)))
(define content (decode-content str))
(make-title-decl
(prefix->string prefix)
(convert-tag tag content)
version
(let* ([s (convert-part-style 'title style)]
[s (if date
(make-style (style-name s) (cons (make-document-date date) (style-properties s)))
s)]
[s
(if short (make-style (style-name s) (cons (short-title short) (style-properties s))) s)])
s)
content))

(define (author #:orcid [orcid #f]
#:affiliation [affiliation '()]
Expand Down
28 changes: 13 additions & 15 deletions scribble-lib/scribble/acmart/lang.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -191,21 +191,19 @@
#,authorversion? #,font-size #,nonacm? #,timestamp?
#,author-draft? #,acmthm? #,format?) () . body)])))]))

(define ((post-process . opts) doc)
(let ([options
(if (ormap values opts)
(format "[~a]" (apply string-append (add-between (filter values opts) ", ")))
"")])
(add-acmart-styles
(add-defaults doc
(string->bytes/utf-8
(format "\\documentclass~a{acmart}\n~a"
options
unicode-encoding-packages))
(scribble-file "acmart/style.tex")
(list (scribble-file "acmart/acmart.cls"))
#f
#:replacements (hash "scribble-load-replace.tex" (scribble-file "acmart/acmart-load.tex"))))))
(define ((post-process . opts) doc)
(define options
(if (ormap values opts)
(format "[~a]" (apply string-append (add-between (filter values opts) ", ")))
""))
(add-acmart-styles
(add-defaults
doc
(string->bytes/utf-8 (format "\\documentclass~a{acmart}\n~a" options unicode-encoding-packages))
(scribble-file "acmart/style.tex")
(list (scribble-file "acmart/acmart.cls"))
#f
#:replacements (hash "scribble-load-replace.tex" (scribble-file "acmart/acmart-load.tex")))))

(define (add-acmart-styles doc)
(struct-copy part doc
Expand Down
44 changes: 19 additions & 25 deletions scribble-lib/scribble/comment-reader.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
(read-syntax/recursive src port)))

(define (read-unsyntaxer port)
(let ([p (peeking-input-port port)])
(if (eq? (read p) '#:escape-id)
(begin (read port) (read port))
'unsyntax)))
(define p (peeking-input-port port))
(cond
[(eq? (read p) '#:escape-id)
(read port)
(read port)]
[else 'unsyntax]))

(define (make-comment-readtable #:readtable [rt (current-readtable)])
(make-readtable rt
Expand All @@ -32,11 +34,8 @@
(do-comment port (lambda () (read/recursive port #\@)))]
[(char port src line col pos)
(let ([v (do-comment port (lambda () (read-syntax/recursive src port #\@)))])
(let-values ([(eline ecol epos) (port-next-location port)])
(datum->syntax
#f
v
(list src line col pos (and pos epos (- epos pos))))))])))
(define-values (eline ecol epos) (port-next-location port))
(datum->syntax #f v (list src line col pos (and pos epos (- epos pos)))))])))

(define (do-comment port recur)
(let loop ()
Expand All @@ -50,16 +49,11 @@
(t
,@(append-strings
(let loop ()
(let ([c (read-char port)])
(cond
[(or (eof-object? c)
(char=? c #\newline))
null]
[(char=? c #\@)
(cons (recur) (loop))]
[else
(cons (string c)
(loop))]))))))))
(define c (read-char port))
(cond
[(or (eof-object? c) (char=? c #\newline)) null]
[(char=? c #\@) (cons (recur) (loop))]
[else (cons (string c) (loop))])))))))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, this is a rare place where I find the refomatting suboptimal. I often prefer to write cond "questions" and "answers" on separate lines so that I can see all the possible answers more clearly. I don't object enough to stand in the way of the overall improvements, though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree w/ Matthew here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @sorawee, since this is a fmt choice.

In this case I disagree, since everything is so short. But I can understand the reasoning.

Copy link
Contributor Author

@jackfirth jackfirth Aug 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you also prefer that the else and its accompanying expression be on opposite lines? The cond expression on line 23 above has the regular branch split across lines, but the else clause is a single line.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, yes. I often go back and forth on this while editing code, and usually end up happiest after I've added newlines consistently, but probably not always.


(define (append-strings l)
(let loop ([l l][s null])
Expand All @@ -76,9 +70,9 @@
(loop (cdr l) null)))])))

(define (preserve-space s)
(let ([m (regexp-match-positions #rx" +" s)])
(if m
(append (preserve-space (substring s 0 (caar m)))
(list `(hspace ,(- (cdar m) (caar m))))
(preserve-space (substring s (cdar m))))
(list s))))
(define m (regexp-match-positions #rx" +" s))
(if m
(append (preserve-space (substring s 0 (caar m)))
(list `(hspace ,(- (cdar m) (caar m))))
(preserve-space (substring s (cdar m))))
(list s)))
8 changes: 4 additions & 4 deletions scribble-lib/scribble/contract-render.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@
(hash-set! index-table k (cons txt-loc (hash-ref index-table k '()))))))

(define (r-blockss+cont blockss mode index-table)
(for ([blocks (in-list blockss)])
(for ([block (in-list blocks)])
(unless (eq? block 'cont)
(r-block block mode index-table)))))
(for* ([blocks (in-list blockss)]
[block (in-list blocks)])
(unless (eq? block 'cont)
(r-block block mode index-table))))

(define (r-blockss blockss mode index-table)
(for ([blocks (in-list blockss)])
Expand Down