-
-
Notifications
You must be signed in to change notification settings - Fork 647
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
Change cider-interactive-eval-override
to make it more usable
#3663
Comments
Thanks for the accurate report! Taking a look at the commit that introduced this 02c4e80 - originally all params were forwarded. Surely that was unawarely broken later. I'm on the fence as to whether to introduce a breaking change. Looks like we have a neat option: detect the arity of the user-set Demo:
Would you be interested in creating a PR? Cheers - V |
That's a great idea, I'll try to submit a PR that checks the number of arguments. Thanks for the pointer! |
There is a (let* ((arities (func-arity cider-interactive-eval-override))
(min-arity (car arities))
(max-arity (cdr arities)))
(if (or (eq 'many max-arity)
(and (numberp min-arity)
(numberp max-arity)
(<= min-arity 4 max-arity)))
(funcall cider-interactive-eval-override form callback bounds additional-params)
(funcall cider-interactive-eval-override form callback bounds))) But there is an issue. When using (defun println-override (form &rest extra-args)
(let ((cider-interactive-eval-override nil))
(apply 'cider-interactive-eval
(concat "(do (println :wrapped) " form ")")
extra-args))) So maybe a better way is not to check the arities, but to try to call the arity-4 version anyway, and if an arity error occurs, fallback on the previous arity-3 call site: (condition-case _
(funcall cider-interactive-eval-override form callback bounds additional-params)
(wrong-number-of-arguments
(funcall cider-interactive-eval-override form callback bounds))) @vemv what do you think? |
Hi @chpill kudos for looking into it! Yes, suporting a simple So your proposal seems great. |
@vemv thanks a lot! |
Is your feature request related to a problem? Please describe.
The
cider-interactive-eval-override
variable can be used to change the way forms are evaluated bycider-interactive-eval
, but contrary to what is said in the docstring, it does not actually forwardcider-interactive-eval
's last optional argumentadditional-params
.Consider the following example, where I want to be able to wrap every evaluation with a custom form which simply prints
:wrapped
before the target form is evaluated:This almost works, it correctly wraps any form evaluated and the
println
happens, but the pretty printing of some commands (likecider-pprint-eval-last-sexp
) does not work anymore, because the last argument was not forwarded.Describe the solution you'd like
Adding the missing argument to
cider-interactive-eval-override
's call site(funcall cider-interactive-eval-override form callback bounds additional-params)
is very easy, but it would break backward compatibility. I'm not very fluent in Elisp so maybe there is a way to work around that.With that change, the previous code can be changed to the following:
Which seems to work perfectly.
Additional context
As I searched for examples of correct usage of
cider-interactive-eval-override
on Github, it seems that it is in fact very rarely used. There might be a better way to wrap evaluation than this.The text was updated successfully, but these errors were encountered: