-
-
Notifications
You must be signed in to change notification settings - Fork 648
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
macrostep like macroexpand #1850
Comments
Legacy. We just did it the way it was done in SLIME. Including inline expansion of macros shouldn't be hard and we discussed it in the past. If someone is willing to implement this we'd be happy to accept it. |
Inline expansion isn't hard, but "stepping" is a bit trickier. The macroexpansion functions in CIDER do not currently do that. It'd be necessary to ask the middleware whether the form we're looking at is a macro. See |
You can already get this info from the var-info middleware. On Monday, 26 September 2016, Tianxiang Xiong [email protected]
Best Regards, |
Here's a proof of concept: First define some Clojure functions: (defn macro? [form]
(not (= (macroexpand-1 form) form)))
(defn expand-once [form]
(let [expanded? (atom false)]
(walk/prewalk (fn [x]
(if (and (not @expanded?)
(macro? x))
(do (reset! expanded? true)
(macroexpand-1 x))
x))
form))) Then set the relevant values for (setq-default macrostep-sexp-bounds-function
(lambda ()
(let ((pos (cider-sexp-at-point t)))
(cons (car pos) (cadr pos)))))
(setq-default macrostep-sexp-at-point-function
(lambda (&rest _ignore)
(cider-sexp-at-point)))
(setq-default macrostep-expand-1-function
(lambda (form env)
(nrepl-dbind-response (cider-nrepl-sync-request:eval (format "(expand-once '%s)" form))
(value)
value)))
(setq-default macrostep-print-function
(lambda (sexp env)
(insert sexp))) Obviously we should be setting these in a hook, but this is a POC... Then call (defn foo [x]
(defn bar [y]
(defn baz [z]
(+ 1 2)))) |
@xiongtx I think you forgot to include something. :-) |
Yes, accidentally hit Is there a way to pretty-print a Clojure form in an Emacs buffer? Not I don't see anything in the |
CIDER's macroexpansion pretty-prints the macro forms (they are processed in the middleware). I'm not sure it's a good idea to plug something into |
P.S. I'm fine with developing a macrostep integration if macrostep brings a lot of added functionality to the table. |
It does Clojure (defn foo [x] (defn bar [y] (defn baz [z] (+ 1 2)))) and output: (defn foo
[x]
(defn bar
[y]
(defn baz
[z]
(+ 1 2)))) which isn't quite right, but close. Clojure's
I'd think that the most desirable feature of |
@xiongtx |
@xiongtx I'm guessing clj-fmt or https://github.com/kkinnear/zprint should be able to format the code in this manner |
Would that need to be pulled into |
We simply add them as deps in |
It seems that |
Sure. See Line 1561 in c698df1
|
Macro-stepping is now part of Do we want |
I guess that depends on whether |
@xiongtx Ping :-) |
@xiongtx Ping 2 ;-) |
Trying to work on it, but I'm not satisfied with the current way of hooking into
Needs more investigation... |
@xiongtx status? |
What is the added value of this? And does it really work? Macros could expand to something completely unrelated to the original code, so my gut feeling is that this functionality is bound to be broken outside of very basic macros. Plus, there are benefits of having it in separate buffer. You see the whole expansion and can continue working on your macro at the same time. I personally find the "read-only" mode of elisp debugger quite limiting. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding! |
This issues been automatically closed due to lack of activity. Feel free to re-open it if you ever come back to it. |
I have just pushed Alternatively, I can offer an adapted version of that package that is |
@nbfalcon That's for letting me know. The package is relatively small, so I'm not particularly worried about code duplication. That being said - I'm fine with this being a separate package, although I think with a name with It'd be nice if there was a package named |
Is there any reason that cider opted to use a separate buffer for outputting the result of expanding a macro? I quite like the way https://github.com/joddie/macrostep expands macros inline in emacs lisp. Would the maintainers consider an optional change that maybe even reuses some of that code?
The text was updated successfully, but these errors were encountered: