Skip to content

Commit

Permalink
racket-expand-file: Improve behavior when no steps
Browse files Browse the repository at this point in the history
When no steps at all, still show "Final" output.

When no steps left, show simple message there is nothing left to
expand (as opposed to having the back end raise an exception).

Although I noticed this when investigating #697, it is adjacent not
strictly related.
  • Loading branch information
greghendershott committed Jan 22, 2024
1 parent e36d434 commit e78a627
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
30 changes: 16 additions & 14 deletions racket-stepper.el
Original file line number Diff line number Diff line change
Expand Up @@ -160,20 +160,22 @@ INTO-BASE is treated as a raw command prefix arg and converted to boolp."
,(and into-base t))
#'racket-stepper--insert)))

(defun racket-stepper--insert (steps)
(with-current-buffer (racket--stepper-buffer-name)
(let ((inhibit-read-only t))
(goto-char (point-max))
(dolist (step steps)
(pcase step
(`(original . ,text)
(delete-region (point-min) (point-max))
(insert "Original\n" text "\n" "\n"))
(`(final . ,text) (insert "Final\n" text "\n"))
(`(,label . ,diff) (insert label "\n" diff "\n"))))
(racket-stepper-previous-item)
(when (equal (selected-window) (get-buffer-window (current-buffer)))
(recenter)))))
(defun racket-stepper--insert (nothing-or-steps)
(if (eq nothing-or-steps 'nothing)
(message "Nothing to expand")
(with-current-buffer (racket--stepper-buffer-name)
(let ((inhibit-read-only t))
(goto-char (point-max))
(dolist (step nothing-or-steps)
(pcase step
(`(original . ,text)
(delete-region (point-min) (point-max))
(insert "Original\n" text "\n" "\n"))
(`(final . ,text) (insert "Final\n" text "\n"))
(`(,label . ,diff) (insert label "\n" diff "\n"))))
(racket-stepper-previous-item)
(when (equal (selected-window) (get-buffer-window (current-buffer)))
(recenter))))))

(defun racket-stepper-step (prefix)
(interactive "P")
Expand Down
10 changes: 5 additions & 5 deletions racket/commands/macro.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
macro-stepper/next)

(define step/c (cons/c (or/c 'original string? 'final) string?))
(define step-proc/c (-> (or/c 'next 'all) (listof step/c)))
(define step-proc/c (-> (or/c 'next 'all)
(or/c 'nothing (listof step/c))))
(define step-proc #f)
(define (nothing-step-proc _) 'nothing)

(define/contract (make-expr-stepper str)
(-> string? step-proc/c)
Expand Down Expand Up @@ -73,7 +75,7 @@
(stepper-text stx
(if into-base? (λ _ #t) (not-in-base)))))
(define step-num #f)
(define step-last-after "")
(define step-last-after (pretty-format-syntax stx))
(log-racket-mode-debug "~v ~v ~v" path into-base? raw-step)
(define/contract (step what) step-proc/c
(cond [(not step-num)
Expand Down Expand Up @@ -131,11 +133,9 @@
(macro-stepper/next 'next))

(define/contract (macro-stepper/next what) step-proc/c
(unless step-proc
(error 'macro-stepper "Nothing to expand"))
(define v (step-proc what))
(match v
[(list (cons 'final _)) (set! step-proc #f)]
[(list (cons 'final _)) (set! step-proc nothing-step-proc)]
[_ (void)])
v)

Expand Down

0 comments on commit e78a627

Please sign in to comment.