Skip to content

Commit 4abb2bc

Browse files
authored
Force a linebreak with define-syntax-rule (#67)
* Force a linebreak with `define-syntax-rule` Fixes #59. * Regenerate tests
1 parent baa865c commit 4abb2bc

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

conventions.rkt

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,13 @@
311311
[#:else (format-#%app doc)]))
312312

313313
;; try to fit in one line if the body has exactly one form,
314-
;; else will be multiple lines
314+
;; else will be multiple lines. if #:force-linebreak? is true,
315+
;; the one line form is never allowed.
315316
#;(define-values (xxxxxxxxxxx yyyyyyyyyyy) 1)
316317
#;(define-values (xxxxxxxxxxx yyyyyyyyyyy)
317318
11111111111111111111111111111111111111111111111111111111111111111111111)
318-
(define-pretty (format-define-like #:head-formatter [format-head #f])
319+
(define-pretty (format-define-like #:head-formatter [format-head #f]
320+
#:force-linebreak? [force-linebreak? #f])
319321
#:type node?
320322
#:default [format-head pretty]
321323
(match/extract (node-content doc) #:as unfits tail
@@ -325,18 +327,20 @@
325327
c
326328
d
327329
e)
328-
(alt ((format-uniform-body/helper 1 #:arg-formatter format-head) doc)
329-
;; fit in one line case; only when there are either two or three things
330-
#;(define a b)
331-
(pretty-node
332-
#:unfits unfits
333-
(try-indent
334-
#:because-of tail
335-
(flatten
336-
(match tail
337-
['() (<s> (pretty -define) (format-head -head))]
338-
[(list -e) (<s> (pretty -define) (format-head -head) (pretty -e))]
339-
[_ fail])))))]
330+
(define general-case ((format-uniform-body/helper 1 #:arg-formatter format-head) doc))
331+
;; fit in one line case; only when there are either two or three things
332+
#;(define a b)
333+
(define one-line-case
334+
(pretty-node
335+
#:unfits unfits
336+
(try-indent
337+
#:because-of tail
338+
(flatten
339+
(match tail
340+
['() (<s> (pretty -define) (format-head -head))]
341+
[(list -e) (<s> (pretty -define) (format-head -head) (pretty -e))]
342+
[_ fail])))))
343+
(if force-linebreak? general-case (alt general-case one-line-case))]
340344
[#:else (format-#%app doc)]))
341345

342346
;; this is similar to let*, but because the macro name is so long,
@@ -452,7 +456,7 @@
452456

453457
[("define") (format-define)]
454458
[("define-for-syntax") (format-define-like)]
455-
[("define-syntax-rule") (format-define-like)]
459+
[("define-syntax-rule") (format-define-like #:force-linebreak? #true)]
456460
[("define-syntax") (format-define-like)]
457461
[("define-syntax-parameter") (format-define-like)]
458462
[("define/public" "define/private" "define/override" "define/augment") (format-define-like)]

tests/benchmarks/list.rkt.out

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,8 @@
399399
(define (remove-duplicates l [=? equal?] #:key [key #f])
400400
;; `no-key' is used to optimize the case for long lists, it could be done for
401401
;; shorter ones too, but that adds a ton of code to the result (about 2k).
402-
(define-syntax-rule (no-key x) x)
402+
(define-syntax-rule (no-key x)
403+
x)
403404
(unless (list? l)
404405
(raise-argument-error 'remove-duplicates "list?" l))
405406
(let* ([len (length l)]

0 commit comments

Comments
 (0)