Skip to content

Commit

Permalink
Fix the macro stepper commands
Browse files Browse the repository at this point in the history
They didn't get updated correctly to work with possible multiple
REPLs.
  • Loading branch information
greghendershott committed Mar 9, 2020
1 parent 2679610 commit c699d41
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
6 changes: 3 additions & 3 deletions racket-repl.el
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@
;; variable `racket--repl-session-id'. (Note that
;; `racket-repl-buffer-name' only has meaning for `racket-mode'
;; buffers, and `racket--repl-session-id' only has meaning for
;; `racket-repl-mode' bufers. Emacs variables _exist_ for all buffers
;; using all major modes. All we can do is remember to ignore them in
;; some modes.)
;; `racket-repl-mode' buffers. Emacs variables exist for all buffers
;; using all major modes. All we can do is remember in which buffers
;; they mean something as opposed to being ignored..)

(defvar racket-repl-buffer-name "*Racket REPL*"
"The name of the `racket-repl-mode' buffer associated with `racket-mode' buffer.
Expand Down
17 changes: 14 additions & 3 deletions racket-stepper.el
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
;;; racket-stepper.el -*- lexical-binding: t; -*-

;; Copyright (c) 2018 by Greg Hendershott.
;; Copyright (c) 2018-2020 by Greg Hendershott.
;; Portions Copyright (C) 1985-1986, 1999-2013 Free Software Foundation, Inc.

;; Author: Greg Hendershott
Expand All @@ -20,6 +20,7 @@
(require 'rx)
(require 'racket-cmd)
(require 'racket-custom)
(require 'racket-repl)
(require 'racket-util)

;; Need to define this before racket-stepper-mode
Expand Down Expand Up @@ -127,11 +128,21 @@ Uses Racket's `expand-once` in the namespace from the most recent
(buffer-substring-no-properties beg end)
prefix))))

(defvar racket--stepper-repl-session-id nil
"The REPL session used when stepping.
May be nil for 'file stepping, but must be valid for 'expr stepping.")

(defun racket-stepper--start (which str into-base)
"Ensure buffer and issue initial command.
WHICH should be 'expr or 'file.
STR should be the expression or pathname.
INTO-BASE is treated as a raw prefix arg and converted to boolp."
(unless (eq major-mode 'racket-mode)
(error "Only works from racket-mode buffers"))
(setq racket--stepper-repl-session-id (racket--repl-session-id))
(unless (or racket--stepper-repl-session-id
(eq which 'file))
(error "Only works when the racket-mode buffer has a REPL buffer, and, you should racket-run first"))
;; Create buffer if necessary
(unless (get-buffer racket-stepper--buffer-name)
(with-current-buffer (get-buffer-create racket-stepper--buffer-name)
Expand All @@ -144,7 +155,7 @@ INTO-BASE is treated as a raw prefix arg and converted to boolp."
(let ((inhibit-read-only t))
(delete-region (point-min) (point-max))
(insert "Starting macro expansion stepper... please wait...\n"))
(racket--cmd/async nil
(racket--cmd/async racket--stepper-repl-session-id
`(macro-stepper (,which . ,str)
,(and into-base t))
#'racket-stepper--insert))
Expand All @@ -165,7 +176,7 @@ INTO-BASE is treated as a raw prefix arg and converted to boolp."

(defun racket-stepper-step ()
(interactive)
(racket--cmd/async nil
(racket--cmd/async racket--stepper-repl-session-id
`(macro-stepper/next)
#'racket-stepper--insert))

Expand Down
19 changes: 14 additions & 5 deletions racket/commands/macro.rkt
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
#lang racket/base

(require racket/contract
(require (only-in macro-debugger/stepper-text
stepper-text)
racket/contract
racket/file
racket/format
racket/match
(only-in racket/path
path-only)
racket/pretty
racket/system
"../elisp.rkt"
"../repl.rkt"
"../syntax.rkt"
"../util.rkt")

Expand All @@ -18,6 +23,8 @@

(define/contract (make-expr-stepper str)
(-> string? step-thunk/c)
(unless (current-session-id)
(error 'make-expr-stepper "Does not work without a running REPL"))
(define step-num #f)
(define last-stx (string->namespace-syntax str))
(define (step)
Expand All @@ -40,15 +47,16 @@

(define/contract (make-file-stepper path into-base?)
(-> (and/c path-string? absolute-path?) boolean? step-thunk/c)
;; If the dynamic-require fails, just let it bubble up.
(define stepper-text (dynamic-require 'macro-debugger/stepper-text 'stepper-text))
(define stx (file->syntax path))
(define-values (dir _name _dir) (split-path path))
(define raw-step (parameterize ([current-load-relative-directory dir])
(define dir (path-only path))
(define ns (make-base-namespace))
(define raw-step (parameterize ([current-load-relative-directory dir]
[current-namespace ns])
(stepper-text stx
(if into-base? (λ _ #t) (not-in-base)))))
(define step-num #f)
(define step-last-after "")
(log-racket-mode-debug "~v ~v ~v" path into-base? raw-step)
(define/contract (step) step-thunk/c
(cond [(not step-num)
(set! step-num 0)
Expand All @@ -59,6 +67,7 @@
(parameterize ([current-output-port out])
(cond [(raw-step 'next)
(set! step-num (add1 step-num))
(log-racket-mode-debug "~v" (get-output-string out))
(match-define (list title before after)
(step-parts (get-output-string out)))
(set! step-last-after after)
Expand Down

0 comments on commit c699d41

Please sign in to comment.