Skip to content
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

define cider-eval-last-sexp-at-point #2328

Closed
zcaudate opened this issue Jun 17, 2018 · 5 comments
Closed

define cider-eval-last-sexp-at-point #2328

zcaudate opened this issue Jun 17, 2018 · 5 comments

Comments

@zcaudate
Copy link
Contributor

zcaudate commented Jun 17, 2018

I'm hoping to have a functionality to be used for evaluating -> and ->> macros where:


given the form:

(-> (+ 1 1)
    (+ 1)
    (+ 1)
    (+ 1))

it is possible to have evalution at subsequent steps, ie:

(-> (+ 1 1)| ; => 2
    (+ 1)
    (+ 1)
    (+ 1))
(-> (+ 1 1)
    (+ 1)| ;=> 3
    (+ 1)
    (+ 1))
(-> (+ 1 1)
    (+ 1)
    (+ 1)| ;=> 4
    (+ 1))
(-> (+ 1 1)
    (+ 1)
    (+ 1)
    (+ 1)|) ;=> 5

The interaction would be to move the parenthesis forward to the point of the cursor, evaluate and then move the parenthesis back to the original position.

I tried but was a bit stuck. It'd be super useful for me if someone can implement it.

@bbatsov
Copy link
Member

bbatsov commented Jun 17, 2018

Funny enough something like this already exists. See 2db31b0

What I've implemented works only for top-level forms, but obviously we can use the same approach for inner forms as well.

@zcaudate
Copy link
Contributor Author

Oh that's awesome. Let me have a play with it.

@zcaudate
Copy link
Contributor Author

zcaudate commented Jun 18, 2018

is this the function?

(defun cider-read-and-eval-defun-at-point ()
  "Insert the toplevel form at point in the minibuffer and output its result.
The point is placed next to the function name in the minibuffer to allow
passing arguments."
  (interactive)
  (let* ((fn-name (cadr (split-string (cider-defun-at-point))))
         (form (format "(%s)" fn-name)))
    (cider-read-and-eval (cons form (length form)))))

So is it possible to change the behaviour by replacing cider-defun-at-point with something like cider-current-form-at-point?

@bbatsov
Copy link
Member

bbatsov commented Jun 18, 2018

No, the function is cider-eval-defun-to-point. Seems you want to create a variant of it - cider-eval-sexp-to-point.

@zcaudate
Copy link
Contributor Author

zcaudate commented Jun 19, 2018

I have this function:

(defun cider-eval-sexp-to-point ()
  (interactive)
  (let* ((begin (save-excursion (up-list) (backward-list) (point)))
         (code  (buffer-substring-no-properties begin (point)))
         (code  (concat code '(41))))
    (cider-interactive-eval code)))

however, using cider-interactive-eval, it prints the code => res which causes an error.

screen shot 2018-06-19 at 10 47 55 am

Is there a way to add a ;; before the string to comment out the result before printing? i.e
;;=> res

zcaudate pushed a commit to zcaudate-me/cider that referenced this issue Jun 19, 2018
zcaudate pushed a commit to zcaudate-me/cider that referenced this issue Jun 19, 2018
zcaudate pushed a commit to zcaudate-me/cider that referenced this issue Jun 19, 2018
zcaudate pushed a commit to zcaudate-me/cider that referenced this issue Jun 19, 2018
zcaudate pushed a commit to zcaudate-me/cider that referenced this issue Jun 19, 2018
zcaudate pushed a commit to zcaudate-me/cider that referenced this issue Jun 21, 2018
zcaudate pushed a commit to zcaudate-me/cider that referenced this issue Jun 21, 2018
zcaudate pushed a commit to zcaudate-me/cider that referenced this issue Jun 22, 2018
bbatsov pushed a commit that referenced this issue Jun 22, 2018
It's similar in nature to cider-eval-defun-to-point, but operates on the current sexp.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants