From e78a627a7fbb9466a2f5d46e753097b38a8a9d96 Mon Sep 17 00:00:00 2001 From: Greg Hendershott Date: Mon, 22 Jan 2024 11:20:55 -0500 Subject: [PATCH] racket-expand-file: Improve behavior when no steps 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. --- racket-stepper.el | 30 ++++++++++++++++-------------- racket/commands/macro.rkt | 10 +++++----- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/racket-stepper.el b/racket-stepper.el index b9ce42af..25dd4d7c 100644 --- a/racket-stepper.el +++ b/racket-stepper.el @@ -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") diff --git a/racket/commands/macro.rkt b/racket/commands/macro.rkt index 613c474a..8de37d19 100644 --- a/racket/commands/macro.rkt +++ b/racket/commands/macro.rkt @@ -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) @@ -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) @@ -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)